use of org.eclipse.core.runtime.OperationCanceledException in project che by eclipse.
the class ProjectDescription method createExistentResourceFromHandle.
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.internal.ide.undo.ResourceDescription#createExistentResourceFromHandle(org.eclipse.core.resources.IResource,
* org.eclipse.core.runtime.IProgressMonitor)
*/
public void createExistentResourceFromHandle(IResource resource, IProgressMonitor monitor) throws CoreException {
Assert.isLegal(resource instanceof IProject);
if (resource.exists()) {
return;
}
IProject projectHandle = (IProject) resource;
//$NON-NLS-1$
monitor.beginTask("", 200);
monitor.setTaskName(UndoMessages.FolderDescription_NewFolderProgress);
if (projectDescription == null) {
projectHandle.create(new SubProgressMonitor(monitor, 100));
} else {
projectHandle.create(projectDescription, new SubProgressMonitor(monitor, 100));
}
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
if (openOnCreate) {
projectHandle.open(IResource.NONE, new SubProgressMonitor(monitor, 100));
}
monitor.done();
}
use of org.eclipse.core.runtime.OperationCanceledException 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);
}
}
}
use of org.eclipse.core.runtime.OperationCanceledException in project che by eclipse.
the class ReplaceInvocationsRefactoring method checkFinalConditions.
@Override
public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException {
//$NON-NLS-1$
pm.beginTask("", 20);
fChangeManager = new TextChangeManager();
RefactoringStatus result = new RefactoringStatus();
fSourceProvider = resolveSourceProvider(fMethodBinding, result);
if (result.hasFatalError())
return result;
result.merge(fSourceProvider.checkActivation());
if (result.hasFatalError())
return result;
fSourceProvider.initialize();
fTargetProvider.initialize();
pm.setTaskName(RefactoringCoreMessages.InlineMethodRefactoring_searching);
RefactoringStatus searchStatus = new RefactoringStatus();
String binaryRefsDescription = Messages.format(RefactoringCoreMessages.ReferencesInBinaryContext_ref_in_binaries_description, BasicElementLabels.getJavaElementName(fSourceProvider.getMethodName()));
ReferencesInBinaryContext binaryRefs = new ReferencesInBinaryContext(binaryRefsDescription);
ICompilationUnit[] units = fTargetProvider.getAffectedCompilationUnits(searchStatus, binaryRefs, new SubProgressMonitor(pm, 1));
binaryRefs.addErrorIfNecessary(searchStatus);
if (searchStatus.hasFatalError()) {
result.merge(searchStatus);
return result;
}
IFile[] filesToBeModified = getFilesToBeModified(units);
result.merge(Checks.validateModifiesFiles(filesToBeModified, getValidationContext()));
if (result.hasFatalError())
return result;
result.merge(ResourceChangeChecker.checkFilesToBeChanged(filesToBeModified, new SubProgressMonitor(pm, 1)));
checkOverridden(result, new SubProgressMonitor(pm, 4));
IProgressMonitor sub = new SubProgressMonitor(pm, 15);
//$NON-NLS-1$
sub.beginTask("", units.length * 3);
for (int c = 0; c < units.length; c++) {
ICompilationUnit unit = units[c];
sub.subTask(Messages.format(RefactoringCoreMessages.InlineMethodRefactoring_processing, BasicElementLabels.getFileName(unit)));
CallInliner inliner = null;
try {
boolean added = false;
MultiTextEdit root = new MultiTextEdit();
CompilationUnitChange change = (CompilationUnitChange) fChangeManager.get(unit);
change.setEdit(root);
BodyDeclaration[] bodies = fTargetProvider.getAffectedBodyDeclarations(unit, new SubProgressMonitor(pm, 1));
if (bodies.length == 0)
continue;
inliner = new CallInliner(unit, (CompilationUnit) bodies[0].getRoot(), fSourceProvider);
for (int b = 0; b < bodies.length; b++) {
BodyDeclaration body = bodies[b];
inliner.initialize(body);
RefactoringStatus nestedInvocations = new RefactoringStatus();
ASTNode[] invocations = removeNestedCalls(nestedInvocations, unit, fTargetProvider.getInvocations(body, new SubProgressMonitor(sub, 2)));
for (int i = 0; i < invocations.length; i++) {
ASTNode invocation = invocations[i];
result.merge(inliner.initialize(invocation, fTargetProvider.getStatusSeverity()));
if (result.hasFatalError())
break;
if (result.getSeverity() < fTargetProvider.getStatusSeverity()) {
added = true;
TextEditGroup group = new TextEditGroup(RefactoringCoreMessages.InlineMethodRefactoring_edit_inline);
change.addTextEditGroup(group);
result.merge(inliner.perform(group));
}
}
// do this after we have inlined the method calls. We still want
// to generate the modifications.
result.merge(nestedInvocations);
}
if (!added) {
fChangeManager.remove(unit);
} else {
root.addChild(inliner.getModifications());
ImportRewrite rewrite = inliner.getImportEdit();
if (rewrite.hasRecordedChanges()) {
TextEdit edit = rewrite.rewriteImports(null);
if (edit instanceof MultiTextEdit ? ((MultiTextEdit) edit).getChildrenSize() > 0 : true) {
root.addChild(edit);
change.addTextEditGroup(new TextEditGroup(RefactoringCoreMessages.InlineMethodRefactoring_edit_import, new TextEdit[] { edit }));
}
}
}
} finally {
if (inliner != null)
inliner.dispose();
}
sub.worked(1);
if (sub.isCanceled())
throw new OperationCanceledException();
}
result.merge(searchStatus);
sub.done();
pm.done();
return result;
}
use of org.eclipse.core.runtime.OperationCanceledException 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;
}
use of org.eclipse.core.runtime.OperationCanceledException 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();
}
Aggregations