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 90835 - Moving java files from across packages messes up package and class declaration statements
Summary: Moving java files from across packages messes up package and class declaratio...
Status: RESOLVED DUPLICATE of bug 88424
Alias: None
Product: java
Classification: Unclassified
Component: Source (show other bugs)
Version: 6.x
Hardware: All All
: P1 blocker (vote)
Assignee: Pavel Flaska
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-12-08 17:24 UTC by ssoong
Modified: 2007-02-14 11:42 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Attribute1.java (24.70 KB, text/plain)
2007-01-14 20:08 UTC, ssoong
Details

Note You need to log in before you can comment on or make changes to this bug.
Description ssoong 2006-12-08 17:24:33 UTC
NetBeans 6.0 IDE Dev (Build 200612061900)
1.5.0_05; Java HotSpot(TM) Client VM 1.5.0_05-b05
Windows XP version 5.1 running on x86
==================================================

A. Moving java files from one project to another messes up package statement

Create a java file in
projectA:a12345678.b123456789.c12345678.d12345678.Z.java

Create a package in
projectB:w12345678.x12345678.y12345678.z12345678

At project explorer, click on
projectA:a123456789.b12345678.c12345678.d12345678.Z.java

and move it by mouse to package
projectB:w12345678.x12345678.y12345678.z12345678

File projectB:w12345678.x12345678.y12345678.z12345678.Z.java
would probably have the package line as
- keyword package would be missing -
w12345678.x12345678.y12345678.z1w1234567


B. On the other hand, while moving a file to another package within the same 
project I encountered the public class declaration line messed up.

public class calisto()
{..
}

became

gibberish 
{ ..
}
Comment 1 ssoong 2006-12-08 17:30:04 UTC
Need to clarify that in case B,
I did a move + rename.
Comment 2 Jiri Prox 2006-12-12 16:22:15 UTC
Cannot reproduce any of the mentionned problems. Please provide more info, as
peroject type (normal, free form) etc.

In the second problem, isn't there additional pair of brackets in the class
definition? 
Comment 3 ssoong 2007-01-11 21:36:53 UTC
Did you test it under JDK1.5? I was using JDK1.5 when encountering this 
problem. I have not tested under JDK6.
Comment 4 Jiri Prox 2007-01-12 09:19:41 UTC
I've verified it again and I haven't seen reported behaviour. 

A. Please check if the line endings are correct (there is similar issue when
moving file which was cecked out form cvs and has line edinigs from differen OS)

B. There were huge improvements and fixing in this area last days, is it
reproducible in last build?

NetBeans IDE Dev (Build 070112)
1.5.0_11; Java HotSpot(TM) Client VM 1.5.0_11-b03
Windows XP version 5.1 running on x86
en_US (nb); Cp1252
Comment 5 ssoong 2007-01-14 20:06:04 UTC
I discovered that if you created a simple project with a barebone java class, 
you will not see any problems.

You need to use a large project - try this:

Download jdom-1.0 source zip from jdom site.
Unzip and rename build folder to _build and build.xml to _build.xml (or delete 
them).
Create a new java class project with existing source (NOT existing ant).
Specify ..../src/java as source path and add all the jars in lib into project 
library path.

Build project:
26 warnings
BUILD SUCCESSFUL (total time: 1 second)

At package org.jdom of project explorer, right click and copy Attribute.java .
Right click on the same package and paste->Refactor copy = Attribute1.java .

Now inspect Attribute1.java: Lots of errors.

Comment 6 ssoong 2007-01-14 20:08:22 UTC
Created attachment 37353 [details]
Attribute1.java
Comment 7 ssoong 2007-01-14 20:12:12 UTC
I attached Attribute1.java which resulted from my paste->refactor copy.

When trying the jdom project I used :

NetBeans IDE Dev (Build 200701111900)
1.5.0_05; Java HotSpot(TM) Client VM 1.5.0_05-b05
Windows XP version 5.1 running on x86
Comment 8 Jiri Prox 2007-01-15 08:36:48 UTC
Yes, I can see the error now. Thanks for info.

The problem is probably caused by the line ending. The provided project uses
CRLF and the code got corrupted (even when invoked on Win). The the files are
converted to use only LF it's all ok (even on Win!). There is one additional
problem - incompatible type on "return this" but I'll file it as separate issue.
Comment 9 Pavel Flaska 2007-01-15 09:47:42 UTC
See #88424.
Comment 10 ssoong 2007-01-17 17:46:53 UTC
I believe there is an issue already lodged (either by me or someone else but I 
can't find it) about refactoring within the same source file. Since it is 
probably due to the same cause as this issue, I'll describe them here without 
opening a redundant issue entry.

Such refactoring either adds additional unwanted text or removes text.
For example.

Original method:
===============
protected int Verification(int maxVerificationLoops, State currentState)
{
  int verificationLoops = 0, verifications = 0;
  while (verificationLoops++<maxVerificationLoops &&
      !CurrentState.Verified)
  {
  ...
  }
  
  return verifications;
}


After refactor->rename [currentState to entryState].
Notice the line with redundate declaration of
int verificationLoops = 0:
===================================================
protected int Verification(int maxVerificationLoops, State entryState)
{
  int verificationLoops = 0,int verificationLoops = 0, verifications = 0;
  while (verificationLoops++<maxVerificationLoops &&
      !CurrentState.Verified)
  {
  ...
  }
  
  return verifications;
}

Comment 11 ssoong 2007-01-17 17:48:54 UTC
oops ... typo

"redundant" not "redundate"
Comment 12 Jan Becicka 2007-02-12 10:52:07 UTC
If I understand this issue well, it is generator issue..
Comment 13 Pavel Flaska 2007-02-14 11:36:36 UTC
In this issue, many things is mixed together. 

Messed up source
----------------
When you move file, it mess up the source. -- The root cause of problem is
positions, at UNIX platform this is not reproducible. -- Again, see issue
#88424. I think this is a duplicate. Positions are incorrect (because computed
from file with CR/LF, but generating to LF only file.) Generator does not have
any chance to solve it if bad positions are provided. There exists hack, but it
slows down many generating use-cases.

Variable declaration separated by commas
----------------------------------------
Different issue. Very similar to #91010. All the declaration are represented by
separate var. declaration in tree. Code generator has to do some hacky stuff to
recognize if variable is declared separately or in a "field group" (i.e. comma
separated declaration.) Unfortunately there is no support for it and it is still
not implemented.
Comment 14 Pavel Flaska 2007-02-14 11:42:16 UTC
Marking as a duplicate. For the second reported problem, new issue was created.
(see #95533)

*** This issue has been marked as a duplicate of 88424 ***