use of org.eclipse.jdt.internal.corext.refactoring.structure.MoveInnerToTopRefactoring in project eclipse.jdt.ls by eclipse.
the class MoveHandler method moveTypeToNewFile.
private static RefactorWorkspaceEdit moveTypeToNewFile(CodeActionParams params, IProgressMonitor monitor) {
final ICompilationUnit unit = JDTUtils.resolveCompilationUnit(params.getTextDocument().getUri());
if (unit == null) {
return new RefactorWorkspaceEdit("Failed to move type to new file because cannot find the compilation unit associated with " + params.getTextDocument().getUri());
}
IType type = getSelectedType(unit, params);
if (type == null) {
return new RefactorWorkspaceEdit("Failed to move type to new file because no type is selected.");
}
SubMonitor subMonitor = SubMonitor.convert(monitor, "Moving type to new file...", 100);
try {
MoveInnerToTopRefactoring refactoring = new MoveInnerToTopRefactoring(type, PreferenceManager.getCodeGenerationSettings(unit));
CheckConditionsOperation check = new CheckConditionsOperation(refactoring, CheckConditionsOperation.ALL_CONDITIONS);
check.run(subMonitor.split(50));
if (check.getStatus().getSeverity() >= RefactoringStatus.FATAL) {
JavaLanguageServerPlugin.logError("Failed to execute the 'move' refactoring.");
JavaLanguageServerPlugin.logError(check.getStatus().toString());
return new RefactorWorkspaceEdit("Failed to move type to new file. Reason: " + check.getStatus().toString());
}
Change change = refactoring.createChange(subMonitor.split(50));
return new RefactorWorkspaceEdit(ChangeUtil.convertToWorkspaceEdit(change));
} catch (CoreException e) {
JavaLanguageServerPlugin.log(e);
return new RefactorWorkspaceEdit("Failed to move type to new file because of " + e.toString());
} catch (OperationCanceledException e) {
return null;
}
}
Aggregations