When I get the ISourceRange for an AnonymousClassDeclaration with the following code snippet, I am getting the startposition and length of the ClassInstanceCreation which is the parent of the AnonymousClassDecalration.
AnonymousClassDeclaration anonClassDec = (AnonymousClassDeclaration) node;
ITypeBinding binding = anonClassDec.resolveBinding();
IType type = (IType) binding.getJavaElement();
try {
ISourceRange sourceRange = type.getSourceRange();
return new Pair(sourceRange.getOffset(), sourceRange.getLength());
} catch (Exception e) {
e.printStackTrace();
}
Here, Pair is a custom class that stores two objects/primitives.
Is it intended to be this way? Or is it a bug?
The test case:
public class MyClass {
String s = "haha";
public void main(String args[]) {
M m = new M() {
@Override
public String foo() {
return s;
}
};
}
}
Using JDT core 3.17
[Updated on: Fri, 27 November 2020 05:03]
Report message to a moderator