org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring Java Examples
The following examples show how to use
org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JvmRenameRefactoringProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Override public ProcessorBasedRefactoring getRenameRefactoring(IRenameElementContext renameElementContext) { if (renameElementContext instanceof JdtRefactoringContext) { IJavaElement javaElement = ((JdtRefactoringContext) renameElementContext).getJavaElement(); if (isJavaSource(javaElement)) { try { RenameJavaElementDescriptor renameDescriptor = createRenameDescriptor(javaElement, javaElement.getElementName()); return (ProcessorBasedRefactoring) renameDescriptor.createRefactoring(new RefactoringStatus()); } catch (Exception exc) { throw new WrappedException(exc); } } } return super.getRenameRefactoring(renameElementContext); }
Example #2
Source File: PushDownRefactoringContribution.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * {@inheritDoc} */ @Override public final Refactoring createRefactoring(JavaRefactoringDescriptor descriptor, RefactoringStatus status) throws CoreException { JavaRefactoringArguments arguments= new JavaRefactoringArguments(descriptor.getProject(), retrieveArgumentMap(descriptor)); PushDownRefactoringProcessor processor= new PushDownRefactoringProcessor(arguments, status); return new ProcessorBasedRefactoring(processor); }
Example #3
Source File: RefactoringExecutionStarter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static void startIntroduceParameterObject(IMethod method, Shell shell) throws CoreException { RefactoringStatus availability= Checks.checkAvailability(method); if (availability.hasError()){ MessageDialog.openError(shell, RefactoringMessages.RefactoringExecutionStarter_IntroduceParameterObject_problem_title, RefactoringMessages.RefactoringExecutionStarter_IntroduceParameterObject_problem_description); return; } IntroduceParameterObjectDescriptor ipod= RefactoringSignatureDescriptorFactory.createIntroduceParameterObjectDescriptor(); ipod.setMethod(method); IntroduceParameterObjectProcessor processor= new IntroduceParameterObjectProcessor(ipod); final RefactoringStatus status= processor.checkInitialConditions(new NullProgressMonitor()); if (status.hasFatalError()) { final RefactoringStatusEntry entry= status.getEntryMatchingSeverity(RefactoringStatus.FATAL); if (entry.getCode() == RefactoringStatusCodes.OVERRIDES_ANOTHER_METHOD || entry.getCode() == RefactoringStatusCodes.METHOD_DECLARED_IN_INTERFACE) { final Object element= entry.getData(); IMethod superMethod= (IMethod) element; availability= Checks.checkAvailability(superMethod); if (availability.hasError()){ MessageDialog.openError(shell, RefactoringMessages.RefactoringExecutionStarter_IntroduceParameterObject_problem_title, RefactoringMessages.RefactoringExecutionStarter_IntroduceParameterObject_problem_description); return; } String message= Messages.format(RefactoringMessages.RefactoringErrorDialogUtil_okToPerformQuestion, entry.getMessage()); if (element != null && MessageDialog.openQuestion(shell, RefactoringMessages.OpenRefactoringWizardAction_refactoring, message)) { ipod= RefactoringSignatureDescriptorFactory.createIntroduceParameterObjectDescriptor(); ipod.setMethod(superMethod); processor= new IntroduceParameterObjectProcessor(ipod); } else processor=null; } } if (processor != null) { Refactoring refactoring= new ProcessorBasedRefactoring(processor); IntroduceParameterObjectWizard wizard= new IntroduceParameterObjectWizard(processor, refactoring); new RefactoringStarter().activate(wizard, shell, RefactoringMessages.OpenRefactoringWizardAction_refactoring, RefactoringSaveHelper.SAVE_REFACTORING); } }
Example #4
Source File: RefactoringExecutionStarter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static void startPushDownRefactoring(final IMember[] members, final Shell shell) throws JavaModelException { if (!RefactoringAvailabilityTester.isPushDownAvailable(members)) return; PushDownRefactoringProcessor processor= new PushDownRefactoringProcessor(members); Refactoring refactoring= new ProcessorBasedRefactoring(processor); PushDownWizard wizard= new PushDownWizard(processor, refactoring); new RefactoringStarter().activate(wizard, shell, RefactoringMessages.OpenRefactoringWizardAction_refactoring, RefactoringSaveHelper.SAVE_REFACTORING); }
Example #5
Source File: RefactoringExecutionStarter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static void startPullUpRefactoring(final IMember[] members, final Shell shell) throws JavaModelException { if (!RefactoringAvailabilityTester.isPullUpAvailable(members)) return; IJavaProject project= null; if (members != null && members.length > 0) project= members[0].getJavaProject(); PullUpRefactoringProcessor processor= new PullUpRefactoringProcessor(members, JavaPreferencesSettings.getCodeGenerationSettings(project)); Refactoring refactoring= new ProcessorBasedRefactoring(processor); new RefactoringStarter().activate(new PullUpWizard(processor, refactoring), shell, RefactoringMessages.OpenRefactoringWizardAction_refactoring, RefactoringSaveHelper.SAVE_REFACTORING); }
Example #6
Source File: RefactoringExecutionStarter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static void startExtractSupertypeRefactoring(final IMember[] members, final Shell shell) throws JavaModelException { if (!RefactoringAvailabilityTester.isExtractSupertypeAvailable(members)) return; IJavaProject project= null; if (members != null && members.length > 0) project= members[0].getJavaProject(); ExtractSupertypeProcessor processor= new ExtractSupertypeProcessor(members, JavaPreferencesSettings.getCodeGenerationSettings(project)); Refactoring refactoring= new ProcessorBasedRefactoring(processor); ExtractSupertypeWizard wizard= new ExtractSupertypeWizard(processor, refactoring); new RefactoringStarter().activate(wizard, shell, RefactoringMessages.OpenRefactoringWizardAction_refactoring, RefactoringSaveHelper.SAVE_REFACTORING); }
Example #7
Source File: RefactoringExecutionStarter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static void startChangeSignatureRefactoring(final IMethod method, final SelectionDispatchAction action, final Shell shell) throws JavaModelException { if (!RefactoringAvailabilityTester.isChangeSignatureAvailable(method)) return; try { ChangeSignatureProcessor processor= new ChangeSignatureProcessor(method); RefactoringStatus status= processor.checkInitialConditions(new NullProgressMonitor()); if (status.hasFatalError()) { final RefactoringStatusEntry entry= status.getEntryMatchingSeverity(RefactoringStatus.FATAL); if (entry.getCode() == RefactoringStatusCodes.OVERRIDES_ANOTHER_METHOD || entry.getCode() == RefactoringStatusCodes.METHOD_DECLARED_IN_INTERFACE) { Object element= entry.getData(); if (element != null) { String message= Messages.format(RefactoringMessages.RefactoringErrorDialogUtil_okToPerformQuestion, entry.getMessage()); if (MessageDialog.openQuestion(shell, RefactoringMessages.OpenRefactoringWizardAction_refactoring, message)) { IStructuredSelection selection= new StructuredSelection(element); // TODO: should not hijack this // ModifiyParametersAction. // The action is set up on an editor, but we use it // as if it were set up on a ViewPart. boolean wasEnabled= action.isEnabled(); action.selectionChanged(selection); if (action.isEnabled()) { action.run(selection); } else { MessageDialog.openInformation(shell, ActionMessages.ModifyParameterAction_problem_title, ActionMessages.ModifyParameterAction_problem_message); } action.setEnabled(wasEnabled); } } return; } } Refactoring refactoring= new ProcessorBasedRefactoring(processor); ChangeSignatureWizard wizard= new ChangeSignatureWizard(processor, refactoring); new RefactoringStarter().activate(wizard, shell, wizard.getDefaultPageTitle(), RefactoringSaveHelper.SAVE_REFACTORING); } catch (CoreException e) { ExceptionHandler.handle(e, RefactoringMessages.OpenRefactoringWizardAction_refactoring, RefactoringMessages.RefactoringStarter_unexpected_exception); } }
Example #8
Source File: ExtractInterfaceRefactoringContribution.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * {@inheritDoc} */ @Override public final Refactoring createRefactoring(JavaRefactoringDescriptor descriptor, RefactoringStatus status) throws CoreException { JavaRefactoringArguments arguments= new JavaRefactoringArguments(descriptor.getProject(), retrieveArgumentMap(descriptor)); ExtractInterfaceProcessor processor= new ExtractInterfaceProcessor(arguments, status); return new ProcessorBasedRefactoring(processor); }
Example #9
Source File: ChangeMethodSignatureRefactoringContribution.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * {@inheritDoc} */ @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); }
Example #10
Source File: IntroduceParameterObjectContribution.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public Refactoring createRefactoring(JavaRefactoringDescriptor descriptor, RefactoringStatus status) throws CoreException { if (descriptor instanceof IntroduceParameterObjectDescriptor) { IntroduceParameterObjectProcessor processor= new IntroduceParameterObjectProcessor((IntroduceParameterObjectDescriptor) descriptor); return new ProcessorBasedRefactoring(processor); } return null; }
Example #11
Source File: ExtractSupertypeRefactoringContribution.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * {@inheritDoc} */ @Override public final Refactoring createRefactoring(JavaRefactoringDescriptor descriptor, RefactoringStatus status) throws CoreException { JavaRefactoringArguments arguments= new JavaRefactoringArguments(descriptor.getProject(), retrieveArgumentMap(descriptor)); ExtractSupertypeProcessor processor= new ExtractSupertypeProcessor(arguments, status); return new ProcessorBasedRefactoring(processor); }
Example #12
Source File: PullUpRefactoringContribution.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * {@inheritDoc} */ @Override public final Refactoring createRefactoring(JavaRefactoringDescriptor descriptor, RefactoringStatus status) throws CoreException { JavaRefactoringArguments arguments= new JavaRefactoringArguments(descriptor.getProject(), retrieveArgumentMap(descriptor)); PullUpRefactoringProcessor processor= new PullUpRefactoringProcessor(arguments, status); return new ProcessorBasedRefactoring(processor); }
Example #13
Source File: UseSupertypeRefactoringContribution.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * {@inheritDoc} */ @Override public final Refactoring createRefactoring(JavaRefactoringDescriptor descriptor, RefactoringStatus status) throws CoreException { JavaRefactoringArguments arguments= new JavaRefactoringArguments(descriptor.getProject(), retrieveArgumentMap(descriptor)); UseSuperTypeProcessor processor= new UseSuperTypeProcessor(arguments, status); return new ProcessorBasedRefactoring(processor); }
Example #14
Source File: PairedInterfaceRenameParticipant.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
private Change createChangeForInterfaceRename() throws RefactoringException { InterfaceRenameChangeBuilder builder = new InterfaceRenameChangeBuilder( typeContainer.getPairedType(), pairedNewName, processor, typeContainer.getPairedType().getJavaProject().getProject().getWorkspace()); ProcessorBasedRefactoring refactoring = (ProcessorBasedRefactoring) builder.createRefactoring(); RefactoringProcessor nestedProcessor = refactoring.getProcessor(); NestedRefactoringContext.storeForProcessor( nestedProcessor, InterfaceRenameRefactoringContext.newNestedRefactoringContext(typeContainer.getBaseType())); return builder.createChange(); }
Example #15
Source File: PairedMethodRenameParticipant.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
private Change createChangeForMethodRename(IMethod methodToRename) throws RefactoringException { MethodRenameChangeBuilder builder = new MethodRenameChangeBuilder( methodToRename, newMethodName, processor, methodToRename.getJavaProject().getProject().getWorkspace()); ProcessorBasedRefactoring refactoring = (ProcessorBasedRefactoring) builder.createRefactoring(); RefactoringProcessor nestedProcessor = refactoring.getProcessor(); NestedRefactoringContext.storeForProcessor( nestedProcessor, MethodRenameRefactoringContext.newNestedRefactoringContext(refactoringContext)); return builder.createChange(); }
Example #16
Source File: XtendQuickfixProvider.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Fix(IssueCodes.WRONG_FILE) public void fixWrongFileRenameClass(final Issue issue, final IssueResolutionAcceptor acceptor) { URI uri = issue.getUriToProblem(); String className = uri.trimFileExtension().lastSegment(); String label = String.format("Rename class to '%s'", className); acceptor.accept(issue, label, label, null, (element, context) -> { context.getXtextDocument().modify(resource -> { IRenameElementContext renameContext = renameContextFactory.createRenameElementContext(element, null, new TextSelection(context.getXtextDocument(), issue.getOffset(), issue.getLength()), resource); final ProcessorBasedRefactoring refactoring = renameRefactoringProvider.getRenameRefactoring(renameContext); ((RenameElementProcessor) refactoring.getProcessor()).setNewName(className); PlatformUI.getWorkbench().getActiveWorkbenchWindow().run(true, true, monitor -> { try { if (!refactoring.checkFinalConditions(monitor).isOK()) return; Change change = refactoring.createChange(monitor); change.initializeValidationData(monitor); PerformChangeOperation performChangeOperation = new PerformChangeOperation(change); performChangeOperation.setUndoManager(RefactoringCore.getUndoManager(), refactoring.getName()); performChangeOperation.setSchedulingRule(ResourcesPlugin.getWorkspace().getRoot()); performChangeOperation.run(monitor); } catch (CoreException e) { logger.error(e); } }); return null; }); }); }
Example #17
Source File: AbstractXtendRenameRefactoringTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
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; }
Example #18
Source File: AbstractXtendRenameRefactoringTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected RefactoringStatus renameXtendElementWithError(final XtextEditor editor, final int offset, String newName, IProgressMonitor monitor) throws Exception { syncUtil.totalSync(false); ProcessorBasedRefactoring renameRefactoring = createXtendRenameRefactoring(editor, offset, newName); RefactoringStatus status = renameRefactoring.checkAllConditions(monitor); assertFalse("Expected an error", status.isOK()); return status; }
Example #19
Source File: CombinedJvmJdtRenameRefactoringProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public ProcessorBasedRefactoring getRenameRefactoring(IRenameElementContext renameElementContext) { if (renameElementContext instanceof CombinedJvmJdtRenameContext) { RenameProcessor renameProcessor = getRenameProcessor(renameElementContext); if (renameProcessor != null) { return createChangeCombiningRefactoring(renameProcessor); } return null; } return super.getRenameRefactoring(renameElementContext); }
Example #20
Source File: DefaultRenameRefactoringProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public ProcessorBasedRefactoring getRenameRefactoring(IRenameElementContext renameElementContext) { RenameProcessor processor = getRenameProcessor(renameElementContext); if (processor != null) { return new RenameRefactoring(processor); } return null; }
Example #21
Source File: RenameRefactoringExecuter.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected boolean isApplicable(Shell parent, ProcessorBasedRefactoring refactoring) { try { if (refactoring.isApplicable()) { return true; } showFatalErrorMessage(parent, "Refactoring is not applicable"); } catch (CoreException e) { LOG.error("Error detecting applicability of refactoring", e); showFatalErrorMessage(parent, "Cannot apply refactoring. See log for details."); } return false; }
Example #22
Source File: RenameRefactoringXpectMethod.java From n4js with Eclipse Public License 1.0 | 4 votes |
/** * Rename refactoring Xpect method */ // Note: arg1=OFFSET makes the 'offset' parameter contain the right offset value @ParameterParser(syntax = "('at' arg2=OFFSET 'to' arg3=STRING) ('resource' arg4=STRING)?") @Xpect @ConsumedIssues({ Severity.INFO, Severity.ERROR, Severity.WARNING }) public void renameRefactoring( @StringDiffExpectation(whitespaceSensitive = false) IStringDiffExpectation expectation, // arg0 @ThisResource XtextResource resource, // arg1 IEObjectCoveringRegion offset, // arg2 String newName, // arg3 String specifiedResourcePath, // arg4 @N4JSCommaSeparatedValuesExpectation IN4JSCommaSeparatedValuesExpectation expectedResult) throws Exception { try { EObject context = offset.getEObject(); EObject selectedElement = offsetHelper.resolveElementAt((XtextResource) context.eResource(), offset.getOffset()); // LiteralOrComputedPropertyName does not have a type model but its container does if (selectedElement instanceof LiteralOrComputedPropertyName) { selectedElement = selectedElement.eContainer(); } // An IdentifierRef refers to an AST FormalParameter and not TFormalParameter if (!(selectedElement instanceof FormalParameter) && (N4JSLanguageUtils.getDefinedTypeModelElement(selectedElement) != null)) { selectedElement = N4JSLanguageUtils.getDefinedTypeModelElement(selectedElement); } // while (selectedElement != null) { // while (Display.getCurrent().readAndDispatch()) // ; // Display.getCurrent().sleep(); // } URI targetResourceUri = context.eResource().getURI(); Optional<XtextEditor> editorOp = EditorsUtil.openXtextEditor(targetResourceUri, N4JSActivator.ORG_ECLIPSE_N4JS_N4JS); XtextEditor editor = editorOp.get(); final ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection(); IRenameElementContext renameElementContext = renameContextFactory .createRenameElementContext( selectedElement, editor, selection, resource); IRenameSupport renameSupport = renameSupportFactory.create(renameElementContext, newName); // HACK, use reflection to obtain the private field 'renameRefactoring' since we need it to verify the // conditions // Field field = renameSupport.getClass().getDeclaredField("renameRefactoring"); // field.setAccessible(true); ProcessorBasedRefactoring refactoring = (ProcessorBasedRefactoring) ReflectionUtil.getFieldValue( renameSupport, "renameRefactoring"); RefactoringStatus status = refactoring.checkAllConditions(new NullProgressMonitor()); // If rename refactoring's conditions are not satisfied, validate the error message if (status.hasError()) { RefactoringStatusEntry[] entries = status.getEntries(); List<String> errorMessages = Arrays.stream(entries).map(statusEntry -> statusEntry.getMessage()) .collect(Collectors.toList()); expectedResult.assertEquals(errorMessages); } else { String beforeRenameContent = getResourceContentWithoutXpectComment(specifiedResourcePath, resource); renameSupport.startDirectRefactoring(); String afterRenameContent = getResourceContentWithoutXpectComment(specifiedResourcePath, resource); expectation.assertDiffEquals(beforeRenameContent, afterRenameContent); } } finally { EditorsUtil.forceCloseAllEditors(); } }
Example #23
Source File: CombinedJvmJdtRenameRefactoringProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
protected ProcessorBasedRefactoring createChangeCombiningRefactoring(RenameProcessor renameProcessor) { return new ChangeCombiningRenameRefactoring(renameProcessor, textChangeCombiner); }
Example #24
Source File: RefactoringExecutionStarter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public static void startExtractInterfaceRefactoring(final IType type, final Shell shell) { ExtractInterfaceProcessor processor= new ExtractInterfaceProcessor(type, JavaPreferencesSettings.getCodeGenerationSettings(type.getJavaProject())); Refactoring refactoring= new ProcessorBasedRefactoring(processor); new RefactoringStarter().activate(new ExtractInterfaceWizard(processor, refactoring), shell, RefactoringMessages.OpenRefactoringWizardAction_refactoring, RefactoringSaveHelper.SAVE_REFACTORING); }
Example #25
Source File: RenameRefactoringExecuter.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
public CheckConditionsAndCreateChangeRunnable(Shell shell, ProcessorBasedRefactoring refactoring) { this.shell = shell; this.refactoring = refactoring; }
Example #26
Source File: RenameElementWizard.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
public RenameElementWizard(ProcessorBasedRefactoring refactoring, IRenameElementContext context) { super(refactoring, DIALOG_BASED_USER_INTERFACE); setWindowTitle("Rename Element"); this.context = context; renameProcessor = (AbstractRenameProcessor) refactoring.getProcessor(); }
Example #27
Source File: RefactoringExecutionStarter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public static void startUseSupertypeRefactoring(final IType type, final Shell shell) { UseSuperTypeProcessor processor= new UseSuperTypeProcessor(type); Refactoring refactoring= new ProcessorBasedRefactoring(processor); UseSupertypeWizard wizard= new UseSupertypeWizard(processor, refactoring); new RefactoringStarter().activate(wizard, shell, RefactoringMessages.OpenRefactoringWizardAction_refactoring, RefactoringSaveHelper.SAVE_REFACTORING); }
Example #28
Source File: IRenameRefactoringProvider.java From xtext-eclipse with Eclipse Public License 2.0 | votes |
ProcessorBasedRefactoring getRenameRefactoring(IRenameElementContext renameElementContext);