@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()]); }
@Override public int hashCode() { return fPosition.hashCode() + fResolution.hashCode(); }