use of org.eclipse.jdt.internal.corext.refactoring.code.ExtractMethodRefactoring in project che by eclipse.
the class QuickAssistProcessor method getExtractMethodProposal.
private static boolean getExtractMethodProposal(IInvocationContext context, ASTNode coveringNode, boolean problemsAtLocation, Collection<ICommandAccess> proposals) throws CoreException {
if (!(coveringNode instanceof Expression) && !(coveringNode instanceof Statement) && !(coveringNode instanceof Block)) {
return false;
}
if (coveringNode instanceof Block) {
List<Statement> statements = ((Block) coveringNode).statements();
int startIndex = getIndex(context.getSelectionOffset(), statements);
if (startIndex == -1)
return false;
int endIndex = getIndex(context.getSelectionOffset() + context.getSelectionLength(), statements);
if (endIndex == -1 || endIndex <= startIndex)
return false;
}
if (proposals == null) {
return true;
}
final ICompilationUnit cu = context.getCompilationUnit();
final ExtractMethodRefactoring extractMethodRefactoring = new ExtractMethodRefactoring(context.getASTRoot(), context.getSelectionOffset(), context.getSelectionLength());
//$NON-NLS-1$
extractMethodRefactoring.setMethodName("extracted");
if (extractMethodRefactoring.checkInitialConditions(new NullProgressMonitor()).isOK()) {
String label = CorrectionMessages.QuickAssistProcessor_extractmethod_description;
LinkedProposalModel linkedProposalModel = new LinkedProposalModel();
extractMethodRefactoring.setLinkedProposalModel(linkedProposalModel);
Image image = JavaPluginImages.get(JavaPluginImages.DESC_MISC_PUBLIC);
int relevance = problemsAtLocation ? IProposalRelevance.EXTRACT_METHOD_ERROR : IProposalRelevance.EXTRACT_METHOD;
RefactoringCorrectionProposal proposal = new RefactoringCorrectionProposal(label, cu, extractMethodRefactoring, relevance, image);
proposal.setCommandId(EXTRACT_METHOD_INPLACE_ID);
proposal.setLinkedProposalModel(linkedProposalModel);
proposals.add(proposal);
}
return true;
}
Aggregations