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

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

Introduction

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

Prototype

public final ITypeBinding resolveBinding() 

Source Link

Document

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

Usage

From source file:ca.ecliptical.pde.internal.ds.AnnotationProcessor.java

License:Open Source License

@Override
public boolean visit(TypeDeclaration type) {
    if (!Modifier.isPublic(type.getModifiers())) {
        // non-public types cannot be (or have nested) components
        if (errorLevel.isNone())
            return false;

        Annotation annotation = findComponentAnnotation(type);
        if (annotation != null)
            reportProblem(annotation, null, problems,
                    NLS.bind(Messages.AnnotationProcessor_invalidComponentImplementationClass,
                            type.getName().getIdentifier()),
                    type.getName().getIdentifier());

        return true;
    }/* www  .  j  a  va2  s. c om*/

    Annotation annotation = findComponentAnnotation(type);
    if (annotation != null) {
        if (type.isInterface() || Modifier.isAbstract(type.getModifiers())
                || (!type.isPackageMemberTypeDeclaration() && !isNestedPublicStatic(type))
                || !hasDefaultConstructor(type)) {
            // interfaces, abstract types, non-static/non-public nested types, or types with no default constructor cannot be components
            reportProblem(annotation, null, problems,
                    NLS.bind(Messages.AnnotationProcessor_invalidComponentImplementationClass,
                            type.getName().getIdentifier()),
                    type.getName().getIdentifier());
        } else {
            ITypeBinding typeBinding = type.resolveBinding();
            if (typeBinding == null) {
                if (debug.isDebugging())
                    debug.trace(String.format("Unable to resolve binding for type: %s", type)); //$NON-NLS-1$
            } else {
                IAnnotationBinding annotationBinding = annotation.resolveAnnotationBinding();
                if (annotationBinding == null) {
                    if (debug.isDebugging())
                        debug.trace(String.format("Unable to resolve binding for annotation: %s", annotation)); //$NON-NLS-1$
                } else {
                    IDSModel model = processComponent(type, typeBinding, annotation, annotationBinding,
                            problems);
                    models.add(model);
                }
            }
        }
    }

    return true;
}

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   ww w. j a v  a2s.  c o  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);

    }/*  ww  w  . ja v a2 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: {
        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 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 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: {
        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:ca.mcgill.cs.swevo.jayfx.ASTCrawler.java

License:Open Source License

/**
 * Generated the DECLARES relations between a type and and nested types, the
 * EXTENDS relations, and the IMPLEMENTS relation
 */// w ww .  j a v a2 s  .co  m
@Override
public boolean visit(final TypeDeclaration pNode) {
    final ITypeBinding lBinding = pNode.resolveBinding();

    if (ASTCrawler.checkForNull(lBinding))
        return false;

    try {
        this.saveTypeRelation(lBinding);

        // Add Declaration relations if this is a local or nested class
        if (lBinding.isLocal() || lBinding.isAnonymous())
            this.aDB.addRelation(this.aCurrMethod, Relation.DECLARES_TYPE, this.aCurrType);
        else if (lBinding.isNested())
            this.aDB.addRelation(this.aCurrTypeReminder.peek(), Relation.DECLARES_TYPE, this.aCurrType);

        // Find superclass
        if (!pNode.isInterface()) {
            final ITypeBinding lSuperBinding = lBinding.getSuperclass();
            if (lSuperBinding != null) {
                final IElement lSuperClass = ASTCrawler.convertBinding(lSuperBinding);
                this.aDB.addElement(lSuperClass, lSuperBinding.getModifiers());
                this.aDB.addRelationAndTranspose(this.aCurrType, Relation.EXTENDS_CLASS, lSuperClass);
            }
        }

        // Find interfaces.
        final ITypeBinding lInterfaceBindings[] = lBinding.getInterfaces();
        for (final ITypeBinding element : lInterfaceBindings) {
            final IElement lInterface = ASTCrawler.convertBinding(element);
            this.aDB.addElement(lInterface, element.getModifiers() | ASTCrawler.ABSTRACT_FLAG);
            if (pNode.isInterface())
                this.aDB.addRelationAndTranspose(this.aCurrType, Relation.EXTENDS_INTERFACES, lInterface);
            else
                this.aDB.addRelationAndTranspose(this.aCurrType, Relation.IMPLEMENTS_INTERFACE, lInterface);
        }
    } catch (final Exception pException) {
        ProblemManager.reportException(pException);
    }

    return true;
}

From source file:changetypes.ASTVisitorAtomicChange.java

License:Open Source License

public boolean visit(CompilationUnit node) {
    IJavaElement thisFile = node.getJavaElement();
    for (Object abstractTypeDeclaration : node.types()) {
        if ((abstractTypeDeclaration instanceof TypeDeclaration)) {
            TypeDeclaration td = (TypeDeclaration) abstractTypeDeclaration;
            this.typeToFileMap_.put(getQualifiedName(td.resolveBinding()), thisFile);
        }/* ww w .  j  a v  a 2  s  .c o  m*/
    }
    return true;
}

From source file:changetypes.ASTVisitorAtomicChange.java

License:Open Source License

public boolean visit(TypeDeclaration node) {
    ITypeBinding itb = node.resolveBinding();
    this.itbStack.push(itb);
    try {/* w  w  w.  j a v  a 2 s .c  o m*/
        this.facts.add(Fact.makeTypeFact(getQualifiedName(itb), getSimpleName(itb), itb.getPackage().getName(),
                itb.isInterface() ? "interface" : "class"));
    } catch (Exception localException1) {
        System.err.println("Cannot resolve bindings for class " + node.getName().toString());
    }
    ITypeBinding localITypeBinding1;
    ITypeBinding i2;
    try {
        ITypeBinding itb2 = itb.getSuperclass();
        if (itb.getSuperclass() != null) {
            this.facts.add(Fact.makeSubtypeFact(getQualifiedName(itb2), getQualifiedName(itb)));
            this.facts.add(Fact.makeExtendsFact(getQualifiedName(itb2), getQualifiedName(itb)));
        }
        ITypeBinding[] arrayOfITypeBinding;
        int i;
        if (node.isInterface()) {
            i = (arrayOfITypeBinding = itb.getInterfaces()).length;
            for (localITypeBinding1 = 0; localITypeBinding1 < i; localITypeBinding1++) {
                ITypeBinding i2 = arrayOfITypeBinding[localITypeBinding1];
                this.facts.add(Fact.makeSubtypeFact(getQualifiedName(i2), getQualifiedName(itb)));
                this.facts.add(Fact.makeExtendsFact(getQualifiedName(i2), getQualifiedName(itb)));
            }
        } else {
            i = (arrayOfITypeBinding = itb.getInterfaces()).length;
            for (localITypeBinding1 = 0; localITypeBinding1 < i; localITypeBinding1++) {
                i2 = arrayOfITypeBinding[localITypeBinding1];
                this.facts.add(Fact.makeSubtypeFact(getQualifiedName(i2), getQualifiedName(itb)));
                this.facts.add(Fact.makeImplementsFact(getQualifiedName(i2), getQualifiedName(itb)));
            }
        }
    } catch (Exception localException2) {
        System.err.println("Cannot resolve super class bindings for class " + node.getName().toString());
    }
    Object localObject;
    try {
        localITypeBinding1 = (localObject = itb.getDeclaredFields()).length;
        for (i2 = 0; i2 < localITypeBinding1; i2++) {
            IVariableBinding ivb = localObject[i2];
            String visibility = getModifier(ivb);
            String fieldStr = ivb.toString();

            String[] tokens = fieldStr.split(" ");
            String[] arrayOfString1;
            int k = (arrayOfString1 = tokens).length;
            for (int j = 0; j < k; j++) {
                String token = arrayOfString1[j];
                if (this.allowedFieldMods_.contains(token)) {
                    this.facts.add(Fact.makeFieldModifierFact(getQualifiedName(ivb), token));
                }
            }
            this.facts.add(Fact.makeFieldFact(getQualifiedName(ivb), ivb.getName(), getQualifiedName(itb),
                    visibility));
            if (!ivb.getType().isParameterizedType()) {
                this.facts.add(Fact.makeFieldTypeFact(getQualifiedName(ivb), getQualifiedName(ivb.getType())));
            } else {
                this.facts.add(Fact.makeFieldTypeFact(getQualifiedName(ivb), makeParameterizedName(ivb)));
            }
        }
    } catch (Exception localException3) {
        System.err.println("Cannot resolve field bindings for class " + node.getName().toString());
    }
    try {
        ITypeBinding localITypeBinding2 = (localObject = node.getTypes()).length;
        for (i2 = 0; i2 < localITypeBinding2; i2++) {
            TypeDeclaration t = localObject[i2];
            ITypeBinding intb = t.resolveBinding();
            this.facts.add(Fact.makeTypeInTypeFact(getQualifiedName(intb), getQualifiedName(itb)));
        }
    } catch (Exception localException4) {
        System.err.println("Cannot resolve inner type bindings for class " + node.getName().toString());
    }
    return true;
}

From source file:com.android.ide.eclipse.adt.internal.refactorings.extractstring.ReplaceStringsVisitor.java

License:Open Source License

private Expression findContextFieldOrMethod(StringLiteral node) {
    TypeDeclaration clazz = findParentClass(node, TypeDeclaration.class);
    return clazz == null ? null : findContextFieldOrMethod(clazz.resolveBinding());
}

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

License:Open Source License

public static Resource getOptionalCallingRes(ReloASTExtractor extractor) {
    // get calling method
    MethodDeclaration parentMethodDecl = (MethodDeclaration) extractor.getAncestor(MethodDeclaration.class);
    if (parentMethodDecl != null)
        return extractor.bindingToResource(parentMethodDecl.resolveBinding());

    // get calls in initializers
    TypeDeclaration parentTypeDecl = (TypeDeclaration) extractor.getParent(TypeDeclaration.class);
    if (parentTypeDecl != null)
        return extractor.bindingToResource(parentTypeDecl.resolveBinding());

    // there are no calling resources!
    return null;/*from  w w w  . j av  a 2s  .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;// w  w  w .  j a  v  a  2s.  co  m
    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;
}