Search in sources :

Example 1 with MarkerAnnotation

use of org.eclipse.ui.texteditor.MarkerAnnotation in project KaiZen-OpenAPI-Editor by RepreZen.

the class JsonQuickAssistProcessor method getMarkersFor.

protected List<IMarker> getMarkersFor(ISourceViewer sourceViewer, int lineOffset, int lineLength) {
    List<IMarker> result = Lists.newArrayList();
    IAnnotationModel annotationModel = sourceViewer.getAnnotationModel();
    Iterator annotationIter = annotationModel.getAnnotationIterator();
    while (annotationIter.hasNext()) {
        Object annotation = annotationIter.next();
        if (annotation instanceof MarkerAnnotation) {
            MarkerAnnotation markerAnnotation = (MarkerAnnotation) annotation;
            IMarker marker = markerAnnotation.getMarker();
            Position markerPosition = annotationModel.getPosition(markerAnnotation);
            if (markerPosition != null && markerPosition.overlapsWith(lineOffset, lineLength)) {
                result.add(marker);
            }
        }
    }
    return result;
}
Also used : MarkerAnnotation(org.eclipse.ui.texteditor.MarkerAnnotation) Position(org.eclipse.jface.text.Position) Iterator(java.util.Iterator) IMarker(org.eclipse.core.resources.IMarker) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel)

Example 2 with MarkerAnnotation

use of org.eclipse.ui.texteditor.MarkerAnnotation in project bndtools by bndtools.

the class BndMarkerQuickAssistProcessor method computeQuickAssistProposals.

@Override
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext context) {
    List<ICompletionProposal> proposals = new LinkedList<ICompletionProposal>();
    ISourceViewer viewer = context.getSourceViewer();
    @SuppressWarnings("unused") IDocument document = viewer.getDocument();
    IAnnotationModel model = viewer.getAnnotationModel();
    @SuppressWarnings("rawtypes") Iterator iter = model.getAnnotationIterator();
    while (iter.hasNext()) {
        Annotation annotation = (Annotation) iter.next();
        if (annotation instanceof MarkerAnnotation && canFix(annotation)) {
            Position position = model.getPosition(annotation);
            if (isAtPosition(context.getOffset(), position)) {
                IMarker marker = ((MarkerAnnotation) annotation).getMarker();
                String errorType = marker.getAttribute("$bndType", null);
                if (errorType != null) {
                    BuildErrorDetailsHandler handler = BuildErrorDetailsHandlers.INSTANCE.findHandler(errorType);
                    if (handler != null) {
                        proposals.addAll(handler.getProposals(marker));
                    }
                }
            }
        }
    }
    if (proposals.isEmpty()) {
        proposals.add(new NoCompletionsProposal());
    }
    return proposals.toArray(new ICompletionProposal[0]);
}
Also used : Position(org.eclipse.jface.text.Position) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) LinkedList(java.util.LinkedList) MarkerAnnotation(org.eclipse.ui.texteditor.MarkerAnnotation) Annotation(org.eclipse.jface.text.source.Annotation) BuildErrorDetailsHandler(org.bndtools.build.api.BuildErrorDetailsHandler) MarkerAnnotation(org.eclipse.ui.texteditor.MarkerAnnotation) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) Iterator(java.util.Iterator) IMarker(org.eclipse.core.resources.IMarker) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) IDocument(org.eclipse.jface.text.IDocument)

Example 3 with MarkerAnnotation

use of org.eclipse.ui.texteditor.MarkerAnnotation in project bndtools by bndtools.

the class BndMarkerAnnotationHover method getHoverInfo.

public String getHoverInfo(ISourceViewer sourceViewer, int lineNum) {
    @SuppressWarnings("rawtypes") Iterator iter = sourceViewer.getAnnotationModel().getAnnotationIterator();
    while (iter.hasNext()) {
        Object annotation = iter.next();
        if (annotation instanceof MarkerAnnotation) {
            IMarker marker = ((MarkerAnnotation) annotation).getMarker();
            int markerLine = marker.getAttribute(IMarker.LINE_NUMBER, 0);
            // Hover line is zero-based and marker line is one-based. FML.
            if (markerLine == lineNum + 1) {
                return marker.getAttribute(IMarker.MESSAGE, null);
            }
        }
    }
    return null;
}
Also used : MarkerAnnotation(org.eclipse.ui.texteditor.MarkerAnnotation) Iterator(java.util.Iterator) IMarker(org.eclipse.core.resources.IMarker)

Example 4 with MarkerAnnotation

use of org.eclipse.ui.texteditor.MarkerAnnotation in project bndtools by bndtools.

the class BndResourceMarkerAnnotationModel method createMarkerAnnotation.

@Override
protected MarkerAnnotation createMarkerAnnotation(IMarker marker) {
    MarkerAnnotation annotation = super.createMarkerAnnotation(marker);
    boolean fixable = marker.getAttribute(BuildErrorDetailsHandler.PROP_HAS_RESOLUTIONS, false);
    annotation.setQuickFixable(fixable);
    return annotation;
}
Also used : MarkerAnnotation(org.eclipse.ui.texteditor.MarkerAnnotation)

Aggregations

MarkerAnnotation (org.eclipse.ui.texteditor.MarkerAnnotation)4 Iterator (java.util.Iterator)3 IMarker (org.eclipse.core.resources.IMarker)3 Position (org.eclipse.jface.text.Position)2 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)2 LinkedList (java.util.LinkedList)1 BuildErrorDetailsHandler (org.bndtools.build.api.BuildErrorDetailsHandler)1 IDocument (org.eclipse.jface.text.IDocument)1 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)1 Annotation (org.eclipse.jface.text.source.Annotation)1 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)1