Getting compilation errors for a project over JDT markers produces wrong result initially [message #1064856] |
Fri, 21 June 2013 12:19 |
Kivanc Muslu Messages: 153 Registered: November 2010 |
Senior Member |
|
|
Hi all,
I am trying to approximate the compilation errors in a project by retrieving the JDT markers on that project and filtering according to severity == IMarker.SEVERITY_ERROR. In Eclipse, I have auto-building activated and this logic works perfect except the first invocation after Eclipse is loaded.
Here is the related code:
// Join auto-builder
Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_BUILD, null);
IProject project = // related project.
IMarker[] markers = project.findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);
ArrayList<IMarker> result = new ArrayList<>();
for (Marker marker: markers)
{
int severity = marker.getAttribute(IMarker.SEVERITY, Integer.MAX_VALUE);
if (severity == IMarker.SEVERITY_ERROR)
result.add(marker);
}
// Result should contain the compilation errors in 'project'.
This code gets executed in my plug-in, and for some reason, for a project with no compilation errors, it generates one compilation error, only in the first run after Eclipse is loaded. Details for that compilation error:
[org.eclipse.core.resources.IMarker: type = org.eclipse.jdt.core.problem, attributes = {id: 33554515, message: entry cannot be resolved to a variable, arguments: 1:entry, categoryId: 50, charStart: 2447, lineNumber: 57, severity: 2, charEnd: 2452, sourceId: JDT}]
Related code piece:
// main is valid java code.
BibEntry entry2 = main.getEntry("MusluSW2011esecfse");
Assert.assertNotNull(entry2);
Here the compilation error refers to 'entry2' (when you map the line and char start and end attributes) as 'entry' for some reason.
I have also tried turning off auto-build and calling project.build(..) manually, however it creates the same result.
My specific questions:
1. When I join to autobuilder, does it block my code until all problem markers are generated (updated, removed, etc.) or just until the build phase ended? If the latter, is there a way to block my code until all markers are generated?
2. Is there a more reliable way to retrieve the compilation errors for a given project in Eclipse API?
My open-ended question:
3. Do you have any suggestions for debugging the problem and about what might cause the problem?
Thanks, best regards,
|
|
|
Re: Getting compilation errors for a project over JDT markers produces wrong result initially [message #1064979 is a reply to message #1064856] |
Sat, 22 June 2013 12:34 |
Stephan Herrmann Messages: 1853 Registered: July 2009 |
Senior Member |
|
|
Given you see a bogus error marker, the most general approach to understand this would probably be just setting a breakpoint inside org.eclipse.jdt.internal.compiler.problem.ProblemHandler.handle(int, String[], int, String[], int, int, int, ReferenceContext, CompilationResult) just after the "case ProblemSeverities.Error :" line.
Another idea might be to change from joining the JobManager (which I have no experience with) to registering a CompilationParticipant and wait for being called via buildFinished(IJavaProject).
|
|
|
Powered by
FUDForum. Page generated in 0.03168 seconds