Bug 83527 - Wrong fullyQualifiedName for inner classes
Summary: Wrong fullyQualifiedName for inner classes
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: 3.1 M5   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-01-24 07:35 EST by Thomas Buechner CLA
Modified: 2005-06-24 13:20 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 Thomas Buechner CLA 2005-01-24 07:35:40 EST
Wrong fullyQualifiedName for inner classes

In the following example there exist two anonymous inner classes with the 
fullyQualifiedName=="test.Directories$1" which is wrong.
This is because 
org.eclipse.jdt.internal.core.CompilationUnitStructureRequestor.resolveDuplicat
es(SourceRefElement handle) doesnt increment the occurenceCount of a newly 
created type because of a wrong implementation of equals() of 
org.eclipse.jdt.internal.core.SourceType if there are two inner classes which 
are not declared in the same method.
Because of this two different sourceTypes with the same occurenceCount=1 are 
created. 

Example:
package test;

public class Directories {
    public static final Interface i2 = new Interface(){};
    public static final Interface i3 = new Interface(){};
}

I fixed this problem with the following corrections in SourceType.java:

- additional implementation:
public int hashCode() {
    return Util.combineHashCodes(getElementName().hashCode(), 
this.occurrenceCount);
}

- changed implementation of equals(o):
public boolean equals(Object o) {
	if (!(o instanceof SourceType)) return false;
    SourceType other = (SourceType) o;
    boolean namesAndOccurence =  getElementName().equals(other.getElementName
())  && this.occurrenceCount == other.occurrenceCount;
    if(!namesAndOccurence) {
        return false;
    }
    else {
        JavaElement thisCompilationUnit = getCompilationUnit(this);
        JavaElement otherCompilationUnit = getCompilationUnit(other);
        return thisCompilationUnit.equals(otherCompilationUnit);
    }
}
private static JavaElement getCompilationUnit(JavaElement javaElement) {
    if(javaElement instanceof CompilationUnit) {
        return javaElement;
    }
    if(javaElement.parent != null) {
        return getCompilationUnit(javaElement.parent);
    }
    else {
        return null;
    }
}
Comment 1 Thomas Buechner CLA 2005-03-15 08:30:45 EST
fixed in version 3.1M5a
Comment 2 Olivier Thomann CLA 2005-06-24 13:20:59 EDT
Verified.