This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
JMI generates annotation for classes, methods, and local variables on the same line as the class or method statement, which can make the code hard to read, especially when there are more than one annotation for an element, or when the annotation is longer than a single word. The code would be more readable if the annotation were on its own line with the subsequent code indented properly.
Created attachment 22463 [details] current formatting of annotations
Created attachment 22464 [details] preferred formatting
mdr->java/javacore
Pavel will fix it.
Hi Jeri, I'm working on it, there are more problems to solve. Maybe I will not be able to fix all the cases, so I want to try to focus on your usecase. Can you tell me: Do you add annotations to existing elements (classes, methods) or do you generate them together with element?
We generate the annotations together with the element for classes and methods, but for loc variables, we must add them later. These are the use cases: 1. Pass annotation into the create for methods or classes. 2. For local variables we add annotations using these steps in succession: a. create loc var b. create loc var declaration c. add annotation to loc var (this is a workaround that Martin told us to use) After the annotation and its element are generated, we sometimes modify an existing annotation, for example, change the attribute values of a loc var annotation. The changes we make would not require re-formatting. (This may be a future requirement, however)
But all annotations are added (even if later) in the same MDR transaction as the elements (e.g. local variables) are created, right? By saying that doing changes that involve refomatting may be a future requirement, do you mean requirement for JavaOne demo, or post-JavaOne?
yes, all annotations are added (even if later) in the same MDR transaction as the elements. reformatting would be a Post J1 issue.
Created attachment 22744 [details] Patch for placing new annotation on its separate line - tests updated and added
Created attachment 22745 [details] Patch for placing new annotation on its separate line - tests updated and added
I accidently added exactly the same patch two times.
Fixed in trunk. Checking in src/org/netbeans/modules/javacore/jmiimpl/javamodel/AnnotationImpl.java; /cvs/java/javacore/src/org/netbeans/modules/javacore/jmiimpl/javamodel/AnnotationImpl.java,v <-- AnnotationImpl.java new revision: 1.17; previous revision: 1.16 done Checking in src/org/netbeans/modules/javacore/jmiimpl/javamodel/CallableFeatureImpl.java; /cvs/java/javacore/src/org/netbeans/modules/javacore/jmiimpl/javamodel/CallableFeatureImpl.java,v <-- CallableFeatureImpl.java new revision: 1.27; previous revision: 1.26 done Checking in src/org/netbeans/modules/javacore/jmiimpl/javamodel/FeatureImpl.java; /cvs/java/javacore/src/org/netbeans/modules/javacore/jmiimpl/javamodel/FeatureImpl.java,v <-- FeatureImpl.java new revision: 1.42; previous revision: 1.41 done Checking in src/org/netbeans/modules/javacore/jmiimpl/javamodel/FieldImpl.java; /cvs/java/javacore/src/org/netbeans/modules/javacore/jmiimpl/javamodel/FieldImpl.java,v <-- FieldImpl.java new revision: 1.30; previous revision: 1.29 done Checking in src/org/netbeans/modules/javacore/jmiimpl/javamodel/IndentUtil.java; /cvs/java/javacore/src/org/netbeans/modules/javacore/jmiimpl/javamodel/IndentUtil.java,v <-- IndentUtil.java new revision: 1.6; previous revision: 1.5 done Checking in src/org/netbeans/modules/javacore/jmiimpl/javamodel/LocalVarDeclarationImpl.java; /cvs/java/javacore/src/org/netbeans/modules/javacore/jmiimpl/javamodel/LocalVarDeclarationImpl.java,v <-- LocalVarDeclarationImpl.java new revision: 1.12; previous revision: 1.11 done Checking in src/org/netbeans/modules/javacore/jmiimpl/javamodel/MethodImpl.java; /cvs/java/javacore/src/org/netbeans/modules/javacore/jmiimpl/javamodel/MethodImpl.java,v <-- MethodImpl.java new revision: 1.32; previous revision: 1.31 done Checking in test/cfg-unit.xml; /cvs/java/javacore/test/cfg-unit.xml,v <-- cfg-unit.xml new revision: 1.36; previous revision: 1.35 done Checking in test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/AnnotationOnLocVarTest/testAddAnnToLocVar_AnnotationOnLocVarTest.pass; /cvs/java/javacore/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/AnnotationOnLocVarTest/testAddAnnToLocVar_AnnotationOnLocVarTest.pass,v <-- testAddAnnToLocVar_AnnotationOnLocVarTest.pass new revision: 1.2; previous revision: 1.1 done Checking in test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/AnnotationOnLocVarTest/testAddLocVarWithAnn_AnnotationOnLocVarTest.pass; /cvs/java/javacore/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/AnnotationOnLocVarTest/testAddLocVarWithAnn_AnnotationOnLocVarTest.pass,v <-- testAddLocVarWithAnn_AnnotationOnLocVarTest.pass new revision: 1.2; previous revision: 1.1 done Checking in test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/AnnotationTest/testAddAnnWithConstr_AnnotationClass.pass; /cvs/java/javacore/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/AnnotationTest/testAddAnnWithConstr_AnnotationClass.pass,v <-- testAddAnnWithConstr_AnnotationClass.pass new revision: 1.2; previous revision: 1.1 done Checking in test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/AnnotationTest/testAddAnnWithField_AnnotationClass.pass; /cvs/java/javacore/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/AnnotationTest/testAddAnnWithField_AnnotationClass.pass,v <-- testAddAnnWithField_AnnotationClass.pass new revision: 1.2; previous revision: 1.1 done Checking in test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/AnnotationTest/testAddAnnotation_AnnotationClass.pass; /cvs/java/javacore/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/AnnotationTest/testAddAnnotation_AnnotationClass.pass,v <-- testAddAnnotation_AnnotationClass.pass new revision: 1.4; previous revision: 1.3 done RCS file: /cvs/java/javacore/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/indent/AnnIndentTest/testAddAnnotationWithClass_AnnIndentTest.pass,v done Checking in test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/indent/AnnIndentTest/testAddAnnotationWithClass_AnnIndentTest.pass; /cvs/java/javacore/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/indent/AnnIndentTest/testAddAnnotationWithClass_AnnIndentTest.pass,v <-- testAddAnnotationWithClass_AnnIndentTest.pass initial revision: 1.1 done RCS file: /cvs/java/javacore/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/indent/AnnIndentTest/testAddAnnotationWithMethod_AnnIndentTest.pass,v done Checking in test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/indent/AnnIndentTest/testAddAnnotationWithMethod_AnnIndentTest.pass; /cvs/java/javacore/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/indent/AnnIndentTest/testAddAnnotationWithMethod_AnnIndentTest.pass,v <-- testAddAnnotationWithMethod_AnnIndentTest.pass initial revision: 1.1 done RCS file: /cvs/java/javacore/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/indent/AnnIndentTest/testAddAnnotationsToClass_AnnIndentTest.pass,v done Checking in test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/indent/AnnIndentTest/testAddAnnotationsToClass_AnnIndentTest.pass; /cvs/java/javacore/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/indent/AnnIndentTest/testAddAnnotationsToClass_AnnIndentTest.pass,v <-- testAddAnnotationsToClass_AnnIndentTest.pass initial revision: 1.1 done RCS file: /cvs/java/javacore/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/indent/AnnIndentTest/testAddAnnotations_AnnIndentTest.pass,v done Checking in test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/indent/AnnIndentTest/testAddAnnotations_AnnIndentTest.pass; /cvs/java/javacore/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/indent/AnnIndentTest/testAddAnnotations_AnnIndentTest.pass,v <-- testAddAnnotations_AnnIndentTest.pass initial revision: 1.1 done Checking in test/unit/data/projects/default/src/org/netbeans/test/codegen/AnnotationClass.java; /cvs/java/javacore/test/unit/data/projects/default/src/org/netbeans/test/codegen/AnnotationClass.java,v <-- AnnotationClass.java new revision: 1.2; previous revision: 1.1 done RCS file: /cvs/java/javacore/test/unit/data/projects/default/src/org/netbeans/test/codegen/indent/AnnIndentClass.java,v done Checking in test/unit/data/projects/default/src/org/netbeans/test/codegen/indent/AnnIndentClass.java; /cvs/java/javacore/test/unit/data/projects/default/src/org/netbeans/test/codegen/indent/AnnIndentClass.java,v <-- AnnIndentClass.java initial revision: 1.1 done RCS file: /cvs/java/javacore/test/unit/src/org/netbeans/jmi/javamodel/codegen/indent/AnnIndentTest.java,v done Checking in test/unit/src/org/netbeans/jmi/javamodel/codegen/indent/AnnIndentTest.java; /cvs/java/javacore/test/unit/src/org/netbeans/jmi/javamodel/codegen/indent/AnnIndentTest.java,v <-- AnnIndentTest.java initial revision: 1.1 done
Merged also to coke_j1_05_fixes branch.
The annotations in our test looked good and were as expected, except for one method annotation. I will attach the generated java file. The "@WebMethod" annotation is not indented properly. I'll also attach the template file which was used to create the file, and the Java code we used to generate the annotation.
Created attachment 22756 [details] contains method annotation that is not indented properly
Created attachment 22757 [details] template used for initial creation of file
Created attachment 22758 [details] code using JMI to generate annotations (see createMethod())
I have similar test, which seems to work correctly. Can you describe mdr transaction? - I tried to make class looking in the same manner as your template, - then I add in my test annotation to this class and in the same mdr transaction I created a new method with annotation.
I found the case when it fails. It is when there is an annotation on element and you will add new one in new transaction. I will try to fix it immediately.
Additional fixes: Checking in org/netbeans/modules/javacore/jmiimpl/javamodel/CallableFeatureImpl.java; /cvs/java/javacore/src/org/netbeans/modules/javacore/jmiimpl/javamodel/CallableFeatureImpl.java,v <-- CallableFeatureImpl.java new revision: 1.28; previous revision: 1.27 done Checking in org/netbeans/modules/javacore/jmiimpl/javamodel/FeatureImpl.java; /cvs/java/javacore/src/org/netbeans/modules/javacore/jmiimpl/javamodel/FeatureImpl.java,v <-- FeatureImpl.java new revision: 1.43; previous revision: 1.42 done Checking in org/netbeans/modules/javacore/jmiimpl/javamodel/FieldImpl.java; /cvs/java/javacore/src/org/netbeans/modules/javacore/jmiimpl/javamodel/FieldImpl.java,v <-- FieldImpl.java new revision: 1.31; previous revision: 1.30 done Checking in org/netbeans/modules/javacore/jmiimpl/javamodel/IndentUtil.java; /cvs/java/javacore/src/org/netbeans/modules/javacore/jmiimpl/javamodel/IndentUtil.java,v <-- IndentUtil.java new revision: 1.7; previous revision: 1.6 done Checking in org/netbeans/modules/javacore/jmiimpl/javamodel/LocalVarDeclarationImpl.java; /cvs/java/javacore/src/org/netbeans/modules/javacore/jmiimpl/javamodel/ LocalVarDeclarationImpl.java,v <-- LocalVarDeclarationImpl.java new revision: 1.13; previous revision: 1.12 done
Additional fixes merged to coke_j1_05_fixes too.
Hello Pavel, That fixed it! Thank you for your taking care of this so quickly. It's a big help to our demo. We greatly appreciate it! --Jeri
*** Issue 60287 has been marked as a duplicate of this issue. ***
*** Issue 57286 has been marked as a duplicate of this issue. ***
Reorganization of java component