Search in sources :

Example 1 with ITypeConstraint2

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

the class InferTypeArgumentsConstraintsSolver method solveConstraints.

public InferTypeArgumentsUpdate solveConstraints(IProgressMonitor pm) {
    //$NON-NLS-1$
    pm.beginTask("", 2);
    fUpdate = new InferTypeArgumentsUpdate();
    ConstraintVariable2[] allConstraintVariables = fTCModel.getAllConstraintVariables();
    if (allConstraintVariables.length == 0)
        return fUpdate;
    fTypeSetEnvironment = new TypeSetEnvironment(fTCModel.getTypeEnvironment());
    ParametricStructureComputer parametricStructureComputer = new ParametricStructureComputer(allConstraintVariables, fTCModel);
    Collection<CollectionElementVariable2> newVars = parametricStructureComputer.createElemConstraintVariables();
    ArrayList<ConstraintVariable2> newAllConstraintVariables = new ArrayList<ConstraintVariable2>();
    newAllConstraintVariables.addAll(Arrays.asList(allConstraintVariables));
    newAllConstraintVariables.addAll(newVars);
    allConstraintVariables = newAllConstraintVariables.toArray(new ConstraintVariable2[newAllConstraintVariables.size()]);
    //loop over all TypeEquivalenceSets and unify the elements from the fElemStructureEnv with the existing TypeEquivalenceSets
    HashSet<TypeEquivalenceSet> allTypeEquivalenceSets = new HashSet<TypeEquivalenceSet>();
    for (int i = 0; i < allConstraintVariables.length; i++) {
        TypeEquivalenceSet typeEquivalenceSet = allConstraintVariables[i].getTypeEquivalenceSet();
        if (typeEquivalenceSet != null)
            allTypeEquivalenceSets.add(typeEquivalenceSet);
    }
    for (Iterator<TypeEquivalenceSet> iter = allTypeEquivalenceSets.iterator(); iter.hasNext(); ) {
        TypeEquivalenceSet typeEquivalenceSet = iter.next();
        ConstraintVariable2[] contributingVariables = typeEquivalenceSet.getContributingVariables();
        for (int i = 0; i < contributingVariables.length; i++) {
            for (int j = i + 1; j < contributingVariables.length; j++) {
                ConstraintVariable2 first = contributingVariables[i];
                ConstraintVariable2 second = contributingVariables[j];
                // recursively
                fTCModel.createElementEqualsConstraints(first, second);
            }
        }
    }
    ITypeConstraint2[] allTypeConstraints = fTCModel.getAllTypeConstraints();
    for (int i = 0; i < allTypeConstraints.length; i++) {
        ITypeConstraint2 typeConstraint = allTypeConstraints[i];
        fTCModel.createElementEqualsConstraints(typeConstraint.getLeft(), typeConstraint.getRight());
    }
    initializeTypeEstimates(allConstraintVariables);
    if (pm.isCanceled())
        throw new OperationCanceledException();
    fWorkList.addAll(Arrays.asList(allConstraintVariables));
    runSolver(new SubProgressMonitor(pm, 1));
    chooseTypes(allConstraintVariables, new SubProgressMonitor(pm, 1));
    findCastsToRemove(fTCModel.getCastVariables());
    return fUpdate;
}
Also used : CollectionElementVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.CollectionElementVariable2) TypeSetEnvironment(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSetEnvironment) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ArrayList(java.util.ArrayList) TypeEquivalenceSet(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.TypeEquivalenceSet) ITypeConstraint2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ITypeConstraint2) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) ConstraintVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2) HashSet(java.util.HashSet)

Example 2 with ITypeConstraint2

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

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

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

the class InferTypeArgumentsConstraintsSolver method processConstraints.

/**
	 * Given a list of <code>ITypeConstraint2</code>s that all refer to a
	 * given <code>ConstraintVariable2</code> (whose type bound has presumably
	 * just changed), process each <code>ITypeConstraint</code>, propagating
	 * the type bound across the constraint as needed.
	 *
	 * @param usedIn the <code>List</code> of <code>ITypeConstraint2</code>s
	 * to process
	 */
private void processConstraints(List<ITypeConstraint2> usedIn) {
    Iterator<ITypeConstraint2> iter = usedIn.iterator();
    while (iter.hasNext()) {
        ITypeConstraint2 tc = iter.next();
        maintainSimpleConstraint(tc);
    //TODO: prune tcs which cannot cause further changes
    // Maybe these should be pruned after a special first loop over all ConstraintVariables,
    // Since this can only happen once for every CV in the work list.
    //				if (isConstantConstraint(stc))
    //					fTypeConstraintFactory.removeUsedIn(stc, changedCv);
    }
}
Also used : ITypeConstraint2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ITypeConstraint2)

Example 5 with ITypeConstraint2

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

the class ParametricStructureComputer method computeContainerStructure.

private void computeContainerStructure() {
    if (DEBUG_INITIALIZATION)
        //$NON-NLS-1$
        System.out.println("\n*** Computing Container Structure ***\n");
    initializeContainerStructure();
    if (DEBUG_INITIALIZATION)
        dumpContainerStructure();
    while (!fWorkList2.isEmpty()) {
        ConstraintVariable2 v = fWorkList2.pop();
        List<ITypeConstraint2> usedIn = fTCModel.getUsedIn(v);
        for (Iterator<ITypeConstraint2> iter = usedIn.iterator(); iter.hasNext(); ) {
            SubTypeConstraint2 stc = (SubTypeConstraint2) iter.next();
            ConstraintVariable2 lhs = stc.getLeft();
            ConstraintVariable2 rhs = stc.getRight();
            unifyContainerStructure(lhs, rhs);
        }
        TypeEquivalenceSet typeEquivalenceSet = v.getTypeEquivalenceSet();
        if (typeEquivalenceSet != null) {
            ConstraintVariable2[] contributingVariables = typeEquivalenceSet.getContributingVariables();
            for (int i = 0; i + 1 < contributingVariables.length; i++) {
                ConstraintVariable2 first = contributingVariables[i];
                ConstraintVariable2 second = contributingVariables[i + 1];
                unifyContainerStructure(first, second);
            }
        }
    }
    if (DEBUG_INITIALIZATION)
        dumpContainerStructure();
}
Also used : TypeEquivalenceSet(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.TypeEquivalenceSet) ConstraintVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2) ITypeConstraint2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ITypeConstraint2) SubTypeConstraint2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.SubTypeConstraint2)

Aggregations

ConstraintVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2)5 ITypeConstraint2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ITypeConstraint2)5 TypeEquivalenceSet (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.TypeEquivalenceSet)3 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)2 SubTypeConstraint2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.SubTypeConstraint2)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)1 EnumeratedTypeSet (org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.EnumeratedTypeSet)1 SingletonTypeSet (org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.SingletonTypeSet)1 TypeSet (org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet)1 TypeSetEnvironment (org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSetEnvironment)1 CollectionElementVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.CollectionElementVariable2)1