@Override public ICompletionProposal[] computeQuickAssistProposals( IQuickAssistInvocationContext invocationContext) { // prepare AssistContextUI AssistContextUI contextUI; { DartEditor editor = assistant.getEditor(); AssistContext context = editor.getAssistContext(); contextUI = new AssistContextUI(context, editor); } // prepare proposals List<ICompletionProposal> proposals = Lists.newArrayList(); // add Quick Fixes try { QuickFixProcessor_NEW qfProcessor = new QuickFixProcessor_NEW(); AnalysisError problemToFix = assistant.getProblemToFix(); ICompletionProposal[] fixProposals = qfProcessor.computeFix(contextUI, problemToFix); Collections.addAll(proposals, fixProposals); // show problem only if there is are fixes if (fixProposals.length != 0) { assistant.showProblemToFix(); } } catch (Throwable e) { DartToolsPlugin.log(e); } // add Quick Assists if (proposals.isEmpty()) { QuickAssistProcessor qaProcessor = new QuickAssistProcessor(); ICompletionProposal[] assistProposals = qaProcessor.getAssists(contextUI); Collections.addAll(proposals, assistProposals); } // done Collections.sort(proposals, new CompletionProposalComparator()); return proposals.toArray(new ICompletionProposal[proposals.size()]); }
/** * Get the element associated with the editor's current selection. * * @param editor the editor * @return the associated element, or {@code null} if none can be found */ public static Element getElementAtOffset(DartEditor editor) { AssistContext context = editor.getAssistContext(); if (context == null) { return null; } return context.getCoveredElement(); }
/** Uses {@link AssistContext} form {@link DartEditor} to prepare {@link #fDartElement}. */ private void prepareElement() { fDartElement = null; context = fEditor.getAssistContext(); if (context == null) { return; } ASTNode selectedNode = context.getCoveredNode(); if (!(selectedNode instanceof SimpleIdentifier)) { return; } nameNode = (SimpleIdentifier) selectedNode; fDartElement = nameNode.getElement(); fDartElement = getCanonicalElement(fDartElement); }