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 97891 - replacing constructor body produces uncompilable code
Summary: replacing constructor body produces uncompilable code
Status: VERIFIED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Source (show other bugs)
Version: 5.x
Hardware: All All
: P1 blocker (vote)
Assignee: Pavel Flaska
URL:
Keywords:
Depends on:
Blocks: 89821
  Show dependency tree
 
Reported: 2007-03-14 19:16 UTC by Jiri Prazak
Modified: 2007-03-26 16:30 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
stack trace (2.11 KB, application/octet-stream)
2007-03-14 19:18 UTC, Jiri Prazak
Details
Patch (1.76 KB, application/octet-stream)
2007-03-16 13:46 UTC, Pavel Flaska
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jiri Prazak 2007-03-14 19:16:21 UTC
consider the following use case.  I created a data object from template with
default constructor, then generated test methods, based on the test methods
generated i generated one more method required by the testing framework and
attempted to modify the constructor body to reflect the number of test methods
generated (also required by the framework), this messed up all of the code
previously generated.  The code that causes this

String consBody="{\nsuper("+nTests+",\"clsTree.getSimpleName()+"\n);\n}\n";
BlockTree oldBlock=constructorMethod.getBody();
TreeUtilities treeUtils=workingCopy.getTreeUtilities();
Tree newBlock=treeUtils.parseStatement(consBody, new SourcePositions[1]);
assert Tree.Kind.BLOCK == newBlock.getKind();
workingCopy.rewrite(oldBlock,newBlock);

I have tracked this down to WorkingCopy.rewrite(old,new) and at that point
everything was ok, not sure where after that it got jumbled.  Stack trace is
attched.
Comment 1 Jiri Prazak 2007-03-14 19:18:30 UTC
Created attachment 39487 [details]
stack trace
Comment 2 Pavel Flaska 2007-03-16 13:46:07 UTC
Created attachment 39582 [details]
Patch
Comment 3 Pavel Flaska 2007-03-16 13:48:21 UTC
Please, check if it is reproducible with provided patch. Thanks.
Comment 4 Pavel Flaska 2007-03-22 17:09:53 UTC
Test case added. -- The test modifies constructor body and adds new method to
the end of a class in one modification task. Recently I have made changes which
causes that issue is no longer reproducible (considering that my testcase
follows your use case). Please, check that it works for you. If not, provide
your modification scenario. Thanks.

Checking in unit/src/org/netbeans/api/java/source/gen/ClassMemberTest.java;
/cvs/java/source/test/unit/src/org/netbeans/api/java/source/gen/ClassMemberTest.java,v
 <--  ClassMemberTest.java
new revision: 1.17; previous revision: 1.16
done
Comment 5 Jiri Prazak 2007-03-26 16:30:00 UTC
that fixed it