Search in sources :

Example 21 with CollectionElementVariable2

use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.CollectionElementVariable2 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 22 with CollectionElementVariable2

use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.CollectionElementVariable2 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)

Aggregations

CollectionElementVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.CollectionElementVariable2)19 TType (org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TType)11 ConstraintVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2)10 GenericType (org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.GenericType)5 ArrayList (java.util.ArrayList)4 TypeVariable (org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TypeVariable)4 ArrayElementVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ArrayElementVariable2)4 Entry (java.util.Map.Entry)3 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)3 CastExpression (org.eclipse.jdt.core.dom.CastExpression)3 ConditionalExpression (org.eclipse.jdt.core.dom.ConditionalExpression)3 Expression (org.eclipse.jdt.core.dom.Expression)3 ParameterizedType (org.eclipse.jdt.core.dom.ParameterizedType)3 ParenthesizedExpression (org.eclipse.jdt.core.dom.ParenthesizedExpression)3 ThisExpression (org.eclipse.jdt.core.dom.ThisExpression)3 Type (org.eclipse.jdt.core.dom.Type)3 VariableDeclarationExpression (org.eclipse.jdt.core.dom.VariableDeclarationExpression)3 ParameterizedType (org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.ParameterizedType)3 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)2 ArrayType (org.eclipse.jdt.core.dom.ArrayType)2