Search in sources :

Example 16 with ConstraintVariable2

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

the class InferTypeArgumentsTCModel method pruneCvIfUnused.

private boolean pruneCvIfUnused(ConstraintVariable2 cv) {
    if (getUsedIn(cv).size() != 0)
        return false;
    if (cv.getTypeEquivalenceSet() != null) {
        if (cv.getTypeEquivalenceSet().getContributingVariables().length > 0)
            return false;
    }
    ArrayElementVariable2 arrayElementVariable = getArrayElementVariable(cv);
    if (arrayElementVariable != null && !pruneCvIfUnused(arrayElementVariable))
        return false;
    Map<String, CollectionElementVariable2> elementVariables = getElementVariables(cv);
    for (Iterator<CollectionElementVariable2> iter = elementVariables.values().iterator(); iter.hasNext(); ) {
        CollectionElementVariable2 elementVariable = iter.next();
        if (!pruneCvIfUnused(elementVariable))
            return false;
    }
    fConstraintVariables.remove(cv);
    return true;
}
Also used : CollectionElementVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.CollectionElementVariable2) ArrayElementVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ArrayElementVariable2)

Example 17 with ConstraintVariable2

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

the class InferTypeArgumentsTCModel method createEqualsConstraint.

public void createEqualsConstraint(ConstraintVariable2 leftElement, ConstraintVariable2 rightElement) {
    if (leftElement == null || rightElement == null)
        return;
    TypeEquivalenceSet leftSet = leftElement.getTypeEquivalenceSet();
    TypeEquivalenceSet rightSet = rightElement.getTypeEquivalenceSet();
    if (leftSet == null) {
        if (rightSet == null) {
            TypeEquivalenceSet set = new TypeEquivalenceSet(leftElement, rightElement);
            leftElement.setTypeEquivalenceSet(set);
            rightElement.setTypeEquivalenceSet(set);
        } else {
            rightSet.add(leftElement);
            leftElement.setTypeEquivalenceSet(rightSet);
        }
    } else {
        if (rightSet == null) {
            leftSet.add(rightElement);
            rightElement.setTypeEquivalenceSet(leftSet);
        } else if (leftSet == rightSet) {
            return;
        } else {
            ConstraintVariable2[] cvs = rightSet.getContributingVariables();
            leftSet.addAll(cvs);
            for (int i = 0; i < cvs.length; i++) cvs[i].setTypeEquivalenceSet(leftSet);
        }
    }
}
Also used : TypeEquivalenceSet(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.TypeEquivalenceSet)

Example 18 with ConstraintVariable2

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

the class InferTypeArgumentsTCModel method makeSupertypeElementVariables.

private void makeSupertypeElementVariables(ConstraintVariable2 expressionCv, TType supertype) {
    if (supertype.isParameterizedType() || supertype.isRawType()) {
        TType[] typeArguments = null;
        if (supertype.isParameterizedType()) {
            typeArguments = ((ParameterizedType) supertype).getTypeArguments();
        }
        TypeVariable[] typeParameters = ((GenericType) supertype.getTypeDeclaration()).getTypeParameters();
        for (int i = 0; i < typeParameters.length; i++) {
            TypeVariable typeParameter = typeParameters[i];
            TType referenceTypeArgument;
            if (typeArguments == null) {
                // raw type
                referenceTypeArgument = typeParameter.getErasure();
            } else {
                referenceTypeArgument = typeArguments[i];
            }
            if (referenceTypeArgument.isTypeVariable()) {
                CollectionElementVariable2 referenceTypeArgumentCv = getElementVariable(expressionCv, (TypeVariable) referenceTypeArgument);
                if (referenceTypeArgumentCv != null) {
                    setElementVariable(expressionCv, referenceTypeArgumentCv, typeParameter);
                    continue;
                }
            }
            makeElementVariable(expressionCv, typeParameter, CollectionElementVariable2.NOT_DECLARED_TYPE_VARIABLE_INDEX);
        }
    }
    makeElementVariablesFromSupertypes(expressionCv, supertype);
}
Also used : GenericType(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.GenericType) CollectionElementVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.CollectionElementVariable2) TypeVariable(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TypeVariable) TType(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TType)

Example 19 with ConstraintVariable2

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

the class InferTypeArgumentsTCModel method makeFixedElementVariables.

public void makeFixedElementVariables(ConstraintVariable2 expressionCv, TType type) {
    if (isAGenericType(type)) {
        GenericType genericType = (GenericType) type.getTypeDeclaration();
        TType[] typeParameters = genericType.getTypeParameters();
        TType[] typeArguments = null;
        if (type.isParameterizedType())
            typeArguments = ((ParameterizedType) type).getTypeArguments();
        for (int i = 0; i < typeParameters.length; i++) {
            TypeVariable typeVariable = (TypeVariable) typeParameters[i];
            CollectionElementVariable2 elementCv = makeElementVariable(expressionCv, typeVariable, i);
            TType referenceTypeArgument;
            if (typeArguments == null) {
                // do not consider
                continue;
            } else {
                referenceTypeArgument = typeArguments[i];
            }
            createEqualsConstraint(elementCv, makeImmutableTypeVariable(referenceTypeArgument));
        //				if (typeVariable.getBounds().length != 0) {
        //					//TODO: create subtype constraints for bounds
        //				}
        }
    }
    makeFixedElementVariablesFromSupertypes(expressionCv, type.getTypeDeclaration());
}
Also used : ParameterizedType(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.ParameterizedType) GenericType(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.GenericType) CollectionElementVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.CollectionElementVariable2) TypeVariable(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TypeVariable) TType(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TType)

Example 20 with ConstraintVariable2

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

the class InferTypeArgumentsTCModel method makeArrayTypeVariable.

private ArrayTypeVariable2 makeArrayTypeVariable(ArrayType type) {
    ArrayTypeVariable2 cv = new ArrayTypeVariable2(type);
    ArrayTypeVariable2 storedCv = (ArrayTypeVariable2) storedCv(cv);
    if (cv == storedCv) {
        fCuScopedConstraintVariables.add(storedCv);
        makeArrayElementVariable(storedCv);
        if (fStoreToString)
            //$NON-NLS-1$ //$NON-NLS-2$
            storedCv.setData(ConstraintVariable2.TO_STRING, "ArrayType(" + type.getPrettySignature() + ")");
    }
    return storedCv;
}
Also used : ArrayTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ArrayTypeVariable2)

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