Hi,
I'm trying to find out if the class or some of its parent in src folder implements some interface (which is not the part of the project) by its name, but I cannot resolve the superinterfaces, since they are always null.
Don't you know why this happens?
I was trying to use setEnvironment(..) or setProject(..) with the same result.
- paths are correct
- project exists and is open..
superclass (/Users/me/someProject/src/Clazz1.java):
public class Clazz1 implements Interface1 {}
child class (/Users/me/someProject/src/Clazz2.java):
public class Clazz2 extends Clazz1 {}
parsing code:
File javaFile = new File("/Users/me/someProject/src/Clazz2.java")
ASTParser parser = ASTParser.newParser(AST.JLS4);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
String[] srcPaths = {"/Users/me/someProject/src"};
parser.setEnvironment(null, srcPaths, null, false);
//or parser.setProject(existingAndOpenedJavaProject)
parser.setResolveBindings(true);
parser.setBindingsRecovery(true);
String content = FileUtils.readFileToString(javaFile);
parser.setSource(content.toCharArray());
CompilationUnit unit = (CompilationUnit)parser.createAST(new SubProgressMonitor(monitor, 1));
TypeDeclaration type = (TypeDeclaration)unit.types().get(0);
List<Type> interfaces = type.superInterfaceTypes();
// interfaces null at this point