Search in sources :

Example 1 with ArrayElementVariable2

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

the class InferTypeArgumentsTCModel method makeArrayElementVariable.

public void makeArrayElementVariable(ConstraintVariable2 constraintVariable2) {
    if (constraintVariable2.getType() == null || !constraintVariable2.getType().isArrayType())
        return;
    ArrayElementVariable2 storedArrayElementVariable = getArrayElementVariable(constraintVariable2);
    if (storedArrayElementVariable != null)
        return;
    ArrayElementVariable2 arrayElementCv = new ArrayElementVariable2(constraintVariable2);
    arrayElementCv = (ArrayElementVariable2) storedCv(arrayElementCv);
    setArrayElementVariable(constraintVariable2, arrayElementCv);
    //recursive
    makeArrayElementVariable(arrayElementCv);
}
Also used : ArrayElementVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ArrayElementVariable2)

Example 2 with ArrayElementVariable2

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

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

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

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

the class InferTypeArgumentsConstraintCreator method endVisit.

@Override
public void endVisit(ArrayAccess node) {
    if (node.resolveBoxing()) {
        ImmutableTypeVariable2 boxed = fTCModel.makeImmutableTypeVariable(node.resolveTypeBinding(), node);
        setConstraintVariable(node, boxed);
        return;
    }
    ConstraintVariable2 arrayCv = getConstraintVariable(node.getArray());
    if (arrayCv == null)
        return;
    ArrayElementVariable2 arrayElementCv = fTCModel.getArrayElementVariable(arrayCv);
    setConstraintVariable(node, arrayElementCv);
}
Also used : ImmutableTypeVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ImmutableTypeVariable2) ConstraintVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2) ArrayElementVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ArrayElementVariable2)

Aggregations

ArrayElementVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ArrayElementVariable2)7 CollectionElementVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.CollectionElementVariable2)4 ConstraintVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2)4 TType (org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TType)3 ImmutableTypeVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ImmutableTypeVariable2)2 Entry (java.util.Map.Entry)1 ArrayType (org.eclipse.jdt.core.dom.ArrayType)1 CastExpression (org.eclipse.jdt.core.dom.CastExpression)1 ConditionalExpression (org.eclipse.jdt.core.dom.ConditionalExpression)1 Expression (org.eclipse.jdt.core.dom.Expression)1 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)1 ParenthesizedExpression (org.eclipse.jdt.core.dom.ParenthesizedExpression)1 ThisExpression (org.eclipse.jdt.core.dom.ThisExpression)1 VariableDeclarationExpression (org.eclipse.jdt.core.dom.VariableDeclarationExpression)1 ArrayType (org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.ArrayType)1 GenericType (org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.GenericType)1 TypeVariable (org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TypeVariable)1 WildcardType (org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.WildcardType)1 ArrayTypeVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ArrayTypeVariable2)1 CastVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.CastVariable2)1