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 23097 - org.openide.src.ClassElement.removeXXX deletes too much characters
Summary: org.openide.src.ClassElement.removeXXX deletes too much characters
Status: CLOSED DUPLICATE of bug 14546
Alias: None
Product: java
Classification: Unclassified
Component: Unsupported (show other bugs)
Version: 3.x
Hardware: PC Windows ME/2000
: P2 blocker (vote)
Assignee: Svata Dedic
URL:
Keywords:
: 23098 23100 (view as bug list)
Depends on:
Blocks:
 
Reported: 2002-05-03 13:02 UTC by Jens Rommel
Modified: 2007-09-26 09:14 UTC (History)
0 users

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 Jens Rommel 2002-05-03 13:06:54 UTC
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
Comment 1 Svata Dedic 2002-05-03 13:08:51 UTC
*** Issue 23100 has been marked as a duplicate of this issue. ***
Comment 2 Svata Dedic 2002-05-03 13:09:18 UTC
*** Issue 23098 has been marked as a duplicate of this issue. ***
Comment 3 Tomas Hurka 2002-05-03 13:53:13 UTC
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 ***
Comment 4 Quality Engineering 2003-07-01 13:11:31 UTC
Resolved for 3.4.x or earlier, no new info since then -> closing.
Comment 5 Quality Engineering 2003-07-01 13:19:57 UTC
Resolved for 3.4.x or earlier, no new info since then -> closing.