private void findAnnotation() { mPosition = null; mCanFix = false; IDocumentProvider provider = mTextEditor.getDocumentProvider(); IAnnotationModel model = provider.getAnnotationModel(mTextEditor.getEditorInput()); IAnnotationAccessExtension annotationAccess = getAnnotationAccessExtension(); IDocument document = getDocument(); if (model == null) { return; } Iterator<?> iter = model.getAnnotationIterator(); int layer = Integer.MIN_VALUE; while (iter.hasNext()) { Annotation annotation = (Annotation) iter.next(); if (annotation.isMarkedDeleted()) { continue; } int annotationLayer = Integer.MAX_VALUE; if (annotationAccess != null) { annotationLayer = annotationAccess.getLayer(annotation); if (annotationLayer < layer) { continue; } } Position position = model.getPosition(annotation); if (!includesRulerLine(position, document)) { continue; } boolean isReadOnly = mTextEditor instanceof ITextEditorExtension && ((ITextEditorExtension) mTextEditor).isEditorInputReadOnly(); if (!isReadOnly && annotation instanceof INIProblemAnnotation && ((INIProblemAnnotation) annotation).isQuickFixable()) { mPosition = position; mCanFix = true; layer = annotationLayer; continue; } else { AnnotationPreference preference = mAnnotationPreferenceLookup.getAnnotationPreference(annotation); if (preference == null) { continue; } String key = preference.getVerticalRulerPreferenceKey(); if (key == null) { continue; } if (mStore.getBoolean(key)) { mPosition = position; mCanFix = false; layer = annotationLayer; } } } }
@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()]); }