Example usage for org.eclipse.jdt.core.dom ITypeBinding equals

List of usage examples for org.eclipse.jdt.core.dom ITypeBinding equals

Introduction

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

Prototype

@Override
public boolean equals(Object obj);

Source Link

Document

There is no special definition of equality for bindings; equality is simply object identity.

Usage

From source file:br.uff.ic.mergeguider.languageConstructs.MyTypeDeclaration.java

public List<MyVariableDeclaration> getVariableCalls(List<ClassLanguageContructs> languageContructs) {

    List<MyVariableDeclaration> calls = new ArrayList<>();

    for (ClassLanguageContructs languageContruct : languageContructs) {
        for (MyVariableDeclaration variableDeclaration : languageContruct.getVariableDeclarations()) {
            ITypeBinding typeBindingTypeDeclaration = this.getTypeDeclaration().resolveBinding();
            ITypeBinding typeBindingVariableDeclaration = variableDeclaration.resolveTypeBinding();
            if (typeBindingTypeDeclaration.equals(typeBindingVariableDeclaration)) {
                calls.add(variableDeclaration);
            }//from   w ww. j  av a2 s  . com
        }
    }

    return calls;
}

From source file:br.uff.ic.mergeguider.MergeGuider.java

public static boolean sameTypeDeclaration(MyTypeDeclaration typeDeclaration,
        MyVariableDeclaration variableDeclaration) {

    ITypeBinding typeDeclarationBinding = typeDeclaration.getTypeDeclaration().resolveBinding();
    ITypeBinding variableDeclarationBinding = variableDeclaration.resolveTypeBinding();

    if (typeDeclarationBinding != null && variableDeclarationBinding != null
            && typeDeclarationBinding.equals(variableDeclarationBinding)) {
        return true;
    } else {//from   w w  w .j a  v  a 2 s  . c o m
        return false;
    }
}

From source file:br.uff.ic.mergeguider.MergeGuider.java

public static boolean sameTypeDeclaration(MyTypeDeclaration typeDeclaration,
        MyAttributeDeclaration attributeDeclaration) {

    ITypeBinding typeDeclarationBinding = typeDeclaration.getTypeDeclaration().resolveBinding();
    IBinding variableDeclarationBinding = attributeDeclaration.resolveTypeBinding();

    if (typeDeclarationBinding != null && variableDeclarationBinding != null
            && typeDeclarationBinding.equals(variableDeclarationBinding)) {
        return true;
    } else {//from ww  w . j a va 2 s .  c  o m
        return false;
    }
}

From source file:br.uff.ic.mergeguider.MergeGuider.java

public static boolean sameTypeDeclaration(MyTypeDeclaration typeDeclaration, SimpleType interfaace) {

    ITypeBinding typeDeclarationBinding = typeDeclaration.getTypeDeclaration().resolveBinding();
    ITypeBinding variableDeclarationBinding = interfaace.resolveBinding();

    if (typeDeclarationBinding != null && variableDeclarationBinding != null
            && typeDeclarationBinding.equals(variableDeclarationBinding)) {
        return true;
    } else {//from w w w  . j  a  va  2 s .  c  om
        return false;
    }
}

From source file:br.uff.ic.mergeguider.MergeGuider.java

public static boolean sameAnnotation(MyAnnotationDeclaration annotationDeclaration,
        MyAnnotationUsage annotationUsage) {

    ITypeBinding annotationDeclarationBinding = annotationDeclaration.resolveTypeBinding();
    ITypeBinding annotationUsageBinding = annotationUsage.resolveTypeBinding();

    if (annotationDeclarationBinding != null && annotationUsageBinding != null
            && annotationDeclarationBinding.equals(annotationUsageBinding)) {
        return true;
    } else {/* w  w  w  . j  av  a  2  s  . c  o m*/
        return false;
    }
}

From source file:com.google.devtools.j2cpp.gen.CppStatementGenerator.java

License:Open Source License

@Override
public boolean visit(ConditionalExpression node) {
    boolean castNeeded = false;
    boolean castPrinted = false;
    ITypeBinding nodeType = Types.getTypeBinding(node);
    ITypeBinding thenType = Types.getTypeBinding(node.getThenExpression());
    ITypeBinding elseType = Types.getTypeBinding(node.getElseExpression());

    if (!thenType.equals(elseType) && !(node.getThenExpression() instanceof NullLiteral)
            && !(node.getElseExpression() instanceof NullLiteral)) {
        // gcc fails to compile a conditional expression where the two clauses of
        // the expression have differnt type. So cast the expressions to the type
        // of the node, which is guaranteed to be a valid cast.
        castNeeded = true;//from w  w w  . ja v  a  2 s .c  o m
    }

    node.getExpression().accept(this);

    buffer.append(" ? ");
    if (castNeeded) {
        castPrinted = printCast(nodeType);
    }
    node.getThenExpression().accept(this);
    if (castPrinted) {
        buffer.append(')');
    }

    buffer.append(" : ");
    if (castNeeded) {
        castPrinted = printCast(nodeType);
    }
    node.getElseExpression().accept(this);
    if (castPrinted) {
        buffer.append(')');
    }

    return false;
}

From source file:com.google.devtools.j2cpp.translate.Autoboxer.java

License:Open Source License

@Override
public void endVisit(Assignment node) {
    Expression lhs = node.getLeftHandSide();
    ITypeBinding lhType = getBoxType(lhs);
    Expression rhs = node.getRightHandSide();
    ITypeBinding rhType = getBoxType(rhs);
    Assignment.Operator op = node.getOperator();
    if (op != Assignment.Operator.ASSIGN && !lhType.isPrimitive()
            && !lhType.equals(node.getAST().resolveWellKnownType("java.lang.String"))) {
        // Not a simple assignment; need to break the <operation>-WITH_ASSIGN
        // assignment apart.
        node.setOperator(Assignment.Operator.ASSIGN);
        node.setRightHandSide(box(newInfixExpression(lhs, rhs, op, lhType)));
    } else {// w ww.  ja  v  a  2 s.  c om
        if (lhType.isPrimitive() && !rhType.isPrimitive()) {
            node.setRightHandSide(unbox(rhs));
        } else if (!lhType.isPrimitive() && rhType.isPrimitive()) {
            node.setRightHandSide(box(rhs));
        }
    }
}

From source file:com.google.devtools.j2cpp.translate.DeadCodeEliminator.java

License:Open Source License

/**
 * Determines whether a type is visible in the scope of the specified context.
 *//*www .j  av  a 2s . c o  m*/
private boolean inScope(ITypeBinding type, ITypeBinding context) {
    return context.equals(type) || context.getSuperclass() != null && inScope(type, context.getSuperclass())
            || Iterables.any(Arrays.asList(context.getDeclaredTypes()), Predicates.equalTo(type));
}

From source file:com.google.devtools.j2cpp.translate.Rewriter.java

License:Open Source License

/**
 * Rewrites String.format()'s format string to be iOS-compatible.
 *
 * @return true if the node was rewritten
 *///from   ww  w  .j a va  2 s .  c o m
private boolean rewriteStringFormat(MethodInvocation node) {
    IMethodBinding binding = node.resolveMethodBinding();
    if (binding == null) {
        // No binding due to error already reported.
        return false;
    }
    ITypeBinding typeBinding = binding.getDeclaringClass();
    AST ast = node.getAST();
    if (typeBinding.equals(ast.resolveWellKnownType("java.lang.String"))
            && binding.getName().equals("format")) {

        @SuppressWarnings("unchecked")
        List<Expression> args = node.arguments();
        if (args.isEmpty()) {
            return false;
        }
        Expression first = args.get(0);
        typeBinding = first.resolveTypeBinding();
        if (typeBinding.getQualifiedName().equals("java.util.Locale")) {
            args.remove(0); // discard locale parameter
            first = args.get(0);
            typeBinding = first.resolveTypeBinding();
        }
        if (first instanceof StringLiteral) {
            String format = ((StringLiteral) first).getLiteralValue();
            String convertedFormat = convertStringFormatString(format);
            if (!format.equals(convertedFormat)) {
                StringLiteral newLiteral = ast.newStringLiteral();
                newLiteral.setLiteralValue(convertedFormat);
                Types.addBinding(newLiteral, ast.resolveWellKnownType("java.lang.String"));
                args.set(0, newLiteral);
            }
            return true;
        }
    }
    return false;
}

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

License:Open Source License

@Override
public boolean visit(ClassInstanceCreation node) {
    addReference(node.getType());/*www  . jav  a2 s  . c  o m*/
    IMethodBinding binding = Types.getMethodBinding(node);
    if (binding != null) {
        ITypeBinding[] parameterTypes = binding.getParameterTypes();
        for (int i = 0; i < node.arguments().size(); i++) {

            ITypeBinding parameterType;
            if (i < parameterTypes.length) {
                parameterType = parameterTypes[i];
            } else {
                parameterType = parameterTypes[parameterTypes.length - 1];
            }
            ITypeBinding actualType = Types.getTypeBinding(node.arguments().get(i));
            if (!parameterType.equals(actualType) && actualType.isAssignmentCompatible(parameterType)) {
                addReference(actualType);
            }
        }
    }
    return super.visit(node);
}