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

下面列出了怎么用org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: 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;
}
 
源代码2 项目: xds-ide   文件: XBookmarksUtils.java
/**
 * Fetches the marker annotation model for the currently edited document.
 * Note, that I would prefer to declare this as returning e.g.
 * IAnnotationModel, but the method to call somewhere else is
 * <code>updateMarkers(IDocument document)</code> which is not specified by
 * IAnnotationModel (the only interface implemented by
 * AbstractMarkerAnnotationModel).
 * 
 * @return the marker annotation model or <code>null</code>
 */
public static AbstractMarkerAnnotationModel getMarkerAnnotationModel() {
    IDocumentProvider provider = WorkbenchUtils.getActiveDocumentProvider();
    IDocument document = WorkbenchUtils.getActiveDocument();
    if ((provider != null) && (document != null)) {
        IAnnotationModel model = provider.getAnnotationModel(document);
        if (model instanceof AbstractMarkerAnnotationModel) {
            return (AbstractMarkerAnnotationModel) model;
        }
    }
    return null;
}
 
源代码3 项目: spotbugs   文件: 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]);
            }
        }
    }
}
 
源代码4 项目: spotbugs   文件: 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;
}
 
源代码5 项目: birt   文件: DecoratedScriptEditor.java
public void saveDocument( )
{
	ScriptDocumentProvider provider = (ScriptDocumentProvider) getDocumentProvider( );
	try
	{
		( (AbstractMarkerAnnotationModel) provider.getAnnotationModel( getEditorInput( ) ) ).commit( provider.getDocument( getEditorInput( ) ) );
	}
	catch ( CoreException e )
	{
		// do nothing
	}
}
 
源代码6 项目: Pydev   文件: PyMarkerUIUtils.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;
}
 
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;
		}
	}
}
 
源代码8 项目: 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;
}
 
 类所在包
 类方法
 同包方法