Java源码示例:org.eclipse.ui.texteditor.MarkerAnnotation
示例1
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
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
@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
@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);
}
示例5
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;
}
示例6
@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);
}
示例7
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
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
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
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
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
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
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
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
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;
}
}
示例16
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();
}
}
示例17
@Override
protected MarkerAnnotation createMarkerAnnotation(IMarker marker) {
MarkerAnnotation annotation = super.createMarkerAnnotation(marker);
String issueCode = issueUtil.getCode(annotation);
annotation.setQuickFixable(issueResolutionProvider.hasResolutionFor(issueCode));
return annotation;
}
示例18
/**
* 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
@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
@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
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()]);
}
示例22
@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;
}
示例23
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;
}
示例24
/**
* 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;
}
}
示例25
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;
}
}
示例26
@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
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
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
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
/**
* 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));
}