use of org.eclipse.jdt.ls.core.internal.corrections.proposals.CUCorrectionProposal in project eclipse.jdt.ls by eclipse.
the class OrganizeImportsCommand method organizeImportsInCompilationUnit.
public void organizeImportsInCompilationUnit(ICompilationUnit unit, WorkspaceEdit rootEdit) {
try {
InnovationContext context = new InnovationContext(unit, 0, unit.getBuffer().getLength() - 1);
CUCorrectionProposal proposal = new CUCorrectionProposal("OrganizeImports", unit, IProposalRelevance.ORGANIZE_IMPORTS) {
@Override
protected void addEdits(IDocument document, TextEdit editRoot) throws CoreException {
CompilationUnit astRoot = context.getASTRoot();
OrganizeImportsOperation op = new OrganizeImportsOperation(unit, astRoot, true, false, true, null);
editRoot.addChild(op.createTextEdit(null));
}
};
addWorkspaceEdit(unit, proposal, rootEdit);
} catch (CoreException e) {
JavaLanguageServerPlugin.logException("Problem organize imports ", e);
}
}
use of org.eclipse.jdt.ls.core.internal.corrections.proposals.CUCorrectionProposal in project eclipse.jdt.ls by eclipse.
the class QuickAssistProcessor method getAssists.
public CUCorrectionProposal[] getAssists(IInvocationContext context, IProblemLocation[] locations) throws CoreException {
ASTNode coveringNode = context.getCoveringNode();
if (coveringNode != null) {
ArrayList<ASTNode> coveredNodes = getFullyCoveredNodes(context, coveringNode);
ArrayList<CUCorrectionProposal> resultingCollections = new ArrayList<>();
boolean noErrorsAtLocation = noErrorsAtLocation(locations);
if (noErrorsAtLocation) {
boolean problemsAtLocation = locations.length != 0;
// getCatchClauseToThrowsProposals(context, coveringNode, resultingCollections);
// getPickoutTypeFromMulticatchProposals(context, coveringNode, coveredNodes, resultingCollections);
// getConvertToMultiCatchProposals(context, coveringNode, resultingCollections);
// getUnrollMultiCatchProposals(context, coveringNode, resultingCollections);
// getUnWrapProposals(context, coveringNode, resultingCollections);
// getJoinVariableProposals(context, coveringNode, resultingCollections);
// getSplitVariableProposals(context, coveringNode, resultingCollections);
// getAddFinallyProposals(context, coveringNode, resultingCollections);
// getAddElseProposals(context, coveringNode, resultingCollections);
// getAddBlockProposals(context, coveringNode, resultingCollections);
// getInvertEqualsProposal(context, coveringNode, resultingCollections);
// getArrayInitializerToArrayCreation(context, coveringNode, resultingCollections);
// getCreateInSuperClassProposals(context, coveringNode, resultingCollections);
getExtractVariableProposal(context, problemsAtLocation, resultingCollections);
getExtractMethodProposal(context, coveringNode, problemsAtLocation, resultingCollections);
// getInlineLocalProposal(context, coveringNode, resultingCollections);
// getConvertLocalToFieldProposal(context, coveringNode, resultingCollections);
// getConvertAnonymousToNestedProposal(context, coveringNode, resultingCollections);
// getConvertAnonymousClassCreationsToLambdaProposals(context, coveringNode, resultingCollections);
// getConvertLambdaToAnonymousClassCreationsProposals(context, coveringNode, resultingCollections);
// getChangeLambdaBodyToBlockProposal(context, coveringNode, resultingCollections);
// getChangeLambdaBodyToExpressionProposal(context, coveringNode, resultingCollections);
// getAddInferredLambdaParameterTypes(context, coveringNode, resultingCollections);
// getConvertMethodReferenceToLambdaProposal(context, coveringNode, resultingCollections);
// getConvertLambdaToMethodReferenceProposal(context, coveringNode, resultingCollections);
// getFixParenthesesInLambdaExpression(context, coveringNode, resultingCollections);
// if (!getConvertForLoopProposal(context, coveringNode, resultingCollections)) {
// getConvertIterableLoopProposal(context, coveringNode, resultingCollections);
// }
// getConvertEnhancedForLoopProposal(context, coveringNode, resultingCollections);
// getRemoveBlockProposals(context, coveringNode, resultingCollections);
// getMakeVariableDeclarationFinalProposals(context, resultingCollections);
// getConvertStringConcatenationProposals(context, resultingCollections);
// getMissingCaseStatementProposals(context, coveringNode, resultingCollections);
}
return resultingCollections.toArray(new CUCorrectionProposal[resultingCollections.size()]);
}
return new CUCorrectionProposal[0];
}
use of org.eclipse.jdt.ls.core.internal.corrections.proposals.CUCorrectionProposal in project eclipse.jdt.ls by eclipse.
the class CodeActionHandler method getCodeActionCommands.
/**
* @param params
* @return
*/
public List<Command> getCodeActionCommands(CodeActionParams params, IProgressMonitor monitor) {
final ICompilationUnit unit = JDTUtils.resolveCompilationUnit(params.getTextDocument().getUri());
if (unit == null) {
return Collections.emptyList();
}
int start = DiagnosticsHelper.getStartOffset(unit, params.getRange());
int end = DiagnosticsHelper.getEndOffset(unit, params.getRange());
InnovationContext context = new InnovationContext(unit, start, end - start);
context.setASTRoot(getASTRoot(unit));
IProblemLocation[] locations = this.getProblemLocations(unit, params.getContext().getDiagnostics());
List<Command> $ = new ArrayList<>();
try {
CUCorrectionProposal[] corrections = this.quickFixProcessor.getCorrections(context, locations);
Arrays.sort(corrections, new CUCorrectionProposalComparator());
for (CUCorrectionProposal proposal : corrections) {
Command command = this.getCommandFromProposal(proposal);
$.add(command);
}
} catch (CoreException e) {
JavaLanguageServerPlugin.logException("Problem resolving code actions", e);
}
try {
CUCorrectionProposal[] corrections = this.quickAssistProcessor.getAssists(context, locations);
Arrays.sort(corrections, new CUCorrectionProposalComparator());
for (CUCorrectionProposal proposal : corrections) {
Command command = this.getCommandFromProposal(proposal);
$.add(command);
}
} catch (CoreException e) {
JavaLanguageServerPlugin.logException("Problem resolving code actions", e);
}
return $;
}
Aggregations