use of org.eclipse.ltk.core.refactoring.RefactoringStatus 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.ltk.core.refactoring.RefactoringStatus 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.ltk.core.refactoring.RefactoringStatus 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.ltk.core.refactoring.RefactoringStatus in project che by eclipse.
the class RenameTypeProcessor method analyzeAffectedCompilationUnits.
/*
* Analyzes all compilation units in which type is referenced
*/
private RefactoringStatus analyzeAffectedCompilationUnits(IProgressMonitor pm) throws CoreException {
RefactoringStatus result = new RefactoringStatus();
result.merge(Checks.checkCompileErrorsInAffectedFiles(fReferences, fType.getResource()));
//$NON-NLS-1$
pm.beginTask("", fReferences.length);
result.merge(checkConflictingTypes(pm));
return result;
}
use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.
the class RenameTypeProcessor method checkImportedTypes.
private RefactoringStatus checkImportedTypes() throws CoreException {
RefactoringStatus result = new RefactoringStatus();
IImportDeclaration[] imports = fType.getCompilationUnit().getImports();
for (int i = 0; i < imports.length; i++) analyzeImportDeclaration(imports[i], result);
return result;
}
Aggregations