Search in sources :

Example 1 with VariableVariable2

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

the class InferTypeArgumentsConstraintCreator method endVisit.

@Override
public void endVisit(SimpleName node) {
    if (node.resolveBoxing()) {
        ImmutableTypeVariable2 boxed = fTCModel.makeImmutableTypeVariable(node.resolveTypeBinding(), node);
        setConstraintVariable(node, boxed);
        return;
    }
    IBinding binding = node.resolveBinding();
    if (binding instanceof IVariableBinding) {
        //TODO: code is similar to handling of method return value
        IVariableBinding variableBinding = (IVariableBinding) binding;
        ITypeBinding declaredVariableType = variableBinding.getVariableDeclaration().getType();
        if (declaredVariableType.isTypeVariable()) {
            Expression receiver = getSimpleNameReceiver(node);
            if (receiver != null) {
                ConstraintVariable2 receiverCv = getConstraintVariable(receiver);
                // the type variable must come from the receiver!
                Assert.isNotNull(receiverCv);
                ConstraintVariable2 elementCv = fTCModel.getElementVariable(receiverCv, declaredVariableType);
                // [retVal] =^= Elem[receiver]:
                setConstraintVariable(node, elementCv);
                return;
            }
        } else if (declaredVariableType.isParameterizedType()) {
            Expression receiver = getSimpleNameReceiver(node);
            if (receiver != null) {
                ConstraintVariable2 receiverCv = getConstraintVariable(receiver);
                if (receiverCv != null) {
                    //						ITypeBinding genericVariableType= declaredVariableType.getTypeDeclaration();
                    ConstraintVariable2 returnTypeCv = fTCModel.makeParameterizedTypeVariable(declaredVariableType);
                    setConstraintVariable(node, returnTypeCv);
                    // Elem[retVal] =^= Elem[receiver]
                    TType declaredVariableTType = fTCModel.createTType(declaredVariableType);
                    fTCModel.createTypeVariablesEqualityConstraints(receiverCv, Collections.<String, IndependentTypeVariable2>emptyMap(), returnTypeCv, declaredVariableTType);
                    return;
                }
            }
        } else {
        //TODO: array...
        //logUnexpectedNode(node, null);
        }
        // default:
        VariableVariable2 cv = fTCModel.makeVariableVariable(variableBinding);
        setConstraintVariable(node, cv);
    }
// TODO else?
}
Also used : 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) IBinding(org.eclipse.jdt.core.dom.IBinding) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) TType(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TType) ConstraintVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2) IVariableBinding(org.eclipse.jdt.core.dom.IVariableBinding) VariableVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.VariableVariable2) IndependentTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.IndependentTypeVariable2)

Example 2 with VariableVariable2

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

the class InferTypeArgumentsConstraintCreator method visit.

@Override
public boolean visit(CatchClause node) {
    SingleVariableDeclaration exception = node.getException();
    IVariableBinding variableBinding = exception.resolveBinding();
    VariableVariable2 cv = fTCModel.makeDeclaredVariableVariable(variableBinding, fCU);
    setConstraintVariable(exception, cv);
    return true;
}
Also used : SingleVariableDeclaration(org.eclipse.jdt.core.dom.SingleVariableDeclaration) IVariableBinding(org.eclipse.jdt.core.dom.IVariableBinding) VariableVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.VariableVariable2)

Example 3 with VariableVariable2

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

the class InferTypeArgumentsConstraintCreator method endVisit.

@Override
public void endVisit(VariableDeclarationFragment node) {
    VariableVariable2 cv = fTCModel.makeDeclaredVariableVariable(node.resolveBinding(), fCU);
    if (cv == null)
        return;
    setConstraintVariable(node, cv);
    //TODO: prune unused CV for local variables (but not fields)
    Expression initializer = node.getInitializer();
    if (initializer == null)
        return;
    ConstraintVariable2 initializerCv = getConstraintVariable(initializer);
    if (initializerCv == null)
        return;
    fTCModel.createElementEqualsConstraints(cv, initializerCv);
// name= initializer  -->  [initializer] <= [name]
//		if (initializerCv instanceof CollectionElementVariable2)
//			fTCModel.createSubtypeConstraint(initializerCv, cv);
}
Also used : 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) VariableVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.VariableVariable2)

Example 4 with VariableVariable2

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

the class InferTypeArgumentsTCModel method makeVariableVariable.

public VariableVariable2 makeVariableVariable(IVariableBinding variableBinding) {
    if (variableBinding == null)
        return null;
    TType type = getBoxedType(variableBinding.getType(), /*no boxing*/
    null);
    if (type == null)
        return null;
    VariableVariable2 cv = new VariableVariable2(type, variableBinding);
    VariableVariable2 storedCv = (VariableVariable2) storedCv(cv);
    if (storedCv == cv) {
        if (!variableBinding.isField() || Modifier.isPrivate(variableBinding.getModifiers()))
            fCuScopedConstraintVariables.add(storedCv);
        makeElementVariables(storedCv, type);
        makeArrayElementVariable(storedCv);
        if (fStoreToString)
            storedCv.setData(ConstraintVariable2.TO_STRING, '[' + variableBinding.getName() + ']');
    }
    return storedCv;
}
Also used : TType(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TType) VariableVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.VariableVariable2)

Example 5 with VariableVariable2

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

the class InferTypeArgumentsTCModel method makeDeclaredVariableVariable.

public VariableVariable2 makeDeclaredVariableVariable(IVariableBinding variableBinding, ICompilationUnit cu) {
    VariableVariable2 cv = makeVariableVariable(variableBinding);
    if (cv == null)
        return null;
    cv.setCompilationUnit(cu);
    return cv;
}
Also used : VariableVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.VariableVariable2)

Aggregations

VariableVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.VariableVariable2)5 CastExpression (org.eclipse.jdt.core.dom.CastExpression)2 ConditionalExpression (org.eclipse.jdt.core.dom.ConditionalExpression)2 Expression (org.eclipse.jdt.core.dom.Expression)2 IVariableBinding (org.eclipse.jdt.core.dom.IVariableBinding)2 ParenthesizedExpression (org.eclipse.jdt.core.dom.ParenthesizedExpression)2 ThisExpression (org.eclipse.jdt.core.dom.ThisExpression)2 VariableDeclarationExpression (org.eclipse.jdt.core.dom.VariableDeclarationExpression)2 TType (org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TType)2 ConstraintVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2)2 IBinding (org.eclipse.jdt.core.dom.IBinding)1 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)1 SingleVariableDeclaration (org.eclipse.jdt.core.dom.SingleVariableDeclaration)1 ImmutableTypeVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ImmutableTypeVariable2)1 IndependentTypeVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.IndependentTypeVariable2)1