Java 将错误标记添加到SourceViewer中的特定行
嗨,我想在我的源代码查看器中添加错误标记。 我用了密码 除了行号外,一切正常Java 将错误标记添加到SourceViewer中的特定行,java,eclipse-plugin,Java,Eclipse Plugin,嗨,我想在我的源代码查看器中添加错误标记。 我用了密码 除了行号外,一切正常 final ErrorAnnotation errorAnnotation = new ErrorAnnotation(1, "Learn how to spell \"text!\""); // lets underline the word "texst" this.myAnnotationModel.addAnnotation(errorAnnotation, new Position(10,
final ErrorAnnotation errorAnnotation = new ErrorAnnotation(1, "Learn how to spell \"text!\"");
// lets underline the word "texst"
this.myAnnotationModel.addAnnotation(errorAnnotation, new Position(10, 2));
final ErrorAnnotation errorAnnotation1 = new ErrorAnnotation(6, "Learn how to spell \"text!\"");
// lets underline the word "texst"
this.myAnnotationModel.addAnnotation(errorAnnotation1, new Position(34, 3));
所有错误标记仅显示在第一行中
您能建议如何在正确的行中显示错误标记吗。
下面是ErrorAnnotation类。
ErrorAnnotation构造函数的第一个参数是行号。但是getLine()没有在任何地方使用(参考上面链接中的代码)。我不知道在哪里以及如何使用它。如果这不是获得特定行注释的方法,请您建议如何进行
public class ErrorAnnotation extends Annotation {
private final IMarker marker;
private String text;
private int line;
private Position position;
public ErrorAnnotation(final IMarker marker) {
this.marker = marker;
}
public ErrorAnnotation(final int line, final String text) {
super(ERROR_TYPE, true, null);
this.marker = null;
this.line = line;
this.text = text;
}
public IMarker getMarker() {
return this.marker;
}
public int getLine() {
return this.line;
}
@Override
public String getText() {
return this.text;
}
public Image getImage() {
return ERROR_IMAGE;
}
public int getLayer() {
return 3;
}
@Override
public String getType() {
return ERROR_TYPE;
}
public Position getPosition() {
return this.position;
}
public void setPosition(final Position position) {
this.position = position;
}
}
您是否意识到
位置的第一个参数是字符偏移量(不是行号)?是。我的问题包括我的ErrorAnnotation类。我刚刚粘贴了我在上面提到的链接中找到的代码。ErrorAnnotation构造函数的第一个参数是行号。但是getLine()没有在任何地方使用。我不知道在哪里以及如何使用它。如果这不是在特定行中获得注释的方法,请您建议如何进行。您必须计算出行的字符偏移量,并在位置使用该偏移量
谢谢您指出…这很有效。。。