use of org.eclipse.che.plugin.java.server.refactoring.RefactoringException in project che by eclipse.
the class RefactoringSession method createChange.
public ChangeCreationResult createChange() throws RefactoringException {
Change change = createChange(new CreateChangeOperation(new CheckConditionsOperation(refactoring, CheckConditionsOperation.FINAL_CONDITIONS), RefactoringStatus.FATAL), true);
// Status has been updated since we have passed true
RefactoringStatus status = conditionCheckingStatus;
// Creating the change has been canceled
if (change == null && status == null) {
internalSetChange(change);
throw new RefactoringException("Creating the change has been canceled");
}
// Set change if we don't have fatal errors.
if (!status.hasFatalError()) {
internalSetChange(change);
}
ChangeCreationResult result = DtoFactory.newDto(ChangeCreationResult.class);
result.setStatus(DtoConverter.toRefactoringStatusDto(status));
result.setCanShowPreviewPage(status.isOK());
return result;
}
use of org.eclipse.che.plugin.java.server.refactoring.RefactoringException in project che by eclipse.
the class RefactoringSession method updateChangeEnabled.
public void updateChangeEnabled(String changeId, boolean enabled) throws RefactoringException {
PreviewNode node = findNode(previewNode, changeId);
if (node == null) {
throw new RefactoringException("Can't find refactoring change to update enabled state.");
}
node.setEnabled(enabled);
}
use of org.eclipse.che.plugin.java.server.refactoring.RefactoringException in project che by eclipse.
the class RefactoringService method createRenameRefactoring.
/**
* Create rename refactoring session.
*
* @param settings
* rename settings
* @return the rename refactoring session
* @throws CoreException
* when RenameSupport can't be created
* @throws RefactoringException
* when Java element was not found
*/
@POST
@Path("rename/create")
@Produces("application/json")
@Consumes("application/json")
public RenameRefactoringSession createRenameRefactoring(CreateRenameRefactoring settings) throws CoreException, RefactoringException {
IJavaProject javaProject = model.getJavaProject(settings.getProjectPath());
IJavaElement elementToRename;
ICompilationUnit cu = null;
switch(settings.getType()) {
case COMPILATION_UNIT:
elementToRename = javaProject.findType(settings.getPath()).getCompilationUnit();
break;
case PACKAGE:
elementToRename = javaProject.findPackageFragment(new org.eclipse.core.runtime.Path(settings.getPath()));
break;
case JAVA_ELEMENT:
cu = javaProject.findType(settings.getPath()).getCompilationUnit();
elementToRename = getSelectionElement(cu, settings.getOffset());
break;
default:
elementToRename = null;
}
if (elementToRename == null) {
throw new RefactoringException("Can't find java element to rename.");
}
return manager.createRenameRefactoring(elementToRename, cu, settings.getOffset(), settings.isRefactorLightweight());
}
use of org.eclipse.che.plugin.java.server.refactoring.RefactoringException 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.plugin.java.server.refactoring.RefactoringException in project che by eclipse.
the class RefactoringSession method createChange.
private Change createChange(CreateChangeOperation operation, boolean updateStatus) throws RefactoringException {
CoreException exception = null;
try {
ResourcesPlugin.getWorkspace().run(operation, new NullProgressMonitor());
} catch (CoreException e) {
exception = e;
}
if (updateStatus) {
RefactoringStatus status = null;
if (exception != null) {
status = new RefactoringStatus();
String msg = exception.getMessage();
if (msg != null) {
status.addFatalError(Messages.format("{0}. See the error log for more details.", msg));
} else {
status.addFatalError("An unexpected exception occurred while creating a change object. See the error log for more details.");
}
JavaPlugin.log(exception);
} else {
status = operation.getConditionCheckingStatus();
}
setConditionCheckingStatus(status);
} else {
if (exception != null)
throw new RefactoringException(exception);
}
Change change = operation.getChange();
return change;
}
Aggregations