Search in sources :

Example 16 with ImmutableTypeVariable2

use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ImmutableTypeVariable2 in project che by eclipse.

the class InferTypeArgumentsConstraintCreator method endVisit.

@Override
public void endVisit(MethodInvocation node) {
    IMethodBinding methodBinding = node.resolveMethodBinding();
    if (methodBinding == null)
        return;
    Expression receiver;
    if (JdtFlags.isStatic(methodBinding))
        receiver = null;
    else
        receiver = node.getExpression();
    if (isSpecialCloneInvocation(methodBinding, receiver)) {
        ConstraintVariable2 expressionCv = getConstraintVariable(receiver);
        // [retVal] =^= [receiver]:
        setConstraintVariable(node, expressionCv);
    } else if ("getClass".equals(methodBinding.getName()) && methodBinding.getParameterTypes().length == 0) {
        //$NON-NLS-1$
        //special case: see JLS3 4.3.2
        ITypeBinding returnType = node.resolveTypeBinding();
        ITypeBinding returnTypeDeclaration = returnType.getTypeDeclaration();
        ParameterizedTypeVariable2 expressionCv = fTCModel.makeParameterizedTypeVariable(returnTypeDeclaration);
        setConstraintVariable(node, expressionCv);
        ConstraintVariable2 classTypeVariable = fTCModel.getElementVariable(expressionCv, returnTypeDeclaration.getTypeParameters()[0]);
        //type of expression 'e.getClass()' is 'Class<? extends X>' where X is the static type of e
        ITypeBinding capture = returnType.getTypeArguments()[0];
        ITypeBinding wildcard = capture.getWildcard();
        if (wildcard.getBound() == null)
            // workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=234619
            return;
        ImmutableTypeVariable2 wildcardType = fTCModel.makeImmutableTypeVariable(wildcard, /*no boxing*/
        null);
        fTCModel.createSubtypeConstraint(classTypeVariable, wildcardType);
    //			ITypeBinding bound= wildcard.getBound();
    //			ImmutableTypeVariable2 boundType= fTCModel.makeImmutableTypeVariable(bound, node.getAST());
    //			fTCModel.createSubtypeConstraint(classTypeVariable, boundType);
    } else {
        Map<String, IndependentTypeVariable2> methodTypeVariables = createMethodTypeArguments(methodBinding);
        doVisitMethodInvocationReturnType(node, methodBinding, receiver, methodTypeVariables);
        doVisitMethodInvocationArguments(methodBinding, node.arguments(), receiver, methodTypeVariables, /*no created type*/
        null);
    }
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) ImmutableTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ImmutableTypeVariable2) ConditionalExpression(org.eclipse.jdt.core.dom.ConditionalExpression) ThisExpression(org.eclipse.jdt.core.dom.ThisExpression) Expression(org.eclipse.jdt.core.dom.Expression) CastExpression(org.eclipse.jdt.core.dom.CastExpression) VariableDeclarationExpression(org.eclipse.jdt.core.dom.VariableDeclarationExpression) ParenthesizedExpression(org.eclipse.jdt.core.dom.ParenthesizedExpression) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) ParameterizedTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ParameterizedTypeVariable2) ConstraintVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2) Map(java.util.Map) HashMap(java.util.HashMap)

Example 17 with ImmutableTypeVariable2

use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ImmutableTypeVariable2 in project che by eclipse.

the class InferTypeArgumentsConstraintCreator method endVisit.

@Override
public void endVisit(TypeLiteral node) {
    ITypeBinding typeBinding = node.resolveTypeBinding();
    ImmutableTypeVariable2 cv = fTCModel.makeImmutableTypeVariable(typeBinding, /*no boxing*/
    null);
    setConstraintVariable(node, cv);
}
Also used : ImmutableTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ImmutableTypeVariable2) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding)

Example 18 with ImmutableTypeVariable2

use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ImmutableTypeVariable2 in project che by eclipse.

the class InferTypeArgumentsConstraintCreator method endVisit.

@Override
public void endVisit(Assignment node) {
    Expression lhs = node.getLeftHandSide();
    Expression rhs = node.getRightHandSide();
    ConstraintVariable2 left = getConstraintVariable(lhs);
    ConstraintVariable2 right = getConstraintVariable(rhs);
    if (node.resolveBoxing()) {
        ImmutableTypeVariable2 boxed = fTCModel.makeImmutableTypeVariable(node.resolveTypeBinding(), node);
        setConstraintVariable(node, boxed);
    } else {
        // type of assignement is type of 'left'
        setConstraintVariable(node, left);
    }
    if (left == null || right == null)
        return;
    Assignment.Operator op = node.getOperator();
    if (op == Assignment.Operator.PLUS_ASSIGN && (lhs.resolveTypeBinding() == node.getAST().resolveWellKnownType("java.lang.String"))) {
    //$NON-NLS-1$
    //Special handling for automatic String conversion: do nothing; the RHS can be anything.
    } else {
        fTCModel.createElementEqualsConstraints(left, right);
        // left= right;  -->  [right] <= [left]
        fTCModel.createSubtypeConstraint(right, left);
    }
//TODO: other implicit conversions: numeric promotion, autoboxing?
}
Also used : Assignment(org.eclipse.jdt.core.dom.Assignment) ImmutableTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ImmutableTypeVariable2) ConditionalExpression(org.eclipse.jdt.core.dom.ConditionalExpression) ThisExpression(org.eclipse.jdt.core.dom.ThisExpression) Expression(org.eclipse.jdt.core.dom.Expression) CastExpression(org.eclipse.jdt.core.dom.CastExpression) VariableDeclarationExpression(org.eclipse.jdt.core.dom.VariableDeclarationExpression) ParenthesizedExpression(org.eclipse.jdt.core.dom.ParenthesizedExpression) ConstraintVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2)

Example 19 with ImmutableTypeVariable2

use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ImmutableTypeVariable2 in project che by eclipse.

the class InferTypeArgumentsConstraintCreator method endVisit.

@Override
public void endVisit(ConditionalExpression node) {
    // for now, no support for passing generic types through conditional expressions
    ImmutableTypeVariable2 boxed = fTCModel.makeImmutableTypeVariable(node.resolveTypeBinding(), node);
    setConstraintVariable(node, boxed);
}
Also used : ImmutableTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ImmutableTypeVariable2)

Aggregations

ImmutableTypeVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ImmutableTypeVariable2)19 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)11 ConstraintVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2)10 CastExpression (org.eclipse.jdt.core.dom.CastExpression)5 ConditionalExpression (org.eclipse.jdt.core.dom.ConditionalExpression)5 Expression (org.eclipse.jdt.core.dom.Expression)5 ParenthesizedExpression (org.eclipse.jdt.core.dom.ParenthesizedExpression)5 ThisExpression (org.eclipse.jdt.core.dom.ThisExpression)5 VariableDeclarationExpression (org.eclipse.jdt.core.dom.VariableDeclarationExpression)5 TType (org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TType)4 IndependentTypeVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.IndependentTypeVariable2)3 ParameterTypeVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ParameterTypeVariable2)3 ParameterizedTypeVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ParameterizedTypeVariable2)3 ReturnTypeVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ReturnTypeVariable2)3 ArrayType (org.eclipse.jdt.core.dom.ArrayType)2 WildcardType (org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.WildcardType)2 ArrayElementVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ArrayElementVariable2)2 CollectionElementVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.CollectionElementVariable2)2 TypeVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.TypeVariable2)2 HashMap (java.util.HashMap)1