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.
I'm using the classes from org.openide.src and their implementations org.netbeans.modules.java.model to refactor source code automatically. I found an unexpected behaviour with the deletion of java language elements like org.openide.src.FieldElement from an instance of org.openide.src.ClassElement using the appropriate methods like removeFields(). I tried to reduce the relevant parts as much as possible. Here's the observed behaviour: First the test class "SimpleClass" looks like this: public class SimpleClass { // comment 1 class InnerClass{} int i; SimpleClass(){} void method(){} // comment 2 } Then i delete all elements of this test class using the follwong code: ... org.openide.src.ClassElement lClass = lJavaDataObject.getSource().getClasses()[0]; lClass.removeMethods(lClass.getMethods()); lClass.removeConstructors(lClass.getConstructors()); lClass.removeFields(lClass.getFields()); lClass.removeClasses(lClass.getClasses()); lDataObject.getJavaEditor().saveDocument(); ... After saving the file the class looks like this (!!): public class SimpleClass { // comment 1 / comment 2 } Please note that the code has become invalid since a comment slash has been deleted! Also note that this buggy behaviour strongly depends on both, the sequence of the elements in the class as well as the sequence of the deletion: E.g. when i place the method "method" at the top the result looks like this. This is also the result if i shift the call of removeClasses (lClass.getClasses()) to the top of the remove calls. public class SimpleClass { // comment 1 // comment 2 } I assume, that the responsible code can be found in org.netbeans.modules.java.codegen.CodeGenerator.clearBounds . There are several places with the follwing lines: if (doc.getLength() > p2) { p2++; } I don't understand their purpose, but when i remove them it works fine at least for my test case. I do not get this problem when i delete the source elements from the netbeans IDE using the delete context menu item in the class browser. Best regards Jens
*** Issue 23100 has been marked as a duplicate of this issue. ***
*** Issue 23098 has been marked as a duplicate of this issue. ***
This issue is caused by Editor's Document implementation of Element.getEndOffset(). This implementation is inconsistent with Swing's Document implementation. See issue #14546 and attached patch wrong_code.diff *** This issue has been marked as a duplicate of 14546 ***
Resolved for 3.4.x or earlier, no new info since then -> closing.