Example usage for org.eclipse.jdt.core.dom IBinding getKind

List of usage examples for org.eclipse.jdt.core.dom IBinding getKind

Introduction

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

Prototype

public int getKind();

Source Link

Document

Returns the kind of bindings this is.

Usage

From source file:astview.Binding.java

License:Open Source License

public static String getBindingLabel(IBinding binding) {
    String label;// w w  w  .  j a  v  a  2s . com
    if (binding == null) {
        label = ">binding"; //$NON-NLS-1$
    } else {
        switch (binding.getKind()) {
        case IBinding.VARIABLE:
            label = "> variable binding"; //$NON-NLS-1$
            break;
        case IBinding.TYPE:
            label = "> type binding"; //$NON-NLS-1$
            break;
        case IBinding.METHOD:
            label = "> method binding"; //$NON-NLS-1$
            break;
        case IBinding.PACKAGE:
            label = "> package binding"; //$NON-NLS-1$
            break;
        case IBinding.ANNOTATION:
            label = "> annotation binding"; //$NON-NLS-1$
            break;
        case IBinding.MEMBER_VALUE_PAIR:
            label = "> member value pair binding"; //$NON-NLS-1$
            break;
        default:
            label = "> unknown binding"; //$NON-NLS-1$
        }
    }
    return label;
}

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   ww w  .  j  a v a 2s.  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:ca.mcgill.cs.swevo.jayfx.ASTCrawler.java

License:Open Source License

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

    if (lBinding == null)
        // Occurs for all labels (e.g., loop labels)
        // log( "Null binding 4 for " + pNode );
        return false;
    if (lBinding.getKind() == IBinding.VARIABLE)
        if (((IVariableBinding) lBinding).isField()) {
            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);
        }/*  w w  w  .j  av  a 2 s .co  m*/

    return false;
}

From source file:changetypes.ASTVisitorAtomicChange.java

License:Open Source License

private boolean visitName(IBinding ib, IMethodBinding iMethodBinding) throws Exception {
    switch (ib.getKind()) {
    case 3:/*from  ww  w .j a v  a 2  s . c  om*/
        IVariableBinding ivb = (IVariableBinding) ib;
        if (ivb.isField()) {
            this.facts.add(Fact.makeAccessesFact(getQualifiedName(ivb), getQualifiedName(iMethodBinding)));
            try {
                String simpleMethodName = getSimpleName(iMethodBinding);
                if (simpleMethodName.toLowerCase().startsWith("get")) {
                    this.facts
                            .add(Fact.makeGetterFact(getQualifiedName(iMethodBinding), getQualifiedName(ivb)));
                } else if (simpleMethodName.toLowerCase().startsWith("set")) {
                    this.facts
                            .add(Fact.makeSetterFact(getQualifiedName(iMethodBinding), getQualifiedName(ivb)));
                }
            } catch (Exception localException) {
                System.err.println("Cannot resolve bindings for exceptions");
            }
        }
        break;
    }
    return true;
}

From source file:coloredide.astview.ASTViewContentProvider.java

License:Open Source License

private Binding createBinding(ASTNode parent, IBinding binding) {
    String label;//ww w. j  a v a2  s  . co m
    if (binding == null) {
        label = ">binding"; //$NON-NLS-1$
    } else {
        switch (binding.getKind()) {
        case IBinding.VARIABLE:
            label = "> variable binding"; //$NON-NLS-1$
            break;
        case IBinding.TYPE:
            label = "> type binding"; //$NON-NLS-1$
            break;
        case IBinding.METHOD:
            label = "> method binding"; //$NON-NLS-1$
            break;
        case IBinding.PACKAGE:
            label = "> package binding"; //$NON-NLS-1$
            break;
        case IBinding.ANNOTATION:
            label = "> annotation binding"; //$NON-NLS-1$
            break;
        case IBinding.MEMBER_VALUE_PAIR:
            label = "> member value pair binding"; //$NON-NLS-1$
            break;
        default:
            label = "> unknown binding"; //$NON-NLS-1$
        }
    }
    return new Binding(parent, label, binding, true);
}

From source file:com.architexa.diagrams.jdt.builder.ReloASTExtractor.java

License:Open Source License

protected void initResource(Resource res, IBinding binding) {
    switch (binding.getKind()) {
    case IBinding.METHOD:
        rdfModel.addTypeStatement(res, RJCore.methodType);
        break;/*from   w w w. j ava 2  s .  c o  m*/
    case IBinding.PACKAGE:
        rdfModel.addTypeStatement(res, RJCore.packageType);
        rdfModel.addStatement(res, RSECore.initialized, Boolean.toString(true));
        break;
    case IBinding.TYPE:
        if (((ITypeBinding) binding).isInterface())
            rdfModel.addStatement(res, RJCore.isInterface, RJCore.interfaceType);
        else
            rdfModel.addTypeStatement(res, RJCore.classType);
        break;
    case IBinding.VARIABLE:
        FieldDeclaration fieldDecl = (FieldDeclaration) getParent(FieldDeclaration.class);
        if (fieldDecl != null) {
            // field declaration
            rdfModel.addTypeStatement(res, RJCore.fieldType);
        } else {
            // variable declaration in methods
        }
        break;
    }
    rdfModel.addNameStatement(res, RSECore.name, binding.getName());
    rdfModel.addInitializedStatement(res, RSECore.initialized, Boolean.toString(true));
}

From source file:com.flamefire.importsmalinames.astutils.RenameVariablesVisitor.java

License:Open Source License

@Override
public boolean visit(SimpleName node) {
    // We have to be inside a method
    if (curMethod == null)
        return false;
    // Only replace variables
    IBinding binding = node.resolveBinding();
    if (binding == null) {
        if ((node.getParent() instanceof LabeledStatement)
                && ((LabeledStatement) node.getParent()).getLabel().equals(node))
            return false;
        if ((node.getParent() instanceof BreakStatement)
                && ((BreakStatement) node.getParent()).getLabel().equals(node))
            return false;
        if (node.getParent() instanceof QualifiedName)
            return false;
        // This may happen
        System.err.println("Detected SimpleName without binding: " + node + "; Parent:" + node.getParent()
                + "\nThis may happen if there are compile errors");
        // return false;
    } else if (binding.getKind() != IBinding.VARIABLE)
        return false;
    // Check if we need to add a "this"
    // Do this if current node is a field and we may replace a variable with
    // its name/*from w w w.jav  a  2s .  c  om*/
    AST ast = node.getAST();
    IVariableBinding vBinding = (IVariableBinding) binding;
    // Check for field acceses
    if (vBinding != null && vBinding.isField()) {
        // Add this if necessary
        if (renaming.containsValue(node.toString()) && !(node.getParent() instanceof FieldAccess)
                && !(node.getParent() instanceof QualifiedName)) {
            FieldAccess fa = ast.newFieldAccess();
            fa.setExpression(ast.newThisExpression());
            fa.setName(ast.newSimpleName(node.toString()));
            astRewrite.replace(node, fa, null);
        }
        return false;
    }
    String newName = renaming.get(node.toString());
    if (newName == null || newName == "")
        return false;
    astRewrite.replace(node, ast.newSimpleName(newName), null);
    return false;
}

From source file:edu.brown.cs.bubbles.bedrock.BedrockElider.java

License:Open Source License

/********************************************************************************/

private String getFormatType(ASTNode n) {
    String typ = null;//  w  w  w. ja va 2  s  .c  om

    if (n instanceof Name) {
        ASTNode p = n.getParent();
        ASTNode pp = p.getParent();
        StructuralPropertyDescriptor spd = n.getLocationInParent();
        switch (p.getNodeType()) {
        case ASTNode.METHOD_INVOCATION:
            if (n.getLocationInParent() == MethodInvocation.NAME_PROPERTY) {
                typ = "CALL" + getMethodType((Name) n);
            }
            break;
        case ASTNode.SIMPLE_TYPE:
        case ASTNode.QUALIFIED_TYPE:
        case ASTNode.TYPE_PARAMETER:
            typ = "TYPE";
            break;
        case ASTNode.METHOD_DECLARATION:
            if (spd == MethodDeclaration.NAME_PROPERTY) {
                typ = "METHODDECL" + getMethodType((Name) n);
            } else if (spd == MethodDeclaration.THROWN_EXCEPTIONS_PROPERTY)
                typ = "TYPE";
            break;
        case ASTNode.SINGLE_VARIABLE_DECLARATION:
            if (pp.getNodeType() == ASTNode.CATCH_CLAUSE)
                typ = "EXCEPTIONDECL";
            else
                typ = "PARAMDECL";
            break;
        case ASTNode.VARIABLE_DECLARATION_FRAGMENT:
            if (pp.getNodeType() == ASTNode.FIELD_DECLARATION)
                typ = "FIELDDECL";
            else
                typ = "LOCALDECL";
            break;
        case ASTNode.ENUM_DECLARATION:
        case ASTNode.TYPE_DECLARATION:
        case ASTNode.ANNOTATION_TYPE_DECLARATION:
            typ = "CLASSDECL" + getClassType((Name) n);
            break;
        case ASTNode.MARKER_ANNOTATION:
        case ASTNode.NORMAL_ANNOTATION:
        case ASTNode.SINGLE_MEMBER_ANNOTATION:
            typ = "ANNOT";
            break;
        }
    }

    if (typ == null) {
        if (n instanceof SimpleName) {
            IBinding ib = ((Name) n).resolveBinding();
            // BedrockPlugin.logD("BINDING FOR " + ((SimpleName) n).getIdentifier() + " = " + ib);
            if (ib != null && ib.getKind() == IBinding.VARIABLE) {
                IVariableBinding vb = (IVariableBinding) ib;
                if (vb.isEnumConstant())
                    typ = "ENUMC";
                else if (vb.isField()) {
                    typ = "FIELD" + getVariableType((Name) n);
                }
            } else if (ib != null && ib.getKind() == IBinding.METHOD) {
                typ = "CALL" + getMethodType((Name) n);
            } else if (ib != null && ib.getKind() == IBinding.ANNOTATION) {
                typ = "ANNOT";
            } else if (ib != null && ib.getKind() == IBinding.TYPE) {
                typ = "TYPE";
            } else if (ib == null)
                typ = "UNDEF";
        }
    }

    // TODO: indicate whether the name is a user or system name

    return typ;
}

From source file:edu.cmu.cs.crystal.internal.ControlFlowVisitor.java

License:Open Source License

/**
 * Example: (2 in 1)  java.lang.System.out.println("Hello");
 *//*w  w  w. ja  v a2s  . co  m*/
public boolean visit(QualifiedName node) {
    SimpleName name = node.getName();
    Name qualifier = node.getQualifier();
    IBinding nameBinding = name.resolveBinding();
    // If this is a Field access, then add children to CFG
    if (nameBinding.getKind() == IBinding.VARIABLE) {
        IVariableBinding variableBinding = (IVariableBinding) nameBinding;
        if (variableBinding.isField()) {
            ControlFlowNode nameCFN = controlFlowNode.newControlFlowNode(name);
            ControlFlowNode qualifierCFN = controlFlowNode.newControlFlowNode(qualifier);
            controlFlowNode.moveEdges(ControlFlowNode.Direction.BACKWARDS, qualifierCFN);
            qualifierCFN.addEdge(ControlFlowNode.Direction.FORWARDS, nameCFN);
            nameCFN.addEdge(ControlFlowNode.Direction.FORWARDS, controlFlowNode);
            qualifierCFN.evaluate();
            nameCFN.evaluate();
        }
    }
    // If it is NOT a field access, then do not add children to CFG
    return false;
}

From source file:fr.labri.harmony.rta.junit.jdt.JDTVisitorRTA.java

License:Open Source License

public boolean visit(final Assignment node) {
    if (node.getLeftHandSide() instanceof FieldAccess) {
        IVariableBinding b = ((FieldAccess) node.getLeftHandSide()).resolveFieldBinding();
        if (b != null && currentJavaMethod != null) {
            if (b.getDeclaringClass() != null) {

                String fieldId = getVariableBindingId(b);
                //System.err.println("Add "+fieldId);
                currentJavaMethod.getCallsSite().add(fieldId);
            }//from   w w w.j  a  va2  s.co m
        }
    } else if (node.getLeftHandSide() instanceof SuperFieldAccess) {
        IVariableBinding b = ((SuperFieldAccess) node.getLeftHandSide()).resolveFieldBinding();
        if (b != null && currentJavaMethod != null) {
            if (b.getDeclaringClass() != null) {

                String fieldId = getVariableBindingId(b);
                //System.err.println("Add "+fieldId);
                currentJavaMethod.getCallsSite().add(fieldId);
            }
        }
    } else if (node.getLeftHandSide() instanceof SimpleName) {
        IBinding ib = ((Name) node.getLeftHandSide()).resolveBinding();
        if (ib != null) {
            if (ib.getKind() == IBinding.VARIABLE) {

                IVariableBinding b = (IVariableBinding) ((Name) node.getLeftHandSide()).resolveBinding();
                if (b.isField()) {

                    if (b != null && currentJavaMethod != null) {
                        if (b.getDeclaringClass() != null) {

                            String fieldId = getVariableBindingId(b);
                            //System.err.println("Add "+fieldId);
                            currentJavaMethod.getCallsSite().add(fieldId);
                        }
                    }
                }

            }
        }
    }
    return true;
}