Search in sources :

Example 1 with LinkedRenameRefactoringApply

use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.LinkedRenameRefactoringApply in project che by eclipse.

the class RenameRefactoringTest method testApplyLinkedRename.

@Test
public void testApplyLinkedRename() throws Exception {
    StringBuilder b = new StringBuilder();
    b.append("package p;\n");
    b.append("public class A{}\n");
    ICompilationUnit unit = getPackageP().createCompilationUnit("A.java", b.toString(), false, null);
    IType type = unit.getAllTypes()[0];
    RenameRefactoringSession refactoring = manager.createRenameRefactoring(type, unit, b.indexOf("A"), true);
    assertThat(refactoring).isNotNull();
    assertThat(refactoring.getSessionId()).isNotNull().isNotEmpty();
    LinkedRenameRefactoringApply apply = new DtoServerImpls.LinkedRenameRefactoringApplyImpl();
    apply.setSessionId(refactoring.getSessionId());
    apply.setNewName("Test");
    RefactoringStatus status = manager.applyLinkedRename(apply);
    assertThat(status).isNotNull();
    assertThat(status.getSeverity()).isEqualTo(RefactoringStatus.OK);
    assertThat(unit.exists()).isFalse();
    ICompilationUnit newUnit = getPackageP().getCompilationUnit("Test.java");
    assertThat(newUnit.exists()).isTrue();
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) RefactoringStatus(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringStatus) LinkedRenameRefactoringApply(org.eclipse.che.ide.ext.java.shared.dto.refactoring.LinkedRenameRefactoringApply) RenameRefactoringSession(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession) IType(org.eclipse.jdt.core.IType) Test(org.junit.Test)

Example 2 with LinkedRenameRefactoringApply

use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.LinkedRenameRefactoringApply in project che by eclipse.

the class JavaRefactoringRename method createLinkedRenameRefactoringApplyDto.

@NotNull
private LinkedRenameRefactoringApply createLinkedRenameRefactoringApplyDto(String newName, String sessionId) {
    LinkedRenameRefactoringApply dto = dtoFactory.createDto(LinkedRenameRefactoringApply.class);
    dto.setNewName(newName);
    dto.setSessionId(sessionId);
    return dto;
}
Also used : LinkedRenameRefactoringApply(org.eclipse.che.ide.ext.java.shared.dto.refactoring.LinkedRenameRefactoringApply) NotNull(javax.validation.constraints.NotNull)

Example 3 with LinkedRenameRefactoringApply

use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.LinkedRenameRefactoringApply in project che by eclipse.

the class JavaRefactoringRename method performRename.

private void performRename(RenameRefactoringSession session) {
    final LinkedRenameRefactoringApply dto = createLinkedRenameRefactoringApplyDto(newName, session.getSessionId());
    Promise<RefactoringResult> applyModelPromise = refactoringServiceClient.applyLinkedModeRename(dto);
    applyModelPromise.then(new Operation<RefactoringResult>() {

        @Override
        public void apply(RefactoringResult result) throws OperationException {
            switch(result.getSeverity()) {
                case OK:
                case INFO:
                    final VirtualFile file = textEditor.getDocument().getFile();
                    if (file instanceof Resource) {
                        final Optional<Project> project = ((Resource) file).getRelatedProject();
                        refactoringServiceClient.reindexProject(project.get().getLocation().toString());
                    }
                    refactoringUpdater.updateAfterRefactoring(result.getChanges());
                    break;
                case WARNING:
                case ERROR:
                    enableAutoSave();
                    undoChanges();
                    showWarningDialog();
                    break;
                case FATAL:
                    undoChanges();
                    notificationManager.notify(locale.failedToRename(), result.getEntries().get(0).getMessage(), FAIL, FLOAT_MODE);
                    break;
                default:
                    break;
            }
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError arg) throws OperationException {
            enableAutoSave();
            undoChanges();
            notificationManager.notify(locale.failedToRename(), arg.getMessage(), FAIL, FLOAT_MODE);
        }
    });
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) Project(org.eclipse.che.ide.api.resources.Project) PromiseError(org.eclipse.che.api.promises.client.PromiseError) RefactoringResult(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringResult) Resource(org.eclipse.che.ide.api.resources.Resource) LinkedRenameRefactoringApply(org.eclipse.che.ide.ext.java.shared.dto.refactoring.LinkedRenameRefactoringApply) Operation(org.eclipse.che.api.promises.client.Operation) OperationException(org.eclipse.che.api.promises.client.OperationException)

Aggregations

LinkedRenameRefactoringApply (org.eclipse.che.ide.ext.java.shared.dto.refactoring.LinkedRenameRefactoringApply)3 NotNull (javax.validation.constraints.NotNull)1 Operation (org.eclipse.che.api.promises.client.Operation)1 OperationException (org.eclipse.che.api.promises.client.OperationException)1 PromiseError (org.eclipse.che.api.promises.client.PromiseError)1 Project (org.eclipse.che.ide.api.resources.Project)1 Resource (org.eclipse.che.ide.api.resources.Resource)1 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)1 RefactoringResult (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringResult)1 RefactoringStatus (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringStatus)1 RenameRefactoringSession (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 IType (org.eclipse.jdt.core.IType)1 Test (org.junit.Test)1