Search in sources :

Example 11 with ConstraintVariable2

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

the class InferTypeArgumentsConstraintsSolver method runSolver.

private void runSolver(SubProgressMonitor pm) {
    //$NON-NLS-1$
    pm.beginTask("", fWorkList.size() * 3);
    while (!fWorkList.isEmpty()) {
        // Get a variable whose type estimate has changed
        ConstraintVariable2 cv = fWorkList.removeFirst();
        List<ITypeConstraint2> usedIn = fTCModel.getUsedIn(cv);
        processConstraints(usedIn);
        pm.worked(1);
        if (pm.isCanceled())
            throw new OperationCanceledException();
    }
    pm.done();
}
Also used : OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ConstraintVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2) ITypeConstraint2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ITypeConstraint2)

Example 12 with ConstraintVariable2

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

the class InferTypeArgumentsConstraintsSolver method maintainSimpleConstraint.

private void maintainSimpleConstraint(ITypeConstraint2 stc) {
    ConstraintVariable2 left = stc.getLeft();
    ConstraintVariable2 right = stc.getRight();
    TypeEquivalenceSet leftSet = left.getTypeEquivalenceSet();
    TypeEquivalenceSet rightSet = right.getTypeEquivalenceSet();
    TypeSet leftEstimate = (TypeSet) leftSet.getTypeEstimate();
    TypeSet rightEstimate = (TypeSet) rightSet.getTypeEstimate();
    if (leftEstimate.isUniverse() && rightEstimate.isUniverse())
        // nothing to do
        return;
    if (leftEstimate.equals(rightEstimate))
        // nothing to do
        return;
    TypeSet lhsSuperTypes = leftEstimate.superTypes();
    TypeSet rhsSubTypes = rightEstimate.subTypes();
    if (!rhsSubTypes.containsAll(leftEstimate)) {
        TypeSet xsection = leftEstimate.intersectedWith(rhsSubTypes);
        //			if (xsection.isEmpty()) // too bad, but this can happen
        //				throw new IllegalStateException("Type estimate set is now empty for LHS in " + left + " <= " + right + "; estimates were " + leftEstimate + " <= " + rightEstimate); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
        leftSet.setTypeEstimate(xsection);
        fWorkList.addAll(Arrays.asList(leftSet.getContributingVariables()));
    }
    if (!lhsSuperTypes.containsAll(rightEstimate)) {
        TypeSet xsection = rightEstimate.intersectedWith(lhsSuperTypes);
        //			if (xsection.isEmpty())
        //				throw new IllegalStateException("Type estimate set is now empty for RHS in " + left + " <= " + right + "; estimates were " + leftEstimate + " <= " + rightEstimate); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
        rightSet.setTypeEstimate(xsection);
        fWorkList.addAll(Arrays.asList(rightSet.getContributingVariables()));
    }
}
Also used : EnumeratedTypeSet(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.EnumeratedTypeSet) SingletonTypeSet(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.SingletonTypeSet) TypeSet(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet) TypeEquivalenceSet(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.TypeEquivalenceSet) ConstraintVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2)

Example 13 with ConstraintVariable2

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

the class InferTypeArgumentsTCModel method makeCastVariable.

public CastVariable2 makeCastVariable(CastExpression castExpression, ConstraintVariable2 expressionCv) {
    ITypeBinding typeBinding = castExpression.resolveTypeBinding();
    ICompilationUnit cu = RefactoringASTParser.getCompilationUnit(castExpression);
    CompilationUnitRange range = new CompilationUnitRange(cu, castExpression);
    CastVariable2 castCv = new CastVariable2(createTType(typeBinding), range, expressionCv);
    fCastVariables.add(castCv);
    return castCv;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnitRange(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.CompilationUnitRange) CastVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.CastVariable2) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding)

Example 14 with ConstraintVariable2

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

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

the class InferTypeArgumentsTCModel method makeElementVariable.

private CollectionElementVariable2 makeElementVariable(ConstraintVariable2 expressionCv, TypeVariable typeVariable, int declarationTypeVariableIndex) {
    if (expressionCv == null)
        return null;
    CollectionElementVariable2 storedElementVariable = getElementVariable(expressionCv, typeVariable);
    if (storedElementVariable != null)
        return storedElementVariable;
    CollectionElementVariable2 cv = new CollectionElementVariable2(expressionCv, typeVariable, declarationTypeVariableIndex);
    cv = (CollectionElementVariable2) storedCv(cv);
    setElementVariable(expressionCv, cv, typeVariable);
    return cv;
}
Also used : CollectionElementVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.CollectionElementVariable2)

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