Hi @ll,
I got a problem when checking if a method overrides another one.
Consider the following scenario:
public abstract class AbstractExample {
public void foo(){
bar();
}
protected abstract void bar();
}
public calss SubExample {
protected void bar(){
doSomething();
}
}
In the process of my application, SubExample is analysed. I create AST
instances for this type and its supertypes by use of the type
hierarchy and multiple loops with these statements:
parser.setSource(unit);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setCompilerOptions(parserOptions);
parser.setResolveBindings(true);
CompilationUnit node = (CompilationUnit) parser.createAST(null);
hierarchyUnits.add(node);
Afterwards I use an ASTVisitor on all of these ASTs to collect the
MethodDeclarations.
Later on I want to find in the set of MethodDeclarations the
implementing methods of abstract method declarations. After checking
for equality of identifier I call:
boolean overrides(MethodDeclaration subExampleMethod, MethodDeclaration
abstractExampleMethod){
return subExampleMethod.resolveBinding().overrides(
abstractExampleMethod.resolveBinding());
}
But this always returns false.
When debugging into the code I found the line where I assume the
problem to be located.
In org.eclipse.jdt.internal.compiler.lookup.TypeBinding line 287 (lib:
org.eclipse.jdt.core_3.4.4.v_894_R34x.jar)
there is a comparison of two SourceTypeBinding instances "if
(currentType == otherType)" that results to false even if the two
instances represent the same type (AbstractExample). They have
different ids in the Variables view but the same value (at least the
string representation in the value view is identical). Sadly even the
.equals method returns false.
So, what am I doing wrong to get an IMethodBinding that yields another
instance of SourceTypeBinding as is returned as superclass from the
subclass binding?
Do both MethodDeclarations have to originate from the same AST?
Is there something else I could try to get this task done?
Every help or hint is appreciated.
Best regards,
Sebastian