Search in sources :

Example 1 with CuUpdate

use of org.eclipse.jdt.internal.corext.refactoring.generics.InferTypeArgumentsUpdate.CuUpdate 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 2 with CuUpdate

use of org.eclipse.jdt.internal.corext.refactoring.generics.InferTypeArgumentsUpdate.CuUpdate in project che by eclipse.

the class InferTypeArgumentsRefactoring method inferArguments.

public static ParameterizedType[] inferArguments(SimpleType[] types, InferTypeArgumentsUpdate update, InferTypeArgumentsTCModel model, CompilationUnitRewrite rewrite) {
    for (int i = 0; i < types.length; i++) {
        types[i].setProperty(REWRITTEN, null);
    }
    List<ParameterizedType> result = new ArrayList<ParameterizedType>();
    HashMap<ICompilationUnit, CuUpdate> updates = update.getUpdates();
    Set<Entry<ICompilationUnit, CuUpdate>> entrySet = updates.entrySet();
    for (Iterator<Entry<ICompilationUnit, CuUpdate>> iter = entrySet.iterator(); iter.hasNext(); ) {
        Entry<ICompilationUnit, CuUpdate> entry = iter.next();
        rewrite.setResolveBindings(false);
        CuUpdate cuUpdate = entry.getValue();
        for (Iterator<CollectionElementVariable2> cvIter = cuUpdate.getDeclarations().iterator(); cvIter.hasNext(); ) {
            ConstraintVariable2 cv = cvIter.next();
            ParameterizedType newNode = rewriteConstraintVariable(cv, rewrite, model, false, types);
            if (newNode != null)
                result.add(newNode);
        }
    }
    return result.toArray(new ParameterizedType[result.size()]);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CollectionElementVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.CollectionElementVariable2) ArrayList(java.util.ArrayList) ParameterizedType(org.eclipse.jdt.core.dom.ParameterizedType) Entry(java.util.Map.Entry) CuUpdate(org.eclipse.jdt.internal.corext.refactoring.generics.InferTypeArgumentsUpdate.CuUpdate) ConstraintVariable2(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2)

Aggregations

Entry (java.util.Map.Entry)2 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)2 CuUpdate (org.eclipse.jdt.internal.corext.refactoring.generics.InferTypeArgumentsUpdate.CuUpdate)2 CollectionElementVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.CollectionElementVariable2)2 ConstraintVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2)2 ArrayList (java.util.ArrayList)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 ParameterizedType (org.eclipse.jdt.core.dom.ParameterizedType)1 CompilationUnitChange (org.eclipse.jdt.core.refactoring.CompilationUnitChange)1 CompilationUnitRewrite (org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite)1 CastVariable2 (org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.CastVariable2)1