use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.
the class ChangeSignatureProcessor method checkFinalConditions.
/* (non-Javadoc)
* @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#checkFinalConditions(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext)
*/
@Override
public RefactoringStatus checkFinalConditions(IProgressMonitor pm, CheckConditionsContext context) throws CoreException, OperationCanceledException {
try {
pm.beginTask(RefactoringCoreMessages.ChangeSignatureRefactoring_checking_preconditions, 8);
RefactoringStatus result = new RefactoringStatus();
clearManagers();
fBaseCuRewrite.clearASTAndImportRewrites();
fBaseCuRewrite.getASTRewrite().setTargetSourceRangeComputer(new TightSourceRangeComputer());
if (isSignatureSameAsInitial())
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ChangeSignatureRefactoring_unchanged);
result.merge(checkSignature(true));
if (result.hasFatalError())
return result;
if (fDelegateUpdating && isSignatureClashWithInitial())
result.merge(RefactoringStatus.createErrorStatus(RefactoringCoreMessages.ChangeSignatureRefactoring_old_and_new_signatures_not_sufficiently_different));
String binaryRefsDescription = Messages.format(RefactoringCoreMessages.ReferencesInBinaryContext_ref_in_binaries_description, BasicElementLabels.getJavaElementName(getMethodName()));
ReferencesInBinaryContext binaryRefs = new ReferencesInBinaryContext(binaryRefsDescription);
fRippleMethods = RippleMethodFinder2.getRelatedMethods(fMethod, binaryRefs, new SubProgressMonitor(pm, 1), null);
result.merge(checkVarargs());
if (result.hasFatalError())
return result;
fOccurrences = findOccurrences(new SubProgressMonitor(pm, 1), binaryRefs, result);
binaryRefs.addErrorIfNecessary(result);
result.merge(checkVisibilityChanges());
result.merge(checkTypeVariables());
if (!isOrderSameAsInitial())
result.merge(checkReorderings(new SubProgressMonitor(pm, 1)));
else
pm.worked(1);
if (!areNamesSameAsInitial())
result.merge(checkRenamings(new SubProgressMonitor(pm, 1)));
else
pm.worked(1);
if (result.hasFatalError())
return result;
// resolveTypesWithoutBindings(new SubProgressMonitor(pm, 1)); // already done in checkSignature(true)
createChangeManager(new SubProgressMonitor(pm, 1), result);
fCachedTypeHierarchy = null;
if (mustAnalyzeAstOfDeclaringCu())
//TODO: should also check in ripple methods (move into createChangeManager)
result.merge(checkCompilationofDeclaringCu());
if (result.hasFatalError())
return result;
Checks.addModifiedFilesToChecker(getAllFilesToModify(), context);
return result;
} finally {
pm.done();
}
}
use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.
the class ChangeSignatureProcessor method checkInitialConditions.
/* (non-Javadoc)
* @see org.eclipse.ltk.core.refactoring.Refactoring#checkInitialConditions(org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
public RefactoringStatus checkInitialConditions(IProgressMonitor monitor) throws CoreException {
try {
//$NON-NLS-1$
monitor.beginTask("", 5);
RefactoringStatus result = Checks.checkIfCuBroken(fMethod);
if (result.hasFatalError())
return result;
if (fMethod == null || !fMethod.exists()) {
String message = Messages.format(RefactoringCoreMessages.ChangeSignatureRefactoring_method_deleted, BasicElementLabels.getFileName(getCu()));
return RefactoringStatus.createFatalErrorStatus(message);
}
if (fMethod.getDeclaringType().isInterface()) {
fTopMethod = MethodChecks.overridesAnotherMethod(fMethod, fMethod.getDeclaringType().newSupertypeHierarchy(new SubProgressMonitor(monitor, 1)));
monitor.worked(1);
} else if (MethodChecks.isVirtual(fMethod)) {
ITypeHierarchy hierarchy = getCachedTypeHierarchy(new SubProgressMonitor(monitor, 1));
fTopMethod = MethodChecks.isDeclaredInInterface(fMethod, hierarchy, new SubProgressMonitor(monitor, 1));
if (fTopMethod == null)
fTopMethod = MethodChecks.overridesAnotherMethod(fMethod, hierarchy);
}
if (fTopMethod == null)
fTopMethod = fMethod;
if (!fTopMethod.equals(fMethod)) {
if (fTopMethod.getDeclaringType().isInterface()) {
RefactoringStatusContext context = JavaStatusContext.create(fTopMethod);
String message = Messages.format(RefactoringCoreMessages.MethodChecks_implements, new String[] { JavaElementUtil.createMethodSignature(fTopMethod), BasicElementLabels.getJavaElementName(fTopMethod.getDeclaringType().getFullyQualifiedName('.')) });
return RefactoringStatus.createStatus(RefactoringStatus.FATAL, message, context, Corext.getPluginId(), RefactoringStatusCodes.METHOD_DECLARED_IN_INTERFACE, fTopMethod);
} else {
RefactoringStatusContext context = JavaStatusContext.create(fTopMethod);
String message = Messages.format(RefactoringCoreMessages.MethodChecks_overrides, new String[] { JavaElementUtil.createMethodSignature(fTopMethod), BasicElementLabels.getJavaElementName(fTopMethod.getDeclaringType().getFullyQualifiedName('.')) });
return RefactoringStatus.createStatus(RefactoringStatus.FATAL, message, context, Corext.getPluginId(), RefactoringStatusCodes.OVERRIDES_ANOTHER_METHOD, fTopMethod);
}
}
if (monitor.isCanceled())
throw new OperationCanceledException();
if (fBaseCuRewrite == null || !fBaseCuRewrite.getCu().equals(getCu())) {
fBaseCuRewrite = new CompilationUnitRewrite(getCu());
fBaseCuRewrite.getASTRewrite().setTargetSourceRangeComputer(new TightSourceRangeComputer());
}
RefactoringStatus[] status = TypeContextChecker.checkMethodTypesSyntax(fMethod, getParameterInfos(), fReturnTypeInfo);
for (int i = 0; i < status.length; i++) {
result.merge(status[i]);
}
monitor.worked(1);
result.merge(createExceptionInfoList());
monitor.worked(1);
return result;
} finally {
monitor.done();
}
}
use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.
the class RenameSupport method perform.
// /**
// * Opens the refactoring dialog for this rename support.
// *
// * @param parent a shell used as a parent for the refactoring dialog.
// * @throws CoreException if an unexpected exception occurs while opening the
// * dialog.
// *
// * @see #openDialog(Shell, boolean)
// */
// public void openDialog(Shell parent) throws CoreException {
// openDialog(parent, false);
// }
//
// /**
// * Opens the refactoring dialog for this rename support.
// *
// * <p>
// * This method has to be called from within the UI thread.
// * </p>
// *
// * @param parent a shell used as a parent for the refactoring, preview, or error dialog
// * @param showPreviewOnly if <code>true</code>, the dialog skips all user input pages and
// * directly shows the preview or error page. Otherwise, shows all pages.
// * @return <code>true</code> if the refactoring has been executed successfully,
// * <code>false</code> if it has been canceled or if an error has happened during
// * initial conditions checking.
// *
// * @throws CoreException if an error occurred while executing the
// * operation.
// *
// * @see #openDialog(Shell)
// * @since 3.3
// */
// public boolean openDialog(Shell parent, boolean showPreviewOnly) throws CoreException {
// ensureChecked();
// if (fPreCheckStatus.hasFatalError()) {
// showInformation(parent, fPreCheckStatus);
// return false;
// }
//
// UserInterfaceStarter starter;
// if (!showPreviewOnly) {
// starter = RenameUserInterfaceManager.getDefault().getStarter(fRefactoring);
// } else {
// starter = new RenameUserInterfaceStarter();
// RenameRefactoringWizard wizard = new RenameRefactoringWizard(fRefactoring, fRefactoring.getName(), null, null, null) {
// @Override
// protected void addUserInputPages() {
// // nothing to add
// }
// };
// wizard.setForcePreviewReview(showPreviewOnly);
// starter.initialize(wizard);
// }
// return starter.activate(fRefactoring, parent, getJavaRenameProcessor().getSaveMode());
// }
//
/**
* Executes the rename refactoring without showing a dialog to gather
* additional user input (for example the new name of the <tt>IJavaElement</tt>).
* Only an error dialog is shown (if necessary) to present the result
* of the refactoring's full precondition checking.
* <p>
* The method has to be called from within the UI thread.
* </p>
*
*
* @throws InterruptedException if the operation has been canceled by the
* user.
* @throws InvocationTargetException if an error occurred while executing the
* operation.
*/
public RefactoringStatus perform() throws InterruptedException, InvocationTargetException {
try {
ensureChecked();
if (fPreCheckStatus.hasFatalError()) {
return fPreCheckStatus;
}
RefactoringExecutionHelper helper = new RefactoringExecutionHelper(fRefactoring, RefactoringCore.getConditionCheckingFailedSeverity(), getJavaRenameProcessor().getSaveMode());
RefactoringStatus status = helper.perform(true, true);
fPerformChangeOperation = helper.getfPerformChangeOperation();
return status;
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
}
use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.
the class RenameSourceFolderChange method isValid.
@Override
public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException {
RefactoringStatus result = super.isValid(pm);
if (result.hasFatalError())
return result;
IPackageFragmentRoot sourceFolder = getSourceFolder();
result.merge(checkIfModifiable(sourceFolder));
return result;
}
use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.
the class ConvertAnonymousToNestedRefactoring method validateInput.
public RefactoringStatus validateInput() {
RefactoringStatus result = Checks.checkTypeName(fClassName, fCu);
if (result.hasFatalError())
return result;
if (fClassNamesUsed.contains(fClassName))
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_type_exists);
IMethodBinding superConstructorBinding = getSuperConstructorBinding();
if (superConstructorBinding == null)
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_compile_errors);
if (fClassName.equals(superConstructorBinding.getDeclaringClass().getName()))
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_another_name);
if (classNameHidesEnclosingType())
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_name_hides);
return result;
}
Aggregations