Search in sources :

Example 1 with RenameRefactoring

use of org.eclipse.ltk.core.refactoring.participants.RenameRefactoring in project che by eclipse.

the class RefactoringManager method createRenameRefactoring.

/**
     * Create rename refactoring. It can create two rename refactoring types.
     * First is linked mode rename refactoring, second is classic rename refactoring with wizard.
     *
     * @param element
     *         element to rename
     * @param cu
     *         compilation unit which element belongs. null if element is IPackageFragment.
     * @param offset
     *         cursor position inside editor, used only for linked mode
     * @param lightweight
     *         if true try to create linked mode refactoring
     * @return rename refactoring session
     * @throws CoreException
     *         when impossible to create RenameSupport
     * @throws RefactoringException
     *         when we don't support renaming provided element
     */
public RenameRefactoringSession createRenameRefactoring(IJavaElement element, ICompilationUnit cu, int offset, boolean lightweight) throws CoreException, RefactoringException {
    //package fragments are always renamed with wizard
    RenameRefactoringSession session = DtoFactory.newDto(RenameRefactoringSession.class);
    String id = String.format("rename-%s", sessionId.getAndIncrement());
    session.setSessionId(id);
    session.setOldName(element.getElementName());
    session.setWizardType(getWizardType(element));
    if (lightweight && !(element instanceof IPackageFragment)) {
        RenameLinkedModeRefactoringSession refactoringSession = new RenameLinkedModeRefactoringSession(element, cu, offset);
        LinkedModeModel model = refactoringSession.getModel();
        if (model != null) {
            session.setLinkedModeModel(model);
        }
        sessions.put(id, refactoringSession);
        return session;
    } else {
        RenameSupport renameSupport = createRenameSupport(element, null, RenameSupport.UPDATE_REFERENCES);
        if (renameSupport != null && renameSupport.preCheck().isOK()) {
            RenameRefactoring refactoring = renameSupport.getfRefactoring();
            RenameSession renameSession = new RenameSession(refactoring);
            sessions.put(id, renameSession);
            return session;
        }
        throw new RefactoringException("Can't create refactoring session for element: " + element.getElementName());
    }
}
Also used : IPackageFragment(org.eclipse.jdt.core.IPackageFragment) RenameSession(org.eclipse.che.plugin.java.server.refactoring.session.RenameSession) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) RenameLinkedModeRefactoringSession(org.eclipse.che.plugin.java.server.refactoring.session.RenameLinkedModeRefactoringSession) LinkedModeModel(org.eclipse.che.ide.ext.java.shared.dto.LinkedModeModel) RenameRefactoringSession(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession) RenameSupport(org.eclipse.jdt.ui.refactoring.RenameSupport)

Example 2 with RenameRefactoring

use of org.eclipse.ltk.core.refactoring.participants.RenameRefactoring in project che by eclipse.

the class RenameFieldRefactoringContribution method createRefactoring.

/**
	 * {@inheritDoc}
	 */
@Override
public Refactoring createRefactoring(JavaRefactoringDescriptor descriptor, RefactoringStatus status) {
    JavaRefactoringArguments arguments = new JavaRefactoringArguments(descriptor.getProject(), retrieveArgumentMap(descriptor));
    RenameFieldProcessor processor = new RenameFieldProcessor(arguments, status);
    return new RenameRefactoring(processor);
}
Also used : JavaRefactoringArguments(org.eclipse.jdt.internal.corext.refactoring.JavaRefactoringArguments) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) RenameFieldProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.RenameFieldProcessor)

Example 3 with RenameRefactoring

use of org.eclipse.ltk.core.refactoring.participants.RenameRefactoring in project che by eclipse.

the class RenameMethodRefactoringContribution method createRefactoring.

/**
	 * {@inheritDoc}
	 */
@Override
public Refactoring createRefactoring(JavaRefactoringDescriptor descriptor, RefactoringStatus status) throws JavaModelException {
    JavaRefactoringArguments arguments = new JavaRefactoringArguments(descriptor.getProject(), retrieveArgumentMap(descriptor));
    String input = arguments.getAttribute(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT);
    IMethod method = (IMethod) JavaRefactoringDescriptorUtil.handleToElement(arguments.getProject(), input);
    if (method == null) {
        status.addFatalError(Messages.format(RefactoringCoreMessages.RenameMethodRefactoringContribution_could_not_create, new Object[] { BasicElementLabels.getResourceName(arguments.getProject()), input }));
        return null;
    }
    JavaRenameProcessor processor;
    if (MethodChecks.isVirtual(method)) {
        processor = new RenameVirtualMethodProcessor(method, arguments, status);
    } else {
        processor = new RenameNonVirtualMethodProcessor(method, arguments, status);
    }
    return new RenameRefactoring(processor);
}
Also used : JavaRefactoringArguments(org.eclipse.jdt.internal.corext.refactoring.JavaRefactoringArguments) RenameNonVirtualMethodProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.RenameNonVirtualMethodProcessor) RenameVirtualMethodProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.RenameVirtualMethodProcessor) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) JavaRenameProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.JavaRenameProcessor) IMethod(org.eclipse.jdt.core.IMethod)

Example 4 with RenameRefactoring

use of org.eclipse.ltk.core.refactoring.participants.RenameRefactoring in project che by eclipse.

the class RenamePackageRefactoringContribution method createRefactoring.

/**
	 * {@inheritDoc}
	 */
@Override
public Refactoring createRefactoring(JavaRefactoringDescriptor descriptor, RefactoringStatus status) {
    JavaRefactoringArguments arguments = new JavaRefactoringArguments(descriptor.getProject(), retrieveArgumentMap(descriptor));
    RenamePackageProcessor processor = new RenamePackageProcessor(arguments, status);
    return new RenameRefactoring(processor);
}
Also used : JavaRefactoringArguments(org.eclipse.jdt.internal.corext.refactoring.JavaRefactoringArguments) RenamePackageProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.RenamePackageProcessor) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring)

Example 5 with RenameRefactoring

use of org.eclipse.ltk.core.refactoring.participants.RenameRefactoring in project che by eclipse.

the class RenameCompilationUnitRefactoringContribution method createRefactoring.

/**
	 * {@inheritDoc}
	 */
@Override
public Refactoring createRefactoring(JavaRefactoringDescriptor descriptor, RefactoringStatus status) throws CoreException {
    JavaRefactoringArguments arguments = new JavaRefactoringArguments(descriptor.getProject(), retrieveArgumentMap(descriptor));
    RenameCompilationUnitProcessor processor = new RenameCompilationUnitProcessor(arguments, status);
    return new RenameRefactoring(processor);
}
Also used : JavaRefactoringArguments(org.eclipse.jdt.internal.corext.refactoring.JavaRefactoringArguments) RenameCompilationUnitProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.RenameCompilationUnitProcessor) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring)

Aggregations

RenameRefactoring (org.eclipse.ltk.core.refactoring.participants.RenameRefactoring)37 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)13 IType (org.eclipse.jdt.core.IType)12 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)10 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)8 JavaRefactoringArguments (org.eclipse.jdt.internal.corext.refactoring.JavaRefactoringArguments)8 CoreException (org.eclipse.core.runtime.CoreException)5 RenameJavaElementDescriptor (org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor)5 RenameMethodProcessor (org.eclipse.jdt.internal.corext.refactoring.rename.RenameMethodProcessor)5 RenameTypeParameterProcessor (org.eclipse.jdt.internal.corext.refactoring.rename.RenameTypeParameterProcessor)5 RenameArguments (org.eclipse.ltk.core.refactoring.participants.RenameArguments)5 RefactoringWizard (org.eclipse.ltk.ui.refactoring.RefactoringWizard)5 RefactoringWizardOpenOperation (org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation)5 RenameRefactoringWizard (org.eclipse.wst.xsd.ui.internal.refactor.wizard.RenameRefactoringWizard)5 IFile (org.eclipse.core.resources.IFile)4 IResource (org.eclipse.core.resources.IResource)4 IMethod (org.eclipse.jdt.core.IMethod)4 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)4 RenameVirtualMethodProcessor (org.eclipse.jdt.internal.corext.refactoring.rename.RenameVirtualMethodProcessor)4 RenameResourceProcessor (org.eclipse.ltk.internal.core.refactoring.resource.RenameResourceProcessor)4