Bug 15756 - Organizing imports doesn't pick up the right type
Summary: Organizing imports doesn't pick up the right type
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows 2000
: P2 major (vote)
Target Milestone: 2.0 M6   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-05-10 12:01 EDT by Olivier Thomann CLA
Modified: 2002-05-13 10:44 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Olivier Thomann CLA 2002-05-10 12:01:00 EDT
Using 0508, I got invalid imports after doing an "organizing imports" action. I isolated a simple 
test case:

First class:
[package p1;

public class A {

	public static void foo() 
{
	}
}]

Second class:
[package p2;

public class A {
	public static void foo() 
{
	}
}]

Third class:
[package p3;

import p1.*;

public class B {

	public 
static void bar() {
		p2.A.foo();
	}
	public static void main(String[] args) 
{
		A.foo();
	}
}]

The "Organizing imports" action is done on that last class. The 
result is:

[package p3;

import p2.A;

public class B {

	public static void bar() 
{
		p2.A.foo();
	}
	public static void main(String[] args) 
{
		A.foo();
	}
}]

Having only p2.A is incorrect, because the line A.foo() was 
actually referring to p1.A.foo() and not p2.A.foo(). I checked that the DOM/AST binding 
resolution returns two different bindings for the two names (p2.A or A) and (A in A.foo()). We have 
p1.A and p2.A, but the resulting import contains only p2.A. So I wonder why p1.A has been removed. 
Futhermore I think that fully qualified name should never be investigated in this case. p2.A is 
enough and there is no need to have this import in the import's declarations. In this case, having 
p1.A and p2.A would result in a conflict and this is why p2.A has been used as a fully qualified name 
reference in the source. I think it is crucial that "Organize imports" handles this case 
properly. I found it in the JDTCore sources and this led to a message could not be retrieved. So even 
if the code compiles fine, the "Organizing imports" had a side-effect on the runtime. In order to be 
useful and safely use, this needs to be fixed. This is why I set the severity to major.
Comment 1 Martin Aeschlimann CLA 2002-05-11 18:39:20 EDT
When looking at qualified names like 'p1.A.foo()', only the very first qulifier 
('p1') is examined (and imported if it's a type binding)

The problem here is that when asking the SimpleName node p1 for it's binding
the type binding of p1.A is return. This is a bug, no? I was thinking it should 
return a package binding.
Comment 2 Olivier Thomann CLA 2002-05-13 10:44:53 EDT
Fix and released in HEAD.