Eclipse ASTVisitor ImportDeclaration from Package or JAR?

102 views Asked by At

I have an ASTVisitor-implementing class with (among others) this method:

@Override
public boolean visit(final ImportDeclaration node) {...}

Is there any way to find out whether the ImportDeclaration is from another package of the project which the ASTVisitor is going through or if it's from a .jar = library-content?

I tried node.resolveBinding().isSynthetic(), but it seems never to be synthetic despite me having imports from a library.

1

There are 1 answers

0
Phil On BEST ANSWER

Ok, the solution is resolving the node to IBinding and then ITypeBinding and calling isFromSource():

    IBinding b = node.resolveBinding();
    if (b instanceof ITypeBinding && !((ITypeBinding) b).isFromSource()) {
        //do stuff
    }