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 69273 - Redundant new lines when setting body text to method
Summary: Redundant new lines when setting body text to method
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Unsupported (show other bugs)
Version: 5.x
Hardware: All All
: P4 blocker (vote)
Assignee: Pavel Flaska
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-11-24 16:03 UTC by Pavel Flaska
Modified: 2007-09-26 09:14 UTC (History)
1 user (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 Pavel Flaska 2005-11-24 16:03:30 UTC
From conversation with Jean-Francois:

I have an unwanted \n when updating Method body. I am using netbeans50_beta2. It
is only the case on Windows. It is OK on Solaris .....?

Code extract :

MessageFormat bodyform = new MessageFormat(create.getBodyText());
Object[] args = new Object[] { mbean.getName() , constructParams ,
               constructSign };
create.setBodyText(bodyform.format(args).substring(1));
Comment 1 Pavel Flaska 2005-11-24 16:06:19 UTC
Finally I probably see what is wrong. Let me try to clarify several things.

Consider method in source:

void method() {
   // here is the body of method {0} with param {1}
}

> MessageFormat bodyform = new MessageFormat(create.getBodyText());
> Object[] args = new Object[] { mbean.getName() , constructParams ,
>                constructSign };
> create.setBodyText(bodyform.format(args).substring(1));

Then, in your code, method above is in 'create' instance in your code extract.
You obtain body text by calling create.getBodyText(). Then, you modify the
content of this string:

modifiedBodyText = do something with obtained body text

and put it back by calling

setBodyText(modifiedBodyText);

Seems to me that when you obtaining body text, you will get something like that:
[
   // here is the body of method {0} with param {1}
]

When you put it back, you call setBodyText and put there the same string
(modified, but without changing new line characters:

[
   // here is the body of method beanName with param anyParam
]

(I consider here you don't using substring(1) anymore).

I will write a test for this scenario. In tests, I only tried to put completely
new body, so \n characters weren't duplicated. The problem is, that b =
getBodyText() and setBodyText(b) will change source, but it is expected it will
stay unchanged.

getBodyText() returns the area closed to []:

void method() {[
   // here is the body of method {0} with param {1}
]}

setBodyText() then replace area closed to <>:
void method() {
<   // here is the body of method {0} with param {1}
>}

The workaround with sustring(1) can cause, that when data are obtained from file
(not document in editor), there can be '\r\n' characters on windows, it seems to
be the reason why it doesn't work only on Windows.
Comment 2 Pavel Flaska 2005-11-24 16:12:45 UTC
Cc'ing original reporter Jean-Francois.
Comment 3 Pavel Flaska 2005-11-24 16:38:17 UTC
Test which can be used to reproduce this issue.

Checking in cfg-unit.xml;
/cvs/java/javacore/test/cfg-unit.xml,v  <--  cfg-unit.xml
new revision: 1.45; previous revision: 1.44
done
Checking in
unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/indent/MethodBodyTextTest/testModifyBodyText_MethodBodyTextTest.pass;
/cvs/java/javacore/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/indent/MethodBodyTextTest/testModifyBodyText_MethodBodyTextTest.pass,v
 <--  testModifyBodyText_MethodBodyTextTest.pass
new revision: 1.2; previous revision: 1.1
done
Checking in
unit/src/org/netbeans/jmi/javamodel/codegen/indent/MethodBodyTextTest.java;
/cvs/java/javacore/test/unit/src/org/netbeans/jmi/javamodel/codegen/indent/MethodBodyTextTest.java,v
 <--  MethodBodyTextTest.java
new revision: 1.4; previous revision: 1.3
done
Comment 4 Pavel Flaska 2005-11-25 14:53:20 UTC
Checking in
src/org/netbeans/modules/javacore/jmiimpl/javamodel/BehavioralFeatureImpl.java;
/cvs/java/javacore/src/org/netbeans/modules/javacore/jmiimpl/javamodel/BehavioralFeatureImpl.java,v
 <--  BehavioralFeatureImpl.java
new revision: 1.17; previous revision: 1.16
done
Checking in test/cfg-unit.xml;
/cvs/java/javacore/test/cfg-unit.xml,v  <--  cfg-unit.xml
new revision: 1.46; previous revision: 1.45
done
Checking in
test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/indent/MethodBodyTextTest/testCreateWithBodyText_MethodBodyTextTest.pass;
/cvs/java/javacore/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/indent/MethodBodyTextTest/testCreateWithBodyText_MethodBodyTextTest.pass,v
 <--  testCreateWithBodyText_MethodBodyTextTest.pass
new revision: 1.2; previous revision: 1.1
done
Checking in
test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/indent/MethodBodyTextTest/testModifyBodyText_MethodBodyTextTest.pass;
/cvs/java/javacore/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/indent/MethodBodyTextTest/testModifyBodyText_MethodBodyTextTest.pass,v
 <--  testModifyBodyText_MethodBodyTextTest.pass
new revision: 1.3; previous revision: 1.2
done
Checking in
test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/indent/MethodBodyTextTest/testSetBodyText_MethodBodyTextTest.pass;
/cvs/java/javacore/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/indent/MethodBodyTextTest/testSetBodyText_MethodBodyTextTest.pass,v
 <--  testSetBodyText_MethodBodyTextTest.pass
new revision: 1.2; previous revision: 1.1
done
Checking in
test/unit/src/org/netbeans/jmi/javamodel/codegen/indent/MethodBodyTextTest.java;
/cvs/java/javacore/test/unit/src/org/netbeans/jmi/javamodel/codegen/indent/MethodBodyTextTest.java,v
 <--  MethodBodyTextTest.java
new revision: 1.5; previous revision: 1.4
done
Comment 5 Quality Engineering 2007-09-20 10:48:30 UTC
Reorganization of java component