Bug 20631 - Declaration of local binary type not found
Summary: Declaration of local binary type not found
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 2.1 M1   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-06-19 07:46 EDT by Jerome Lanneluc CLA
Modified: 2002-09-19 07:37 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 Jerome Lanneluc CLA 2002-06-19 07:46:15 EDT
Build 20020618

1. Create a jar with the following class:
public class X {
void foo() {
	class Y {}
	System.out.println(new Y().toString());
}
}
2. Add jar to build path and attach source
3. Open X$1$Y.class
4. Select Y in Outline and search for type declaration
Observe: None is found.
Comment 1 Jerome Lanneluc CLA 2002-06-19 09:43:51 EDT
Problem seems to be with the creation of the TypeDeclarationPattern: it creates 
a pattern that says the type name should be Y (correct) with no enclosing types 
(incorrect).

Change would require to read the class file to find out that it is a local 
type. This is too much of a change. Propose to defer post 2.0.
Comment 2 Jerome Lanneluc CLA 2002-06-20 06:09:51 EDT
Another failing test case:
Search doesn't find any type declaration for Y in:
public class X {
	class M {
		void foo() {
			class Y {
			}
		}
	}
}
Comment 3 Philipe Mulet CLA 2002-06-20 07:37:55 EDT
Along the line of bug 20532, we have search issues with binary nested types 
(20532 takes care of members, this bug covers local types). Search in binaries 
is a 2.0 addition, so we want to address defects in this area.

Need to come up with a fix really soon for having it in for F4. 
Comment 4 Jerome Lanneluc CLA 2002-06-20 11:50:16 EDT
When traversing the ast to report the matches, in a method we first report the 
references, then the declarations. The local type declaration is found as a 
reference and could not be reported, so it is lost. We should first report the 
declarations then the remaining nodes are references.

Proposed fix (in MatchSet):
/**
 * Visit the given method declaration and report the nodes that match exactly 
the
 * search pattern (ie. the ones in the matching nodes set)
 * Note that the method declaration has already been checked.
 */
private void reportMatching(AbstractMethodDeclaration method, IJavaElement 
parent) throws CoreException {
	// declaration in this method
	// (NB: declarations must be searched first (see bug 20631 Declaration 
of local binary type not found)
	if ((method.bits & AstNode.HasLocalTypeMASK) != 0) {
		LocalDeclarationVisitor localDeclarationVisitor = new 
LocalDeclarationVisitor();
		localDeclarationVisitor.enclosingElement = 
			(parent instanceof IType) ?
				this.locator.createMethodHandle(method, (IType)
parent) :
				parent;
		try {
			method.traverse(localDeclarationVisitor, (ClassScope)
null);
		} catch (WrappedCoreException e) {
			throw e.coreException;
		}
	}
	
	// references in this method
	AstNode[] nodes = this.matchingNodes(method.declarationSourceStart, 
method.declarationSourceEnd);
	for (int i = 0; i < nodes.length; i++) {
		AstNode node = nodes[i];
		Integer level = (Integer)this.matchingNodes.get(node);
		if ((this.matchContainer & SearchPattern.METHOD) != 0) {
			this.locator.reportReference(
				node, 
				method, 
				parent, 
				level.intValue() == 
SearchPattern.ACCURATE_MATCH ?
					IJavaSearchResultCollector.EXACT_MATCH :
				
	IJavaSearchResultCollector.POTENTIAL_MATCH);
			this.matchingNodes.remove(node);
		}
	}
	if (this.potentialMatchingNodes(method.declarationSourceStart, 
method.declarationSourceEnd).length == 0) {
		// no need to resolve the statements in the method
		method.statements = null;
	}
}
Comment 5 Philipe Mulet CLA 2002-06-21 05:05:58 EDT
Not critical enough for considering for 2.0 (nobody but us found it, and fix is 
not trivial).

Deferring, fix needs to be tested
Comment 6 Jerome Lanneluc CLA 2002-08-14 07:43:48 EDT
Added proposed fix, plus a change on LocalDeclarationVisitor so as to report 
local type declaration when one is found.

Added regression test.
Comment 7 David Audel CLA 2002-09-19 07:37:14 EDT
Verified.