use of org.eclipse.core.runtime.SubProgressMonitor in project che by eclipse.
the class RenameVirtualMethodProcessor method checkInitialConditions.
//------------ preconditions -------------
@Override
public RefactoringStatus checkInitialConditions(IProgressMonitor monitor) throws CoreException {
RefactoringStatus result = super.checkInitialConditions(monitor);
if (result.hasFatalError())
return result;
try {
//$NON-NLS-1$
monitor.beginTask("", 3);
if (!fActivationChecked) {
// the following code may change the method to be changed.
IMethod method = getMethod();
fOriginalMethod = method;
ITypeHierarchy hierarchy = null;
IType declaringType = method.getDeclaringType();
if (!declaringType.isInterface())
hierarchy = getCachedHierarchy(declaringType, new SubProgressMonitor(monitor, 1));
IMethod topmost = getMethod();
if (MethodChecks.isVirtual(topmost))
topmost = MethodChecks.getTopmostMethod(getMethod(), hierarchy, monitor);
if (topmost != null)
initialize(topmost);
fActivationChecked = true;
}
} finally {
monitor.done();
}
return result;
}
use of org.eclipse.core.runtime.SubProgressMonitor in project che by eclipse.
the class RenameVirtualMethodProcessor method doCheckFinalConditions.
@Override
protected RefactoringStatus doCheckFinalConditions(IProgressMonitor pm, CheckConditionsContext checkContext) throws CoreException {
try {
//$NON-NLS-1$
pm.beginTask("", 9);
RefactoringStatus result = new RefactoringStatus();
result.merge(super.doCheckFinalConditions(new SubProgressMonitor(pm, 7), checkContext));
if (result.hasFatalError())
return result;
final IMethod method = getMethod();
final IType declaring = method.getDeclaringType();
final ITypeHierarchy hierarchy = getCachedHierarchy(declaring, new SubProgressMonitor(pm, 1));
final String name = getNewElementName();
if (declaring.isInterface()) {
if (isSpecialCase())
result.addError(RefactoringCoreMessages.RenameMethodInInterfaceRefactoring_special_case);
pm.worked(1);
IMethod[] relatedMethods = relatedTypeDeclaresMethodName(new SubProgressMonitor(pm, 1), method, name);
for (int i = 0; i < relatedMethods.length; i++) {
IMethod relatedMethod = relatedMethods[i];
RefactoringStatusContext context = JavaStatusContext.create(relatedMethod);
result.addError(RefactoringCoreMessages.RenameMethodInInterfaceRefactoring_already_defined, context);
}
} else {
if (classesDeclareOverridingNativeMethod(hierarchy.getAllSubtypes(declaring))) {
result.addError(Messages.format(RefactoringCoreMessages.RenameVirtualMethodRefactoring_requieres_renaming_native, //$NON-NLS-1$
new String[] { BasicElementLabels.getJavaElementName(method.getElementName()), "UnsatisfiedLinkError" }));
}
IMethod[] hierarchyMethods = hierarchyDeclaresMethodName(new SubProgressMonitor(pm, 1), hierarchy, method, name);
for (int i = 0; i < hierarchyMethods.length; i++) {
IMethod hierarchyMethod = hierarchyMethods[i];
RefactoringStatusContext context = JavaStatusContext.create(hierarchyMethod);
if (Checks.compareParamTypes(method.getParameterTypes(), hierarchyMethod.getParameterTypes())) {
result.addError(Messages.format(RefactoringCoreMessages.RenameVirtualMethodRefactoring_hierarchy_declares2, BasicElementLabels.getJavaElementName(name)), context);
} else {
result.addWarning(Messages.format(RefactoringCoreMessages.RenameVirtualMethodRefactoring_hierarchy_declares1, BasicElementLabels.getJavaElementName(name)), context);
}
}
}
fCachedHierarchy = null;
return result;
} finally {
pm.done();
}
}
use of org.eclipse.core.runtime.SubProgressMonitor in project che by eclipse.
the class RenameTypeProcessor method doCheckFinalConditions.
@Override
protected RefactoringStatus doCheckFinalConditions(IProgressMonitor pm, CheckConditionsContext context) throws CoreException {
//$NON-NLS-1$
Assert.isNotNull(fType, "type");
//$NON-NLS-1$
Assert.isNotNull(getNewElementName(), "newName");
RefactoringStatus result = new RefactoringStatus();
int referenceSearchTicks = fUpdateReferences || fUpdateSimilarElements ? 15 : 0;
int affectedCusTicks = fUpdateReferences || fUpdateSimilarElements ? 10 : 1;
int similarElementTicks = fUpdateSimilarElements ? 85 : 0;
int createChangeTicks = 5;
int qualifiedNamesTicks = fUpdateQualifiedNames ? 50 : 0;
try {
//$NON-NLS-1$
pm.beginTask("", 12 + referenceSearchTicks + affectedCusTicks + similarElementTicks + createChangeTicks + qualifiedNamesTicks);
pm.setTaskName(RefactoringCoreMessages.RenameTypeRefactoring_checking);
fChangeManager = new TextChangeManager(true);
result.merge(checkNewElementName(getNewElementName()));
if (result.hasFatalError())
return result;
result.merge(Checks.checkIfCuBroken(fType));
if (result.hasFatalError())
return result;
pm.worked(1);
result.merge(checkTypesInCompilationUnit());
pm.worked(1);
result.merge(checkForMethodsWithConstructorNames());
pm.worked(1);
result.merge(checkImportedTypes());
pm.worked(1);
if (Checks.isTopLevel(fType)) {
ICompilationUnit cu = fType.getCompilationUnit();
String newCUName = JavaModelUtil.getRenamedCUName(cu, getNewElementName());
if (!newCUName.equals(cu.getElementName()))
result.merge(Checks.checkCompilationUnitNewName(cu, getNewElementName()));
}
pm.worked(1);
if (isPrimaryType())
result.merge(checkNewPathValidity());
pm.worked(1);
result.merge(checkEnclosingTypes());
pm.worked(1);
result.merge(checkEnclosedTypes());
pm.worked(1);
result.merge(checkTypesInPackage());
pm.worked(1);
result.merge(checkTypesImportedInCu());
pm.worked(1);
result.merge(Checks.checkForMainAndNativeMethods(fType));
pm.worked(1);
// before doing any expensive analysis
if (result.hasFatalError())
return result;
result.merge(analyseEnclosedTypes());
pm.worked(1);
// before doing _the really_ expensive analysis
if (result.hasFatalError())
return result;
// Load references, including similarly named elements
if (fUpdateReferences || fUpdateSimilarElements) {
pm.setTaskName(RefactoringCoreMessages.RenameTypeRefactoring_searching);
result.merge(initializeReferences(new SubProgressMonitor(pm, referenceSearchTicks)));
} else {
fReferences = new SearchResultGroup[0];
}
pm.setTaskName(RefactoringCoreMessages.RenameTypeRefactoring_checking);
if (pm.isCanceled())
throw new OperationCanceledException();
if (fUpdateReferences || fUpdateSimilarElements) {
result.merge(analyzeAffectedCompilationUnits(new SubProgressMonitor(pm, affectedCusTicks)));
} else {
Checks.checkCompileErrorsInAffectedFile(result, fType.getResource());
pm.worked(affectedCusTicks);
}
if (result.hasFatalError())
return result;
if (fUpdateSimilarElements) {
result.merge(initializeSimilarElementsRenameProcessors(new SubProgressMonitor(pm, similarElementTicks), context));
if (result.hasFatalError())
return result;
}
createChanges(new SubProgressMonitor(pm, createChangeTicks));
if (fUpdateQualifiedNames)
computeQualifiedNameMatches(new SubProgressMonitor(pm, qualifiedNamesTicks));
return result;
} finally {
pm.done();
}
}
use of org.eclipse.core.runtime.SubProgressMonitor in project che by eclipse.
the class RenameTypeProcessor method createChanges.
private void createChanges(IProgressMonitor pm) throws CoreException {
try {
//$NON-NLS-1$
pm.beginTask("", 12);
pm.setTaskName(RefactoringCoreMessages.RenameTypeProcessor_creating_changes);
if (fUpdateReferences)
addReferenceUpdates(fChangeManager, new SubProgressMonitor(pm, 3));
// Similar names updates have already been added.
pm.worked(1);
IResource resource = fType.getCompilationUnit().getResource();
// directly. So we have to update the code by ourselves.
if ((resource != null && resource.isLinked()) || !willRenameCU()) {
addTypeDeclarationUpdate(fChangeManager);
pm.worked(1);
addConstructorRenames(fChangeManager);
pm.worked(1);
} else {
pm.worked(2);
}
if (fUpdateTextualMatches) {
pm.subTask(RefactoringCoreMessages.RenameTypeRefactoring_searching_text);
TextMatchUpdater.perform(new SubProgressMonitor(pm, 1), RefactoringScopeFactory.create(fType), this, fChangeManager, fReferences);
if (fUpdateSimilarElements)
addSimilarElementsTextualUpdates(fChangeManager, new SubProgressMonitor(pm, 3));
}
} finally {
pm.done();
}
}
use of org.eclipse.core.runtime.SubProgressMonitor in project che by eclipse.
the class RenameFieldProcessor method getNewReferences.
private SearchResultGroup[] getNewReferences(IProgressMonitor pm, RefactoringStatus status, WorkingCopyOwner owner, ICompilationUnit[] newWorkingCopies) throws CoreException {
//$NON-NLS-1$
pm.beginTask("", 2);
ICompilationUnit declaringCuWorkingCopy = RenameAnalyzeUtil.findWorkingCopyForCu(newWorkingCopies, fField.getCompilationUnit());
if (declaringCuWorkingCopy == null)
return new SearchResultGroup[0];
IField field = getFieldInWorkingCopy(declaringCuWorkingCopy, getNewElementName());
if (field == null || !field.exists())
return new SearchResultGroup[0];
CollectingSearchRequestor requestor = null;
if (fDelegateUpdating && RefactoringAvailabilityTester.isDelegateCreationAvailable(getField())) {
// There will be two new matches inside the delegate (the invocation
// and the javadoc) which are OK and must not be reported.
final IField oldField = getFieldInWorkingCopy(declaringCuWorkingCopy, getCurrentElementName());
requestor = new CollectingSearchRequestor() {
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
if (!oldField.equals(match.getElement()))
super.acceptSearchMatch(match);
}
};
} else
requestor = new CollectingSearchRequestor();
SearchPattern newPattern = SearchPattern.createPattern(field, IJavaSearchConstants.REFERENCES);
IJavaSearchScope scope = RefactoringScopeFactory.create(fField, true, true);
return RefactoringSearchEngine.search(newPattern, owner, scope, requestor, new SubProgressMonitor(pm, 1), status);
}
Aggregations