简体   繁体   English

Eclipse RCP:如何以编程方式获取问题查看记录

[英]Eclipse RCP: How to programmatically get Problems View records

On Eclipse Luna, I need to programmatically build java projects and then retrieve the Problems View's records. 在Eclipse Luna上,我需要以编程方式构建Java项目,然后检索问题视图的记录。 I use the following code 我使用以下代码

IWorkspace workspace = ResourcesPlugin.getWorkspace();
IResource resource = workspace.getRoot();
IMarker[] markers = resource.findMarkers(IMarker.MARKER, true, IResource.DEPTH_INFINITE);
for (IMarker m : markers) {
    System.out.println("Id: " + m.getId());
    System.out.println("Message: " + m.getAttribute(IMarker.MESSAGE));
    System.out.println("Source ID: " + m.getAttribute(IMarker.SOURCE_ID));
    System.out.println("Location: " + m.getAttribute(IMarker.LOCATION));
    System.out.println("Line Number: " + m.getAttribute(IMarker.LINE_NUMBER));
    System.out.println("Marker: " + m.getAttribute(IMarker.MARKER));
}

The message and line number are printed correctly. 信息和行号正确打印。 But IMarker.SOURCE_ID returns "JDT" and IMarker.LOCATION is always null. 但是IMarker.SOURCE_ID返回“ JDT”,并且IMarker.LOCATION始终为空。

Anybody knows how can I get the data shown as "Resource" and "Path" on the Problems View? 谁知道在问题视图中如何获取显示为“资源”和“路径”的数据? I cannot create any custom Marker view using MarkerSupportView. 我无法使用MarkerSupportView创建任何自定义Marker视图。 I need to access the existing Problems View in a programmatic way. 我需要以编程方式访问现有的问题视图。 Thank you for any suggestion. 感谢您的任何建议。

Got it. 得到它了。 Use getResource() instead of getAttribute(). 使用getResource()而不是getAttribute()。

The markers API is pretty flexible, you should read the documentation . 标记API非常灵活,您应该阅读文档

Long story short, there will be other attributes that you're not looking at. 长话短说,您将不会看到其他属性。 Try calling getAttributes and dumping them out. 尝试调用getAttributes并将其转储出去。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM