use of org.eclipse.jdt.internal.corext.refactoring.structure.MoveStaticMembersProcessor in project eclipse.jdt.ls by eclipse.
the class MoveHandler method moveStaticMember.
private static RefactorWorkspaceEdit moveStaticMember(IMember[] members, String destinationTypeName, IProgressMonitor monitor) {
if (members.length == 0 || destinationTypeName == null) {
return new RefactorWorkspaceEdit("Failed to move static member because no members are selected or no destination is specified.");
}
CodeGenerationSettings settings = members[0].getTypeRoot() instanceof ICompilationUnit ? PreferenceManager.getCodeGenerationSettings((ICompilationUnit) members[0].getTypeRoot()) : PreferenceManager.getCodeGenerationSettings(members[0].getJavaProject().getProject());
MoveStaticMembersProcessor processor = new MoveStaticMembersProcessor(members, settings);
Refactoring refactoring = new MoveRefactoring(processor);
CheckConditionsOperation check = new CheckConditionsOperation(refactoring, CheckConditionsOperation.INITIAL_CONDITONS);
SubMonitor subMonitor = SubMonitor.convert(monitor, "Moving static members...", 100);
try {
check.run(subMonitor.split(20));
if (check.getStatus().getSeverity() >= RefactoringStatus.FATAL) {
JavaLanguageServerPlugin.logError("Failed to execute the 'move' refactoring.");
JavaLanguageServerPlugin.logError(check.getStatus().toString());
}
processor.setDestinationTypeFullyQualifiedName(destinationTypeName);
processor.setDeprecateDelegates(false);
check = new CheckConditionsOperation(refactoring, CheckConditionsOperation.FINAL_CONDITIONS);
check.run(subMonitor.split(60));
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 static member. Reason: " + check.getStatus().toString());
}
Change change = processor.createChange(subMonitor.split(20));
return new RefactorWorkspaceEdit(ChangeUtil.convertToWorkspaceEdit(change));
} catch (CoreException e) {
JavaLanguageServerPlugin.log(e);
return new RefactorWorkspaceEdit("Failed to move static member because of " + e.toString());
} finally {
subMonitor.done();
}
}
Aggregations