use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.
the class InlineMethodRefactoring method setCurrentMode.
public RefactoringStatus setCurrentMode(Mode mode) throws JavaModelException {
if (fCurrentMode == mode)
return new RefactoringStatus();
Assert.isTrue(getInitialMode() == Mode.INLINE_SINGLE);
fCurrentMode = mode;
if (mode == Mode.INLINE_SINGLE) {
if (fInitialNode instanceof MethodInvocation)
fTargetProvider = TargetProvider.create((ICompilationUnit) fInitialTypeRoot, (MethodInvocation) fInitialNode);
else if (fInitialNode instanceof SuperMethodInvocation)
fTargetProvider = TargetProvider.create((ICompilationUnit) fInitialTypeRoot, (SuperMethodInvocation) fInitialNode);
else if (fInitialNode instanceof ConstructorInvocation)
fTargetProvider = TargetProvider.create((ICompilationUnit) fInitialTypeRoot, (ConstructorInvocation) fInitialNode);
else
throw new IllegalStateException(String.valueOf(fInitialNode));
} else {
fTargetProvider = TargetProvider.create(fSourceProvider.getDeclaration());
}
return fTargetProvider.checkActivation();
}
use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.
the class IntroduceIndirectionRefactoring method updateReferences.
private RefactoringStatus updateReferences(IProgressMonitor monitor) throws CoreException {
RefactoringStatus result = new RefactoringStatus();
//$NON-NLS-1$
monitor.beginTask("", 90);
if (monitor.isCanceled())
throw new OperationCanceledException();
IMethod[] ripple = RippleMethodFinder2.getRelatedMethods(fTargetMethod, false, new NoOverrideProgressMonitor(monitor, 10), null);
if (monitor.isCanceled())
throw new OperationCanceledException();
SearchResultGroup[] references = Checks.excludeCompilationUnits(getReferences(ripple, new NoOverrideProgressMonitor(monitor, 10), result), result);
if (result.hasFatalError())
return result;
result.merge(Checks.checkCompileErrorsInAffectedFiles(references));
if (monitor.isCanceled())
throw new OperationCanceledException();
int ticksPerCU = references.length == 0 ? 0 : 70 / references.length;
for (int i = 0; i < references.length; i++) {
SearchResultGroup group = references[i];
SearchMatch[] searchResults = group.getSearchResults();
CompilationUnitRewrite currentCURewrite = getCachedCURewrite(group.getCompilationUnit());
for (int j = 0; j < searchResults.length; j++) {
SearchMatch match = searchResults[j];
if (match.isInsideDocComment())
continue;
IMember enclosingMember = (IMember) match.getElement();
ASTNode target = getSelectedNode(group.getCompilationUnit(), currentCURewrite.getRoot(), match.getOffset(), match.getLength());
if (target instanceof SuperMethodInvocation) {
// Cannot retarget calls to super - add a warning
result.merge(createWarningAboutCall(enclosingMember, target, RefactoringCoreMessages.IntroduceIndirectionRefactoring_call_warning_super_keyword));
continue;
}
//$NON-NLS-1$
Assert.isTrue(target instanceof MethodInvocation, "Element of call should be a MethodInvocation.");
MethodInvocation invocation = (MethodInvocation) target;
ITypeBinding typeBinding = getExpressionType(invocation);
if (fIntermediaryFirstParameterType == null) {
// no highest type yet
fIntermediaryFirstParameterType = typeBinding.getTypeDeclaration();
} else {
// check if current type is higher
result.merge(findCommonParent(typeBinding.getTypeDeclaration()));
}
if (result.hasFatalError())
return result;
// create an edit for this particular call
result.merge(updateMethodInvocation(invocation, enclosingMember, currentCURewrite));
// does call see the intermediary method?
// => increase visibility of the type of the intermediary method.
result.merge(adjustVisibility(fIntermediaryType, enclosingMember.getDeclaringType(), new NoOverrideProgressMonitor(monitor, 0)));
if (monitor.isCanceled())
throw new OperationCanceledException();
}
if (!isRewriteKept(group.getCompilationUnit()))
createChangeAndDiscardRewrite(group.getCompilationUnit());
monitor.worked(ticksPerCU);
}
monitor.done();
return result;
}
use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.
the class UndoDocumentChange method isValid.
/**
* {@inheritDoc}
*/
public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException {
if (pm == null)
pm = new NullProgressMonitor();
//$NON-NLS-1$
pm.beginTask("", 1);
RefactoringStatus result = TextChanges.isValid(fDocument, fLength);
pm.worked(1);
return result;
}
use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.
the class DeleteResourcesProcessor 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)
*/
public RefactoringStatus checkFinalConditions(IProgressMonitor pm, CheckConditionsContext context) throws CoreException, OperationCanceledException {
//$NON-NLS-1$
pm.beginTask("", 1);
try {
RefactoringStatus result = new RefactoringStatus();
for (int i = 0; i < fResources.length; i++) {
IResource resource = fResources[i];
if (!resource.isSynchronized(IResource.DEPTH_INFINITE)) {
String pathLabel = BasicElementLabels.getPathLabel(resource.getFullPath(), false);
String locationLabel = null;
IPath location = resource.getLocation();
if (location != null) {
locationLabel = BasicElementLabels.getPathLabel(location, true);
} else {
URI uri = resource.getLocationURI();
if (uri != null) {
locationLabel = BasicElementLabels.getURLPart(uri.toString());
}
}
String warning;
if (resource instanceof IFile) {
if (locationLabel != null) {
warning = Messages.format(RefactoringCoreMessages.DeleteResourcesProcessor_warning_out_of_sync_file_loc, new Object[] { pathLabel, locationLabel });
} else {
warning = Messages.format(RefactoringCoreMessages.DeleteResourcesProcessor_warning_out_of_sync_file, pathLabel);
}
} else {
if (locationLabel != null) {
warning = Messages.format(RefactoringCoreMessages.DeleteResourcesProcessor_warning_out_of_sync_container_loc, new Object[] { pathLabel, locationLabel });
} else {
warning = Messages.format(RefactoringCoreMessages.DeleteResourcesProcessor_warning_out_of_sync_container, pathLabel);
}
}
result.addWarning(warning);
}
}
checkDirtyResources(result);
ResourceChangeChecker checker = (ResourceChangeChecker) context.getChecker(ResourceChangeChecker.class);
IResourceChangeDescriptionFactory deltaFactory = checker.getDeltaFactory();
for (int i = 0; i < fResources.length; i++) {
if (fResources[i].isPhantom()) {
result.addFatalError(Messages.format(RefactoringCoreMessages.DeleteResourcesProcessor_delete_error_phantom, BasicElementLabels.getPathLabel(fResources[i].getFullPath(), false)));
} else if (fDeleteContents && Resources.isReadOnly(fResources[i])) {
result.addFatalError(Messages.format(RefactoringCoreMessages.DeleteResourcesProcessor_delete_error_read_only, BasicElementLabels.getPathLabel(fResources[i].getFullPath(), false)));
} else {
deltaFactory.delete(fResources[i]);
}
}
return result;
} finally {
pm.done();
}
}
use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.
the class MoveResourcesProcessor 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)
*/
public RefactoringStatus checkFinalConditions(IProgressMonitor pm, CheckConditionsContext context) throws CoreException {
//$NON-NLS-1$
pm.beginTask("", 1);
try {
RefactoringStatus status = validateDestination(fDestination);
if (status.hasFatalError()) {
return status;
}
fMoveArguments = new MoveArguments(fDestination, isUpdateReferences());
ResourceChangeChecker checker = (ResourceChangeChecker) context.getChecker(ResourceChangeChecker.class);
IResourceChangeDescriptionFactory deltaFactory = checker.getDeltaFactory();
for (int i = 0; i < fResourcesToMove.length; i++) {
IResource resource = fResourcesToMove[i];
IResource newResource = fDestination.findMember(resource.getName());
if (newResource != null) {
status.addWarning(Messages.format(RefactoringCoreMessages.MoveResourcesProcessor_warning_destination_already_exists, BasicElementLabels.getPathLabel(newResource.getFullPath(), false)));
deltaFactory.delete(newResource);
}
ResourceModifications.buildMoveDelta(deltaFactory, fResourcesToMove[i], fMoveArguments);
}
return status;
} finally {
pm.done();
}
}
Aggregations