Search in sources :

Example 11 with ProcessorBasedRefactoring

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;
}
Also used : CompositeRefactoringProcessor(org.eclipse.xtext.common.types.ui.refactoring.participant.CompositeRefactoringProcessor) RefactoringProcessor(org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor) AbstractRenameProcessor(org.eclipse.xtext.ui.refactoring.impl.AbstractRenameProcessor) IRenameElementContext(org.eclipse.xtext.ui.refactoring.ui.IRenameElementContext) JavaRenameProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.JavaRenameProcessor) ProcessorBasedRefactoring(org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring)

Example 12 with ProcessorBasedRefactoring

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);
        }
    }
}
Also used : CompilationUnitRewrite(org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite) BodyUpdater(org.eclipse.jdt.ls.core.internal.corext.refactoring.BodyUpdater) IJavaElement(org.eclipse.jdt.core.IJavaElement) MethodDeclaration(org.eclipse.jdt.core.dom.MethodDeclaration) RefactoringStatusEntry(org.eclipse.ltk.core.refactoring.RefactoringStatusEntry) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) IMethod(org.eclipse.jdt.core.IMethod) ProcessorBasedRefactoring(org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) ChangeSignatureProcessor(org.eclipse.jdt.ls.core.internal.corext.refactoring.ChangeSignatureProcessor)

Example 13 with ProcessorBasedRefactoring

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);
}
Also used : JavaRefactoringArguments(org.eclipse.jdt.internal.corext.refactoring.JavaRefactoringArguments) ProcessorBasedRefactoring(org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring)

Aggregations

ProcessorBasedRefactoring (org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring)13 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)8 CoreException (org.eclipse.core.runtime.CoreException)4 IMethod (org.eclipse.jdt.core.IMethod)3 Change (org.eclipse.ltk.core.refactoring.Change)3 Refactoring (org.eclipse.ltk.core.refactoring.Refactoring)3 RefactoringProcessor (org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor)3 IRenameElementContext (org.eclipse.xtext.ui.refactoring.ui.IRenameElementContext)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)2 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)2 IType (org.eclipse.jdt.core.IType)2 JavaRenameProcessor (org.eclipse.jdt.internal.corext.refactoring.rename.JavaRenameProcessor)2 ChangeSignatureProcessor (org.eclipse.jdt.internal.corext.refactoring.structure.ChangeSignatureProcessor)2 WorkspaceModifyOperation (org.eclipse.ui.actions.WorkspaceModifyOperation)2 CompositeRefactoringProcessor (org.eclipse.xtext.common.types.ui.refactoring.participant.CompositeRefactoringProcessor)2 AbstractRenameProcessor (org.eclipse.xtext.ui.refactoring.impl.AbstractRenameProcessor)2 ArrayList (java.util.ArrayList)1