下面列出了怎么用org.eclipse.ui.texteditor.SimpleMarkerAnnotation的API类实例代码及写法,或者点击链接到github查看源代码。
public static boolean hasCorrections(Annotation annotation) {
if (annotation instanceof IJavaAnnotation) {
IJavaAnnotation javaAnnotation= (IJavaAnnotation) annotation;
int problemId= javaAnnotation.getId();
if (problemId != -1) {
ICompilationUnit cu= javaAnnotation.getCompilationUnit();
if (cu != null) {
return hasCorrections(cu, problemId, javaAnnotation.getMarkerType());
}
}
}
if (annotation instanceof SimpleMarkerAnnotation) {
return hasCorrections(((SimpleMarkerAnnotation) annotation).getMarker());
}
return false;
}
public int compare(Annotation o1, Annotation o2)
{
if (o1 instanceof SimpleMarkerAnnotation && o2 instanceof SimpleMarkerAnnotation)
{
// Compare the marker offset first. In case it was not set with an offset, compare via the line numbers.
IMarker m1 = ((SimpleMarkerAnnotation) o1).getMarker();
IMarker m2 = ((SimpleMarkerAnnotation) o2).getMarker();
if (m1 != null && m2 != null)
{
// try comparing by offset
int pos1 = m1.getAttribute(IMarker.CHAR_START, -1);
int pos2 = m2.getAttribute(IMarker.CHAR_START, -1);
if (pos1 > -1 && pos2 > -1)
{
return pos1 - pos2;
}
// in case one of the char-start values was not set, try comparing using the line number
pos1 = m1.getAttribute(IMarker.LINE_NUMBER, -1);
pos2 = m2.getAttribute(IMarker.LINE_NUMBER, -1);
if (pos1 > -1 && pos2 > -1)
{
return pos1 - pos2;
}
}
}
// just return 0, as we can't really compare those.
return 0;
}
private static void collectMarkerProposals(SimpleMarkerAnnotation annotation, Collection<IJavaCompletionProposal> proposals) {
IMarker marker= annotation.getMarker();
IMarkerResolution[] res= IDE.getMarkerHelpRegistry().getResolutions(marker);
if (res.length > 0) {
for (int i= 0; i < res.length; i++) {
proposals.add(new MarkerResolutionProposal(res[i], marker));
}
}
}
public static boolean isQuickFixableType(Annotation annotation) {
return (annotation instanceof IJavaAnnotation || annotation instanceof SimpleMarkerAnnotation) && !annotation.isMarkedDeleted();
}
public MarkerAnnotationAndPosition(SimpleMarkerAnnotation markerAnnotation, Position position) {
this.markerAnnotation = markerAnnotation;
this.position = position;
}