eclipse xtext:我怎么知道文件是否包含错误

eclipse xtext: How can I know if file contain errors

我正在 Java 中实现一个 Eclipse 插件。我想写一个函数,对于给定的文件路径(例如file.myDSL)returns文件是否有错误或者是合法文件。

IProject theProject = 
ResourcePlugin.getWorkspace().getRoot().getProject("theProject");
theProject.build(...); // or whatever operation to make sure Xtext checked the file
IFile theFile = project.getFile("file.myDsl");
theFile.getMarkers(IMarker.PROBLEM, true, IResource.DEPTH_ZERO);