use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringResult in project che by eclipse.
the class RefactoringManager method applyLinkedRename.
/**
* Apply linked mode rename refactoring.
*
* @param apply
* contains new element name
* @return refactoring result
* @throws RefactoringException
* when refactoring session not found.
* @throws CoreException
* when impossible to apply rename refactoring
*/
public RefactoringResult applyLinkedRename(LinkedRenameRefactoringApply apply) throws RefactoringException, CoreException {
RefactoringSession session = getRefactoringSession(apply.getSessionId());
if (session instanceof RenameLinkedModeRefactoringSession) {
RenameLinkedModeRefactoringSession renameSession = (RenameLinkedModeRefactoringSession) session;
try {
RefactoringResult refactoringResult = renameSession.doRename(apply.getNewName());
deleteRefactoringSession(apply.getSessionId());
return refactoringResult;
} catch (InvocationTargetException | InterruptedException | AssertionFailedException e) {
LOG.error(e.getMessage(), e);
return DtoConverter.toRefactoringResultDto(org.eclipse.ltk.core.refactoring.RefactoringStatus.createFatalErrorStatus(e.getMessage()));
}
}
throw new RefactoringException("There is no RenameLinkedModeRefactoringSession.");
}
use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringResult in project che by eclipse.
the class RenameLinkedModeRefactoringSession method doRename.
/**
* Make rename operation.
* @param newName the name which will be applied
* @return result of the rename operation
* @throws CoreException if an error occurs while creating the refactoring instance
* @throws InvocationTargetException if an error occurred while executing the
* operation.
* @throws InterruptedException if the operation has been canceled by the
* user.
*/
public RefactoringResult doRename(String newName) throws CoreException, InvocationTargetException, InterruptedException {
if (fOriginalName.equals(newName)) {
return DtoConverter.toRefactoringResultDto(new RefactoringStatus());
}
RenameSupport renameSupport = undoAndCreateRenameSupport(newName);
if (renameSupport == null)
return DtoConverter.toRefactoringResultDto(RefactoringStatus.createFatalErrorStatus("Can't create rename refactoring"));
RefactoringResult refactoringResult = DtoConverter.toRefactoringResultDto(renameSupport.perform());
PerformChangeOperation operation = renameSupport.getfPerformChangeOperation();
if (operation == null) {
return refactoringResult;
}
CompositeChange operationChange = (CompositeChange) operation.getUndoChange();
Change[] changes = operationChange.getChildren();
List<ChangeInfo> changesInfo = new ArrayList<>();
prepareChangesInfo(changes, changesInfo);
refactoringResult.setChanges(changesInfo);
return refactoringResult;
}
use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringResult in project che by eclipse.
the class DtoConverter method toRefactoringResultDto.
/**
* Converts {@link org.eclipse.ltk.core.refactoring.RefactoringStatus} to {@link RefactoringResult}.
*/
public static RefactoringResult toRefactoringResultDto(org.eclipse.ltk.core.refactoring.RefactoringStatus refactoringStatus) {
RefactoringResult result = DtoFactory.newDto(RefactoringResult.class);
convertRefactoringStatus(result, refactoringStatus);
return result;
}
use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringResult in project che by eclipse.
the class RefactoringManager method applyRefactoring.
/**
* Apply refactoring.
*
* @param sessionId
* id of the refactoring session
* @return refactoring result
* @throws RefactoringException
* when refactoring session not found.
*/
public RefactoringResult applyRefactoring(String sessionId) throws RefactoringException {
RefactoringSession session = getRefactoringSession(sessionId);
RefactoringResult result = session.apply();
deleteRefactoringSession(sessionId);
return result;
}
use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringResult in project che by eclipse.
the class RefactoringSession method apply.
/**
* @return instance of {@link org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringStatus}.
* That describes status of the refactoring operation.
*/
public RefactoringResult apply() {
PerformChangeOperation operation = new PerformChangeOperation(change);
FinishResult result = internalPerformFinish(operation);
if (result.isException()) {
return DtoConverter.toRefactoringResultDto(RefactoringStatus.createErrorStatus("Refactoring failed with Exception."));
}
CompositeChange operationChange = (CompositeChange) operation.getUndoChange();
Change[] changes = operationChange.getChildren();
RefactoringStatus validationStatus = operation.getValidationStatus();
if (validationStatus != null) {
List<ChangeInfo> changesInfo = new ArrayList<>();
prepareChangesInfo(changes, changesInfo);
RefactoringResult status = DtoConverter.toRefactoringResultDto(validationStatus);
status.setChanges(changesInfo);
return status;
}
return DtoConverter.toRefactoringResultDto(new RefactoringStatus());
}
Aggregations