Search in sources :

Example 1 with RenameSupport

use of org.eclipse.jdt.ui.refactoring.RenameSupport 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 RenameSupport

use of org.eclipse.jdt.ui.refactoring.RenameSupport in project che by eclipse.

the class RenameLinkedModeRefactoringSession method doRename.

/**
     * Make rename operation.
     * @param newName the name which will be applied
     * @return result of the rename operation
     * @throws CoreException if an error occurs while creating the refactoring instance
     * @throws InvocationTargetException if an error occurred while executing the
     * operation.
     * @throws InterruptedException if the operation has been canceled by the
     * user.
     */
public RefactoringResult doRename(String newName) throws CoreException, InvocationTargetException, InterruptedException {
    if (fOriginalName.equals(newName)) {
        return DtoConverter.toRefactoringResultDto(new RefactoringStatus());
    }
    RenameSupport renameSupport = undoAndCreateRenameSupport(newName);
    if (renameSupport == null)
        return DtoConverter.toRefactoringResultDto(RefactoringStatus.createFatalErrorStatus("Can't create rename refactoring"));
    RefactoringResult refactoringResult = DtoConverter.toRefactoringResultDto(renameSupport.perform());
    PerformChangeOperation operation = renameSupport.getfPerformChangeOperation();
    if (operation == null) {
        return refactoringResult;
    }
    CompositeChange operationChange = (CompositeChange) operation.getUndoChange();
    Change[] changes = operationChange.getChildren();
    List<ChangeInfo> changesInfo = new ArrayList<>();
    prepareChangesInfo(changes, changesInfo);
    refactoringResult.setChanges(changesInfo);
    return refactoringResult;
}
Also used : PerformChangeOperation(org.eclipse.ltk.core.refactoring.PerformChangeOperation) ChangeInfo(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeInfo) RefactoringResult(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringResult) ArrayList(java.util.ArrayList) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) Change(org.eclipse.ltk.core.refactoring.Change) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) RenameSupport(org.eclipse.jdt.ui.refactoring.RenameSupport)

Example 3 with RenameSupport

use of org.eclipse.jdt.ui.refactoring.RenameSupport in project xtext-xtend by eclipse.

the class JavaRefactoringIntegrationTest method renameJavaElement.

protected void renameJavaElement(IField javaElement, String newName) throws CoreException, InterruptedException, InvocationTargetException {
    syncUtil.totalSync(false);
    RenameSupport renameSupport = RenameSupport.create(javaElement, newName, RenameSupport.UPDATE_REFERENCES);
    renameSupport.perform(workbench.getActiveWorkbenchWindow().getShell(), workbench.getActiveWorkbenchWindow());
    syncUtil.totalSync(false);
    assertTrue(compositeRefactoringProcessorAccess.isDisposed());
}
Also used : RenameSupport(org.eclipse.jdt.ui.refactoring.RenameSupport)

Example 4 with RenameSupport

use of org.eclipse.jdt.ui.refactoring.RenameSupport in project xtext-xtend by eclipse.

the class JavaRefactoringIntegrationTest method renameJavaElement.

protected void renameJavaElement(IMethod javaElement, String newName) throws CoreException, InterruptedException, InvocationTargetException {
    syncUtil.totalSync(false);
    RenameSupport renameSupport = RenameSupport.create(javaElement, newName, RenameSupport.UPDATE_REFERENCES);
    renameSupport.perform(workbench.getActiveWorkbenchWindow().getShell(), workbench.getActiveWorkbenchWindow());
    syncUtil.totalSync(false);
    assertTrue(compositeRefactoringProcessorAccess.isDisposed());
}
Also used : RenameSupport(org.eclipse.jdt.ui.refactoring.RenameSupport)

Example 5 with RenameSupport

use of org.eclipse.jdt.ui.refactoring.RenameSupport in project xtext-xtend by eclipse.

the class RenameJvmOperationTest method renameJavaElement.

public void renameJavaElement(final IField javaElement, final String newName) throws Exception {
    this.syncUtil.totalSync(false);
    final RenameSupport renameSupport = RenameSupport.create(javaElement, newName, RenameSupport.UPDATE_REFERENCES);
    renameSupport.perform(this.workbench.getActiveWorkbenchWindow().getShell(), this.workbench.getActiveWorkbenchWindow());
    this.syncUtil.totalSync(false);
    Assert.assertTrue(this.compositeRefactoringProcessorAccess.isDisposed());
}
Also used : RenameSupport(org.eclipse.jdt.ui.refactoring.RenameSupport)

Aggregations

RenameSupport (org.eclipse.jdt.ui.refactoring.RenameSupport)17 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)3 CoreException (org.eclipse.core.runtime.CoreException)2 IJavaElement (org.eclipse.jdt.core.IJavaElement)2 IMethod (org.eclipse.jdt.core.IMethod)2 IType (org.eclipse.jdt.core.IType)2 ArrayList (java.util.ArrayList)1 LinkedModeModel (org.eclipse.che.ide.ext.java.shared.dto.LinkedModeModel)1 ChangeInfo (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeInfo)1 RefactoringResult (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringResult)1 RenameRefactoringSession (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession)1 RenameLinkedModeRefactoringSession (org.eclipse.che.plugin.java.server.refactoring.session.RenameLinkedModeRefactoringSession)1 RenameSession (org.eclipse.che.plugin.java.server.refactoring.session.RenameSession)1 IField (org.eclipse.jdt.core.IField)1 Change (org.eclipse.ltk.core.refactoring.Change)1 CompositeChange (org.eclipse.ltk.core.refactoring.CompositeChange)1 PerformChangeOperation (org.eclipse.ltk.core.refactoring.PerformChangeOperation)1 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)1 RenameRefactoring (org.eclipse.ltk.core.refactoring.participants.RenameRefactoring)1 IRenameSupport (org.eclipse.xtext.ui.refactoring.ui.IRenameSupport)1