Java 类org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel 实例源码

项目:texlipse    文件:SpellChecker.java   
/**
 * Returns the actual position of <i>marker</i> or null if the marker was
 * deleted. Code inspired by 
 * @param marker
 * @param sourceViewer
 * @return
 */
private static int[] getMarkerPosition(IMarker marker, ISourceViewer sourceViewer) {
    int[] p = new int[2];
    p[0] = marker.getAttribute(IMarker.CHAR_START, -1);
    p[1] = marker.getAttribute(IMarker.CHAR_END, -1);
 // look up the current range of the marker when the document has been edited
    IAnnotationModel model= sourceViewer.getAnnotationModel();
    if (model instanceof AbstractMarkerAnnotationModel) {

        AbstractMarkerAnnotationModel markerModel= (AbstractMarkerAnnotationModel) model;
        Position pos= markerModel.getMarkerPosition(marker);
        if (pos != null && !pos.isDeleted()) {
            // use position instead of marker values
            p[0] = pos.getOffset();
            p[1] = pos.getOffset() + pos.getLength();
        }

        if (pos != null && pos.isDeleted()) {
            // do nothing if position has been deleted
            return null;
        }
    }
    return p;
}
项目:Source    文件:QuickFixContributionItem.java   
/**
 * Gets the {@link List} of {@link IMarker} for the current line of the given {@link ITextEditor}.
 * 
 * @param editor
 *            the {@link ITextEditor}
 * @param rulerInfo
 *            the {@link IVerticalRulerInfo}
 * @return the {@link List} of {@link IMarker} for the current line of the given {@link ITextEditor}
 */
protected List<IMarker> getMarkers(final ITextEditor editor, final IVerticalRulerInfo rulerInfo) {
    final List<IMarker> res = new ArrayList<IMarker>();

    final IDocument document = (IDocument)editor.getDocumentProvider().getDocument(editor
            .getEditorInput());
    if (document != null) {
        final AbstractMarkerAnnotationModel model = getAnnotationModel(editor);
        if (model != null) {
            final int activeLine = rulerInfo.getLineOfLastMouseButtonActivity();
            res.addAll(getMarkers(document, model, activeLine));
        }
    }

    return res;
}
项目:mesfavoris    文件:GetLinkedBookmarksOperation.java   
private AbstractMarkerAnnotationModel getAnnotationModel(ITextEditor editor) {
    IDocumentProvider provider = editor.getDocumentProvider();
    IAnnotationModel model = provider.getAnnotationModel(editor.getEditorInput());
    if (model instanceof AbstractMarkerAnnotationModel)
        return (AbstractMarkerAnnotationModel) model;
    return null;
}
项目:FindBug-for-Domino-Designer    文件:MarkerRulerAction.java   
/**
 * Fills markers field with all of the FindBugs markers associated with the
 * current line in the text editor's ruler marign.
 */
protected void obtainFindBugsMarkers() {
    // Delete old markers
    markers.clear();
    if (editor == null || ruler == null) {
        return;
    }

    // Obtain all markers in the editor
    IResource resource = (IResource) editor.getEditorInput().getAdapter(IFile.class);
    if(resource == null){
        return;
    }
    IMarker[] allMarkers = MarkerUtil.getMarkers(resource, IResource.DEPTH_ZERO);
    if(allMarkers.length == 0) {
        return;
    }
    // Discover relevant markers, i.e. FindBugsMarkers
    AbstractMarkerAnnotationModel model = getModel();
    IDocument document = getDocument();
    for (int i = 0; i < allMarkers.length; i++) {
        if (includesRulerLine(model.getMarkerPosition(allMarkers[i]), document)) {
            if (MarkerUtil.isFindBugsMarker(allMarkers[i])) {
                markers.add(allMarkers[i]);
            }
        }
    }
}
项目:FindBug-for-Domino-Designer    文件:MarkerRulerAction.java   
/**
 * Retrieves the AbstractMarkerAnnontationsModel from the editor.
 *
 * @return AbstractMarkerAnnotatiosnModel from the editor
 */
@CheckForNull
protected AbstractMarkerAnnotationModel getModel() {
    if(editor == null) {
        return null;
    }
    IDocumentProvider provider = editor.getDocumentProvider();
    IAnnotationModel model = provider.getAnnotationModel(editor.getEditorInput());
    if (model instanceof AbstractMarkerAnnotationModel) {
        return (AbstractMarkerAnnotationModel) model;
    }
    return null;
}
项目:birt    文件:DecoratedScriptEditor.java   
public void saveDocument( )
{
    ScriptDocumentProvider provider = (ScriptDocumentProvider) getDocumentProvider( );
    try
    {
        ( (AbstractMarkerAnnotationModel) provider.getAnnotationModel( getEditorInput( ) ) ).commit( provider.getDocument( getEditorInput( ) ) );
    }
    catch ( CoreException e )
    {
        // do nothing
    }
}
项目:Pydev    文件:PyMarkerUtils.java   
/**
 * @return the position for a marker.
 */
public static Position getMarkerPosition(IDocument document, IMarker marker, IAnnotationModel model) {
    if (model instanceof AbstractMarkerAnnotationModel) {
        Position ret = ((AbstractMarkerAnnotationModel) model).getMarkerPosition(marker);
        if (ret != null) {
            return ret;
        }
    }
    int start = MarkerUtilities.getCharStart(marker);
    int end = MarkerUtilities.getCharEnd(marker);

    if (start > end) {
        end = start + end;
        start = end - start;
        end = end - start;
    }

    if (start == -1 && end == -1) {
        // marker line number is 1-based
        int line = MarkerUtilities.getLineNumber(marker);
        if (line > 0 && document != null) {
            try {
                start = document.getLineOffset(line - 1);
                end = start;
            } catch (BadLocationException x) {
            }
        }
    }

    if (start > -1 && end > -1) {
        return new Position(start, end - start);
    }

    return null;
}
项目:ftc    文件:SyntaxColoring.java   
private AbstractMarkerAnnotationModel getAnnotationModel() {
    IAnnotationModel m = sourceViewer.getAnnotationModel();
    Check.isTrue(m instanceof AbstractMarkerAnnotationModel);
    return (AbstractMarkerAnnotationModel) m;
}
项目:Eclipse-Postfix-Code-Completion    文件:JavaSelectAnnotationRulerAction.java   
private void findJavaAnnotation() {
    fPosition= null;
    fAnnotation= null;
    fHasCorrection= false;

    AbstractMarkerAnnotationModel model= getAnnotationModel();
    IAnnotationAccessExtension annotationAccess= getAnnotationAccessExtension();

    IDocument document= getDocument();
    if (model == null)
        return ;

    boolean hasAssistLightbulb= fStore.getBoolean(PreferenceConstants.EDITOR_QUICKASSIST_LIGHTBULB);

    Iterator<Annotation> iter= model.getAnnotationIterator();
    int layer= Integer.MIN_VALUE;

    while (iter.hasNext()) {
        Annotation annotation= iter.next();
        if (annotation.isMarkedDeleted())
            continue;

        int annotationLayer= layer;
        if (annotationAccess != null) {
            annotationLayer= annotationAccess.getLayer(annotation);
            if (annotationLayer < layer)
                continue;
        }

        Position position= model.getPosition(annotation);
        if (!includesRulerLine(position, document))
            continue;

        AnnotationPreference preference= fAnnotationPreferenceLookup.getAnnotationPreference(annotation);
        if (preference == null)
            continue;

        String key= preference.getVerticalRulerPreferenceKey();
        if (key == null)
            continue;

        if (!fStore.getBoolean(key))
            continue;

        boolean isReadOnly= fTextEditor instanceof ITextEditorExtension && ((ITextEditorExtension)fTextEditor).isEditorInputReadOnly();
        if (!isReadOnly
                && (
                    ((hasAssistLightbulb && annotation instanceof AssistAnnotation)
                    || JavaCorrectionProcessor.hasCorrections(annotation)))) {
            fPosition= position;
            fAnnotation= annotation;
            fHasCorrection= true;
            layer= annotationLayer;
            continue;
        } else if (!fHasCorrection) {
                fPosition= position;
                fAnnotation= annotation;
                layer= annotationLayer;
        }
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavaSelectAnnotationRulerAction.java   
private void findJavaAnnotation() {
    fPosition= null;
    fAnnotation= null;
    fHasCorrection= false;

    AbstractMarkerAnnotationModel model= getAnnotationModel();
    IAnnotationAccessExtension annotationAccess= getAnnotationAccessExtension();

    IDocument document= getDocument();
    if (model == null)
        return ;

    boolean hasAssistLightbulb= fStore.getBoolean(PreferenceConstants.EDITOR_QUICKASSIST_LIGHTBULB);

    Iterator<Annotation> iter= model.getAnnotationIterator();
    int layer= Integer.MIN_VALUE;

    while (iter.hasNext()) {
        Annotation annotation= iter.next();
        if (annotation.isMarkedDeleted())
            continue;

        int annotationLayer= layer;
        if (annotationAccess != null) {
            annotationLayer= annotationAccess.getLayer(annotation);
            if (annotationLayer < layer)
                continue;
        }

        Position position= model.getPosition(annotation);
        if (!includesRulerLine(position, document))
            continue;

        boolean isReadOnly= fTextEditor instanceof ITextEditorExtension && ((ITextEditorExtension)fTextEditor).isEditorInputReadOnly();
        if (!isReadOnly
                && (
                    ((hasAssistLightbulb && annotation instanceof AssistAnnotation)
                    || JavaCorrectionProcessor.hasCorrections(annotation)))) {
            fPosition= position;
            fAnnotation= annotation;
            fHasCorrection= true;
            layer= annotationLayer;
            continue;
        } else if (!fHasCorrection) {
            AnnotationPreference preference= fAnnotationPreferenceLookup.getAnnotationPreference(annotation);
            if (preference == null)
                continue;

            String key= preference.getVerticalRulerPreferenceKey();
            if (key == null)
                continue;

            if (fStore.getBoolean(key)) {
                fPosition= position;
                fAnnotation= annotation;
                layer= annotationLayer;
            }
        }
    }
}
项目:birt    文件:ReportXMLSourceEditorFormPage.java   
public boolean selectReveal( Object marker )
{
    int start = MarkerUtilities.getCharStart( (IMarker) marker );
    int end = MarkerUtilities.getCharEnd( (IMarker) marker );

    boolean selectLine = start < 0 || end < 0;

    // look up the current range of the marker when the document has been
    // edited
    IAnnotationModel model = reportXMLEditor.getDocumentProvider( )
            .getAnnotationModel( reportXMLEditor.getEditorInput( ) );
    if ( model instanceof AbstractMarkerAnnotationModel )
    {
        AbstractMarkerAnnotationModel markerModel = (AbstractMarkerAnnotationModel) model;
        Position pos = markerModel.getMarkerPosition( (IMarker) marker );
        if ( pos != null )
        {
            if ( !pos.isDeleted( ) )
            {
                // use position instead of marker values
                start = pos.getOffset( );
                end = pos.getOffset( ) + pos.getLength( );
            }
            else
            {
                return false;
            }
        }
    }

    IDocument document = reportXMLEditor.getDocumentProvider( )
            .getDocument( reportXMLEditor.getEditorInput( ) );
    if ( selectLine )
    {
        int line;
        try
        {
            if ( start >= 0 )
                line = document.getLineOfOffset( start );
            else
            {
                line = MarkerUtilities.getLineNumber( (IMarker) marker );
                // Marker line numbers are 1-based
                if ( line >= 1 )
                {
                    line--;
                }
                start = document.getLineOffset( line );
            }
            end = start + document.getLineLength( line ) - 1;
        }
        catch ( BadLocationException e )
        {
            return false;
        }
    }

    int length = document.getLength( );
    if ( end - 1 < length && start < length )
        reportXMLEditor.selectAndReveal( start, end - start );
    return true;
}