Search in sources :

Example 51 with ConstraintVariable2

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

the class InferTypeArgumentsTCModel method makeFixedSupertypeElementVariables.

private void makeFixedSupertypeElementVariables(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) {
                // do not consider
                continue;
            } else {
                referenceTypeArgument = typeArguments[i];
            }
            if (referenceTypeArgument.isTypeVariable()) {
                CollectionElementVariable2 referenceTypeArgumentCv = getElementVariable(expressionCv, (TypeVariable) referenceTypeArgument);
                setElementVariable(expressionCv, referenceTypeArgumentCv, typeParameter);
            } else {
                CollectionElementVariable2 elementCv = makeElementVariable(expressionCv, typeParameter, CollectionElementVariable2.NOT_DECLARED_TYPE_VARIABLE_INDEX);
                createEqualsConstraint(elementCv, makeImmutableTypeVariable(referenceTypeArgument));
            }
        }
    }
    makeFixedElementVariablesFromSupertypes(expressionCv, supertype);
}
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 52 with ConstraintVariable2

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

the class InferTypeArgumentsTCModel method internalCreateElementEqualsConstraints.

private void internalCreateElementEqualsConstraints(ConstraintVariable2 cv, ConstraintVariable2 initializerCv, boolean isAssignment) {
    if (cv == null || initializerCv == null)
        return;
    Map<String, CollectionElementVariable2> leftElements = getElementVariables(cv);
    Map<String, CollectionElementVariable2> rightElements = getElementVariables(initializerCv);
    for (Iterator<Entry<String, CollectionElementVariable2>> leftIter = leftElements.entrySet().iterator(); leftIter.hasNext(); ) {
        Entry<String, CollectionElementVariable2> leftEntry = leftIter.next();
        String leftTypeVariableKey = leftEntry.getKey();
        CollectionElementVariable2 rightElementVariable = rightElements.get(leftTypeVariableKey);
        if (rightElementVariable != null) {
            CollectionElementVariable2 leftElementVariable = leftEntry.getValue();
            createEqualsConstraint(leftElementVariable, rightElementVariable);
            // recursive
            internalCreateElementEqualsConstraints(leftElementVariable, rightElementVariable, false);
        }
    }
    ArrayElementVariable2 leftArrayElement = getArrayElementVariable(cv);
    ArrayElementVariable2 rightArrayElement = getArrayElementVariable(initializerCv);
    if (leftArrayElement != null && rightArrayElement != null) {
        if (isAssignment)
            createSubtypeConstraint(rightArrayElement, leftArrayElement);
        else
            createEqualsConstraint(leftArrayElement, rightArrayElement);
        // recursive
        internalCreateElementEqualsConstraints(leftArrayElement, rightArrayElement, false);
    }
}
Also used : Entry(java.util.Map.Entry) CollectionElementVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.CollectionElementVariable2) ArrayElementVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ArrayElementVariable2)

Example 53 with ConstraintVariable2

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

the class InferTypeArgumentsTCModel method createSubtypeConstraint.

public void createSubtypeConstraint(ConstraintVariable2 cv1, ConstraintVariable2 cv2) {
    if (!keep(cv1, cv2))
        return;
    ConstraintVariable2 storedCv1 = storedCv(cv1);
    ConstraintVariable2 storedCv2 = storedCv(cv2);
    ITypeConstraint2 typeConstraint = new SubTypeConstraint2(storedCv1, storedCv2);
    Object storedTc = fTypeConstraints.get(typeConstraint);
    if (storedTc == null) {
        fTypeConstraints.put(typeConstraint, typeConstraint);
    } else {
        typeConstraint = (ITypeConstraint2) storedTc;
    }
    registerCvWithTc(storedCv1, typeConstraint);
    registerCvWithTc(storedCv2, typeConstraint);
}
Also used : ConstraintVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2) ITypeConstraint2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ITypeConstraint2) SubTypeConstraint2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.SubTypeConstraint2)

Example 54 with ConstraintVariable2

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

the class InferTypeArgumentsTCModel method makeParameterTypeVariable.

public ParameterTypeVariable2 makeParameterTypeVariable(IMethodBinding methodBinding, int parameterIndex) {
    if (methodBinding == null)
        return null;
    TType type = getBoxedType(methodBinding.getParameterTypes()[parameterIndex], /*no boxing*/
    null);
    if (type == null)
        return null;
    ParameterTypeVariable2 cv = new ParameterTypeVariable2(type, parameterIndex, methodBinding);
    ParameterTypeVariable2 storedCv = (ParameterTypeVariable2) storedCv(cv);
    if (storedCv == cv) {
        if (methodBinding.getDeclaringClass().isLocal() || Modifier.isPrivate(methodBinding.getModifiers()))
            fCuScopedConstraintVariables.add(cv);
        makeElementVariables(storedCv, type);
        makeArrayElementVariable(storedCv);
        if (fStoreToString)
            //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            storedCv.setData(ConstraintVariable2.TO_STRING, "[Parameter(" + parameterIndex + "," + Bindings.asString(methodBinding) + ")]");
    }
    return storedCv;
}
Also used : ParameterTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ParameterTypeVariable2) TType(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TType)

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