Java Code Examples for org.eclipse.core.resources.IFile#findMaxProblemSeverity()

The following examples show how to use org.eclipse.core.resources.IFile#findMaxProblemSeverity() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BuildInstruction.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
private boolean shouldGenerate(Resource resource, IProject aProject) {
	try {
		Iterable<Pair<IStorage, IProject>> storages = storage2UriMapper.getStorages(resource.getURI());
		for (Pair<IStorage, IProject> pair : storages) {
			if (pair.getFirst() instanceof IFile && pair.getSecond().equals(aProject)) {
				IFile file = (IFile) pair.getFirst();
				int findMaxProblemSeverity = file.findMaxProblemSeverity(null, true, IResource.DEPTH_INFINITE);
				// If the generator itself placed an error marker on the resource, we have to ignore that error.
				// Easiest way here is to remove that error marker-type and look for other severe errors once more:
				if (findMaxProblemSeverity == IMarker.SEVERITY_ERROR) {
					// clean
					GeneratorMarkerSupport generatorMarkerSupport = injector
							.getInstance(GeneratorMarkerSupport.class);
					generatorMarkerSupport.deleteMarker(resource);
					// and recompute:
					findMaxProblemSeverity = file.findMaxProblemSeverity(null, true, IResource.DEPTH_INFINITE);
				}
				// the final decision to build:
				return findMaxProblemSeverity != IMarker.SEVERITY_ERROR;
			}
		}
		return false;
	} catch (CoreException exc) {
		throw new WrappedException(exc);
	}
}
 
Example 2
Source File: MarkerAssertions.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public void assertNoErrorMarker(IFile file) throws CoreException {
	int severity = file.findMaxProblemSeverity(null, true, IResource.DEPTH_INFINITE);
	if (severity != -1) {
		StringBuilder errors = new StringBuilder();
		for (IMarker marker : file.findMarkers(null, true, IResource.DEPTH_INFINITE)) {
			errors.append("\n").append(marker.getAttribute(IMarker.MESSAGE));
		}
		fail("Expected no error but got" + errors.toString());
	}
}