org.eclipse.ui.texteditor.MarkerAnnotation Java Examples

The following examples show how to use org.eclipse.ui.texteditor.MarkerAnnotation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExternalBreakpointWatcher.java    From goclipse with Eclipse Public License 1.0 6 votes vote down vote up
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;
			}
		}
	}
}
 
Example #2
Source File: JsonQuickAssistProcessor.java    From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 6 votes vote down vote up
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;
}
 
Example #3
Source File: AbstractASTResolution.java    From eclipse-cs with GNU Lesser General Public License v2.1 6 votes vote down vote up
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;
  }
 
Example #4
Source File: JavaEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@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);
}
 
Example #5
Source File: CompilationUnitAnnotationModelEvent.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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);
		}
	}
}
 
Example #6
Source File: SourceCodeTextEditor.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
@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);
}
 
Example #7
Source File: XtextQuickAssistProcessor.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@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;
}
 
Example #8
Source File: OrganizeImportsFixesUnused.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
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);

}
 
Example #9
Source File: AnnotationIssueProcessor.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
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;
}
 
Example #10
Source File: ScriptDocumentProvider.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
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;
}
 
Example #11
Source File: ScriptDocumentProvider.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
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 );
}
 
Example #12
Source File: ScriptDocumentProvider.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
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;
}
 
Example #13
Source File: AdditionalInfoTestsBase.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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));
}
 
Example #14
Source File: ProblemHover.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@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;
}
 
Example #15
Source File: JavaAnnotationIterator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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;
	}
}
 
Example #16
Source File: PyEditBreakpointSync.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
private void updateAnnotations() {
    if (edit == null) {
        return;
    }
    IDocumentProvider provider = edit.getDocumentProvider();
    if (provider == null) {
        return;
    }
    IAnnotationModel model = provider.getAnnotationModel(edit.getEditorInput());
    if (model == null) {
        return;
    }

    IAnnotationModelExtension modelExtension = (IAnnotationModelExtension) model;

    List<Annotation> existing = new ArrayList<Annotation>();
    Iterator<Annotation> it = model.getAnnotationIterator();
    if (it == null) {
        return;
    }
    while (it.hasNext()) {
        existing.add(it.next());
    }

    IDocument doc = edit.getDocument();
    IResource resource = PyMarkerUIUtils.getResourceForTextEditor(edit);
    IEditorInput externalFileEditorInput = AbstractBreakpointRulerAction.getExternalFileEditorInput(edit);
    List<IMarker> markers = AbstractBreakpointRulerAction.getMarkersFromEditorResource(resource, doc,
            externalFileEditorInput, 0, false, model);

    Map<Annotation, Position> annotationsToAdd = new HashMap<Annotation, Position>();
    for (IMarker m : markers) {
        Position pos = PyMarkerUIUtils.getMarkerPosition(doc, m, model);
        MarkerAnnotation newAnnotation = new MarkerAnnotation(m);
        annotationsToAdd.put(newAnnotation, pos);
    }

    //update all in a single step
    modelExtension.replaceAnnotations(existing.toArray(new Annotation[0]), annotationsToAdd);
}
 
Example #17
Source File: JavaEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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;
	}
}
 
Example #18
Source File: JavaAnnotationIterator.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
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;
	}
}
 
Example #19
Source File: ProblemsLabelDecorator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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;
}
 
Example #20
Source File: ExternalBreakpointWatcher.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
protected void removeMarkerAnnotation(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)) {
				annotationModel.removeAnnotation(markerAnnotation);
				return;
			}
		}
	}
}
 
Example #21
Source File: JsonQuickAssistProcessor.java    From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 5 votes vote down vote up
@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;
}
 
Example #22
Source File: XtextResourceMarkerAnnotationModel.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected MarkerAnnotation createMarkerAnnotation(IMarker marker) {
	MarkerAnnotation annotation = super.createMarkerAnnotation(marker);
	String issueCode = issueUtil.getCode(annotation);
	annotation.setQuickFixable(issueResolutionProvider.hasResolutionFor(issueCode));
	return annotation;
}
 
Example #23
Source File: IssueUtil.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
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;
}
 
Example #24
Source File: IssueUtil.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
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;
}
 
Example #25
Source File: IssueUtil.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
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;
}
 
Example #26
Source File: IssueUtil.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
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;
}
 
Example #27
Source File: AnnotationIssueProcessor.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
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();
}
 
Example #28
Source File: XtextEditor.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
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;
	}
}
 
Example #29
Source File: XtextMarkerAnnotationImageProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
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();
	}
}
 
Example #30
Source File: TLAAnnotationHover.java    From tlaplus with MIT License 5 votes vote down vote up
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()]);
}