Bug 6538

Summary: searchDeclarationsOf* incorrect
Product: [Eclipse Project] JDT Reporter: Adam Kiezun <akiezun>
Component: CoreAssignee: Jerome Lanneluc <jerome_lanneluc>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 2.0   
Target Milestone: 2.0 M1   
Hardware: PC   
OS: Windows 2000   
Whiteboard:

Description Adam Kiezun CLA 2001-12-04 04:45:28 EST
in a file 'B.java' i have:

package p;

import java.util.ArrayList;
import java.util.List;

class A{
	int i(){
		return 0;
	}
}

class B {
	int f;
	void i(){
		y();
		List l= new ArrayList(f);
	}
	private void y(){
	}

}

class C extends A{
	public  int i(){
		return 0;
	}
}

now, use searchDeclarationsOfAccessedFields on method C::i() and you'll get
B.f for example

searchDeclarationsOfReferencedTypes on the same method gives you B::y()

both are incorrect
note also that the results are correct if the file is called, for instance, 
X.java.
Comment 1 Adam Kiezun CLA 2001-12-04 04:47:05 EST
i wrote searchDeclarationsOfReferencedTypes but i meant 
searchDeclarationsOfSentMessages
Comment 2 Adam Kiezun CLA 2001-12-07 10:50:39 EST
this might be related so i'll paste it here:
if you have sth like this in one cu:
package p;

class A {
}

class B extends A {
	private int f;
	private class P{}
	private void a(){}
	void m() { 
		f++;
		P p= new P();
		a();
	}	
}

and searchDeclarationsOfAccessedFields - you find none!
same for the other 2 searchDeclarationsOf* methods (in their respective test 
cases)
Comment 3 Jerome Lanneluc CLA 2001-12-10 09:55:28 EST
These are actually 2 different problems:
1. In the original test case, we did not restrict the search to the given method 
but to its compilation unit
2. In the second one, the declaration is found in a secondary type (thus not 
visible)

Fixed the first problem by passing the given element to the DeclarationOf* 
pattern.
Fixed the second problem by looking at the compilation unit of the given element 
to find the declaring type.