Search in sources :

Example 6 with CollectionElementVariable2

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

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

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

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

the class InferTypeArgumentsTCModel method createTypeVariablesEqualityConstraints.

/**
	 * Create equality constraints between generic type variables of expressionCv and referenceCv.
	 * For example, the generic interface <code>java.lang.Iterable&lt;E&gt;</code> defines a method
	 * <code>Iterator&lt;E&gt; iterator()</code>. Given
	 * <ul>
	 *   <li>an expressionCv of a subtype of <code>Iterable</code>,</li>
	 *   <li>a referenceCv of a subtype of <code>Iterator</code>, and</li>
	 *   <li>a reference binding of the Iterable#iterator()'s return type (the parameterized type <code>Iterator&lt;E&gt;</code>),</li>
	 * </ul>
	 * this method creates an equality constraint between the type variable E in expressionCV and
	 * the type variable E in referenceCV.
	 *
	 * @param expressionCv the type constraint variable of an expression
	 * @param methodTypeVariables
	 * @param referenceCv the type constraint variable of a type reference
	 * @param reference the declared type reference
	 */
public void createTypeVariablesEqualityConstraints(ConstraintVariable2 expressionCv, Map<String, IndependentTypeVariable2> methodTypeVariables, ConstraintVariable2 referenceCv, TType reference) {
    if (reference.isParameterizedType() || reference.isRawType()) {
        TType[] referenceTypeArguments = null;
        if (reference.isParameterizedType()) {
            referenceTypeArguments = ((ParameterizedType) reference).getTypeArguments();
        }
        TType[] referenceTypeParameters = ((GenericType) reference.getTypeDeclaration()).getTypeParameters();
        for (int i = 0; i < referenceTypeParameters.length; i++) {
            TypeVariable referenceTypeParameter = (TypeVariable) referenceTypeParameters[i];
            TType referenceTypeArgument;
            if (referenceTypeArguments == null)
                referenceTypeArgument = referenceTypeParameter.getErasure();
            else
                referenceTypeArgument = referenceTypeArguments[i];
            if (referenceTypeArgument.isTypeVariable()) {
                ConstraintVariable2 referenceTypeArgumentCv = getElementTypeCv(referenceTypeArgument, expressionCv, methodTypeVariables);
                CollectionElementVariable2 referenceTypeParametersCv = getElementVariable(referenceCv, referenceTypeParameter);
                createEqualsConstraint(referenceTypeArgumentCv, referenceTypeParametersCv);
            } else if (referenceTypeArgument.isWildcardType()) {
                //block it for now (bug 106174)
                ConstraintVariable2 referenceTypeArgumentCv = makeImmutableTypeVariable(fTypeEnvironment.VOID);
                CollectionElementVariable2 referenceTypeParametersCv = getElementVariable(referenceCv, referenceTypeParameter);
                createEqualsConstraint(referenceTypeArgumentCv, referenceTypeParametersCv);
            //					WildcardType wildcardType= (WildcardType) referenceTypeArgument;
            //					if (wildcardType.isUnboundWildcardType()) {
            //						ConstraintVariable2 referenceTypeArgumentCv= makeImmutableTypeVariable(wildcardType);
            //						CollectionElementVariable2 referenceTypeParametersCv= getElementVariable(referenceCv, referenceTypeParameter);
            //						createEqualsConstraint(referenceTypeArgumentCv, referenceTypeParametersCv);
            //					} else if (wildcardType.isSuperWildcardType() && wildcardType.getBound().isTypeVariable()) {
            //						ConstraintVariable2 referenceTypeArgumentBoundCv= getElementTypeCv(wildcardType.getBound(), expressionCv, methodTypeVariables);
            //						CollectionElementVariable2 referenceTypeParametersCv= getElementVariable(referenceCv, referenceTypeParameter);
            //						//TODO: need *strict* subtype constraint?
            //						createSubtypeConstraint(referenceTypeParametersCv, referenceTypeArgumentBoundCv);
            //					}
            // else: TODO
            //				} else if (referenceTypeArgument.isParameterizedType()) {
            //					//TODO: nested containers
            //					ParameterizedType parameterizedType= (ParameterizedType) referenceTypeArgument;
            //					ParameterizedTypeVariable2 parameterizedTypeCv= makeParameterizedTypeVariable(parameterizedType.getTypeDeclaration());
            //					CollectionElementVariable2 referenceTypeParametersCv= getElementVariable(referenceCv, referenceTypeParameter);
            //					createEqualsConstraint(parameterizedTypeCv, referenceTypeParametersCv);
            //					createElementEqualsConstraints(parameterizedTypeCv, referenceTypeParametersCv);
            } else {
            //TODO
            }
        }
    } else if (reference.isArrayType()) {
        TType elementType = ((ArrayType) reference).getElementType();
        if (elementType.isRawType())
            elementType = elementType.getErasure();
        ConstraintVariable2 elementTypeCv = getElementTypeCv(elementType, expressionCv, methodTypeVariables);
        ArrayElementVariable2 arrayElementTypeCv = getArrayElementVariable(referenceCv);
        createEqualsConstraint(elementTypeCv, arrayElementTypeCv);
    }
}
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) ConstraintVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2) ArrayElementVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ArrayElementVariable2)

Example 10 with CollectionElementVariable2

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

the class ParametricStructureComputer method updateParentContainerStructureFrom.

/**
	 * Updates the structure of the parent container variable of the given
	 * CollectionElementVariable2 from the structure of 'v1'.
	 * @param elemVar
	 * @param v1
	 */
private void updateParentContainerStructureFrom(CollectionElementVariable2 elemVar, ConstraintVariable2 v1) {
    ConstraintVariable2 elemContainer = elemVar.getParentConstraintVariable();
    // This could be something that appears like it should have container
    // structure, but doesn't, e.g., an array access for an array of containers
    // (JDK 1.5 disallows arrays of parametric types). So if it doesn't have
    // container structure, ignore it.
    ParametricStructure elemContainerStructure = elemStructure(elemContainer);
    if (elemContainerStructure == ParametricStructure.NONE)
        return;
    if (elemContainerStructure == null) {
        // handle clone()
        elemContainerStructure = newParametricType(elemContainer.getType());
        setStructureAndPush(elemContainer, elemContainerStructure);
    }
    ParametricStructure v1Structure = elemStructure(v1);
    //TODO: index is NOT_DECLARED_TYPE_VARIABLE_INDEX if the type variable comes from a supertype!!!
    int parmIdx = elemVar.getDeclarationTypeVariableIndex();
    if (parmIdx == CollectionElementVariable2.NOT_DECLARED_TYPE_VARIABLE_INDEX)
        //TODO: ParametricStructure should use type variable keys instead of index
        return;
    if (elemContainerStructure == v1Structure || containsSubStructure(v1Structure, elemContainerStructure)) {
        // avoid creating cyclic structure
        if (!(elemStructure(elemVar) == ParametricStructure.NONE))
            setStructureAndPush(elemVar, ParametricStructure.NONE);
        if (elemContainerStructure.getParameters()[parmIdx] == null) {
            elemContainerStructure.getParameters()[parmIdx] = ParametricStructure.NONE;
            fWorkList2.push(elemContainer);
        }
    } else if (updateStructureOfIthParamFrom(elemContainerStructure, parmIdx, v1Structure)) {
        setStructureAndPush(elemVar, elemContainerStructure.getParameters()[parmIdx]);
        fWorkList2.push(elemContainer);
        if (DEBUG_INITIALIZATION)
            //$NON-NLS-1$ //$NON-NLS-2$
            System.out.println("  updated structure of " + elemContainer + " to " + elemContainerStructure);
    }
}
Also used : ConstraintVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2)

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