private void populateDataModelForAnnotation(SimpleMarkerAnnotation annotation) { // grab the local resolutions first IMarker marker = annotation.getMarker(); if (!fResMap.containsKey(marker)) { ArrayList<IMarkerResolution> resolutions = new ArrayList<>(5); IMarkerResolution[] localResolutions = fGenerator.getResolutions(marker); resolutions.addAll(Arrays.asList(localResolutions)); // grab the contributed resolutions IMarkerResolution[] contributedResolutions = IDE.getMarkerHelpRegistry().getResolutions(marker); for (int i = 0; i < contributedResolutions.length; i++) { IMarkerResolution resolution = contributedResolutions[i]; // only add contributed marker resolutions if they don't come from PDE if (!(resolution instanceof AbstractPDEMarkerResolution) && !resolutions.contains(contributedResolutions[i])) resolutions.add(contributedResolutions[i]); } if (resolutions.size() > 0) { fResMap.put(marker, resolutions.toArray(new IMarkerResolution[resolutions.size()])); } } }
@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()]); }