Search in sources :

Example 41 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(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 42 with ConstraintVariable2

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

the class InferTypeArgumentsConstraintsSolver method processConstraints.

/**
	 * Given a list of <code>ITypeConstraint2</code>s that all refer to a
	 * given <code>ConstraintVariable2</code> (whose type bound has presumably
	 * just changed), process each <code>ITypeConstraint</code>, propagating
	 * the type bound across the constraint as needed.
	 *
	 * @param usedIn the <code>List</code> of <code>ITypeConstraint2</code>s
	 * to process
	 */
private void processConstraints(List<ITypeConstraint2> usedIn) {
    Iterator<ITypeConstraint2> iter = usedIn.iterator();
    while (iter.hasNext()) {
        ITypeConstraint2 tc = iter.next();
        maintainSimpleConstraint(tc);
    //TODO: prune tcs which cannot cause further changes
    // Maybe these should be pruned after a special first loop over all ConstraintVariables,
    // Since this can only happen once for every CV in the work list.
    //				if (isConstantConstraint(stc))
    //					fTypeConstraintFactory.removeUsedIn(stc, changedCv);
    }
}
Also used : ITypeConstraint2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ITypeConstraint2)

Example 43 with ConstraintVariable2

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

the class InferTypeArgumentsConstraintsSolver method findCastsToRemove.

private void findCastsToRemove(CastVariable2[] castVariables) {
    for (int i = 0; i < castVariables.length; i++) {
        CastVariable2 castCv = castVariables[i];
        ConstraintVariable2 expressionVariable = castCv.getExpressionVariable();
        TType chosenType = InferTypeArgumentsConstraintsSolver.getChosenType(expressionVariable);
        TType castType = castCv.getType();
        TType expressionType = expressionVariable.getType();
        if (chosenType != null && TTypes.canAssignTo(chosenType, castType)) {
            if (chosenType.equals(expressionType))
                // The type has not changed. Don't remove the cast, since it could be
                continue;
            // there to get access to default-visible members or to
            // unify types of conditional expressions.
            fUpdate.addCastToRemove(castCv);
        } else if (expressionVariable instanceof ArrayTypeVariable2 && castType.isArrayType()) {
            // bug 97258
            ArrayElementVariable2 arrayElementCv = fTCModel.getArrayElementVariable(expressionVariable);
            if (arrayElementCv == null)
                continue;
            TType chosenArrayElementType = InferTypeArgumentsConstraintsSolver.getChosenType(arrayElementCv);
            if (chosenArrayElementType != null && TTypes.canAssignTo(chosenArrayElementType, ((ArrayType) castType).getComponentType())) {
                if (expressionType instanceof ArrayType && chosenArrayElementType.equals(((ArrayType) expressionType).getComponentType()))
                    // The type has not changed. Don't remove the cast, since it could be
                    continue;
                // there to unify types of conditional expressions.
                fUpdate.addCastToRemove(castCv);
            }
        }
    }
}
Also used : ArrayType(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.ArrayType) CastVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.CastVariable2) ArrayTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ArrayTypeVariable2) TType(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TType) ConstraintVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2) ArrayElementVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ArrayElementVariable2)

Example 44 with ConstraintVariable2

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

the class InferTypeArgumentsConstraintsSolver method initializeTypeEstimates.

private void initializeTypeEstimates(ConstraintVariable2[] allConstraintVariables) {
    for (int i = 0; i < allConstraintVariables.length; i++) {
        ConstraintVariable2 cv = allConstraintVariables[i];
        //TODO: not necessary for types that are not used in a TypeConstraint but only as type in CollectionElementVariable
        //TODO: handle nested element variables; see ParametricStructureComputer.createAndInitVars()
        TypeEquivalenceSet set = cv.getTypeEquivalenceSet();
        if (set == null) {
            set = new TypeEquivalenceSet(cv);
            set.setTypeEstimate(createInitialEstimate(cv));
            cv.setTypeEquivalenceSet(set);
        } else {
            TypeSet typeEstimate = (TypeSet) cv.getTypeEstimate();
            if (typeEstimate == null) {
                ConstraintVariable2[] cvs = set.getContributingVariables();
                typeEstimate = fTypeSetEnvironment.getUniverseTypeSet();
                for (//TODO: optimize: just try to find an immutable CV; if not found, use Universe
                int j = 0; //TODO: optimize: just try to find an immutable CV; if not found, use Universe
                j < cvs.length; //TODO: optimize: just try to find an immutable CV; if not found, use Universe
                j++) typeEstimate = typeEstimate.intersectedWith(createInitialEstimate(cvs[j]));
                set.setTypeEstimate(typeEstimate);
            }
        }
    }
}
Also used : EnumeratedTypeSet(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.EnumeratedTypeSet) SingletonTypeSet(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.SingletonTypeSet) TypeSet(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet) TypeEquivalenceSet(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.TypeEquivalenceSet) ConstraintVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2)

Example 45 with ConstraintVariable2

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

the class InferTypeArgumentsConstraintsSolver method getChosenType.

public static TType getChosenType(ConstraintVariable2 cv) {
    TType type = (TType) cv.getData(CHOSEN_TYPE);
    if (type != null)
        return type;
    TypeEquivalenceSet set = cv.getTypeEquivalenceSet();
    if (set == null) {
        //TODO: should not have to set this here. Clean up when caching chosen type
        return null;
    //			// no representative == no restriction
    //			set= new TypeEquivalenceSet(cv);
    //			set.setTypeEstimate(TypeUniverseSet.create());
    //			cv.setTypeEquivalenceSet(set);
    }
    return cv.getTypeEstimate().chooseSingleType();
}
Also used : TType(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TType) TypeEquivalenceSet(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.TypeEquivalenceSet)

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