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.

Bug 89873 - TreeMaker.Method(..., String bodyText, ...) ignores comments
Summary: TreeMaker.Method(..., String bodyText, ...) ignores comments
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Source (show other bugs)
Version: 6.x
Hardware: All All
: P2 blocker (vote)
Assignee: Pavel Flaska
URL:
Keywords:
Depends on:
Blocks: 90451
  Show dependency tree
 
Reported: 2006-11-22 15:30 UTC by Radko Najman
Modified: 2007-05-10 15:25 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Radko Najman 2006-11-22 15:30:37 UTC
If I create a method using TreeMaker.Method(..., String bodyText, ...) and
bodyText parameter contains comments, the method is created without these comments.
Comment 1 Pavel Flaska 2007-01-11 10:49:14 UTC
Support for comments will be finished and fixed in M7.
Comment 2 Pavel Flaska 2007-02-20 17:38:10 UTC
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
Comment 3 Pavel Flaska 2007-02-20 17:38:55 UTC
Postponed to M8.
Comment 4 Pavel Flaska 2007-03-12 08:55:15 UTC
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
Comment 5 _ deva 2007-03-19 20:13:31 UTC
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
Comment 6 Pavel Flaska 2007-03-20 09:49:56 UTC
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.
Comment 7 Pavel Flaska 2007-03-20 10:19:38 UTC
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
Comment 8 Pavel Flaska 2007-03-20 15:29:42 UTC
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
Comment 9 _ deva 2007-03-22 23:58:41 UTC
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
Comment 10 Pavel Flaska 2007-03-23 09:29:10 UTC
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?


Comment 11 _ deva 2007-04-24 19:54:05 UTC
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
Comment 12 Pavel Flaska 2007-04-25 14:47:59 UTC
Is it enough to fix it to M10?
Comment 13 Pavel Flaska 2007-05-09 13:54:52 UTC
Last reported problem was fixed already.
Comment 14 Pavel Flaska 2007-05-09 13:56:48 UTC
> 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
Comment 15 Pavel Flaska 2007-05-10 10:15:51 UTC
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.
Comment 16 Pavel Flaska 2007-05-10 15:25:52 UTC
-f.