org.eclipse.ui.texteditor.MarkerAnnotation源码实例Demo

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

下面列出了org.eclipse.ui.texteditor.MarkerAnnotation 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: eclipse-cs   文件: AbstractASTResolution.java
private MarkerAnnotation getMarkerAnnotation(IAnnotationModel annotationModel, IMarker marker) {

    Iterator<Annotation> it = annotationModel.getAnnotationIterator();
    while (it.hasNext()) {
      Annotation tmp = it.next();

      if (tmp instanceof MarkerAnnotation) {

        IMarker theMarker = ((MarkerAnnotation) tmp).getMarker();

        if (theMarker.equals(marker)) {
          return (MarkerAnnotation) tmp;
        }
      }
    }
    return null;
  }
 
源代码2 项目: xtext-eclipse   文件: AnnotationIssueProcessor.java
protected List<Annotation> getAnnotationsToRemove(IProgressMonitor monitor) {
	if (monitor.isCanceled() || annotationModel == null) {
		return Lists.newArrayList();
	}
	Iterator<Annotation> annotationIterator = annotationModel.getAnnotationIterator();
	List<Annotation> toBeRemoved = Lists.newArrayList();
	while (annotationIterator.hasNext()) {
		if (monitor.isCanceled()) {
			return toBeRemoved;
		}
		Annotation annotation = annotationIterator.next();
		String type = annotation.getType();
		if (isRelevantAnnotationType(type)) {
			if (!(annotation instanceof MarkerAnnotation)) {
				toBeRemoved.add(annotation);
			}
		}
	}
	return toBeRemoved;
}
 
源代码3 项目: xtext-eclipse   文件: XtextQuickAssistProcessor.java
@Override
public boolean canFix(Annotation annotation) {
	if (annotation.isMarkedDeleted())
		return false;

	// non-persisted annotation
	if (annotation instanceof XtextAnnotation) {
		XtextAnnotation a = (XtextAnnotation) annotation;
		return getResolutionProvider().hasResolutionFor(a.getIssueCode());
	}

	// persisted markerAnnotation
	if (annotation instanceof MarkerAnnotation) {
		MarkerAnnotation markerAnnotation = (MarkerAnnotation) annotation;
		if (!markerAnnotation.isQuickFixableStateSet())
			markerAnnotation.setQuickFixable(getResolutionProvider().hasResolutionFor(
					issueUtil.getCode(markerAnnotation)));
		return markerAnnotation.isQuickFixable();
	}

	if (annotation instanceof SpellingAnnotation) {
		return true;
	}

	return false;
}
 
源代码4 项目: xds-ide   文件: SourceCodeTextEditor.java
@Override
public int getLayer(Annotation annotation) {
       if (annotation instanceof MarkerAnnotation) {
           MarkerAnnotation markerAnnotation = (MarkerAnnotation)annotation;
           IMarker im = markerAnnotation.getMarker();
           try {
                  if (XdsMarkerConstants.BUILD_PROBLEM_MARKER_TYPE.equals(im.getType()) &&
                      im.getAttribute(XdsMarkerConstants.MARKER_GRAY_STATE, false)) 
                  {
                      markerAnnotation.markDeleted(true);
                      return IAnnotationAccessExtension.DEFAULT_LAYER; // place gray markers under all other 
                  }
              } catch (Exception e) { // hz
              }
       }
          return super.getLayer(annotation);
}
 
protected List<IMarker> getMarkersFor(ISourceViewer sourceViewer, int lineOffset, int lineLength) {
    List<IMarker> result = new ArrayList<>();
    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;
}
 
@Override
protected void updateMarkerViews(Annotation annotation) {
	if (annotation instanceof IJavaAnnotation) {
		Iterator<IJavaAnnotation> e= ((IJavaAnnotation) annotation).getOverlaidIterator();
		if (e != null) {
			while (e.hasNext()) {
				Object o= e.next();
				if (o instanceof MarkerAnnotation) {
					super.updateMarkerViews((MarkerAnnotation)o);
					return;
				}
			}
		}
		return;
	}
	super.updateMarkerViews(annotation);
}
 
private void testIfProblemMarker(Annotation annotation) {
	if (fIncludesProblemMarkerAnnotations) {
		return;
	}
	if (annotation instanceof JavaMarkerAnnotation) {
		fIncludesProblemMarkerAnnotations= ((JavaMarkerAnnotation) annotation).isProblem();
	} else if (annotation instanceof MarkerAnnotation) {
		try {
			IMarker marker= ((MarkerAnnotation) annotation).getMarker();
			if (!marker.exists() || marker.isSubtypeOf(IMarker.PROBLEM)) {
				fIncludesProblemMarkerAnnotations= true;
			}
		} catch (CoreException e) {
			JavaPlugin.log(e);
		}
	}
}
 
源代码8 项目: Pydev   文件: OrganizeImportsFixesUnused.java
private void findAndDeleteUnusedImports(PySelection ps, PyEdit edit, IDocumentExtension4 doc, IFile f)
        throws Exception {
    Iterator<MarkerAnnotationAndPosition> it;
    if (edit != null) {
        it = edit.getPySourceViewer().getMarkerIterator();
    } else {

        IMarker markers[] = f.findMarkers(IMiscConstants.PYDEV_ANALYSIS_PROBLEM_MARKER, true, IResource.DEPTH_ZERO);
        MarkerAnnotationAndPosition maap[] = new MarkerAnnotationAndPosition[markers.length];
        int ix = 0;
        for (IMarker m : markers) {
            int start = (Integer) m.getAttribute(IMarker.CHAR_START);
            int end = (Integer) m.getAttribute(IMarker.CHAR_END);
            maap[ix++] =
                    new MarkerAnnotationAndPosition(new MarkerAnnotation(m), new Position(start, end - start));
        }
        it = Arrays.asList(maap).iterator();
    }
    ArrayList<MarkerAnnotationAndPosition> unusedImportsMarkers = getUnusedImports(it);
    sortInReverseDocumentOrder(unusedImportsMarkers);
    deleteImports(doc, ps, unusedImportsMarkers);

}
 
源代码9 项目: goclipse   文件: ExternalBreakpointWatcher.java
protected void updateMarkerAnnotation(IMarker marker) {
	
	Iterator<Annotation> iter = annotationModel.getAnnotationIterator();
	
	for (Annotation ann : (Iterable<Annotation>) () -> iter) {
		if(ann instanceof MarkerAnnotation) {
			MarkerAnnotation markerAnnotation = (MarkerAnnotation) ann;
			if(markerAnnotation.getMarker().equals(marker)) {
				
				Position position = annotationModel.getPosition(markerAnnotation);
				
				// Trigger a model update.
				annotationModelExt.modifyAnnotationPosition(markerAnnotation, position);
				
				return;
			}
		}
	}
}
 
源代码10 项目: xtext-eclipse   文件: IssueUtil.java
public Issue getIssueFromAnnotation(Annotation annotation) {
	if (annotation instanceof XtextAnnotation) {
		XtextAnnotation xtextAnnotation = (XtextAnnotation) annotation;
		return xtextAnnotation.getIssue();
	} else if(annotation instanceof MarkerAnnotation) {
		MarkerAnnotation markerAnnotation = (MarkerAnnotation)annotation;
		return createIssue(markerAnnotation.getMarker());
	} else
		return null;
}
 
源代码11 项目: xtext-eclipse   文件: IssueUtil.java
public String getCode(Annotation annotation) {
	if (annotation instanceof MarkerAnnotation) {
		MarkerAnnotation ma = (MarkerAnnotation) annotation;
		return getCode(ma.getMarker());
	}
	if (annotation instanceof XtextAnnotation) {
		XtextAnnotation xa = (XtextAnnotation) annotation;
		return xa.getIssueCode();	
	}
	return null;
}
 
源代码12 项目: xtext-eclipse   文件: IssueUtil.java
public String[] getIssueData(Annotation annotation) {
	if (annotation instanceof MarkerAnnotation) {
		MarkerAnnotation ma = (MarkerAnnotation) annotation;
		return getIssueData(ma.getMarker());
	}
	if (annotation instanceof XtextAnnotation) {
		XtextAnnotation xa = (XtextAnnotation) annotation;
		return xa.getIssueData();	
	}
	return null;
}
 
源代码13 项目: xtext-eclipse   文件: IssueUtil.java
public URI getUriToProblem(Annotation annotation) {
	if (annotation instanceof MarkerAnnotation) {
		MarkerAnnotation ma = (MarkerAnnotation) annotation;
		return getUriToProblem(ma.getMarker());
	}
	if (annotation instanceof XtextAnnotation) {
		XtextAnnotation xa = (XtextAnnotation) annotation;
		return xa.getUriToProblem();
	}
	return null;
}
 
源代码14 项目: xtext-eclipse   文件: AnnotationIssueProcessor.java
protected void updateMarkerAnnotations(IProgressMonitor monitor) {
	if (monitor.isCanceled()) {
		return;
	}

	Iterator<MarkerAnnotation> annotationIterator = Iterators.filter(annotationModel.getAnnotationIterator(),
			MarkerAnnotation.class);

	// every markerAnnotation produced by fast validation can be marked as deleted.
	// If its predicate still holds, the validation annotation will be covered anyway.
	while (annotationIterator.hasNext() && !monitor.isCanceled()) {
		final MarkerAnnotation annotation = annotationIterator.next();
		if (!annotation.isMarkedDeleted())
			try {
				if (isRelevantAnnotationType(annotation.getType())) {
					boolean markAsDeleted = annotation.getMarker().isSubtypeOf(MarkerTypes.FAST_VALIDATION);
					if (markAsDeleted) {
						annotation.markDeleted(true);
						queueOrFireAnnotationChangedEvent(annotation);
					}
				}
			} catch (CoreException e) {
				// marker type cannot be resolved - keep state of annotation
			}
	}
	fireQueuedEvents();
}
 
源代码15 项目: xtext-eclipse   文件: XtextEditor.java
private boolean isProblemMarkerAnnotation(final Annotation annotation) {
	if (!(annotation instanceof MarkerAnnotation))
		return false;
	try {
		return (((MarkerAnnotation) annotation).getMarker().isSubtypeOf(IMarker.PROBLEM));
	} catch (final CoreException e) {
		return false;
	}
}
 
private Map<String, Image> getImages(Annotation annotation) {
	if(annotation.isMarkedDeleted())
		return XtextPluginImages.getAnnotationImagesDeleted();
	else {
		if (annotation instanceof MarkerAnnotation) {
			MarkerAnnotation ma = (MarkerAnnotation) annotation;
			if(ma.isQuickFixableStateSet() && ma.isQuickFixable())
				return XtextPluginImages.getAnnotationImagesFixable();
		}
		return XtextPluginImages.getAnnotationImagesNonfixable();
	}
}
 
@Override
protected MarkerAnnotation createMarkerAnnotation(IMarker marker) {
	MarkerAnnotation annotation = super.createMarkerAnnotation(marker);
	String issueCode = issueUtil.getCode(annotation);
	annotation.setQuickFixable(issueResolutionProvider.hasResolutionFor(issueCode));
	return annotation;
}
 
源代码18 项目: texlipse   文件: TexAnnotationHover.java
/**
 * Find a problem marker from the given line and return its error message.
 * 
 * @param sourceViewer the source viewer
 * @param lineNumber line number in the file, starting from zero
 * @return the message of the marker of null, if no marker at the specified line
 */
public String getHoverInfo(ISourceViewer sourceViewer, int lineNumber) {
    IDocument document= sourceViewer.getDocument();
    IAnnotationModel model= sourceViewer.getAnnotationModel();
    
    if (model == null)
        return null;
    
    List<String> lineMarkers = null;

    Iterator<Annotation> e= model.getAnnotationIterator();
    while (e.hasNext()) {
        Annotation o= e.next();
        if (o instanceof MarkerAnnotation) {
            MarkerAnnotation a= (MarkerAnnotation) o;
            if (isRulerLine(model.getPosition(a), document, lineNumber)) {
                if (lineMarkers == null)
                    lineMarkers = new LinkedList<String>();
                lineMarkers.add(a.getMarker().getAttribute(IMarker.MESSAGE, null));
            }
        }
    }
    if (lineMarkers != null)
        return getMessage(lineMarkers);
    
    return null;
}
 
源代码19 项目: xds-ide   文件: MarkerAnnotationPaintHandler.java
@Override
public boolean paint(SourceCodeTextEditor editor, Annotation annotation, GC gc, Canvas canvas, Rectangle bounds) {
	if (annotation instanceof MarkerAnnotation) {
		return paint(editor, (MarkerAnnotation)annotation, gc, canvas, bounds);
	}
	return false;
}
 
源代码20 项目: xds-ide   文件: ModulaEditor.java
@Override
 	public boolean paint(SourceCodeTextEditor editor, MarkerAnnotation annotation,
 			GC gc, Canvas canvas, Rectangle bounds) {
 		IMarker marker = annotation.getMarker();
try {
	if (marker.exists() && XdsMarkerConstants.PARSER_PROBLEM.equals(marker.getType())) {
		boolean isInCompilationSet = CompilationSetManager.getInstance().isInCompilationSet((IFile)marker.getResource());
		if (!isInCompilationSet) {
			int actualSeverity = marker.getAttribute(XdsMarkerConstants.PARSER_PROBLEM_SEVERITY_ATTRIBUTE, -1);
			if (actualSeverity > -1) {
				Image image = null;
				switch (actualSeverity) {
				case IMarker.SEVERITY_ERROR:
					image = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_ERROR_TSK); 
					break;
				case IMarker.SEVERITY_WARNING:
					image = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_WARN_TSK); 
					break;
				default:
					break;
				}

				if (image != null) {
					ImageUtilities.drawImage(image, gc, canvas, bounds, SWT.CENTER, SWT.TOP);
					return true;
				}

				return false;
			}
		}
	}
} catch (CoreException e) {
	LogHelper.logError(e);
}
 		return false;
 	}
 
源代码21 项目: tlaplus   文件: TLAAnnotationHover.java
private String[] getMessagesForLine(final ISourceViewer viewer, final int line) {
	final IAnnotationModel model = viewer.getAnnotationModel();

	if (model == null) {
		return new String[0];
	}

	final Iterator<Annotation> it = model.getAnnotationIterator();
	final IDocument document = viewer.getDocument();
	final ArrayList<String> messages = new ArrayList<>();
	final HashMap<Position, Set<String>> placeMessagesMap = new HashMap<>();
	while (it.hasNext()) {
		final Annotation annotation = it.next();
		if (annotation instanceof MarkerAnnotation) {
			final MarkerAnnotation ma = (MarkerAnnotation) annotation;
			final Position p = model.getPosition(ma);
			if (compareRulerLine(p, document, line)) {
				final IMarker marker = ma.getMarker();
				final String message = marker.getAttribute(IMarker.MESSAGE, null);
				if ((message != null) && (message.trim().length() > 0)) {
					Set<String> priorMessages = placeMessagesMap.get(p);
					if (priorMessages == null) {
						priorMessages = new HashSet<>();
						placeMessagesMap.put(p, priorMessages);
					}
					
					if (!priorMessages.contains(message)) {
						messages.add(message);
						priorMessages.add(message);
					}
				}
			}
		}
	}
	return (String[]) messages.toArray(new String[messages.size()]);
}
 
@Override
public boolean canFix(Annotation annotation) {
    if (annotation.isMarkedDeleted()) {
        return false;
    }
    if (annotation instanceof MarkerAnnotation) {
        MarkerAnnotation markerAnnotation = (MarkerAnnotation) annotation;
        if (!markerAnnotation.isQuickFixableStateSet()) {
            markerAnnotation.setQuickFixable(
                    generators.stream().anyMatch(e -> e.hasResolutions(markerAnnotation.getMarker())));
        }
        return markerAnnotation.isQuickFixable();
    }
    return false;
}
 
private IMarker isAnnotationInRange(IAnnotationModel model, Annotation annot, ISourceReference sourceElement) throws CoreException {
	if (annot instanceof MarkerAnnotation) {
		if (sourceElement == null || isInside(model.getPosition(annot), sourceElement)) {
			IMarker marker= ((MarkerAnnotation) annot).getMarker();
			if (marker.exists() && marker.isSubtypeOf(IMarker.PROBLEM)) {
				return marker;
			}
		}
	}
	return null;
}
 
/**
 * Tells whether the given annotation stands for a problem marker.
 *
 * @param annotation the annotation
 * @return <code>true</code> if it is a problem marker
 * @since 3.4
 */
private static boolean isProblemMarkerAnnotation(Annotation annotation) {
	if (!(annotation instanceof MarkerAnnotation))
		return false;
	try {
		return(((MarkerAnnotation)annotation).getMarker().isSubtypeOf(IMarker.PROBLEM));
	} catch (CoreException e) {
		return false;
	}
}
 
private static boolean isProblemMarkerAnnotation(Annotation annotation) {
	if (!(annotation instanceof MarkerAnnotation))
		return false;
	try {
		return(((MarkerAnnotation)annotation).getMarker().isSubtypeOf(IMarker.PROBLEM));
	} catch (CoreException e) {
		return false;
	}
}
 
@Override
public ICompletionProposal[] getCompletionProposals() {
	if (annotation instanceof IJavaAnnotation) {
		ICompletionProposal[] result= getJavaAnnotationFixes((IJavaAnnotation) annotation);
		if (result.length > 0)
			return result;
	}

	if (annotation instanceof MarkerAnnotation)
		return getMarkerAnnotationFixes((MarkerAnnotation) annotation);

	return NO_PROPOSALS;
}
 
源代码27 项目: birt   文件: ScriptDocumentProvider.java
public void beforeChangeText()
{		
	for (Iterator e= getAnnotationIterator(true); e.hasNext();) {
		Object o= e.next();
		if (o instanceof MarkerAnnotation) {
			MarkerAnnotation a= (MarkerAnnotation) o;
			
			//System.out.println(a.getType( ));
			IMarker mark = a.getMarker( );
			try
			{
				if (mark == null || !getId( ).equals( mark.getAttribute( SUBNAME ) ))
				{
					continue;
				}
				if (!(ScriptDocumentProvider.MARK_TYPE.equals( a.getMarker( ).getType( ))))
				{
					continue;
				}
			}
			catch ( CoreException e1 )
			{
				continue;
			}
			Position p= getPosition( a );
			if (p != null && !p.isDeleted( )) {
				Position tempCopy = new Position(p.getOffset(),p.getLength());
				markMap.put( a, tempCopy );
			}
		}
	}

	change = true;
}
 
源代码28 项目: birt   文件: ScriptDocumentProvider.java
protected void addAnnotation(Annotation annotation, Position position, boolean fireModelChanged)throws BadLocationException
{
	if (annotation instanceof MarkerAnnotation)
	{
		IMarker marker = ((MarkerAnnotation)annotation).getMarker( );
		if (marker != null)
		{
			try
			{
				if (!getId( ).equals( marker.getAttribute( SUBNAME ) ))
				{
					return;
				}
				if (!(ScriptDocumentProvider.MARK_TYPE.equals( marker.getType( ))))
				{
					return;
				}
			
			}
			catch ( CoreException e )
			{
				//do nothing now
			}
		}
	}
	super.addAnnotation( annotation, position, fireModelChanged );
}
 
源代码29 项目: birt   文件: ScriptDocumentProvider.java
private IMarker findTrueMark(MarkerAnnotation a)
{
	for (Iterator<MarkerAnnotation> e= markMap.keySet( ).iterator( ); e.hasNext();) 
	{
		MarkerAnnotation temp = e.next( );
		if (a.getMarker( ).equals( temp.getMarker( ) ))
		{
			return temp.getMarker( );
		}
	}
	return null;
}
 
源代码30 项目: Pydev   文件: AdditionalInfoTestsBase.java
/**
 * This method creates a marker stub
 *
 * @param start start char
 * @param end end char
 * @param type the marker type
 * @return the created stub
 */
protected MarkerAnnotationAndPosition createMarkerStub(int start, int end, int type) {
    HashMap<String, Object> attrs = new HashMap<String, Object>();

    attrs.put(AnalysisRunner.PYDEV_ANALYSIS_TYPE, type);
    attrs.put(IMarker.CHAR_START, start);
    attrs.put(IMarker.CHAR_END, end);

    MarkerStub marker = new MarkerStub(attrs);
    return new MarkerAnnotationAndPosition(
            new MarkerAnnotation("org.eclipse.core.resources.problemmarker", marker), new Position(start, end
                    - start));
}
 
源代码评论
动弹
沙发等你来抢
 类所在包
 类方法
 同包方法