Search in sources :

Example 1 with CollectionElementVariable2

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

the class InferTypeArgumentsRefactoring method hasUnboundElement.

private static boolean hasUnboundElement(ConstraintVariable2 methodReceiverCv, InferTypeArgumentsTCModel tCModel) {
    ArrayList<CollectionElementVariable2> typeArgumentCvs = getTypeArgumentCvs(methodReceiverCv, tCModel);
    for (Iterator<CollectionElementVariable2> iter = typeArgumentCvs.iterator(); iter.hasNext(); ) {
        CollectionElementVariable2 elementCv = iter.next();
        TType chosenElementType = InferTypeArgumentsConstraintsSolver.getChosenType(elementCv);
        if (chosenElementType == null)
            return true;
    }
    return false;
}
Also used : CollectionElementVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.CollectionElementVariable2) TType(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TType)

Example 2 with CollectionElementVariable2

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

the class InferTypeArgumentsRefactoring method rewriteDeclarations.

private void rewriteDeclarations(InferTypeArgumentsUpdate update, IProgressMonitor pm) throws CoreException {
    HashMap<ICompilationUnit, CuUpdate> updates = update.getUpdates();
    Set<Entry<ICompilationUnit, CuUpdate>> entrySet = updates.entrySet();
    //$NON-NLS-1$
    pm.beginTask("", entrySet.size());
    pm.setTaskName(RefactoringCoreMessages.InferTypeArgumentsRefactoring_creatingChanges);
    for (Iterator<Entry<ICompilationUnit, CuUpdate>> iter = entrySet.iterator(); iter.hasNext(); ) {
        if (pm.isCanceled())
            throw new OperationCanceledException();
        Entry<ICompilationUnit, CuUpdate> entry = iter.next();
        ICompilationUnit cu = entry.getKey();
        pm.worked(1);
        pm.subTask(BasicElementLabels.getFileName(cu));
        CompilationUnitRewrite rewrite = new CompilationUnitRewrite(cu);
        rewrite.setResolveBindings(false);
        CuUpdate cuUpdate = entry.getValue();
        for (Iterator<CollectionElementVariable2> cvIter = cuUpdate.getDeclarations().iterator(); cvIter.hasNext(); ) {
            ConstraintVariable2 cv = cvIter.next();
            rewriteConstraintVariable(cv, rewrite, fTCModel, fLeaveUnconstrainedRaw, null);
        }
        for (Iterator<CastVariable2> castsIter = cuUpdate.getCastsToRemove().iterator(); castsIter.hasNext(); ) {
            CastVariable2 castCv = castsIter.next();
            rewriteCastVariable(castCv, rewrite, fTCModel);
        }
        CompilationUnitChange change = rewrite.createChange(true);
        if (change != null) {
            fChangeManager.manage(cu, change);
        }
    }
}
Also used : CompilationUnitRewrite(org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CollectionElementVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.CollectionElementVariable2) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) Entry(java.util.Map.Entry) CastVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.CastVariable2) CuUpdate(org.eclipse.jdt.internal.corext.refactoring.generics.InferTypeArgumentsUpdate.CuUpdate) ConstraintVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2) CompilationUnitChange(org.eclipse.jdt.core.refactoring.CompilationUnitChange)

Example 3 with CollectionElementVariable2

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

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

the class InferTypeArgumentsConstraintsSolver method chooseTypes.

private void chooseTypes(ConstraintVariable2[] allConstraintVariables, SubProgressMonitor pm) {
    //$NON-NLS-1$
    pm.beginTask("", allConstraintVariables.length);
    for (int i = 0; i < allConstraintVariables.length; i++) {
        ConstraintVariable2 cv = allConstraintVariables[i];
        TypeEquivalenceSet set = cv.getTypeEquivalenceSet();
        if (set == null)
            //TODO: should not happen iff all unused constraint variables got pruned
            continue;
        //TODO: should calculate only once per EquivalenceRepresentative; can throw away estimate TypeSet afterwards
        //TODO: is null for Universe TypeSet
        TType type = chooseSingleType((TypeSet) cv.getTypeEstimate());
        setChosenType(cv, type);
        if (cv instanceof CollectionElementVariable2) {
            CollectionElementVariable2 elementCv = (CollectionElementVariable2) cv;
            fUpdate.addDeclaration(elementCv);
        }
        pm.worked(1);
        if (pm.isCanceled())
            throw new OperationCanceledException();
    }
    pm.done();
}
Also used : CollectionElementVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.CollectionElementVariable2) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) TypeEquivalenceSet(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.TypeEquivalenceSet) TType(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TType) ConstraintVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2)

Example 5 with CollectionElementVariable2

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

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