Eclipse RCP: How to programmatically get Problems View records

牧云@^-^@ 提交于 2019-12-24 12:42:01

问题


On Eclipse Luna, I need to programmatically build java projects and then retrieve the Problems View's records. 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.

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. I need to access the existing Problems View in a programmatic way. Thank you for any suggestion.


回答1:


Got it. Use getResource() instead of getAttribute().




回答2:


The markers API is pretty flexible, you should read the documentation.

Long story short, there will be other attributes that you're not looking at. Try calling getAttributes and dumping them out.



来源:https://stackoverflow.com/questions/29016719/eclipse-rcp-how-to-programmatically-get-problems-view-records

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!