Search in sources :

Example 26 with ConstraintVariable2

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

the class InferTypeArgumentsConstraintCreator method endVisit.

@Override
public void endVisit(CastExpression node) {
    //		if (! (expressionCv instanceof CollectionElementVariable2))
    //			return; //TODO: returns too early when dealing with nested collections.
    Type type = node.getType();
    ITypeBinding typeBinding = type.resolveBinding();
    if (typeBinding.isPrimitive()) {
        ImmutableTypeVariable2 boxed = fTCModel.makeImmutableTypeVariable(typeBinding, node);
        setConstraintVariable(node, boxed);
        // avoid removing numeric conversions
        return;
    }
    ConstraintVariable2 typeCv = getConstraintVariable(type);
    if (typeCv == null)
        return;
    //TODO: can this be loosened when we remove casts?
    setConstraintVariable(node, typeCv);
    Expression expression = node.getExpression();
    ConstraintVariable2 expressionCv = getConstraintVariable(expression);
    //Avoid removing casts that have not been made obsolete by this refactoring:
    if (expressionCv == null)
        return;
    if (expressionCv instanceof ImmutableTypeVariable2)
        return;
    if (!(expressionCv instanceof TypeVariable2 || expressionCv instanceof IndependentTypeVariable2 || expressionCv instanceof CollectionElementVariable2) && fTCModel.getElementVariables(expressionCv).size() == 0 && fTCModel.getArrayElementVariable(expressionCv) == null)
        return;
    fTCModel.createAssignmentElementConstraints(typeCv, expressionCv);
    if (expression instanceof MethodInvocation) {
        MethodInvocation invoc = (MethodInvocation) expression;
        if (!isSpecialCloneInvocation(invoc.resolveMethodBinding(), invoc.getExpression())) {
            fTCModel.makeCastVariable(node, expressionCv);
        }
    } else {
        fTCModel.makeCastVariable(node, expressionCv);
    }
    boolean eitherIsIntf = typeBinding.isInterface() || expression.resolveTypeBinding().isInterface();
    if (eitherIsIntf)
        return;
//TODO: preserve up- and down-castedness!
}
Also used : GenericType(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.GenericType) ParameterizedType(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.ParameterizedType) WildcardType(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.WildcardType) ArrayType(org.eclipse.jdt.core.dom.ArrayType) Type(org.eclipse.jdt.core.dom.Type) TType(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TType) ImmutableTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ImmutableTypeVariable2) CollectionElementVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.CollectionElementVariable2) 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) ParameterTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ParameterTypeVariable2) TypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.TypeVariable2) IndependentTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.IndependentTypeVariable2) ParameterizedTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ParameterizedTypeVariable2) ImmutableTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ImmutableTypeVariable2) ReturnTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ReturnTypeVariable2) MethodInvocation(org.eclipse.jdt.core.dom.MethodInvocation) ConstraintVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2) IndependentTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.IndependentTypeVariable2)

Example 27 with ConstraintVariable2

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

the class InferTypeArgumentsConstraintCreator method endVisit.

@Override
public void endVisit(FieldAccess node) {
    if (node.resolveBoxing()) {
        ImmutableTypeVariable2 boxed = fTCModel.makeImmutableTypeVariable(node.resolveTypeBinding(), node);
        setConstraintVariable(node, boxed);
        return;
    }
    ConstraintVariable2 nameCv = getConstraintVariable(node.getName());
    setConstraintVariable(node, nameCv);
}
Also used : ImmutableTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ImmutableTypeVariable2) ConstraintVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2)

Example 28 with ConstraintVariable2

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

the class InferTypeArgumentsConstraintCreator method endVisitFieldVariableDeclaration.

private void endVisitFieldVariableDeclaration(Type type, List<VariableDeclarationFragment> list) {
    ConstraintVariable2 typeCv = getConstraintVariable(type);
    if (typeCv == null)
        return;
    for (Iterator<VariableDeclarationFragment> iter = list.iterator(); iter.hasNext(); ) {
        VariableDeclarationFragment fragment = iter.next();
        ConstraintVariable2 fragmentCv = getConstraintVariable(fragment);
        fTCModel.createElementEqualsConstraints(typeCv, fragmentCv);
    }
}
Also used : VariableDeclarationFragment(org.eclipse.jdt.core.dom.VariableDeclarationFragment) ConstraintVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2)

Example 29 with ConstraintVariable2

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

the class InferTypeArgumentsConstraintCreator method addConstraintsForOverriding.

private void addConstraintsForOverriding(IMethodBinding methodBinding, ConstraintVariable2 returnTypeCv, ConstraintVariable2[] parameterTypeCvs) {
    boolean hasParameterElementCvs = false;
    for (int i = 0; i < parameterTypeCvs.length; i++) if (parameterTypeCvs[i] != null)
        hasParameterElementCvs = true;
    if (returnTypeCv == null && !hasParameterElementCvs)
        return;
    ITypeBinding[] allSuperTypes = Bindings.getAllSuperTypes(methodBinding.getDeclaringClass());
    for (int i = 0; i < allSuperTypes.length; i++) {
        ITypeBinding superType = allSuperTypes[i];
        IMethodBinding superMethod = Bindings.findOverriddenMethodInType(superType, methodBinding);
        if (superMethod == null)
            continue;
        for (int p = 0; p < parameterTypeCvs.length; p++) {
            if (parameterTypeCvs[p] == null)
                continue;
            ParameterTypeVariable2 parameterTypeCv = fTCModel.makeParameterTypeVariable(superMethod, p);
            fTCModel.createElementEqualsConstraints(parameterTypeCv, parameterTypeCvs[p]);
        }
        if (returnTypeCv != null) {
            ReturnTypeVariable2 superMethodReturnTypeCv = fTCModel.makeReturnTypeVariable(superMethod);
            fTCModel.createElementEqualsConstraints(superMethodReturnTypeCv, returnTypeCv);
        }
    }
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) ParameterTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ParameterTypeVariable2) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) ReturnTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ReturnTypeVariable2)

Example 30 with ConstraintVariable2

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

the class ParametricStructureComputer method initializeContainerStructure.

//TODO hard-wired to collections
private void initializeContainerStructure() {
    if (DEBUG_INITIALIZATION)
        //$NON-NLS-1$
        System.out.println("  *** Seeding container structure ***");
    for (int i = 0; i < fAllConstraintVariables.length; i++) {
        ConstraintVariable2 v = fAllConstraintVariables[i];
        TType varType = declaredTypeOf(v);
        if (varType != null) {
            // List<String> to a binary method taking a raw List.
            if (isParametricType(varType) && !isUnmodifiableFieldOrMethod(v)) {
                //$NON-NLS-1$
                if (DEBUG_INITIALIZATION)
                    System.out.println("Entity has           container structure: " + v);
                setStructureAndPush(v, newParametricType(varType));
            } else if (!mightBeParametric(varType)) {
                //$NON-NLS-1$
                if (DEBUG_INITIALIZATION)
                    System.out.println("Entity DOES NOT have container structure: " + v);
                setStructureAndPush(v, ParametricStructure.NONE);
            }
        // else we're not sure yet whether this has container structure
        } else {
        //				TType exprType= v.getType(); // TODO: always null!
        //
        //				if (isArrayAccess(v)) {
        //					if (DEBUG_INITIALIZATION) System.out.println("Entity DOES NOT have container structure: " + v);
        //					setStructureAndPush(v, NO_STRUCTURE); // definitely not container structure, Java 1.5 says no generics inside arrays
        //				} else if (isParametricType(exprType)) {
        //					if (DEBUG_INITIALIZATION) System.out.println("Entity has           container structure: " + v);
        //					setStructureAndPush(v, newParametricType(exprType));
        //				} else if (exprType != null && !mightBeParametric(exprType)) {
        //					// Not a supertype of any container type - can't have container structure
        //					if (DEBUG_INITIALIZATION) System.out.println("Entity DOES NOT have container structure: " + v);
        //					setStructureAndPush(v, NO_STRUCTURE);
        //				}
        // TODO Markus: the following just updates the set of child element variables of the parent variable of 'v'.
        // You already maintain this information automatically, so the code below is not needed...
        //				if (v instanceof CollectionElementVariable2) {
        //					CollectionElementVariable2 ev= (CollectionElementVariable2) v;
        //					int idx= ev.getDeclarationTypeVariableIndex(); //TODO : INDEX IS -1 IF THE TYPE VARIABLE COMES FROM A SUPERTYPE!!!
        //
        //					Collection/*<ConstraintVariable2>*/ vars= fTCModel.getElementVariables(ev).values();
        //
        //					if (vars == null) vars= new ConstraintVariable2[ev.getNumContainerTypeParams()];
        //					vars[idx]= ev;
        //					fVariableElementEnv.setElementVariables(ev.getParentConstraintVariable(), vars);
        //				}
        // else we're not sure yet whether this has container structure
        }
    }
// Every variable v in fAllVariables is now in one of 3 states:
//  - elemStructure(v) == some parametric type:       definitely container structure, but we may not know the sub-structure yet
//  - elemStructure(v) == some AbstractTypeParameter: definitely not container structure
//  - elemStructure(v) == null:                       we know nothing yet about its structure
}
Also used : TType(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TType) ConstraintVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2)

Aggregations

ConstraintVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2)32 TType (org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TType)20 CollectionElementVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.CollectionElementVariable2)16 ImmutableTypeVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ImmutableTypeVariable2)11 CastExpression (org.eclipse.jdt.core.dom.CastExpression)9 Expression (org.eclipse.jdt.core.dom.Expression)9 ParenthesizedExpression (org.eclipse.jdt.core.dom.ParenthesizedExpression)9 ConditionalExpression (org.eclipse.jdt.core.dom.ConditionalExpression)8 ThisExpression (org.eclipse.jdt.core.dom.ThisExpression)8 VariableDeclarationExpression (org.eclipse.jdt.core.dom.VariableDeclarationExpression)8 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)7 GenericType (org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.GenericType)7 ArrayElementVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ArrayElementVariable2)7 TypeEquivalenceSet (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.TypeEquivalenceSet)7 IMethodBinding (org.eclipse.jdt.core.dom.IMethodBinding)5 ParameterizedType (org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.ParameterizedType)5 ITypeConstraint2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ITypeConstraint2)5 IndependentTypeVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.IndependentTypeVariable2)5 ParameterTypeVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ParameterTypeVariable2)5 ReturnTypeVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ReturnTypeVariable2)5