use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.CreateMoveRefactoring in project che by eclipse.
the class RefactoringService method createMoveRefactoring.
/**
* Create move refactoring session.
*
* @param cmr
* move settings, contains resource paths to move.
* @return refactoring session id.
* @throws JavaModelException
* when JavaModel has a failure
* @throws RefactoringException
* when impossible to create move refactoring session
*/
@POST
@Path("move/create")
@Consumes("application/json")
@Produces("text/plain")
public String createMoveRefactoring(CreateMoveRefactoring cmr) throws JavaModelException, RefactoringException {
IJavaProject javaProject = model.getJavaProject(cmr.getProjectPath());
IJavaElement[] javaElements;
try {
Function<ElementToMove, IJavaElement> map = javaElement -> {
try {
if (javaElement.isPack()) {
return javaProject.findPackageFragment(new org.eclipse.core.runtime.Path(javaElement.getPath()));
} else {
return javaProject.findType(javaElement.getPath()).getCompilationUnit();
}
} catch (JavaModelException e) {
throw new IllegalArgumentException(e);
}
};
javaElements = cmr.getElements().stream().map(map).toArray(IJavaElement[]::new);
} catch (IllegalArgumentException e) {
if (e.getCause() instanceof JavaModelException) {
throw (JavaModelException) e.getCause();
} else {
throw e;
}
}
if (RefactoringAvailabilityTester.isMoveAvailable(new IResource[0], javaElements)) {
return manager.createMoveRefactoringSession(javaElements);
}
throw new RefactoringException("Can't create move refactoring.");
}
use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.CreateMoveRefactoring in project che by eclipse.
the class MovePresenter method show.
/**
* Show Move panel with the special information.
*
* @param refactorInfo
* information about the move operation
*/
public void show(final RefactorInfo refactorInfo) {
this.refactorInfo = refactorInfo;
view.setEnablePreviewButton(false);
view.setEnableAcceptButton(false);
view.clearErrorLabel();
CreateMoveRefactoring moveRefactoring = createMoveDto();
Promise<String> sessionIdPromise = refactorService.createMoveRefactoring(moveRefactoring);
sessionIdPromise.then(new Operation<String>() {
@Override
public void apply(String sessionId) throws OperationException {
MovePresenter.this.refactoringSessionId = sessionId;
showProjectsAndPackages();
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
notificationManager.notify(error.getMessage(), Status.FAIL, FLOAT_MODE);
}
});
}
use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.CreateMoveRefactoring in project che by eclipse.
the class MovePresenter method createMoveDto.
private CreateMoveRefactoring createMoveDto() {
List<ElementToMove> elements = new ArrayList<>();
Project project = null;
for (Resource resource : refactorInfo.getResources()) {
ElementToMove element = dtoFactory.createDto(ElementToMove.class);
if (resource instanceof Container) {
element.setPath(resource.getLocation().toString());
element.setPack(true);
} else {
element.setPath(JavaUtil.resolveFQN(resource));
element.setPack(false);
}
elements.add(element);
if (project == null) {
project = resource.getRelatedProject().get();
}
}
CreateMoveRefactoring moveRefactoring = dtoFactory.createDto(CreateMoveRefactoring.class);
moveRefactoring.setElements(elements);
if (project != null) {
moveRefactoring.setProjectPath(project.getLocation().toString());
}
return moveRefactoring;
}
Aggregations