Example usage for org.eclipse.jdt.internal.core JavaProject flushClasspathProblemMarkers

List of usage examples for org.eclipse.jdt.internal.core JavaProject flushClasspathProblemMarkers

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core JavaProject flushClasspathProblemMarkers.

Prototype

   protected void flushClasspathProblemMarkers(boolean flushCycleMarkers, boolean flushClasspathFormatMarkers,
           boolean flushOverlappingOutputMarkers) 

Source Link

Document

Remove all markers denoting classpath problems

Usage

From source file:org.eclipse.jdt.internal.core.JavaProject.java

License:Open Source License

public static void validateCycles(Map preferredClasspaths) throws JavaModelException {

    //long start = System.currentTimeMillis();

    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    IProject[] rscProjects = workspaceRoot.getProjects();
    int length = rscProjects.length;
    JavaProject[] projects = new JavaProject[length];

    LinkedHashSet cycleParticipants = new LinkedHashSet();
    HashSet traversed = new HashSet();

    // compute cycle participants
    ArrayList prereqChain = new ArrayList();
    for (int i = 0; i < length; i++) {
        if (hasJavaNature(rscProjects[i])) {
            JavaProject project = (projects[i] = (JavaProject) JavaCore.create(rscProjects[i]));
            if (!traversed.contains(project.getPath())) {
                prereqChain.clear();//from   w w  w.  ja v  a  2s  . c  om
                project.updateCycleParticipants(prereqChain, cycleParticipants, workspaceRoot, traversed,
                        preferredClasspaths);
            }
        }
    }
    //System.out.println("updateAllCycleMarkers: " + (System.currentTimeMillis() - start) + " ms");

    for (int i = 0; i < length; i++) {
        JavaProject project = projects[i];
        if (project != null) {
            if (cycleParticipants.contains(project.getPath())) {
                IMarker cycleMarker = project.getCycleMarker();
                String circularCPOption = project.getOption(JavaCore.CORE_CIRCULAR_CLASSPATH, true);
                int circularCPSeverity = JavaCore.ERROR.equals(circularCPOption) ? IMarker.SEVERITY_ERROR
                        : IMarker.SEVERITY_WARNING;
                if (cycleMarker != null) {
                    // update existing cycle marker if needed
                    try {
                        int existingSeverity = ((Integer) cycleMarker.getAttribute(IMarker.SEVERITY))
                                .intValue();
                        if (existingSeverity != circularCPSeverity) {
                            cycleMarker.setAttribute(IMarker.SEVERITY, circularCPSeverity);
                        }
                    } catch (CoreException e) {
                        throw new JavaModelException(e);
                    }
                } else {
                    IJavaProject[] projectsInCycle;
                    String cycleString = ""; //$NON-NLS-1$
                    if (cycleParticipants.isEmpty()) {
                        projectsInCycle = null;
                    } else {
                        projectsInCycle = new IJavaProject[cycleParticipants.size()];
                        Iterator it = cycleParticipants.iterator();
                        int k = 0;
                        while (it.hasNext()) {
                            //projectsInCycle[i++] = (IPath) it.next();
                            IResource member = workspaceRoot.findMember((IPath) it.next());
                            if (member != null && member.getType() == IResource.PROJECT) {
                                projectsInCycle[k] = JavaCore.create((IProject) member);
                                if (projectsInCycle[k] != null) {
                                    if (k != 0)
                                        cycleString += ", "; //$NON-NLS-1$
                                    cycleString += projectsInCycle[k++].getElementName();
                                }
                            }
                        }
                    }
                    // create new marker
                    project.createClasspathProblemMarker(new JavaModelStatus(
                            IJavaModelStatusConstants.CLASSPATH_CYCLE, project, cycleString));
                }
            } else {
                project.flushClasspathProblemMarkers(true, false, false);
            }
        }
    }
}