Example usage for org.eclipse.jdt.core.dom IVariableBinding toString

List of usage examples for org.eclipse.jdt.core.dom IVariableBinding toString

Introduction

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

Prototype

@Override
public String toString();

Source Link

Document

Returns a string representation of this binding suitable for debugging purposes only.

Usage

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  a2 s.  c  om*/
        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.cronopista.mapme.handler.Map.java

License:Open Source License

private ClassToMap prepareClass(ITypeBinding a) {

    ClassToMap res = new ClassToMap();
    res.setName(a.getName());/*from ww  w  .  j  av  a2s.c  o  m*/
    res.setPackageName(a.getPackage().getName());
    res.setFields(new ArrayList<Field>());

    for (IVariableBinding field : a.getDeclaredFields()) {
        if (!field.toString().contains("static")) {

            ITypeBinding inEclipseType = field.getType();

            Field f = new Field();
            f.setBasicType(TypeUtil.resolveType(inEclipseType.isPrimitive(), inEclipseType.getName(),
                    inEclipseType.getQualifiedName(), inEclipseType.getTypeDeclaration().getQualifiedName()));
            if (f.getBasicType() != 0) {
                f.setSize(TypeUtil.getSize(inEclipseType.getName()));
                f.setName(field.getName());
                f.setShortTypeName(inEclipseType.getName());
                f.setFullTypeName(inEclipseType.getQualifiedName());

                if (TypeUtil.isObject(f)) {
                    f.setClassToMap(prepareClass(inEclipseType));
                }

                if (TypeUtil.isCollection(f)) {
                    ITypeBinding colType = inEclipseType.getTypeArguments()[0];

                    f.setClassToMap(prepareClass(colType));

                    f.setFullCollectionListType(inEclipseType.getTypeDeclaration().getQualifiedName());
                    f.setShortCollectionListType(inEclipseType.getTypeDeclaration().getName());

                    f.setCollectionType(new Field());

                    f.getCollectionType()
                            .setBasicType(TypeUtil.resolveType(colType.isPrimitive(), colType.getName(),
                                    colType.getQualifiedName(),
                                    colType.getTypeDeclaration().getQualifiedName()));
                    f.getCollectionType().setSize(TypeUtil.getSize(colType.getName()));
                    f.getCollectionType().setShortTypeName(colType.getName());
                    f.getCollectionType().setFullTypeName(colType.getQualifiedName());

                }

                res.getFields().add(f);
            }
        }
    }

    return res;

}

From source file:com.google.devtools.j2objc.util.NameTable.java

License:Open Source License

public void setVariableName(IVariableBinding var, String name) {
    var = var.getVariableDeclaration();
    String previousName = variableNames.get(var);
    if (previousName != null && !previousName.equals(name)) {
        logger.fine(String.format("Changing previous rename for variable: %s. Was: %s, now: %s", var.toString(),
                previousName, name));//from w w  w. j  a v  a2 s .com
    }
    variableNames.put(var, name);
}

From source file:lang.java.jdt.internal.JDTImporter.java

License:Open Source License

private void importBindingInfo(ASTNode n) {

    // type bindings
    ITypeBinding tb = null;/*from   w w  w . j  a  v  a 2 s  .c  om*/

    if (n instanceof org.eclipse.jdt.core.dom.Type) {
        tb = ((org.eclipse.jdt.core.dom.Type) n).resolveBinding();
    } else if (n instanceof AbstractTypeDeclaration) {
        tb = ((AbstractTypeDeclaration) n).resolveBinding();
    } else if (n instanceof AnonymousClassDeclaration) {
        tb = ((AnonymousClassDeclaration) n).resolveBinding();
    } else if (n instanceof Expression) {
        tb = ((Expression) n).resolveTypeBinding();
    } else if (n instanceof TypeDeclarationStatement) {
        tb = ((TypeDeclarationStatement) n).resolveBinding();
    } else if (n instanceof TypeParameter) {
        tb = ((TypeParameter) n).resolveBinding();
    } else if (n instanceof EnumDeclaration) {
        tb = ((EnumDeclaration) n).resolveBinding();
    } else if (n instanceof AnnotationTypeDeclaration) {
        tb = ((AnnotationTypeDeclaration) n).resolveBinding();
    }

    if (tb != null) {
        Initializer possibleParent = null;
        try {
            ASTNode scope = scopeStack.peek();
            if (scope instanceof Initializer) {
                possibleParent = (Initializer) scope;
            }
        } catch (EmptyStackException e) {
            // ignore
        }
        if (fillOldStyleUsage) {
            addBinding(typeBindings, n, bindingCache.getEntity(tb, possibleParent));
        }
    }

    // method and constructor bindings
    IMethodBinding mb = null;
    IMethodBinding cb = null;

    if (n instanceof ClassInstanceCreation) {
        cb = ((ClassInstanceCreation) n).resolveConstructorBinding();
    } else if (n instanceof ConstructorInvocation) {
        cb = ((ConstructorInvocation) n).resolveConstructorBinding();
    } else if (n instanceof EnumConstantDeclaration) {
        cb = ((EnumConstantDeclaration) n).resolveConstructorBinding();
    } else if (n instanceof MethodDeclaration) {
        mb = ((MethodDeclaration) n).resolveBinding();
    } else if (n instanceof MethodInvocation) {
        mb = ((MethodInvocation) n).resolveMethodBinding();
        // if this is a method invocation on an AnonymousClassDeclaration,
        // call importBindingInfo first to get declaration Entity.
        Expression exp = ((MethodInvocation) n).getExpression();
        if (exp instanceof ClassInstanceCreation) {
            AnonymousClassDeclaration acdc = ((ClassInstanceCreation) exp).getAnonymousClassDeclaration();
            if (acdc != null) {
                importBindingInfo(acdc);
            }
        }
    } else if (n instanceof SuperConstructorInvocation) {
        cb = ((SuperConstructorInvocation) n).resolveConstructorBinding();
    } else if (n instanceof SuperMethodInvocation) {
        mb = ((SuperMethodInvocation) n).resolveMethodBinding();
    }

    if (mb != null) {
        if (fillOldStyleUsage) {
            addBinding(methodBindings, n, bindingCache.getEntity(mb));
        }
        if (n instanceof MethodDeclaration) {
            addBinding(methodDecls, n, bindingCache.getEntity(mb));
            addMethodBody((MethodDeclaration) n, mb);
        }
        if (n instanceof MethodInvocation) {
            MethodInvocation mi = (MethodInvocation) n;
            int mods = mi.resolveMethodBinding().getMethodDeclaration().getModifiers();
            List<IValue> modsForN = bindingCache.getModifiers(mods);
            if (mi.resolveMethodBinding().getMethodDeclaration().isDeprecated())
                modsForN.add(BindingConverter.deprecatedModifier);
            for (IValue modifier : modsForN)
                modifiers.insert(VF.tuple(bindingCache.getEntity(mb), modifier));
        }
    }

    if (cb != null && fillOldStyleUsage) {
        addBinding(constructorBindings, n, bindingCache.getEntity(cb));
    }

    // field and variable bindings
    IVariableBinding vb = null;
    IVariableBinding fb = null;

    if (n instanceof EnumConstantDeclaration) {
        fb = ((EnumConstantDeclaration) n).resolveVariable();
    } else if (n instanceof FieldDeclaration) {
        FieldDeclaration fd = (FieldDeclaration) n;
        for (Object vdfo : fd.fragments()) {
            VariableDeclarationFragment vdf = (VariableDeclarationFragment) vdfo;
            addBinding(fieldDecls, n, bindingCache.getEntity(vdf.resolveBinding()));
        }
    } else if (n instanceof FieldAccess) {
        FieldAccess fa = (FieldAccess) n;
        fb = fa.resolveFieldBinding();

        // check for 'length' access of array object
        Expression exp = fa.getExpression();
        if (exp.resolveTypeBinding().isArray() && fb.getName().equals("length")) {
            // put arrayLengthField in idStore, so it doesn't have to call
            // importVariableBinding()
            // (which cannot distinguish between 'length' access and a local
            // var inside an initializer).
            // don't include type of exp, b/c we can't do the same further
            // down
            bindingCache.put(fb.getKey(), BindingConverter.arrayLengthField);
        }

        // if the field is accessed on an AnonymousClassDeclaration,
        // call importBindingInfo first to get declaration Entity.
        if (exp instanceof ClassInstanceCreation) {
            AnonymousClassDeclaration acdc = ((ClassInstanceCreation) exp).getAnonymousClassDeclaration();
            if (acdc != null) {
                importBindingInfo(acdc);
            }
        }
    } else if (n instanceof SuperFieldAccess) {
        fb = ((SuperFieldAccess) n).resolveFieldBinding();
    } else if (n instanceof VariableDeclaration) {
        vb = ((VariableDeclaration) n).resolveBinding();
    } else if (n instanceof SimpleName) {
        // local variable, parameter or field.
        SimpleName name = (SimpleName) n;
        IBinding b = name.resolveBinding();
        if (b instanceof IVariableBinding) {
            vb = (IVariableBinding) b;

            if (vb.getDeclaringClass() != null) {
                // field
                fb = vb;
                vb = null;
            } else {
                // The field 'length' of an array type has no declaring
                // class
                // Let's try to distinguish between 'length' access and a
                // local variable/parameter
                ASTNode parent = n.getParent();
                if (vb.getName().equals("length") && parent != null && parent instanceof QualifiedName
                        && vb.toString().equals("public final int length")) {
                    // assume 'length' access of array object (local
                    // variables can't be public)
                    // put arrayLengthField in idStore, so it doesn't have
                    // to call importVariableBinding()
                    // (which cannot distinguish between 'length' access and
                    // a local var inside an initializer).
                    // we can't get the array type of the object of which
                    // the field was accessed
                    bindingCache.put(vb.getKey(), BindingConverter.arrayLengthField);
                }
            }
        }
    }

    if (fb != null || vb != null) {
        Initializer possibleParent = null;
        try {
            ASTNode scope = scopeStack.peek();
            if (scope instanceof Initializer) {
                possibleParent = (Initializer) scope;
            }
        } catch (EmptyStackException e) {
            // ignore
        }

        if (fb != null && fillOldStyleUsage) {
            addBinding(fieldBindings, n, bindingCache.getEntity(fb, possibleParent));
        }
        if (vb != null) {
            addBinding(variableBindings, n, bindingCache.getEntity(vb, possibleParent));
        }
    }

    // package bindings
    IPackageBinding pb = null;
    if (n instanceof PackageDeclaration) {
        pb = ((PackageDeclaration) n).resolveBinding();
    }

    if (pb != null) {
        addBinding(packageBindings, n, bindingCache.getEntity(pb));
    }
}

From source file:net.sf.j2s.core.astvisitors.Bindings.java

License:Open Source License

private static String asString(IVariableBinding variableBinding) {
    if (!variableBinding.isField())
        return variableBinding.toString();
    if (variableBinding.getDeclaringClass() == null) {
        Assert.isTrue(variableBinding.getName().equals("length"));//$NON-NLS-1$
        return ARRAY_LENGTH_FIELD_BINDING_STRING;
    }/*from  ww w . j a  va  2  s  .  c  o m*/
    StringBuffer result = new StringBuffer();
    result.append(variableBinding.getDeclaringClass().getName());
    result.append(':');
    result.append(variableBinding.getName());
    return result.toString();
}

From source file:org.evosuite.junit.CompoundTestCase.java

License:Open Source License

/**
 * <p>/*from   w  w w. jav a  2 s .c  o  m*/
 * addVariable
 * </p>
 * 
 * @param varBinding
 *            a {@link org.eclipse.jdt.core.dom.IVariableBinding} object.
 * @param varRef
 *            a {@link org.evosuite.testcase.VariableReference} object.
 */
public void addVariable(IVariableBinding varBinding, VariableReference varRef) {
    if ((currentScope == TestScope.FIELDS) || (currentScope == TestScope.STATICFIELDS)) {
        fieldVars.put(varBinding.toString(), varRef);
        return;
    }
    currentMethodVars.put(varBinding.toString(), varRef);
}

From source file:org.evosuite.junit.CompoundTestCase.java

License:Open Source License

private VariableReference getVariableReferenceInternally(IVariableBinding varBinding) {
    VariableReference varRef = currentMethodVars.get(varBinding.toString());
    if (varRef != null) {
        return varRef;
    }/*from  w w w.  j  a va 2 s . c o  m*/
    varRef = fieldVars.get(varBinding.toString());
    if (varRef != null) {
        return varRef;
    }
    if (parent != null) {
        return parent.getVariableReferenceInternally(varBinding);
    }
    return null;
}

From source file:org.incha.core.jswingripples.parser.BindingSupport.java

License:Open Source License

private String asString(final IVariableBinding variableBinding) {
    if (!variableBinding.isField())
        return variableBinding.toString();
    if (variableBinding.getDeclaringClass() == null) {
        Assert.isTrue(variableBinding.getName().equals("length"));//$NON-NLS-1$
        return ARRAY_LENGTH_FIELD_BINDING_STRING;
    }//w ww.ja  v  a  2  s .c  o m
    final StringBuffer result = new StringBuffer();
    result.append(variableBinding.getDeclaringClass().getName());
    result.append(':');
    result.append(variableBinding.getName());
    return result.toString();
}