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

The following examples show how to use org.eclipse.core.resources.IResource#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: EclipseBasedShouldGenerate.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public boolean shouldGenerate(Resource resource, CancelIndicator cancelIndicator) {
	URI uri = resource.getURI();
	if (uri == null || !uri.isPlatformResource()) {
		return false;
	}

	IResource member = ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(uri.toPlatformString(true)));
	if (member != null && member.getType() == IResource.FILE) {
		ProjectConfigAdapter projectConfigAdapter = ProjectConfigAdapter.findInEmfObject(resource.getResourceSet());
		if (projectConfigAdapter != null) {
			IProjectConfig projectConfig = projectConfigAdapter.getProjectConfig();
			if (projectConfig != null && Objects.equals(member.getProject().getName(), projectConfig.getName())) {
				try {
					return member.findMaxProblemSeverity(null, true, IResource.DEPTH_INFINITE) != IMarker.SEVERITY_ERROR;
				} catch (CoreException e) {
					LOG.error("The resource " + member.getName() + " does not exist", e);
					return false;
				}
			}
		}
	}
	return false;
}
 
Example 2
Source File: ProblemTickUpdater.java    From typescript.java with MIT License 6 votes vote down vote up
private void updateTitleImageForResource(IResource resource) {
	if (resource == null || !resource.isAccessible()) {
		editor.updateTitleImage(null);
		return;
	}

	// Determine the current maximum problem severity
	int severity;
	try {
		severity = resource.findMaxProblemSeverity(IMarker.PROBLEM, true, 0);
	} catch (CoreException e) {
		JSDTTypeScriptUIPlugin.log(e);
		return;
	}

	ITypeScriptFile tsFile = editor.getTypeScriptFile();
	ScriptKindName scriptKind = tsFile.getScriptKind();
	if (scriptKind == null) {
		scriptKind = ScriptKindName.TS;
	}

	// Prepare the image
	Image image = getImage(severity, scriptKind);

	editor.updateTitleImage(image);
}
 
Example 3
Source File: ProblemsLabelDecorator.java    From goclipse with Eclipse Public License 1.0 6 votes vote down vote up
protected ImageDescriptor getErrorTicksFromMarkers(IResource res, int depth) throws CoreException {
		if (res == null || !res.isAccessible()) {
			return null;
		}
		
		int severity= 0;
//			if (res instanceof IProject) {
//				severity= res.findMaxProblemSeverity(IJavaModelMarker.BUILDPATH_PROBLEM_MARKER, true, IResource.DEPTH_ZERO);
//				if (severity == IMarker.SEVERITY_ERROR) {
//					return ERRORTICK_BUILDPATH_ERROR;
//				}
//				severity= res.findMaxProblemSeverity(JavaRuntime.JRE_CONTAINER_MARKER, true, IResource.DEPTH_ZERO);
//				if (severity == IMarker.SEVERITY_ERROR) {
//					return ERRORTICK_BUILDPATH_ERROR;
//				}
//			}
			severity= res.findMaxProblemSeverity(IMarker.PROBLEM, true, depth);
		if (severity == IMarker.SEVERITY_ERROR) {
			return LangImages.DESC_OVR_ERROR;
		} else if (severity == IMarker.SEVERITY_WARNING) {
			return LangImages.DESC_OVR_WARNING;
		}
		return null;
	}
 
Example 4
Source File: ProblemsLabelDecorator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private int getErrorTicksFromMarkers(IResource res, int depth, ISourceReference sourceElement) throws CoreException {
	if (res == null || !res.isAccessible()) {
		return 0;
	}
	int severity= 0;
	if (sourceElement == null) {
		if (res instanceof IProject) {
			severity= res.findMaxProblemSeverity(IJavaModelMarker.BUILDPATH_PROBLEM_MARKER, true, IResource.DEPTH_ZERO);
			if (severity == IMarker.SEVERITY_ERROR) {
				return ERRORTICK_BUILDPATH_ERROR;
			}
			severity= res.findMaxProblemSeverity(JavaRuntime.JRE_CONTAINER_MARKER, true, IResource.DEPTH_ZERO);
			if (severity == IMarker.SEVERITY_ERROR) {
				return ERRORTICK_BUILDPATH_ERROR;
			}
		}
		severity= res.findMaxProblemSeverity(IMarker.PROBLEM, true, depth);
	} else {
		IMarker[] markers= res.findMarkers(IMarker.PROBLEM, true, depth);
		if (markers != null && markers.length > 0) {
			for (int i= 0; i < markers.length && (severity != IMarker.SEVERITY_ERROR); i++) {
				IMarker curr= markers[i];
				if (isMarkerInRange(curr, sourceElement)) {
					int val= curr.getAttribute(IMarker.SEVERITY, -1);
					if (val == IMarker.SEVERITY_WARNING || val == IMarker.SEVERITY_ERROR) {
						severity= val;
					}
				}
			}
		}
	}
	if (severity == IMarker.SEVERITY_ERROR) {
		return ERRORTICK_ERROR;
	} else if (severity == IMarker.SEVERITY_WARNING) {
		return ERRORTICK_WARNING;
	}
	return 0;
}
 
Example 5
Source File: ProblemsLabelDecorator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private int getPackageErrorTicksFromMarkers(IPackageFragment pack) throws CoreException {
	// Packages are special: They must not consider markers on subpackages.
	
	IResource res= pack.getResource();
	if (res == null || !res.isAccessible()) {
		return 0;
	}
	
	// markers on package itself (e.g. missing @NonNullByDefault)
	int severity= res.findMaxProblemSeverity(IMarker.PROBLEM, true, IResource.DEPTH_ZERO);
	if (severity == IMarker.SEVERITY_ERROR)
		return ERRORTICK_ERROR;
	
	// markers on CUs
	for (ICompilationUnit cu : pack.getCompilationUnits()) {
		severity= Math.max(severity, cu.getResource().findMaxProblemSeverity(IMarker.PROBLEM, true, IResource.DEPTH_ZERO));
		if (severity == IMarker.SEVERITY_ERROR)
			return ERRORTICK_ERROR;
	}
	
	// markers on files and folders
	for (Object object : pack.getNonJavaResources()) {
		if (object instanceof IResource) {
			IResource resource= (IResource) object;
			severity= Math.max(severity, resource.findMaxProblemSeverity(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE));
			if (severity == IMarker.SEVERITY_ERROR)
				return ERRORTICK_ERROR;
		}
	}
	
	// SEVERITY_ERROR already handled above
	if (severity == IMarker.SEVERITY_WARNING) {
		return ERRORTICK_WARNING;
	}
	return 0;
}
 
Example 6
Source File: ProblemsLabelDecorator.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
private int getErrorTicksFromMarkers(IResource res, int depth) throws CoreException {
    if (!res.isAccessible()) {
        return 0;
    }
    return res.findMaxProblemSeverity(IMarker.PROBLEM, true, depth);
}