/* * @see IContentAssistProcessor#computeCompletionProposals(ITextViewer, int) */ @Override public ICompletionProposal[] computeQuickAssistProposals( IQuickAssistInvocationContext quickAssistContext) { ISourceViewer viewer = quickAssistContext.getSourceViewer(); int documentOffset = quickAssistContext.getOffset(); int length = viewer != null ? viewer.getSelectedRange().y : -1; TextInvocationContext context = new TextInvocationContext(viewer, documentOffset, length); IAnnotationModel model = viewer.getAnnotationModel(); if (model == null) return fgNoSuggestionsProposal; List<ICompletionProposal> proposals = computeProposals(context, model); if (proposals.isEmpty()) return fgNoSuggestionsProposal; return proposals.toArray(new ICompletionProposal[proposals.size()]); }
@Override public ICompletionProposal[] computeQuickAssistProposals( IQuickAssistInvocationContext quickAssistContext) { ISourceViewer viewer = quickAssistContext.getSourceViewer(); int documentOffset = quickAssistContext.getOffset(); IEditorPart part = fAssistant.getEditor(); CompilationUnit cu = DartUI.getWorkingCopyManager().getWorkingCopy(part.getEditorInput()); IAnnotationModel model = DartUI.getDocumentProvider().getAnnotationModel(part.getEditorInput()); AssistContext context = null; if (cu != null) { int length = viewer != null ? viewer.getSelectedRange().y : 0; context = new AssistContext(cu, viewer, part, documentOffset, length); } Annotation[] annotations = fAssistant.getAnnotationsAtOffset(); fErrorMessage = null; ICompletionProposal[] res = null; if (model != null && context != null && annotations != null) { List<IDartCompletionProposal> proposals = Lists.newArrayList(); IStatus status = collectProposals( context, model, annotations, true, !fAssistant.isUpdatedOffset(), proposals); res = proposals.toArray(new ICompletionProposal[proposals.size()]); if (!status.isOK()) { fErrorMessage = status.getMessage(); DartToolsPlugin.log(status); } } if (res == null || res.length == 0) { return new ICompletionProposal[] { new ChangeCorrectionProposal( CorrectionMessages.NoCorrectionProposal_description, new NullChange(""), 0, null) }; //$NON-NLS-1$ } if (res.length > 1) { Arrays.sort(res, new CompletionProposalComparator()); } return res; }
private List<ICompletionProposal> computeProposals( IQuickAssistInvocationContext context, IAnnotationModel model) { int offset = context.getOffset(); ArrayList<SpellingProblem> annotationList = new ArrayList<>(); Iterator<Annotation> iter = model.getAnnotationIterator(); while (iter.hasNext()) { Annotation annotation = iter.next(); if (canFix(annotation)) { Position pos = model.getPosition(annotation); if (isAtPosition(offset, pos)) { collectSpellingProblems(annotation, annotationList); } } } SpellingProblem[] spellingProblems = annotationList.toArray(new SpellingProblem[annotationList.size()]); return computeProposals(context, spellingProblems); }
public ICompletionProposal[] computeQuickAssistProposals( IQuickAssistInvocationContext invocationContext) { ISourceViewer sourceViewer = invocationContext.getSourceViewer(); int offset = -1; int length = 0; if (invocationContext instanceof TextInvocationContext) { TextInvocationContext textContext = (TextInvocationContext) invocationContext; offset = textContext.getOffset(); length = textContext.getLength(); } List<org.dresdenocl.language.ocl.resource.ocl.IOclQuickFix> quickFixes = getQuickFixes(sourceViewer, offset, length); ICompletionProposal[] proposals = new ICompletionProposal[quickFixes.size()]; for (int i = 0; i < proposals.length; i++) { proposals[i] = createCompletionProposal(sourceViewer, quickFixes.get(i)); } return proposals; }
public org.eclipse.jface.text.contentassist.ICompletionProposal[] computeQuickAssistProposals( org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext invocationContext) { org.eclipse.jface.text.source.ISourceViewer sourceViewer = invocationContext.getSourceViewer(); int offset = -1; int length = 0; if (invocationContext instanceof org.eclipse.jface.text.source.TextInvocationContext) { org.eclipse.jface.text.source.TextInvocationContext textContext = (org.eclipse.jface.text.source.TextInvocationContext) invocationContext; offset = textContext.getOffset(); length = textContext.getLength(); } java.util.List<ASPM.resource.ASPM.IASPMQuickFix> quickFixes = getQuickFixes(sourceViewer, offset, length); org.eclipse.jface.text.contentassist.ICompletionProposal[] proposals = new org.eclipse.jface.text.contentassist.ICompletionProposal[quickFixes.size()]; for (int i = 0; i < proposals.length; i++) { proposals[i] = createCompletionProposal(sourceViewer, quickFixes.get(i)); } return proposals; }
@Override public ICompletionProposal[] computeQuickAssistProposals( IQuickAssistInvocationContext invocationContext) { IAnnotationModel amodel = invocationContext.getSourceViewer().getAnnotationModel(); IDocument doc = invocationContext.getSourceViewer().getDocument(); int offset = invocationContext.getOffset(); Iterator<?> it = amodel.getAnnotationIterator(); TreeSet<ICompletionProposal> proposalSet = new TreeSet<>( new Comparator<Object>() { @Override public int compare(Object o1, Object o2) { if (o1 instanceof ICompletionProposal && o2 instanceof ICompletionProposal) { ICompletionProposal proposal1 = (ICompletionProposal) o1; ICompletionProposal proposal2 = (ICompletionProposal) o2; return proposal1 .getDisplayString() .compareToIgnoreCase(proposal2.getDisplayString()); } return 0; } }); while (it.hasNext()) { Object key = it.next(); if (!(key instanceof SimpleMarkerAnnotation)) { if (key instanceof SpellingAnnotation) { SpellingAnnotation annotation = (SpellingAnnotation) key; if (amodel.getPosition(annotation).overlapsWith(offset, 1)) { ICompletionProposal[] proposals = annotation.getSpellingProblem().getProposals(); for (ICompletionProposal proposal : proposals) { proposalSet.add(proposal); } } } continue; } SimpleMarkerAnnotation annotation = (SimpleMarkerAnnotation) key; populateDataModelForAnnotation(annotation); IMarker marker = annotation.getMarker(); IMarkerResolution[] mapping = fResMap.get(marker); if (mapping != null) { Position pos = amodel.getPosition(annotation); try { int line = doc.getLineOfOffset(pos.getOffset()); int start = pos.getOffset(); String delim = doc.getLineDelimiter(line); int delimLength = delim != null ? delim.length() : 0; int end = doc.getLineLength(line) + start - delimLength; if (offset >= start && offset <= end) { for (IMarkerResolution markerResolution : mapping) { PDECompletionProposal proposal = new PDECompletionProposal(markerResolution, pos, marker); if (!proposalSet.contains(proposal)) { proposalSet.add(proposal); } } } } catch (BadLocationException e) { } } } return proposalSet.toArray(new ICompletionProposal[proposalSet.size()]); }