use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.ElementToMove 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.ElementToMove 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