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.
If I create a method using TreeMaker.Method(..., String bodyText, ...) and bodyText parameter contains comments, the method is created without these comments.
Support for comments will be finished and fixed in M7.
Checking in src/org/netbeans/api/java/source/WorkingCopy.java; /cvs/java/source/src/org/netbeans/api/java/source/WorkingCopy.java,v <-- WorkingCopy.java new revision: 1.13; previous revision: 1.12 done Checking in test/cfg-unit.xml; /cvs/java/source/test/cfg-unit.xml,v <-- cfg-unit.xml new revision: 1.18; previous revision: 1.17 done RCS file: /cvs/java/source/test/unit/src/org/netbeans/api/java/source/gen/CommentsTest.java,v done Checking in test/unit/src/org/netbeans/api/java/source/gen/CommentsTest.java; /cvs/java/source/test/unit/src/org/netbeans/api/java/source/gen/CommentsTest.java,v <-- CommentsTest.java initial revision: 1.1 done
Postponed to M8.
Should work right now, but still needs some improvements. Leaving opened for the time being till the most visible problems will be fixed. Checking in src/org/netbeans/api/java/source/TreeMaker.java; /cvs/java/source/src/org/netbeans/api/java/source/TreeMaker.java,v <-- TreeMaker.java new revision: 1.13; previous revision: 1.12 done Checking in test/unit/src/org/netbeans/api/java/source/gen/CommentsTest.java; /cvs/java/source/test/unit/src/org/netbeans/api/java/source/gen/CommentsTest.java,v <-- CommentsTest.java new revision: 1.7; previous revision: 1.6 done
I still see some issues, for example if I pass the body string as "\n // TODO: Process the button click action. Return value is a navigation\n // case name where null will return to the same page.\n return null;" expecting the following in the source public String foo() { // case name where null will return to the same page. // TODO: Process the button click action. Return value is a navigation return null; } but what I get is the following public String foo() { // case name where null will return to the same page. // TODO: Process the button click action. Return value is a navigation return null; } I have two issues 1) Line comments are exchanged 2) New line goes missing before the return statement
Formatting is one of the reason why I have left the issue opened. I haven't known about incorrect ordering (better say reverse ordering), I fix it.
Comments reverse order fixed. Checking in src/org/netbeans/api/java/source/TreeMaker.java; /cvs/java/source/src/org/netbeans/api/java/source/TreeMaker.java,v <-- TreeMaker.java new revision: 1.16; previous revision: 1.15 done Checking in src/org/netbeans/modules/java/source/save/PositionEstimator.java; /cvs/java/source/src/org/netbeans/modules/java/source/save/PositionEstimator.java,v <-- PositionEstimator.java new revision: 1.14; previous revision: 1.13 done Checking in test/unit/src/org/netbeans/api/java/source/gen/CommentsTest.java; /cvs/java/source/test/unit/src/org/netbeans/api/java/source/gen/CommentsTest.java,v <-- CommentsTest.java new revision: 1.8; previous revision: 1.7 done
Now, reported problems should be fixed. Checking in src/org/netbeans/modules/java/source/save/CasualDiff.java; /cvs/java/source/src/org/netbeans/modules/java/source/save/CasualDiff.java,v <-- CasualDiff.java new revision: 1.89; previous revision: 1.88 done Checking in src/org/netbeans/modules/java/source/save/PositionEstimator.java; /cvs/java/source/src/org/netbeans/modules/java/source/save/PositionEstimator.java,v <-- PositionEstimator.java new revision: 1.15; previous revision: 1.14 done Checking in test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/ConstructorTest/ConstructorTest/testAddConstructor2.pass; /cvs/java/source/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/ConstructorTest/ConstructorTest/testAddConstructor2.pass,v <-- testAddConstructor2.pass new revision: 1.4; previous revision: 1.3 done Checking in test/unit/src/org/netbeans/api/java/source/gen/BodyStatementTest.java; /cvs/java/source/test/unit/src/org/netbeans/api/java/source/gen/BodyStatementTest.java,v <-- BodyStatementTest.java new revision: 1.25; previous revision: 1.24 done Checking in test/unit/src/org/netbeans/api/java/source/gen/CommentsTest.java; /cvs/java/source/test/unit/src/org/netbeans/api/java/source/gen/CommentsTest.java,v <-- CommentsTest.java new revision: 1.9; previous revision: 1.8 done Checking in test/unit/src/org/netbeans/api/java/source/gen/ConstructorTest.java; /cvs/java/source/test/unit/src/org/netbeans/api/java/source/gen/ConstructorTest.java,v <-- ConstructorTest.java new revision: 1.4; previous revision: 1.3 done Checking in test/unit/src/org/netbeans/api/java/source/gen/MethodBodyTest.java; /cvs/java/source/test/unit/src/org/netbeans/api/java/source/gen/MethodBodyTest.java,v <-- MethodBodyTest.java new revision: 1.2; previous revision: 1.1 done Checking in test/unit/src/org/netbeans/api/java/source/gen/MethodBodyTextTest.java; /cvs/java/source/test/unit/src/org/netbeans/api/java/source/gen/MethodBodyTextTest.java,v <-- MethodBodyTextTest.java new revision: 1.8; previous revision: 1.7 done Checking in test/unit/src/org/netbeans/api/java/source/gen/TwoModificationsTest.java; /cvs/java/source/test/unit/src/org/netbeans/api/java/source/gen/TwoModificationsTest.java,v <-- TwoModificationsTest.java new revision: 1.2; previous revision: 1.1 done
There are still two outstanding issues - 1) For body text "// TODO: Replace with your code\n", the generated method has empty block 2) For body text "// TODO: Replace with your code\n\nreturn null;", the generated method doesn't include new lines
Yes, both problems are known, I think Jean-Franocois has pointed 1) out recently. My comments: 1) Let me clarify things: Current comment handler connects every comment to any statement (or feature, depending on tree). Every statement has preceding and trailing comments. Currently there is no way how to add comment to empty body. But definitely this has to be supported. 2) Current API does not support custom formatting, it respects just options. When you set body as a text, it has to be parsed and then parsed tree is printed. -- Comments are mapped to its statements and printed with it. (Previously, comments were removed to.) This could be hacked to comments support, where I can define that there is number of new lines before/after comment. This is perhaps the most straightforward solution, but I do not think about correctness. I'll discuss this with other team members. Changing target milestone. Are these problems blockers any milestone build?
Found one more issue, if the body text is " // TODO: Process the action. Return value is a navigation // case name where null will return to the same page. return null;" The generated method looks as follows public void foo() { /* * TODO: Process the action. Return value is a navigation */ /* * case name where null will return to the same page. */ return null; } Note that the line comments are converted to separate multi-line comments. This should be fixed atleast as soon as possible
Is it enough to fix it to M10?
Last reported problem was fixed already.
> 2) For body text "// TODO: Replace with your code\n\nreturn null;", > the generated method doesn't include new lines New line should be preserved. Checking in src/org/netbeans/api/java/source/Comment.java; /cvs/java/source/src/org/netbeans/api/java/source/Comment.java,v <-- Comment.java new revision: 1.7; previous revision: 1.6 done Checking in src/org/netbeans/api/java/source/TreeMaker.java; /cvs/java/source/src/org/netbeans/api/java/source/TreeMaker.java,v <-- TreeMaker.java new revision: 1.19; previous revision: 1.18 done Checking in src/org/netbeans/modules/java/source/pretty/VeryPretty.java; /cvs/java/source/src/org/netbeans/modules/java/source/pretty/VeryPretty.java,v <-- VeryPretty.java new revision: 1.19; previous revision: 1.18 done Checking in test/unit/src/org/netbeans/api/java/source/gen/CommentsTest.java; /cvs/java/source/test/unit/src/org/netbeans/api/java/source/gen/CommentsTest.java,v <-- CommentsTest.java new revision: 1.14; previous revision: 1.13 done
The summary of the issue is already fixed. For > 1) For body text "// TODO: Replace with your code\n", the generated method > has empty block I've created #103623 with P3 priority.
-f.