Search in sources :

Example 71 with IMethodBinding

use of org.eclipse.jdt.core.dom.IMethodBinding in project che by eclipse.

the class FullConstraintCreator method create.

/* (non-Javadoc)
	 * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.MethodDeclaration)
	 */
@Override
public ITypeConstraint[] create(MethodDeclaration declaration) {
    List<ITypeConstraint> result = new ArrayList<ITypeConstraint>();
    IMethodBinding methodBinding = declaration.resolveBinding();
    if (methodBinding == null)
        return new ITypeConstraint[0];
    ITypeConstraint[] constraints = fTypeConstraintFactory.createDefinesConstraint(fConstraintVariableFactory.makeDeclaringTypeVariable(methodBinding), fConstraintVariableFactory.makeRawBindingVariable(methodBinding.getDeclaringClass()));
    result.addAll(Arrays.asList(constraints));
    if (!methodBinding.isConstructor() && !methodBinding.getReturnType().isPrimitive()) {
        ConstraintVariable returnTypeBindingVariable = fConstraintVariableFactory.makeReturnTypeVariable(methodBinding);
        ConstraintVariable returnTypeVariable = fConstraintVariableFactory.makeTypeVariable(declaration.getReturnType2());
        ITypeConstraint[] defines = fTypeConstraintFactory.createDefinesConstraint(returnTypeBindingVariable, returnTypeVariable);
        result.addAll(Arrays.asList(defines));
    }
    for (int i = 0, n = declaration.parameters().size(); i < n; i++) {
        SingleVariableDeclaration paramDecl = (SingleVariableDeclaration) declaration.parameters().get(i);
        ConstraintVariable parameterTypeVariable = fConstraintVariableFactory.makeParameterTypeVariable(methodBinding, i);
        ConstraintVariable parameterNameVariable = fConstraintVariableFactory.makeExpressionOrTypeVariable(paramDecl.getName(), getContext());
        ITypeConstraint[] constraint = fTypeConstraintFactory.createDefinesConstraint(parameterTypeVariable, parameterNameVariable);
        result.addAll(Arrays.asList(constraint));
    }
    if (MethodChecks.isVirtual(methodBinding)) {
        Collection<ITypeConstraint> constraintsForOverriding = getConstraintsForOverriding(methodBinding);
        result.addAll(constraintsForOverriding);
    }
    return result.toArray(new ITypeConstraint[result.size()]);
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) SingleVariableDeclaration(org.eclipse.jdt.core.dom.SingleVariableDeclaration) ArrayList(java.util.ArrayList)

Example 72 with IMethodBinding

use of org.eclipse.jdt.core.dom.IMethodBinding in project che by eclipse.

the class FullConstraintCreator method getRootDefs.

//--- RootDef ----//
protected static IMethodBinding[] getRootDefs(IMethodBinding methodBinding) {
    Set<ITypeBinding> declaringSuperTypes = getDeclaringSuperTypes(methodBinding);
    Set<IMethodBinding> result = new LinkedHashSet<IMethodBinding>();
    for (Iterator<ITypeBinding> iter = declaringSuperTypes.iterator(); iter.hasNext(); ) {
        ITypeBinding type = iter.next();
        if (!containsASuperType(type, declaringSuperTypes))
            result.add(findMethod(methodBinding, type));
    }
    if (result.size() == 0) {
        result.add(methodBinding);
    }
    return result.toArray(new IMethodBinding[result.size()]);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding)

Example 73 with IMethodBinding

use of org.eclipse.jdt.core.dom.IMethodBinding in project che by eclipse.

the class FullConstraintCreator method create.

/* (non-Javadoc)
	 * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.MethodInvocation)
	 */
@Override
public ITypeConstraint[] create(MethodInvocation invocation) {
    List<Expression> arguments = invocation.arguments();
    List<ITypeConstraint> result = new ArrayList<ITypeConstraint>(arguments.size());
    IMethodBinding methodBinding = invocation.resolveMethodBinding();
    if (methodBinding == null)
        return new ITypeConstraint[0];
    ITypeConstraint[] returnTypeConstraint = getReturnTypeConstraint(invocation, methodBinding);
    result.addAll(Arrays.asList(returnTypeConstraint));
    result.addAll(Arrays.asList(getArgumentConstraints(arguments, methodBinding)));
    if (invocation.getExpression() != null) {
        if (MethodChecks.isVirtual(methodBinding)) {
            IMethodBinding[] rootDefs = getRootDefs(methodBinding);
            Assert.isTrue(rootDefs.length > 0);
            ConstraintVariable expressionVar = fConstraintVariableFactory.makeExpressionOrTypeVariable(invocation.getExpression(), getContext());
            if (rootDefs.length == 1) {
                result.addAll(Arrays.asList(fTypeConstraintFactory.createSubtypeConstraint(expressionVar, fConstraintVariableFactory.makeDeclaringTypeVariable(rootDefs[0]))));
            } else {
                Collection<ITypeConstraint> constraints = new ArrayList<ITypeConstraint>();
                for (int i = 0; i < rootDefs.length; i++) {
                    ConstraintVariable rootDefTypeVar = fConstraintVariableFactory.makeDeclaringTypeVariable(rootDefs[i]);
                    ITypeConstraint[] tc = fTypeConstraintFactory.createSubtypeConstraint(expressionVar, rootDefTypeVar);
                    constraints.addAll(Arrays.asList(tc));
                }
                ITypeConstraint[] constraintsArray = constraints.toArray(new ITypeConstraint[constraints.size()]);
                if (constraintsArray.length > 0) {
                    result.add(fTypeConstraintFactory.createCompositeOrTypeConstraint(constraintsArray));
                }
            }
        } else {
            ConstraintVariable typeVar = fConstraintVariableFactory.makeDeclaringTypeVariable(methodBinding);
            ConstraintVariable expressionVar = fConstraintVariableFactory.makeExpressionOrTypeVariable(invocation.getExpression(), getContext());
            result.addAll(Arrays.asList(fTypeConstraintFactory.createSubtypeConstraint(expressionVar, typeVar)));
        }
    }
    return result.toArray(new ITypeConstraint[result.size()]);
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) ConditionalExpression(org.eclipse.jdt.core.dom.ConditionalExpression) InstanceofExpression(org.eclipse.jdt.core.dom.InstanceofExpression) ThisExpression(org.eclipse.jdt.core.dom.ThisExpression) Expression(org.eclipse.jdt.core.dom.Expression) ParenthesizedExpression(org.eclipse.jdt.core.dom.ParenthesizedExpression) CastExpression(org.eclipse.jdt.core.dom.CastExpression) VariableDeclarationExpression(org.eclipse.jdt.core.dom.VariableDeclarationExpression) ArrayList(java.util.ArrayList)

Example 74 with IMethodBinding

use of org.eclipse.jdt.core.dom.IMethodBinding in project che by eclipse.

the class FullConstraintCreator method create.

/* (non-Javadoc)
	 * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.ClassInstanceCreation)
	 */
@Override
public ITypeConstraint[] create(ClassInstanceCreation instanceCreation) {
    List<Expression> arguments = instanceCreation.arguments();
    List<ITypeConstraint> result = new ArrayList<ITypeConstraint>(arguments.size());
    IMethodBinding methodBinding = instanceCreation.resolveConstructorBinding();
    result.addAll(Arrays.asList(getArgumentConstraints(arguments, methodBinding)));
    if (instanceCreation.getAnonymousClassDeclaration() == null) {
        ConstraintVariable constructorVar = fConstraintVariableFactory.makeExpressionOrTypeVariable(instanceCreation, getContext());
        ConstraintVariable typeVar = fConstraintVariableFactory.makeRawBindingVariable(instanceCreation.resolveTypeBinding());
        result.addAll(Arrays.asList(fTypeConstraintFactory.createDefinesConstraint(constructorVar, typeVar)));
    }
    return result.toArray(new ITypeConstraint[result.size()]);
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) ConditionalExpression(org.eclipse.jdt.core.dom.ConditionalExpression) InstanceofExpression(org.eclipse.jdt.core.dom.InstanceofExpression) ThisExpression(org.eclipse.jdt.core.dom.ThisExpression) Expression(org.eclipse.jdt.core.dom.Expression) ParenthesizedExpression(org.eclipse.jdt.core.dom.ParenthesizedExpression) CastExpression(org.eclipse.jdt.core.dom.CastExpression) VariableDeclarationExpression(org.eclipse.jdt.core.dom.VariableDeclarationExpression) ArrayList(java.util.ArrayList)

Example 75 with IMethodBinding

use of org.eclipse.jdt.core.dom.IMethodBinding in project che by eclipse.

the class FullConstraintCreator method create.

/* (non-Javadoc)
	 * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.SuperConstructorInvocation)
	 */
@Override
public ITypeConstraint[] create(SuperConstructorInvocation invocation) {
    List<Expression> arguments = invocation.arguments();
    List<ITypeConstraint> result = new ArrayList<ITypeConstraint>(arguments.size());
    IMethodBinding methodBinding = invocation.resolveConstructorBinding();
    result.addAll(Arrays.asList(getArgumentConstraints(arguments, methodBinding)));
    return result.toArray(new ITypeConstraint[result.size()]);
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) ConditionalExpression(org.eclipse.jdt.core.dom.ConditionalExpression) InstanceofExpression(org.eclipse.jdt.core.dom.InstanceofExpression) ThisExpression(org.eclipse.jdt.core.dom.ThisExpression) Expression(org.eclipse.jdt.core.dom.Expression) ParenthesizedExpression(org.eclipse.jdt.core.dom.ParenthesizedExpression) CastExpression(org.eclipse.jdt.core.dom.CastExpression) VariableDeclarationExpression(org.eclipse.jdt.core.dom.VariableDeclarationExpression) ArrayList(java.util.ArrayList)

Aggregations

IMethodBinding (org.eclipse.jdt.core.dom.IMethodBinding)173 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)110 ASTNode (org.eclipse.jdt.core.dom.ASTNode)46 Expression (org.eclipse.jdt.core.dom.Expression)36 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)33 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)32 IVariableBinding (org.eclipse.jdt.core.dom.IVariableBinding)29 ArrayList (java.util.ArrayList)27 IBinding (org.eclipse.jdt.core.dom.IBinding)25 ParenthesizedExpression (org.eclipse.jdt.core.dom.ParenthesizedExpression)21 CastExpression (org.eclipse.jdt.core.dom.CastExpression)20 SimpleName (org.eclipse.jdt.core.dom.SimpleName)20 ASTRewrite (org.eclipse.jdt.core.dom.rewrite.ASTRewrite)20 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)19 MethodInvocation (org.eclipse.jdt.core.dom.MethodInvocation)19 ThisExpression (org.eclipse.jdt.core.dom.ThisExpression)19 VariableDeclarationExpression (org.eclipse.jdt.core.dom.VariableDeclarationExpression)17 Image (org.eclipse.swt.graphics.Image)16 AST (org.eclipse.jdt.core.dom.AST)15 Type (org.eclipse.jdt.core.dom.Type)15