use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession 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());
}
}
use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession in project che by eclipse.
the class JavaRefactoringRename method createLinkedRenameSession.
private void createLinkedRenameSession() {
final CreateRenameRefactoring refactoringSession = createRenameRefactoringDto(textEditor, true);
Promise<RenameRefactoringSession> createRenamePromise = refactoringServiceClient.createRenameRefactoring(refactoringSession);
createRenamePromise.then(new Operation<RenameRefactoringSession>() {
@Override
public void apply(RenameRefactoringSession session) throws OperationException {
activateLinkedModeIntoEditor(session, textEditor.getDocument());
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
isActiveLinkedEditor = false;
showError();
}
});
}
use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession in project che by eclipse.
the class JavaRefactoringRename method createRenameSession.
private void createRenameSession() {
final CreateRenameRefactoring refactoringSession = createRenameRefactoringDto(textEditor, false);
Promise<RenameRefactoringSession> createRenamePromise = refactoringServiceClient.createRenameRefactoring(refactoringSession);
createRenamePromise.then(new Operation<RenameRefactoringSession>() {
@Override
public void apply(RenameRefactoringSession session) throws OperationException {
renamePresenter.show(session);
if (mode != null) {
mode.exitLinkedMode(false);
}
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
showError();
}
});
}
use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession in project che by eclipse.
the class RenamePresenter method show.
/**
* Show Rename window with the special information.
*
* @param refactorInfo
* information about the rename operation
*/
public void show(RefactorInfo refactorInfo) {
this.refactorInfo = refactorInfo;
final CreateRenameRefactoring createRenameRefactoring = createRenameRefactoringDto(refactorInfo);
Promise<RenameRefactoringSession> createRenamePromise = refactorService.createRenameRefactoring(createRenameRefactoring);
createRenamePromise.then(new Operation<RenameRefactoringSession>() {
@Override
public void apply(RenameRefactoringSession session) throws OperationException {
show(session);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
notificationManager.notify(locale.failedToRename(), arg.getMessage(), FAIL, FLOAT_MODE);
}
});
}
use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession in project che by eclipse.
the class RenameRefactoringTest method testRenamePreviewChanges.
@Test
public void testRenamePreviewChanges() throws Exception {
StringBuilder b = new StringBuilder();
b.append("package p;\n");
b.append("public class A{\n private A a; \n}\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("MyClass");
RefactoringStatus status = manager.renameValidateNewName(validateNewName);
manager.createChange(refactoring.getSessionId());
RefactoringPreview preview = manager.getRefactoringPreview(refactoring.getSessionId());
RefactoringChange change1 = new DtoServerImpls.ChangeEnabledStateImpl();
change1.setSessionId(refactoring.getSessionId());
change1.setChangeId(preview.getChildrens().get(0).getId());
ChangePreview changePreview = manager.getChangePreview(change1);
assertThat(changePreview).isNotNull();
assertThat(changePreview.getFileName()).isNotNull().isNotEmpty();
assertThat(changePreview.getOldContent()).isNotNull().isNotEmpty();
assertThat(changePreview.getNewContent()).isNotNull().isNotEmpty();
assertThat(changePreview.getNewContent()).isNotEqualTo(changePreview.getOldContent());
}
Aggregations