Search in sources :

Example 11 with RenameRefactoringSession

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

the class RenameRefactoringTest method testCreateRename.

@Test
public void testCreateRename() 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"), false);
    assertThat(refactoring).isNotNull();
    assertThat(refactoring.getSessionId()).isNotNull().isNotEmpty();
    assertThat(refactoring.getLinkedModeModel()).isNull();
    assertThat(refactoring.getWizardType()).isEqualTo(RenameRefactoringSession.RenameWizard.TYPE);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) RenameRefactoringSession(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession) IType(org.eclipse.jdt.core.IType) Test(org.junit.Test)

Example 12 with RenameRefactoringSession

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

the class RenameRefactoringTest method testRenamePackage.

@Test
public void testRenamePackage() throws Exception {
    final IPackageFragment packageFragment = getRoot().createPackageFragment("p.a.b.c", true, null);
    RenameRefactoringSession refactoring = manager.createRenameRefactoring(packageFragment, null, -1, false);
    assertThat(refactoring).isNotNull();
    assertThat(refactoring.getSessionId()).isNotNull().isNotEmpty();
    final ValidateNewName validateNewName = new DtoServerImpls.ValidateNewNameImpl().withNewName("p.x.s.z");
    validateNewName.setSessionId(refactoring.getSessionId());
    final RefactoringStatus status = manager.renameValidateNewName(validateNewName);
    assertThat(status.getSeverity()).isEqualTo(RefactoringStatus.OK);
}
Also used : IPackageFragment(org.eclipse.jdt.core.IPackageFragment) ValidateNewName(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ValidateNewName) DtoServerImpls(org.eclipse.che.plugin.java.server.dto.DtoServerImpls) RefactoringStatus(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringStatus) RenameRefactoringSession(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession) Test(org.junit.Test)

Example 13 with RenameRefactoringSession

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

the class RenameRefactoringTest method testRenameValidateInvalidName.

@Test
public void testRenameValidateInvalidName() 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"), false);
    DtoServerImpls.ValidateNewNameImpl validateNewName = new DtoServerImpls.ValidateNewNameImpl();
    validateNewName.setSessionId(refactoring.getSessionId());
    validateNewName.setNewName("My#Class");
    RefactoringStatus status = manager.renameValidateNewName(validateNewName);
    assertThat(status).isNotNull();
    assertThat(status.getSeverity()).isEqualTo(RefactoringStatus.FATAL);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) DtoServerImpls(org.eclipse.che.plugin.java.server.dto.DtoServerImpls) RefactoringStatus(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringStatus) RenameRefactoringSession(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession) IType(org.eclipse.jdt.core.IType) Test(org.junit.Test)

Aggregations

RenameRefactoringSession (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession)13 Test (org.junit.Test)9 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)8 IType (org.eclipse.jdt.core.IType)7 RefactoringStatus (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringStatus)6 DtoServerImpls (org.eclipse.che.plugin.java.server.dto.DtoServerImpls)5 Operation (org.eclipse.che.api.promises.client.Operation)3 OperationException (org.eclipse.che.api.promises.client.OperationException)3 PromiseError (org.eclipse.che.api.promises.client.PromiseError)3 CreateRenameRefactoring (org.eclipse.che.ide.ext.java.shared.dto.refactoring.CreateRenameRefactoring)3 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)2 LinkedModeModel (org.eclipse.che.ide.ext.java.shared.dto.LinkedModeModel)1 ChangeCreationResult (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeCreationResult)1 ChangePreview (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangePreview)1 LinkedRenameRefactoringApply (org.eclipse.che.ide.ext.java.shared.dto.refactoring.LinkedRenameRefactoringApply)1 RefactoringChange (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringChange)1 RefactoringPreview (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringPreview)1 RenameSettings (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameSettings)1 ValidateNewName (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ValidateNewName)1 RenameLinkedModeRefactoringSession (org.eclipse.che.plugin.java.server.refactoring.session.RenameLinkedModeRefactoringSession)1