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

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

Introduction

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

Prototype

public final IBinding resolveBinding() 

Source Link

Document

Resolves and returns the binding for the entity referred to by this name.

Usage

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

License:Open Source License

@Override
public boolean visit(final QualifiedName pNode) {
    final IBinding lBinding = pNode.resolveBinding();

    if (lBinding == null) {
        ASTCrawler.log("Null binding 3 for " + pNode);
        return false;
    }//from w w  w  . j  av  a2s  . c o m

    if (lBinding.getKind() == IBinding.VARIABLE)
        if (((IVariableBinding) lBinding).isField() && this.aCurrMethod != null) {
            this.addAccessRelation((IVariableBinding) lBinding);

            final Assignment assignment = ASTCrawler.getAssignment(pNode);
            if (assignment != null) {
                this.addSetsRelation((IVariableBinding) lBinding);

                if (!(assignment.getOperator() == Assignment.Operator.ASSIGN))
                    this.addGetsRelation((IVariableBinding) lBinding);
            } else
                this.addGetsRelation((IVariableBinding) lBinding);
        }
    return false;
}

From source file:cc.kave.eclipse.namefactory.visitors.QualifiedNameVisitor.java

License:Apache License

public QualifiedName getName(String name) {
    for (QualifiedName i : names) {
        if (i.resolveBinding().getName().equals(name)) {
            return i;
        }/*from  w  w w  . j a v a  2s . c om*/
    }
    return null;
}

From source file:changetypes.ASTVisitorAtomicChange.java

License:Open Source License

public boolean visit(QualifiedName node) {
    if ((this.mtbStack.isEmpty()) && (!this.itbStack.isEmpty())) {
        return false;
    }//from www. j a va 2 s.com
    if (!this.mtbStack.isEmpty()) {
        if (node.getName().getIdentifier().equals("length")) {
            return true;
        }
        try {
            return visitName(node.resolveBinding(), (IMethodBinding) this.mtbStack.peek());
        } catch (Exception localException) {
            System.err.println(
                    "Cannot resolve qualified name \"" + node.getFullyQualifiedName().toString() + "\"");
            return false;
        }
    }
    return false;
}

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

License:Open Source License

@Override
public boolean visit(QualifiedName node) {
    //System.err.println("processing: " + node.toString());
    addRefFromOptionalCaller(bindingToResource(node.resolveBinding()));
    return true;/*from   w ww.  j av a2 s.  co  m*/
}

From source file:com.google.dart.java2dart.SyntaxTranslator.java

License:Open Source License

@Override
public boolean visit(org.eclipse.jdt.core.dom.QualifiedName node) {
    PropertyAccess result = propertyAccess(translateExpression(node.getQualifier()),
            translateSimpleName(node.getName()));
    context.putNodeBinding(result, node.resolveBinding());
    return done(result);
}

From source file:com.google.devtools.j2cpp.types.BindingMapBuilder.java

License:Open Source License

@Override
public boolean visit(QualifiedName node) {
    put(node, node.resolveBinding());
    return true;
}

From source file:com.ibm.wala.cast.java.translator.jdt.JDTJava2CAstTranslator.java

License:Open Source License

/**
 * QualifiedNames may be: 1) static of non-static field accesses -- we handle this case here 2) type names used in the context of:
 * a) field access (QualifiedName) b) method invocation c) qualifier of "this" in these cases we get the binding info in each of
 * these three functions and use them there, thus we return an EMPTY (no-op) here. 3) package names used in the context of a
 * QualifiedName class we return a EMPTY (no-op) here.
 * /*from   www  . j  a  v  a 2  s .  c o m*/
 * @param n
 * @param context
 * @return
 */
private CAstNode visit(QualifiedName n, WalkContext context) {
    // "package.Class" is a QualifiedName, but also is "Class.staticField"
    // only handle if it's a "Class.staticField" ("Field" in polyglot AST)

    if (n.resolveBinding() instanceof IVariableBinding) {
        IVariableBinding binding = (IVariableBinding) n.resolveBinding();
        assert binding.isField() : "Non-field variable QualifiedName!";

        // if field access is static, visitNode(n.getQualifier()) will come back here
        // and we will return an EMPTY node
        return createFieldAccess(visitNode(n.getQualifier(), context), n.getName().getIdentifier(), binding, n,
                context);
    } else
        return makeNode(context, fFactory, null, CAstNode.EMPTY);
    // type name, handled in surrounding context
}

From source file:edu.cmu.cs.crystal.tac.eclipse.EclipseTACInstructionFactory.java

License:Open Source License

public TACInstruction create(QualifiedName node, IEclipseVariableQuery eclipseVariableQuery) {
    // careful with the disambiguation of field accesses
    IBinding binding = node.resolveBinding();
    if (binding instanceof IVariableBinding) {
        // expect this to be a field
        IVariableBinding var = (IVariableBinding) binding;
        if (var.isField() || var.isEnumConstant()) {
            if (isLoad(node))
                return new LoadFieldInstructionImpl(node,
                        new EclipseBrokenFieldAccess(node, eclipseVariableQuery), eclipseVariableQuery);
            else/*from w  ww .  jav  a2  s.c o  m*/
                return null;
        } else
            throw new UnsupportedOperationException("Unexpected variable in qualified name");
    }
    // else expect this to be a package or type
    // in particular, method calls should never be qualified names
    if (binding instanceof IMethodBinding)
        throw new UnsupportedOperationException("Unexpected occurrance of method call as qualified name.");
    return null;
}

From source file:edu.cmu.cs.plural.concurrent.syncorswim.IsSynchronizedRefAnalysis.java

License:Open Source License

/**
 * If this is a field or variable, return the variable biding, else NONE.
 *//* w w w.  ja v a  2s. c om*/
static Option<IVariableBinding> asVar(Expression expr) {
    if (expr instanceof FieldAccess) {
        FieldAccess field = (FieldAccess) expr;
        return Option.some(field.resolveFieldBinding());
    } else if (expr instanceof SimpleName) {
        SimpleName name = (SimpleName) expr;
        if (name.resolveBinding() instanceof IVariableBinding) {
            IVariableBinding binding = (IVariableBinding) name.resolveBinding();
            return Option.some(binding);
        }
    } else if (expr instanceof Name) {
        Name name = (Name) expr;
        if (name.resolveBinding() instanceof IVariableBinding) {
            IVariableBinding binding = (IVariableBinding) name.resolveBinding();
            return Option.some(binding);
        }
    } else if (expr instanceof QualifiedName) {
        QualifiedName qname = (QualifiedName) expr;
        if (qname.resolveBinding() instanceof IVariableBinding) {
            IVariableBinding binding = (IVariableBinding) qname.resolveBinding();
            return Option.some(binding);
        }
    }

    // If we get down to here, it wasn't a field...
    return Option.none();
}

From source file:edu.uci.ics.sourcerer.extractor.ast.ReferenceExtractorVisitor.java

License:Open Source License

/**
 * This method writes://from  ww  w .  ja va 2s.com
 *<ul>
 *  <li>For any type reference:
 *  <ul>
 *    <li>Uses relation to <code>IRelationWriter</code>.</li>
 *  </ul></li>
 *</ul>
 */
@Override
public boolean visit(QualifiedName node) {
    IBinding binding = node.resolveBinding();

    if (binding instanceof IVariableBinding) {
        IVariableBinding varBinding = (IVariableBinding) binding;
        if (varBinding.isField()) {
            node.getName().accept(this);
            inLhsAssignment = false;
            node.getQualifier().accept(this);
        } else {
            logger.log(Level.SEVERE, "Unexpected type of qualified name variable binding: ", varBinding);
        }
    } else if (binding instanceof ITypeBinding) {
        ITypeBinding typeBinding = getBaseType((ITypeBinding) binding);
        IBinding qualifierBinding = node.getQualifier().resolveBinding();
        if (qualifierBinding instanceof IPackageBinding) {
            // Write the uses relation
            relationWriter.writeUses(fqnStack.getFqn(), getTypeFqn(typeBinding), getLocation(node));
        } else {
            // Write the uses relation
            relationWriter.writeUses(fqnStack.getFqn(), getTypeFqn(typeBinding), getLocation(node.getName()));
            node.getQualifier().accept(this);
        }
    } else if (binding instanceof IPackageBinding) {
    } else if (binding == null) {
    } else {
        logger.log(Level.SEVERE, "Unknown binding type encountered:", binding);
    }
    return false;
}