use of org.eclipse.core.runtime.SubProgressMonitor 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.SubProgressMonitor 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.SubProgressMonitor in project che by eclipse.
the class CreateFileChange method perform.
@Override
public Change perform(IProgressMonitor pm) throws CoreException, OperationCanceledException {
InputStream is = null;
try {
pm.beginTask(NLSChangesMessages.createFile_creating_resource, 3);
initializeEncoding();
IFile file = getOldFile(new SubProgressMonitor(pm, 1));
/*
if (file.exists()) {
CompositeChange composite= new CompositeChange(getName());
composite.add(new DeleteFileChange(file));
composite.add(new CreateFileChange(fPath, fSource, fEncoding, fStampToRestore, fExplicitEncoding));
pm.worked(1);
return composite.perform(new SubProgressMonitor(pm, 1));
} else { */
try {
is = new ByteArrayInputStream(fSource.getBytes(fEncoding));
file.create(is, false, new SubProgressMonitor(pm, 1));
if (fStampToRestore != IResource.NULL_STAMP) {
file.revertModificationStamp(fStampToRestore);
}
if (fExplicitEncoding) {
file.setCharset(fEncoding, new SubProgressMonitor(pm, 1));
} else {
pm.worked(1);
}
return new DeleteResourceChange(file.getFullPath(), true);
} catch (UnsupportedEncodingException e) {
throw new JavaModelException(e, IJavaModelStatusConstants.IO_EXCEPTION);
}
} finally {
try {
if (is != null)
is.close();
} catch (IOException ioe) {
throw new JavaModelException(ioe, IJavaModelStatusConstants.IO_EXCEPTION);
} finally {
pm.done();
}
}
}
use of org.eclipse.core.runtime.SubProgressMonitor in project che by eclipse.
the class ChangeSignatureProcessor method createChangeManager.
private TextChangeManager createChangeManager(IProgressMonitor pm, RefactoringStatus result) throws CoreException {
pm.beginTask(RefactoringCoreMessages.ChangeSignatureRefactoring_preview, 2);
fChangeManager = new TextChangeManager();
boolean isNoArgConstructor = isNoArgConstructor();
Map<ICompilationUnit, Set<IType>> namedSubclassMapping = null;
if (isNoArgConstructor) {
//create only when needed;
namedSubclassMapping = createNamedSubclassMapping(new SubProgressMonitor(pm, 1));
} else {
pm.worked(1);
}
for (int i = 0; i < fOccurrences.length; i++) {
if (pm.isCanceled())
throw new OperationCanceledException();
SearchResultGroup group = fOccurrences[i];
ICompilationUnit cu = group.getCompilationUnit();
if (cu == null)
continue;
CompilationUnitRewrite cuRewrite;
if (cu.equals(getCu())) {
cuRewrite = fBaseCuRewrite;
} else {
cuRewrite = new CompilationUnitRewrite(cu);
cuRewrite.getASTRewrite().setTargetSourceRangeComputer(new TightSourceRangeComputer());
}
ASTNode[] nodes = ASTNodeSearchUtil.findNodes(group.getSearchResults(), cuRewrite.getRoot());
//IntroduceParameterObjectRefactoring needs to update declarations first:
List<OccurrenceUpdate<? extends ASTNode>> deferredUpdates = new ArrayList<OccurrenceUpdate<? extends ASTNode>>();
for (int j = 0; j < nodes.length; j++) {
OccurrenceUpdate<? extends ASTNode> update = createOccurrenceUpdate(nodes[j], cuRewrite, result);
if (update instanceof DeclarationUpdate) {
update.updateNode();
} else {
deferredUpdates.add(update);
}
}
for (Iterator<OccurrenceUpdate<? extends ASTNode>> iter = deferredUpdates.iterator(); iter.hasNext(); ) {
iter.next().updateNode();
}
if (isNoArgConstructor && namedSubclassMapping.containsKey(cu)) {
//only non-anonymous subclasses may have noArgConstructors to modify - see bug 43444
Set<IType> subtypes = namedSubclassMapping.get(cu);
for (Iterator<IType> iter = subtypes.iterator(); iter.hasNext(); ) {
IType subtype = iter.next();
AbstractTypeDeclaration subtypeNode = ASTNodeSearchUtil.getAbstractTypeDeclarationNode(subtype, cuRewrite.getRoot());
if (subtypeNode != null)
modifyImplicitCallsToNoArgConstructor(subtypeNode, cuRewrite);
}
}
TextChange change = cuRewrite.createChange(true);
if (change != null)
fChangeManager.manage(cu, change);
}
pm.done();
return fChangeManager;
}
use of org.eclipse.core.runtime.SubProgressMonitor in project che by eclipse.
the class ChangeSignatureProcessor method createNamedSubclassMapping.
private Map<ICompilationUnit, Set<IType>> createNamedSubclassMapping(IProgressMonitor pm) throws JavaModelException {
IType[] subclasses = getCachedTypeHierarchy(new SubProgressMonitor(pm, 1)).getSubclasses(fMethod.getDeclaringType());
Map<ICompilationUnit, Set<IType>> result = new HashMap<ICompilationUnit, Set<IType>>();
for (int i = 0; i < subclasses.length; i++) {
IType subclass = subclasses[i];
if (subclass.isAnonymous())
continue;
ICompilationUnit cu = subclass.getCompilationUnit();
if (!result.containsKey(cu))
result.put(cu, new HashSet<IType>());
result.get(cu).add(subclass);
}
return result;
}
Aggregations