Bug 52479 - Code Format fails on not on-demand imports
Summary: Code Format fails on not on-demand imports
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.0 M8   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-02-19 10:16 EST by Bertrand Cormier CLA
Modified: 2004-03-25 07:28 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bertrand Cormier CLA 2004-02-19 10:16:50 EST
I've got a TestingMyClass.java file :
------------------------------------
package stdjavatest;

import junit.framework.*;
import mypackage.MyClass;

public class TestingMyClass extends TestCase {
public void test_method() {
MyClass objA = null;
objA = new MyClass();
objA.method();
}
}
------------------------------------

If I format this file either with right-click->Source->Format, or 
programmatically thanks to a CodeFormatter, nothing happens.
If I change my import "import mypackage.MyClass;" to "import mypackage.*;" 
then it works !

After some debug session, I figured out that the issue is coming from the 
method visit(ImportReference importRef, CompilationUnitScope scope) in 
org.eclipse.jdt.internal.formatter.CodeFormatterVisitor. In this method, it 
seems that the call to scribe.printQualifiedReference(importRef.sourceEnd); 
with an importRef which is not on-demand returns "mypackage." instead 
of "mypackage.MyClass" !
Comment 1 Olivier Thomann CLA 2004-02-19 14:17:17 EST
What build are you using?
I cannot reproduce with M7. This looks like an old bug, but I cannot find the
previous bug report.
Comment 2 Olivier Thomann CLA 2004-02-19 19:03:03 EST
Close as WORKSFORME.
Please reopen if you can reproduce it with M7 or above.
Comment 3 Bertrand Cormier CLA 2004-02-20 04:31:36 EST
Dear Olivier,

That's M7 :
Eclipse Platform

Version: 3.0.0
Build id: 200402122000

I think I know why you didn't reproduce it : my mistake ! It seems that the 
bug occurs if the imported class is one-byte length. The example I've sent you 
before was working, but this one doesn't :
---------------------------------------
import com.ibm.rational.test.ct.A;

public class Foo extends A {
public Foo() {
super();
}
}
---------------------------------------

It doesn't work if you try to format this source.
Sorry for the mistake and the extra work !
/Bertrand
Comment 4 Olivier Thomann CLA 2004-02-23 13:27:00 EST
Reproduced.
Fixed and released in HEAD.
Regression test added.
Comment 5 Frederic Fusier CLA 2004-03-25 07:28:36 EST
Verified for 3.0 using build I200403250010.