use of org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring in project xtext-xtend by eclipse.
the class AbstractXtendRenameRefactoringTest method createXtendRenameRefactoring.
protected ProcessorBasedRefactoring createXtendRenameRefactoring(final XtextEditor editor, final int offset, String newName) {
IRenameElementContext renameElementContext = createRenameElementContext(editor, offset);
ProcessorBasedRefactoring renameRefactoring = renameRefactoringProvider.getRenameRefactoring(renameElementContext);
RefactoringProcessor processor = renameRefactoring.getProcessor();
if (processor instanceof AbstractRenameProcessor)
((AbstractRenameProcessor) processor).setNewName(newName);
else if (processor instanceof JavaRenameProcessor)
((JavaRenameProcessor) processor).setNewElementName(newName);
return renameRefactoring;
}
use of org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring in project eclipse.jdt.ls by eclipse.
the class IntroduceParameterRefactoring method checkInitialConditions.
// --- checkActivation
@Override
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException {
try {
// $NON-NLS-1$
pm.beginTask("", 7);
if (!fSourceCU.isStructureKnown()) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.IntroduceParameterRefactoring_syntax_error);
}
IJavaElement enclosingElement = resolveEnclosingElement(fSourceCU, fSelectionStart, fSelectionLength);
if (!(enclosingElement instanceof IMethod)) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.IntroduceParameterRefactoring_expression_in_method);
}
fMethod = (IMethod) enclosingElement;
pm.worked(1);
RefactoringStatus result = new RefactoringStatus();
if (fArguments != null) {
// invoked by script
fChangeSignatureProcessor = new ChangeSignatureProcessor(fArguments, result);
if (!result.hasFatalError()) {
fChangeSignatureRefactoring = new ProcessorBasedRefactoring(fChangeSignatureProcessor);
fChangeSignatureRefactoring.setValidationContext(getValidationContext());
result.merge(fChangeSignatureProcessor.checkInitialConditions(new SubProgressMonitor(pm, 2)));
if (result.hasFatalError()) {
return result;
}
} else {
pm.worked(2);
return result;
}
} else {
// first try:
fChangeSignatureProcessor = RefactoringAvailabilityTester.isChangeSignatureAvailable(fMethod) ? new ChangeSignatureProcessor(fMethod) : null;
if (fChangeSignatureProcessor == null) {
return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.IntroduceParameterRefactoring_expression_in_method);
}
fChangeSignatureRefactoring = new ProcessorBasedRefactoring(fChangeSignatureProcessor);
fChangeSignatureRefactoring.setValidationContext(getValidationContext());
result.merge(fChangeSignatureProcessor.checkInitialConditions(new SubProgressMonitor(pm, 1)));
if (result.hasFatalError()) {
RefactoringStatusEntry entry = result.getEntryMatchingSeverity(RefactoringStatus.FATAL);
if (entry.getCode() == RefactoringStatusCodes.OVERRIDES_ANOTHER_METHOD || entry.getCode() == RefactoringStatusCodes.METHOD_DECLARED_IN_INTERFACE) {
// second try:
IMethod method = (IMethod) entry.getData();
fChangeSignatureProcessor = RefactoringAvailabilityTester.isChangeSignatureAvailable(method) ? new ChangeSignatureProcessor(method) : null;
if (fChangeSignatureProcessor == null) {
String msg = Messages.format(RefactoringCoreMessages.IntroduceParameterRefactoring_cannot_introduce, entry.getMessage());
return RefactoringStatus.createFatalErrorStatus(msg);
}
fChangeSignatureRefactoring = new ProcessorBasedRefactoring(fChangeSignatureProcessor);
fChangeSignatureRefactoring.setValidationContext(getValidationContext());
result = fChangeSignatureProcessor.checkInitialConditions(new SubProgressMonitor(pm, 1));
if (result.hasFatalError()) {
return result;
}
} else {
return result;
}
} else {
pm.worked(1);
}
}
CompilationUnitRewrite cuRewrite = fChangeSignatureProcessor.getBaseCuRewrite();
if (!cuRewrite.getCu().equals(fSourceCU)) {
// TODO: should try to avoid throwing away this AST
cuRewrite = new CompilationUnitRewrite(fSourceCU);
}
initializeSelectedExpression(cuRewrite);
pm.worked(1);
result.merge(checkSelection(cuRewrite, new SubProgressMonitor(pm, 3)));
if (result.hasFatalError()) {
return result;
}
initializeExcludedParameterNames(cuRewrite);
addParameterInfo(cuRewrite);
fChangeSignatureProcessor.setBodyUpdater(new BodyUpdater() {
@Override
public void updateBody(MethodDeclaration methodDeclaration, CompilationUnitRewrite rewrite, RefactoringStatus updaterResult) {
replaceSelectedExpression(rewrite);
}
});
return result;
} finally {
pm.done();
if (fChangeSignatureRefactoring != null) {
fChangeSignatureRefactoring.setValidationContext(null);
}
}
}
use of org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring in project eclipse.jdt.ls by eclipse.
the class ChangeMethodSignatureRefactoringContribution method createRefactoring.
@Override
public Refactoring createRefactoring(JavaRefactoringDescriptor descriptor, RefactoringStatus status) throws CoreException {
JavaRefactoringArguments arguments = new JavaRefactoringArguments(descriptor.getProject(), retrieveArgumentMap(descriptor));
ChangeSignatureProcessor processor = new ChangeSignatureProcessor(arguments, status);
return new ProcessorBasedRefactoring(processor);
}
Aggregations