Example usage for org.eclipse.jdt.core.dom PackageDeclaration resolveBinding

List of usage examples for org.eclipse.jdt.core.dom PackageDeclaration resolveBinding

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom PackageDeclaration resolveBinding.

Prototype

public IPackageBinding resolveBinding() 

Source Link

Document

Resolves and returns the binding for the package declared in this package declaration.

Usage

From source file:ca.mcgill.cs.swevo.jayfx.ASTCrawler.java

License:Open Source License

@Override
public boolean visit(final MarkerAnnotation node) {
    final ITypeBinding binding = node.resolveTypeBinding();
    if (ASTCrawler.checkForNull(binding))
        return false;
    final IElement annoteElem = ASTCrawler.convertBinding(binding);
    this.aDB.addElement(annoteElem, binding.getModifiers());

    final ASTNode annotatedNode = node.getParent();
    switch (annotatedNode.getNodeType()) {
    case ASTNode.METHOD_DECLARATION: {
        final MethodDeclaration annotatedMethod = (MethodDeclaration) annotatedNode;
        final IMethodBinding mBinding = annotatedMethod.resolveBinding();
        return this.addAnnotationRelation(annoteElem, mBinding);

    }//from   w w  w  .j a v  a2 s. co  m
    case ASTNode.ANNOTATION_TYPE_DECLARATION: {
        final AnnotationTypeDeclaration annotatedAnnotation = (AnnotationTypeDeclaration) annotatedNode;
        final ITypeBinding tBinding = annotatedAnnotation.resolveBinding();
        return this.addAnnotationRelation(annoteElem, tBinding);
    }
    case ASTNode.VARIABLE_DECLARATION_STATEMENT: {
        return processVariableDeclarationStatement(annoteElem, (VariableDeclarationStatement) annotatedNode);
    }
    case ASTNode.VARIABLE_DECLARATION_FRAGMENT: {
        return processVariableDeclarationFragment(annoteElem, (VariableDeclarationFragment) annotatedNode);
    }
    case ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION: {
        AnnotationTypeMemberDeclaration atmd = (AnnotationTypeMemberDeclaration) annotatedNode;
        IMethodBinding methodBinding = atmd.resolveBinding();
        return this.addAnnotationRelation(annoteElem, methodBinding);
    }

    case ASTNode.PACKAGE_DECLARATION: {
        final PackageDeclaration packDecl = (PackageDeclaration) annotatedNode;
        final IPackageBinding pBinding = packDecl.resolveBinding();
        return this.addAnnotationRelation(annoteElem, pBinding);
    }

    case ASTNode.SINGLE_VARIABLE_DECLARATION: {
        final SingleVariableDeclaration svd = (SingleVariableDeclaration) annotatedNode;
        final IVariableBinding vBinding = svd.resolveBinding();
        return this.addAnnotationRelation(annoteElem, vBinding);
    }
    case ASTNode.TYPE_DECLARATION: {
        final TypeDeclaration tDecl = (TypeDeclaration) annotatedNode;
        final ITypeBinding tBinding = tDecl.resolveBinding();
        return this.addAnnotationRelation(annoteElem, tBinding);
    }
    case ASTNode.ENUM_DECLARATION: {
        final EnumDeclaration eDecl = (EnumDeclaration) annotatedNode;
        final ITypeBinding tBinding = eDecl.resolveBinding();
        return this.addAnnotationRelation(annoteElem, tBinding);
    }

    case ASTNode.FIELD_DECLARATION: {
        final FieldDeclaration fieldDecl = (FieldDeclaration) annotatedNode;
        for (final Object obj : fieldDecl.fragments()) {
            final VariableDeclarationFragment vdf = (VariableDeclarationFragment) obj;
            final IVariableBinding vBinding = vdf.resolveBinding();
            return this.addAnnotationRelation(annoteElem, vBinding);
        }
    }

    default: {
        throw new IllegalStateException("Illegal annotated node type: " + annotatedNode);
    }
    }
}

From source file:ca.mcgill.cs.swevo.jayfx.ASTCrawler.java

License:Open Source License

@Override
public boolean visit(final NormalAnnotation node) {
    final ITypeBinding binding = node.resolveTypeBinding();
    if (ASTCrawler.checkForNull(binding))
        return false;
    final IElement annoteElem = ASTCrawler.convertBinding(binding);
    this.aDB.addElement(annoteElem, binding.getModifiers());

    final ASTNode annotatedNode = node.getParent();
    switch (annotatedNode.getNodeType()) {
    case ASTNode.METHOD_DECLARATION: {
        final MethodDeclaration annotatedMethod = (MethodDeclaration) annotatedNode;
        final IMethodBinding mBinding = annotatedMethod.resolveBinding();
        return this.addAnnotationRelation(annoteElem, mBinding);

    }/*from   w  w w . jav a  2 s.  com*/
    case ASTNode.ANNOTATION_TYPE_DECLARATION: {
        final AnnotationTypeDeclaration annotatedAnnotation = (AnnotationTypeDeclaration) annotatedNode;
        final ITypeBinding tBinding = annotatedAnnotation.resolveBinding();
        return this.addAnnotationRelation(annoteElem, tBinding);
    }
    case ASTNode.VARIABLE_DECLARATION_STATEMENT: {
        return processVariableDeclarationStatement(annoteElem, (VariableDeclarationStatement) annotatedNode);
    }
    case ASTNode.VARIABLE_DECLARATION_FRAGMENT: {
        return processVariableDeclarationFragment(annoteElem, (VariableDeclarationFragment) annotatedNode);
    }

    case ASTNode.PACKAGE_DECLARATION: {
        final PackageDeclaration packDecl = (PackageDeclaration) annotatedNode;
        final IPackageBinding pBinding = packDecl.resolveBinding();
        return this.addAnnotationRelation(annoteElem, pBinding);
    }

    case ASTNode.SINGLE_VARIABLE_DECLARATION: {
        final SingleVariableDeclaration svd = (SingleVariableDeclaration) annotatedNode;
        final IVariableBinding vBinding = svd.resolveBinding();
        return this.addAnnotationRelation(annoteElem, vBinding);
    }
    case ASTNode.TYPE_DECLARATION: {
        final TypeDeclaration tDecl = (TypeDeclaration) annotatedNode;
        final ITypeBinding tBinding = tDecl.resolveBinding();
        return this.addAnnotationRelation(annoteElem, tBinding);
    }
    case ASTNode.ENUM_DECLARATION: {
        final EnumDeclaration eDecl = (EnumDeclaration) annotatedNode;
        final ITypeBinding tBinding = eDecl.resolveBinding();
        return this.addAnnotationRelation(annoteElem, tBinding);
    }
    case ASTNode.FIELD_DECLARATION: {
        final FieldDeclaration fieldDecl = (FieldDeclaration) annotatedNode;
        for (final Object obj : fieldDecl.fragments()) {
            final VariableDeclarationFragment vdf = (VariableDeclarationFragment) obj;
            final IVariableBinding vBinding = vdf.resolveBinding();
            return this.addAnnotationRelation(annoteElem, vBinding);
        }
    }
    default: {
        throw new IllegalStateException("Illegal annotated node type: " + annotatedNode);
    }
    }
}

From source file:ca.mcgill.cs.swevo.jayfx.ASTCrawler.java

License:Open Source License

@Override
public boolean visit(final PackageDeclaration pNode) {
    final IPackageBinding binding = pNode.resolveBinding();
    if (ASTCrawler.checkForNull(binding))
        return false;
    final IElement packageElem = this.convertBinding(binding);

    this.aDB.addElement(packageElem, binding.getModifiers());

    final CompilationUnit parent = (CompilationUnit) pNode.getParent();
    @SuppressWarnings("rawtypes")
    final List containedTypes = parent.types();
    for (@SuppressWarnings("rawtypes")
    final Iterator it = containedTypes.iterator(); it.hasNext();) {
        final AbstractTypeDeclaration type = (AbstractTypeDeclaration) it.next();
        final ITypeBinding typeBinding = type.resolveBinding();
        final IElement typeElem = ASTCrawler.convertBinding(typeBinding);
        this.aDB.addElement(typeElem, typeBinding.getModifiers());
        this.aDB.addRelation(packageElem, Relation.CONTAINS, typeElem);
    }/*from   w w  w .  ja  v  a2s  .c  om*/

    return true;
}

From source file:ca.mcgill.cs.swevo.jayfx.ASTCrawler.java

License:Open Source License

@Override
public boolean visit(final SingleMemberAnnotation node) {
    final ITypeBinding binding = node.resolveTypeBinding();
    if (ASTCrawler.checkForNull(binding))
        return false;
    final IElement annoteElem = ASTCrawler.convertBinding(binding);
    this.aDB.addElement(annoteElem, binding.getModifiers());

    final ASTNode annotatedNode = node.getParent();
    switch (annotatedNode.getNodeType()) {
    case ASTNode.METHOD_DECLARATION: {
        final MethodDeclaration annotatedMethod = (MethodDeclaration) annotatedNode;
        final IMethodBinding mBinding = annotatedMethod.resolveBinding();
        return this.addAnnotationRelation(annoteElem, mBinding);

    }//from  w ww  . ja va2  s  . c om
    case ASTNode.ANNOTATION_TYPE_DECLARATION: {
        final AnnotationTypeDeclaration annotatedAnnotation = (AnnotationTypeDeclaration) annotatedNode;
        final ITypeBinding tBinding = annotatedAnnotation.resolveBinding();
        return this.addAnnotationRelation(annoteElem, tBinding);
    }

    case ASTNode.VARIABLE_DECLARATION_STATEMENT: {
        VariableDeclarationStatement vds = (VariableDeclarationStatement) annotatedNode;
        return processVariableDeclarationStatement(annoteElem, vds);
    }

    case ASTNode.VARIABLE_DECLARATION_FRAGMENT: {
        return processVariableDeclarationFragment(annoteElem, (VariableDeclarationFragment) annotatedNode);
    }

    case ASTNode.PACKAGE_DECLARATION: {
        final PackageDeclaration packDecl = (PackageDeclaration) annotatedNode;
        final IPackageBinding pBinding = packDecl.resolveBinding();
        return this.addAnnotationRelation(annoteElem, pBinding);
    }

    case ASTNode.SINGLE_VARIABLE_DECLARATION: {
        final SingleVariableDeclaration svd = (SingleVariableDeclaration) annotatedNode;
        final IVariableBinding vBinding = svd.resolveBinding();
        return this.addAnnotationRelation(annoteElem, vBinding);
    }
    case ASTNode.TYPE_DECLARATION: {
        final TypeDeclaration tDecl = (TypeDeclaration) annotatedNode;
        final ITypeBinding tBinding = tDecl.resolveBinding();
        return this.addAnnotationRelation(annoteElem, tBinding);
    }
    case ASTNode.ENUM_DECLARATION: {
        final EnumDeclaration eDecl = (EnumDeclaration) annotatedNode;
        final ITypeBinding tBinding = eDecl.resolveBinding();
        return this.addAnnotationRelation(annoteElem, tBinding);
    }
    case ASTNode.FIELD_DECLARATION: {
        final FieldDeclaration fieldDecl = (FieldDeclaration) annotatedNode;
        for (final Object obj : fieldDecl.fragments()) {
            final VariableDeclarationFragment vdf = (VariableDeclarationFragment) obj;
            final IVariableBinding vBinding = vdf.resolveBinding();
            return this.addAnnotationRelation(annoteElem, vBinding);
        }
    }
    default: {
        throw new IllegalStateException("Illegal annotated node type: " + annotatedNode);
    }
    }
}

From source file:cc.kave.eclipse.namefactory.NodeFactory.java

License:Apache License

public static Name createNodeName(ASTNode node) {

    switch (node.getNodeType()) {

    case ASTNode.METHOD_DECLARATION:
        return createMethodDeclName((MethodDeclaration) node);

    case ASTNode.METHOD_INVOCATION:
        return createMethodInvName(node);

    case ASTNode.SUPER_METHOD_INVOCATION:
        return createSuperMethodInvName(node);

    case ASTNode.VARIABLE_DECLARATION_FRAGMENT:
        return createVariableName(node.getParent());

    case ASTNode.QUALIFIED_NAME:
        return createQualifiedName(node);

    case ASTNode.SINGLE_VARIABLE_DECLARATION:
        return createSingleVariableDeclName(node);

    case ASTNode.IMPORT_DECLARATION:
        ImportDeclaration importNode = (ImportDeclaration) node;
        return CsTypeName.newTypeName(BindingFactory.getBindingName(importNode.resolveBinding()));

    case ASTNode.PACKAGE_DECLARATION:
        PackageDeclaration packageNode = (PackageDeclaration) node;
        return CsNamespaceName.newNamespaceName(packageNode.resolveBinding().getName());

    case ASTNode.FIELD_DECLARATION:
        return createVariableName(node);

    case ASTNode.VARIABLE_DECLARATION_STATEMENT:
        return createVariableName(node);

    case ASTNode.VARIABLE_DECLARATION_EXPRESSION:
        return createVariableName(node);

    default:/*w  w w  .java 2 s .c om*/
        return null;
    }
}

From source file:com.architexa.diagrams.jdt.extractors.ContainmentHeirarchyExtractor.java

License:Open Source License

@Override
public boolean visit(PackageDeclaration pckgDecl) {
    Resource pkgDeclRes = bindingToResource(pckgDecl.resolveBinding());
    addContains(currProjRes, pkgDeclRes);
    return true;//from  ww  w .ja va 2 s  .c  o m
}

From source file:com.architexa.diagrams.jdt.extractors.ContainmentHeirarchyExtractor.java

License:Open Source License

@Override
public boolean visit(TypeDeclaration typeDecl) {
    TypeDeclaration parentType = (TypeDeclaration) getParent(TypeDeclaration.class);
    Resource parentRes;/*ww w.  j  a va 2 s .  com*/
    if (parentType != null) {
        // embedded type
        parentRes = bindingToResource(parentType.resolveBinding());
    } else {
        // top-level type (parent is package)
        CompilationUnit cu = (CompilationUnit) getRequiredParent(CompilationUnit.class);
        PackageDeclaration pckgDecl = cu.getPackage();
        if (pckgDecl == null)
            return true; // default package

        parentRes = bindingToResource(pckgDecl.resolveBinding());
    }

    Resource typeDeclRes = bindingToResource(typeDecl.resolveBinding());
    addContains(parentRes, typeDeclRes);
    return true;
}

From source file:com.codenvy.ide.ext.java.server.internal.core.util.DOMFinder.java

License:Open Source License

public boolean visit(PackageDeclaration node) {
    if (found(node, node) && this.resolveBinding)
        this.foundBinding = node.resolveBinding();
    return true;//from w  w w  .  j av a  2  s.c  o m
}

From source file:com.google.devtools.j2objc.jdt.BindingConverter.java

License:Apache License

/**
 * JDT package bindings do not include annotations, so add them from the
 * package's AST node.// w w  w. j a  v a 2 s .c  o  m
 */
public static JdtPackageElement getPackageElement(PackageDeclaration pkg) {
    IPackageBinding binding = pkg.resolveBinding();
    JdtPackageElement pkgElement = (JdtPackageElement) getElement(binding);
    if (pkgElement.getAnnotationMirrors().isEmpty() && pkg.annotations().size() > 0) {
        for (Object modifier : pkg.annotations()) {
            IAnnotationBinding annotation = ((org.eclipse.jdt.core.dom.Annotation) modifier)
                    .resolveAnnotationBinding();
            pkgElement.addAnnotation(new JdtAnnotationMirror(annotation));
        }
    }
    return pkgElement;
}

From source file:de.ovgu.cide.typing.jdt.checks.resolutions.ASTBindingFinder.java

License:Open Source License

public boolean visit(PackageDeclaration node) {
    if (result != null)
        return false;
    IBinding binding = node.resolveBinding();
    if (binding != null && binding.getKey().equals(target))
        result = node;/*from w ww.  j av a 2s  . c  om*/
    return super.visit(node);
}