Search in sources :

Example 1 with RenameLinkedModeRefactoringSession

use of org.eclipse.che.plugin.java.server.refactoring.session.RenameLinkedModeRefactoringSession in project che by eclipse.

the class RefactoringManager method applyLinkedRename.

/**
     * Apply linked mode rename refactoring.
     *
     * @param apply
     *         contains new element name
     * @return refactoring result
     * @throws RefactoringException
     *         when refactoring session not found.
     * @throws CoreException
     *         when impossible to apply rename refactoring
     */
public RefactoringResult applyLinkedRename(LinkedRenameRefactoringApply apply) throws RefactoringException, CoreException {
    RefactoringSession session = getRefactoringSession(apply.getSessionId());
    if (session instanceof RenameLinkedModeRefactoringSession) {
        RenameLinkedModeRefactoringSession renameSession = (RenameLinkedModeRefactoringSession) session;
        try {
            RefactoringResult refactoringResult = renameSession.doRename(apply.getNewName());
            deleteRefactoringSession(apply.getSessionId());
            return refactoringResult;
        } catch (InvocationTargetException | InterruptedException | AssertionFailedException e) {
            LOG.error(e.getMessage(), e);
            return DtoConverter.toRefactoringResultDto(org.eclipse.ltk.core.refactoring.RefactoringStatus.createFatalErrorStatus(e.getMessage()));
        }
    }
    throw new RefactoringException("There is no RenameLinkedModeRefactoringSession.");
}
Also used : RefactoringResult(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringResult) RenameLinkedModeRefactoringSession(org.eclipse.che.plugin.java.server.refactoring.session.RenameLinkedModeRefactoringSession) MoveRefactoringSession(org.eclipse.che.plugin.java.server.refactoring.session.MoveRefactoringSession) RenameLinkedModeRefactoringSession(org.eclipse.che.plugin.java.server.refactoring.session.RenameLinkedModeRefactoringSession) ReorgRefactoringSession(org.eclipse.che.plugin.java.server.refactoring.session.ReorgRefactoringSession) RefactoringSession(org.eclipse.che.plugin.java.server.refactoring.session.RefactoringSession) RenameRefactoringSession(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession) AssertionFailedException(org.eclipse.core.runtime.AssertionFailedException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with RenameLinkedModeRefactoringSession

use of org.eclipse.che.plugin.java.server.refactoring.session.RenameLinkedModeRefactoringSession 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)

Aggregations

RenameRefactoringSession (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession)2 RenameLinkedModeRefactoringSession (org.eclipse.che.plugin.java.server.refactoring.session.RenameLinkedModeRefactoringSession)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 LinkedModeModel (org.eclipse.che.ide.ext.java.shared.dto.LinkedModeModel)1 RefactoringResult (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringResult)1 MoveRefactoringSession (org.eclipse.che.plugin.java.server.refactoring.session.MoveRefactoringSession)1 RefactoringSession (org.eclipse.che.plugin.java.server.refactoring.session.RefactoringSession)1 RenameSession (org.eclipse.che.plugin.java.server.refactoring.session.RenameSession)1 ReorgRefactoringSession (org.eclipse.che.plugin.java.server.refactoring.session.ReorgRefactoringSession)1 AssertionFailedException (org.eclipse.core.runtime.AssertionFailedException)1 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)1 RenameSupport (org.eclipse.jdt.ui.refactoring.RenameSupport)1 RenameRefactoring (org.eclipse.ltk.core.refactoring.participants.RenameRefactoring)1