Search in sources :

Example 1 with TypeSet

use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet 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 2 with TypeSet

use of org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet in project che by eclipse.

the class InferTypeArgumentsConstraintsSolver method initializeTypeEstimates.

private void initializeTypeEstimates(ConstraintVariable2[] allConstraintVariables) {
    for (int i = 0; i < allConstraintVariables.length; i++) {
        ConstraintVariable2 cv = allConstraintVariables[i];
        //TODO: not necessary for types that are not used in a TypeConstraint but only as type in CollectionElementVariable
        //TODO: handle nested element variables; see ParametricStructureComputer.createAndInitVars()
        TypeEquivalenceSet set = cv.getTypeEquivalenceSet();
        if (set == null) {
            set = new TypeEquivalenceSet(cv);
            set.setTypeEstimate(createInitialEstimate(cv));
            cv.setTypeEquivalenceSet(set);
        } else {
            TypeSet typeEstimate = (TypeSet) cv.getTypeEstimate();
            if (typeEstimate == null) {
                ConstraintVariable2[] cvs = set.getContributingVariables();
                typeEstimate = fTypeSetEnvironment.getUniverseTypeSet();
                for (//TODO: optimize: just try to find an immutable CV; if not found, use Universe
                int j = 0; //TODO: optimize: just try to find an immutable CV; if not found, use Universe
                j < cvs.length; //TODO: optimize: just try to find an immutable CV; if not found, use Universe
                j++) typeEstimate = typeEstimate.intersectedWith(createInitialEstimate(cvs[j]));
                set.setTypeEstimate(typeEstimate);
            }
        }
    }
}
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)

Aggregations

EnumeratedTypeSet (org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.EnumeratedTypeSet)2 SingletonTypeSet (org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.SingletonTypeSet)2 TypeSet (org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet)2 ConstraintVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2)2 TypeEquivalenceSet (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.TypeEquivalenceSet)2