Example usage for org.eclipse.jdt.core IClasspathEntry CPE_PROJECT

List of usage examples for org.eclipse.jdt.core IClasspathEntry CPE_PROJECT

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IClasspathEntry CPE_PROJECT.

Prototype

int CPE_PROJECT

To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_PROJECT.

Click Source Link

Document

Entry kind constant describing a classpath entry identifying a required project.

Usage

From source file:edu.rice.cs.drjava.plugins.eclipse.repl.EclipseInteractionsModel.java

License:BSD License

private void _addProjectToClasspath(IJavaProject jProj, IJavaModel jModel, IWorkspaceRoot root)
        throws CoreException {
    // Get the project's location on disk
    IProject proj = jProj.getProject();//from   w  w w.  j a va2  s.c o  m
    URI projRoot = proj.getDescription().getLocationURI();
    // Note: getLocation returns null if the default location is used
    //  (brilliant...)

    // Get the resolved classpath entries - this should filter out
    //   all CPE_VARIABLE and CPE_CONTAINER entries.
    IClasspathEntry entries[] = jProj.getResolvedClasspath(true);

    // For each of the classpath entries...
    for (int j = 0; j < entries.length; j++) {
        IClasspathEntry entry = entries[j];

        // Check what kind of entry it is...
        int kind = entry.getEntryKind();

        // And get the appropriate path.
        IPath path;
        switch (kind) {
        case IClasspathEntry.CPE_LIBRARY:
            // The raw location of a JAR.
            path = entry.getPath();
            //System.out.println("Adding library: " + path.toOSString());
            addToClassPath(path.toOSString());
            break;
        case IClasspathEntry.CPE_SOURCE:
            // The output location of source.
            // Need to append it to the user's workspace directory.
            path = entry.getOutputLocation();
            if (path == null) {
                path = jProj.getOutputLocation();
                //System.out.println(" output location from proj: " + path);
            }

            // At this point, the output location contains the project
            //  name followed by the actual output folder name

            if (projRoot != null && (!projRoot.isAbsolute() || projRoot.getScheme().equals("file"))) {
                // We have a custom project location, so the project name
                //  is not part of the *actual* output directory.  We need
                //  to remove the project name (first segment) and then
                //  append the rest of the output location to projRoot.
                path = path.removeFirstSegments(1);
                path = new Path(projRoot.getPath()).append(path);
            } else {
                // A null projRoot means use the default location, which
                //  *does* include the project name in the output directory.
                path = root.getLocation().append(path);
            }

            //System.out.println("Adding source: " + path.toOSString());
            //addToClassPath(path.toOSString());
            addBuildDirectoryClassPath(path.toOSString());
            break;
        case IClasspathEntry.CPE_PROJECT:
            // In this case, just the project name is given.
            // We don't actually need to add anything to the classpath,
            //  since the project is open and we will get its classpath
            //  on another pass.
            break;
        default:
            // This should never happen.
            throw new RuntimeException("Unsupported classpath entry type.");
        }
    }
}

From source file:es.optsicom.res.client.util.ProjectDependenciesResolver.java

License:Eclipse Public License

private void calculateDependencies(IClasspathEntry[] cpe, IProject project)
        throws DependenciesResolverException {
    try {/*from  w w w  . j  a v a2s .co m*/

        IWorkspace workspace = project.getWorkspace();
        IPath workspacePath = workspace.getRoot().getLocation();
        String nombreWorkspace = workspacePath.toString();
        IJavaProject jp = JavaCore.create(project);

        if (!dependencies.contains(project.getLocation().toString())) {
            // Aadimos la carpeta bin
            classpathFiles.add(workspacePath.append(jp.getOutputLocation()).toFile());
            classpath.add(jp.getOutputLocation().toString());
        }

        for (IClasspathEntry cpEntry : cpe) {

            String path = cpEntry.getPath().toString();
            String dependency = nombreWorkspace.concat(path);

            if (!dependencies.contains(dependency)) {
                RESClientPlugin.log("Adding dependency: " + dependency);
                dependencies.add(dependency);

                if (cpEntry.getOutputLocation() != null) {
                    RESClientPlugin.log("Binarios: " + cpEntry.getOutputLocation().toString());
                    classpath.add(cpEntry.getOutputLocation().makeRelativeTo(workspacePath).toString());
                    classpathFiles.add(cpEntry.getOutputLocation().toFile());
                }

                int tipo = cpEntry.getEntryKind();

                //Si la dependencia es de una libreria(

                if (tipo == IClasspathEntry.CPE_LIBRARY) {

                    String dep = cpEntry.getPath().makeRelativeTo(workspacePath).toString();
                    //mgarcia: Optsicom res Evolution
                    if (new File(workspacePath.toFile(), cpEntry.getPath().toOSString()).exists()) {
                        classpathFiles.add(new File(workspacePath.toFile(), cpEntry.getPath().toOSString()));

                        //Aadimos las dependencias a las properties
                        RESClientPlugin.log("Adding library: " + dep);
                        classpath.add(cpEntry.getPath().toString());
                    } else {
                        throw new DependenciesResolverException();
                    }

                } else if (tipo == IClasspathEntry.CPE_PROJECT) {

                    //                  File[] files = new File(dependency).listFiles();
                    //                  for (File f : files){
                    //                     lista.add(f);
                    //                     String dep = f.getPath();
                    //                     RESClientPlugin.log("Adding dependency: " + dep);
                    //                     dependencies.add(dep);
                    //                  }

                    IProject p = workspace.getRoot().getProject(cpEntry.getPath().lastSegment());
                    IJavaProject projectDependency = JavaCore.create(p);
                    IClasspathEntry[] cp = projectDependency.getRawClasspath();

                    classpathFiles.add(workspacePath.append(projectDependency.getOutputLocation()).toFile());
                    classpath.add(projectDependency.getOutputLocation().toString());

                    RESClientPlugin.log("Populating files from: " + p.getName());
                    calculateDependencies(cp, p);

                } else if (tipo == IClasspathEntry.CPE_SOURCE) {

                    File f = new File(dependency);
                    classpathFiles.add(f);
                    RESClientPlugin.log("Adding source: " + dependency);

                } else if (tipo == IClasspathEntry.CPE_VARIABLE) {

                    IClasspathEntry[] clpe = new IClasspathEntry[1];
                    clpe[0] = JavaCore.getResolvedClasspathEntry(cpEntry);
                    if (clpe[0] != null) {
                        RESClientPlugin.log("Populating files from: " + clpe[0].getPath().toOSString());
                        calculateDependencies(clpe, project);
                    }

                } else if (tipo == IClasspathEntry.CPE_CONTAINER) {

                    if (cpEntry.getPath().toOSString().contains("JRE_CONTAINER")
                            || cpEntry.getPath().toOSString().contains("requiredPlugins")) {
                        continue;
                    }

                    IClasspathContainer cc = JavaCore.getClasspathContainer(cpEntry.getPath(), jp);
                    IClasspathEntry[] entradas = cc.getClasspathEntries();

                    RESClientPlugin.log("Populating files from: " + cc.getPath().toOSString());
                    calculateDependencies(entradas, project);

                }
            }
        }
    } catch (JavaModelException e) {
        RESClientPlugin.log(e);
    }

    for (String path : classpath) {
        RESClientPlugin.log("Classpath: " + path);
    }
    for (File file : classpathFiles) {
        RESClientPlugin.log("Classpath file: " + file.getAbsolutePath());
    }
}

From source file:fr.obeo.acceleo.tools.classloaders.AcceleoGenClassLoader.java

License:Open Source License

private static void computeURLs(IProject project, List URLs) {
    IFolder binFolder = Resources.getOutputFolder(project);
    if (binFolder != null) {
        String location = binFolder.getLocation().toString();
        if (location.startsWith("/")) { //$NON-NLS-1$
            location = '/' + location;
        }// www .j  ava 2  s  .co  m
        try {
            URLs.add(new URL("file:/" + location + '/')); //$NON-NLS-1$
        } catch (MalformedURLException e) {
            // continue
        }
    }
    IJavaProject javaProject = JavaCore.create(project);
    IClasspathEntry[] entries;
    try {
        entries = javaProject.getResolvedClasspath(true);
    } catch (JavaModelException e1) {
        entries = new IClasspathEntry[] {};
    }
    for (IClasspathEntry entry : entries) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
            IProject reference = ResourcesPlugin.getWorkspace().getRoot()
                    .getProject(entry.getPath().toString());
            if (reference.exists()) {
                AcceleoGenClassLoader.computeURLs(reference, URLs);
            }
        } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            try {
                IFile reference = ResourcesPlugin.getWorkspace().getRoot().getFile(entry.getPath());
                if (reference.exists()) {
                    URL url = (URL) AcceleoGenClassLoader.cacheURL.get(reference.getLocation().toFile());
                    if (url == null) {
                        url = reference.getLocation().toFile().toURL();
                        AcceleoGenClassLoader.cacheURL.put(reference.getLocation().toFile(), url);
                    }
                    URLs.add(url);
                } else {
                    URL url = (URL) AcceleoGenClassLoader.cacheURL.get(entry.getPath().toFile());
                    if (url == null) {
                        url = entry.getPath().toFile().toURL();
                        AcceleoGenClassLoader.cacheURL.put(entry.getPath().toFile(), url);
                    }
                    URLs.add(url);
                }
            } catch (MalformedURLException e) {
                // continue
            }
        } else {
            try {
                URL url = (URL) AcceleoGenClassLoader.cacheURL.get(entry.getPath().toFile());
                if (url == null) {
                    url = entry.getPath().toFile().toURL();
                    AcceleoGenClassLoader.cacheURL.put(entry.getPath().toFile(), url);
                }
                URLs.add(url);
            } catch (MalformedURLException e) {
                // continue
            }
        }
    }
}

From source file:in.software.analytics.parichayana.core.internal.builder.ParichayanaBuilder.java

License:Open Source License

private IProject[] getRequiredProjects(boolean includeBinaryPrerequisites) {
    JavaProject javaProject = (JavaProject) JavaCore.create(this.project);
    IWorkspaceRoot workspaceRoot = this.project.getWorkspace().getRoot();
    if (javaProject == null || workspaceRoot == null) {
        return ZERO_PROJECT;
    }//from  w w  w .  ja v a2 s  . c  o m

    List<IProject> projects = new ArrayList<IProject>();
    ExternalFoldersManager externalFoldersManager = JavaModelManager.getExternalManager();
    try {
        IClasspathEntry[] entries = javaProject.getExpandedClasspath();
        for (int i = 0, l = entries.length; i < l; i++) {
            IClasspathEntry entry = entries[i];
            IPath path = entry.getPath();
            IProject p = null;
            switch (entry.getEntryKind()) {
            case IClasspathEntry.CPE_PROJECT:
                p = workspaceRoot.getProject(path.lastSegment()); // missing projects are considered too
                if (((ClasspathEntry) entry).isOptional() && !JavaProject.hasJavaNature(p)) // except if entry is optional
                    p = null;
                break;
            case IClasspathEntry.CPE_LIBRARY:
                if (includeBinaryPrerequisites && path.segmentCount() > 0) {
                    // some binary resources on the class path can come from projects that are not included in the project references
                    IResource resource = workspaceRoot.findMember(path.segment(0));
                    if (resource instanceof IProject) {
                        p = (IProject) resource;
                    } else {
                        resource = externalFoldersManager.getFolder(path);
                        if (resource != null)
                            p = resource.getProject();
                    }
                }
            }
            if (p != null && !projects.contains(p))
                projects.add(p);
        }
    } catch (JavaModelException e) {
        return ZERO_PROJECT;
    }
    IProject[] result = new IProject[projects.size()];
    projects.toArray(result);
    return result;
}

From source file:io.sarl.eclipse.util.JavaClasspathParser.java

License:Apache License

/**
 * Decodes one XML element with the XML stream.
 *
 * @param element//from   w  w  w. j  a v a  2s  .c om
 *            - the considered element
 * @param projectName
 *            - the name of project containing the .classpath file
 * @param projectRootAbsoluteFullPath
 *            - he path to project containing the .classpath file
 * @param unknownElements
 *            - map of unknown elements
 * @return the set of CLasspath ENtries extracted from the considered element
 */
@SuppressWarnings({ "checkstyle:npathcomplexity", "checkstyle:cyclomaticcomplexity" })
public static IClasspathEntry elementDecode(Element element, String projectName,
        IPath projectRootAbsoluteFullPath, Map<IPath, UnknownXmlElements> unknownElements) {
    final IPath projectPath = projectRootAbsoluteFullPath;
    final NamedNodeMap attributes = element.getAttributes();
    final NodeList children = element.getChildNodes();
    final boolean[] foundChildren = new boolean[children.getLength()];
    final String kindAttr = removeAttribute(ClasspathEntry.TAG_KIND, attributes);
    final String pathAttr = removeAttribute(ClasspathEntry.TAG_PATH, attributes);

    // ensure path is absolute
    IPath path = new Path(pathAttr);
    final int kind = kindFromString(kindAttr);
    if (kind != IClasspathEntry.CPE_VARIABLE && kind != IClasspathEntry.CPE_CONTAINER && !path.isAbsolute()) {
        if (!(path.segmentCount() > 0 && path.segment(0).equals(ClasspathEntry.DOT_DOT))) {
            path = projectPath.append(path);
        }
    }
    // source attachment info (optional)
    IPath sourceAttachmentPath = element.hasAttribute(ClasspathEntry.TAG_SOURCEPATH)
            ? new Path(removeAttribute(ClasspathEntry.TAG_SOURCEPATH, attributes))
            : null;
    if (kind != IClasspathEntry.CPE_VARIABLE && sourceAttachmentPath != null
            && !sourceAttachmentPath.isAbsolute()) {
        sourceAttachmentPath = projectPath.append(sourceAttachmentPath);
    }
    final IPath sourceAttachmentRootPath = element.hasAttribute(ClasspathEntry.TAG_ROOTPATH)
            ? new Path(removeAttribute(ClasspathEntry.TAG_ROOTPATH, attributes))
            : null;

    // exported flag (optional)
    final boolean isExported = removeAttribute(ClasspathEntry.TAG_EXPORTED, attributes).equals("true"); //$NON-NLS-1$

    // inclusion patterns (optional)
    IPath[] inclusionPatterns = decodePatterns(attributes, ClasspathEntry.TAG_INCLUDING);
    if (inclusionPatterns == null) {
        inclusionPatterns = ClasspathEntry.INCLUDE_ALL;
    }

    // exclusion patterns (optional)
    IPath[] exclusionPatterns = decodePatterns(attributes, ClasspathEntry.TAG_EXCLUDING);
    if (exclusionPatterns == null) {
        exclusionPatterns = ClasspathEntry.EXCLUDE_NONE;
    }

    // access rules (optional)
    NodeList attributeList = getChildAttributes(ClasspathEntry.TAG_ACCESS_RULES, children, foundChildren);
    IAccessRule[] accessRules = decodeAccessRules(attributeList);

    // backward compatibility
    if (accessRules == null) {
        accessRules = getAccessRules(inclusionPatterns, exclusionPatterns);
    }

    // combine access rules (optional)
    final boolean combineAccessRestrictions = !removeAttribute(ClasspathEntry.TAG_COMBINE_ACCESS_RULES,
            attributes).equals("false"); //$NON-NLS-1$

    // extra attributes (optional)
    attributeList = getChildAttributes(ClasspathEntry.TAG_ATTRIBUTES, children, foundChildren);
    final IClasspathAttribute[] extraAttributes = decodeExtraAttributes(attributeList);

    // custom output location
    final IPath outputLocation = element.hasAttribute(ClasspathEntry.TAG_OUTPUT)
            ? projectPath.append(removeAttribute(ClasspathEntry.TAG_OUTPUT, attributes))
            : null;

    String[] unknownAttributes = null;
    ArrayList<String> unknownChildren = null;

    if (unknownElements != null) {
        // unknown attributes
        final int unknownAttributeLength = attributes.getLength();
        if (unknownAttributeLength != 0) {
            unknownAttributes = new String[unknownAttributeLength * 2];
            for (int i = 0; i < unknownAttributeLength; i++) {
                final Node attribute = attributes.item(i);
                unknownAttributes[i * 2] = attribute.getNodeName();
                unknownAttributes[i * 2 + 1] = attribute.getNodeValue();
            }
        }

        // unknown children
        for (int i = 0, length = foundChildren.length; i < length; i++) {
            if (!foundChildren[i]) {
                final Node node = children.item(i);
                if (node.getNodeType() != Node.ELEMENT_NODE) {
                    continue;
                }
                if (unknownChildren == null) {
                    unknownChildren = new ArrayList<>();
                }
                final StringBuffer buffer = new StringBuffer();
                decodeUnknownNode(node, buffer);
                unknownChildren.add(buffer.toString());
            }
        }
    }

    // recreate the CP entry
    IClasspathEntry entry = null;
    switch (kind) {

    case IClasspathEntry.CPE_PROJECT:
        /*
         * IPackageFragmentRoot.K_SOURCE, IClasspathEntry.CPE_PROJECT, path, ClasspathEntry.INCLUDE_ALL, // inclusion patterns
         * ClasspathEntry.EXCLUDE_NONE, // exclusion patterns null, // source attachment null, // source attachment root null, // specific output
         * folder
         */
        entry = new ClasspathEntry(IPackageFragmentRoot.K_SOURCE, IClasspathEntry.CPE_PROJECT, path,
                ClasspathEntry.INCLUDE_ALL, ClasspathEntry.EXCLUDE_NONE, null, null, null, isExported,
                accessRules, combineAccessRestrictions, extraAttributes);
        break;
    case IClasspathEntry.CPE_LIBRARY:
        entry = JavaCore.newLibraryEntry(path, sourceAttachmentPath, sourceAttachmentRootPath, accessRules,
                extraAttributes, isExported);
        break;
    case IClasspathEntry.CPE_SOURCE:
        // must be an entry in this project or specify another project
        final String projSegment = path.segment(0);
        if (projSegment != null && projSegment.equals(projectName)) {
            // this project
            entry = JavaCore.newSourceEntry(path, inclusionPatterns, exclusionPatterns, outputLocation,
                    extraAttributes);
        } else {
            if (path.segmentCount() == 1) {
                // another project
                entry = JavaCore.newProjectEntry(path, accessRules, combineAccessRestrictions, extraAttributes,
                        isExported);
            } else {
                // an invalid source folder
                entry = JavaCore.newSourceEntry(path, inclusionPatterns, exclusionPatterns, outputLocation,
                        extraAttributes);
            }
        }
        break;
    case IClasspathEntry.CPE_VARIABLE:
        entry = JavaCore.newVariableEntry(path, sourceAttachmentPath, sourceAttachmentRootPath, accessRules,
                extraAttributes, isExported);
        break;
    case IClasspathEntry.CPE_CONTAINER:
        entry = JavaCore.newContainerEntry(path, accessRules, extraAttributes, isExported);
        break;
    case ClasspathEntry.K_OUTPUT:
        if (!path.isAbsolute()) {
            return null;
        }
        /*
         * ClasspathEntry.EXCLUDE_NONE, null, // source attachment null, // source attachment root null, // custom output location false, null, //
         * no access rules false, // no accessible files to combine
         */
        entry = new ClasspathEntry(ClasspathEntry.K_OUTPUT, IClasspathEntry.CPE_LIBRARY, path,
                ClasspathEntry.INCLUDE_ALL, ClasspathEntry.EXCLUDE_NONE, null, null, null, false, null, false,
                ClasspathEntry.NO_EXTRA_ATTRIBUTES);
        break;
    default:
        throw new AssertionFailedException(Messages.bind(Messages.classpath_unknownKind, kindAttr));
    }

    if (unknownAttributes != null || unknownChildren != null) {
        final UnknownXmlElements unknownXmlElements = new UnknownXmlElements();
        unknownXmlElements.attributes = unknownAttributes;
        unknownXmlElements.children = unknownChildren;
        if (unknownElements != null) {
            unknownElements.put(path, unknownXmlElements);
        }
    }

    return entry;
}

From source file:io.sarl.eclipse.util.JavaClasspathParser.java

License:Apache License

/**
 * Returns the kind of a <code>PackageFragmentRoot</code> from its <code>String</code> form.
 *
 * @param kindStr//from ww  w.j  a va  2 s .co  m
 *            - string to test
 * @return the integer identifier of the type of the specified string: CPE_PROJECT, CPE_VARIABLE, CPE_CONTAINER, etc.
 */
@SuppressWarnings("checkstyle:equalsavoidnull")
private static int kindFromString(String kindStr) {

    if (kindStr.equalsIgnoreCase("prj")) { //$NON-NLS-1$
        return IClasspathEntry.CPE_PROJECT;
    }
    if (kindStr.equalsIgnoreCase("var")) { //$NON-NLS-1$
        return IClasspathEntry.CPE_VARIABLE;
    }
    if (kindStr.equalsIgnoreCase("con")) { //$NON-NLS-1$
        return IClasspathEntry.CPE_CONTAINER;
    }
    if (kindStr.equalsIgnoreCase("src")) { //$NON-NLS-1$
        return IClasspathEntry.CPE_SOURCE;
    }
    if (kindStr.equalsIgnoreCase("lib")) { //$NON-NLS-1$
        return IClasspathEntry.CPE_LIBRARY;
    }
    if (kindStr.equalsIgnoreCase("output")) { //$NON-NLS-1$
        return ClasspathEntry.K_OUTPUT;
    }
    return -1;
}

From source file:jasima_gui.EclipseProjectClassLoader.java

License:Open Source License

protected Resource findResource(final String name, IJavaProject proj, boolean onlyExported)
        throws CoreException {
    IClasspathEntry[] classpath = proj.getResolvedClasspath(true);

    byte[] content;

    content = readResource(proj.getOutputLocation().makeRelative(), name);
    if (content != null) {
        return new Resource(proj.getOutputLocation().makeRelative(), content);
    }/*  www  . ja va2s . com*/

    for (IClasspathEntry entry : classpath) {
        if (onlyExported && !entry.isExported())
            continue;

        if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            content = readResource(entry.getPath(), name);
            if (content != null) {
                return new Resource(entry.getPath(), content);
            }
        } else if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
            IProject projEntry = (IProject) ResourcesPlugin.getWorkspace().getRoot()
                    .findMember(entry.getPath());
            Resource result = findResource(name, JavaCore.create(projEntry), true);
            if (result != null) {
                return result;
            }
        }
    }
    return null;
}

From source file:me.gladwell.eclipse.m2e.android.configuration.ObjectSerializationClasspathPersister.java

License:Open Source License

public void save(String project, List<IClasspathEntry> classpath) {
    ObjectOutputStream os = null;
    try {//from  www . ja v a  2s.  c om
        File file = new File(stateLocation, project);
        os = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(file))) {
            {
                enableReplaceObject(true);
            }

            protected Object replaceObject(Object o) throws IOException {
                if (o instanceof IClasspathEntry) {
                    IClasspathEntry e = (IClasspathEntry) o;
                    if (e.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                        return new ProjectEntryReplace(e);
                    } else if (e.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                        return new LibraryEntryReplace(e);
                    }
                } else if (o instanceof IClasspathAttribute) {
                    return new ClasspathAttributeReplace((IClasspathAttribute) o);
                } else if (o instanceof IAccessRule) {
                    return new AccessRuleReplace((IAccessRule) o);
                } else if (o instanceof IPath) {
                    return new PathReplace((IPath) o);
                }
                return super.replaceObject(o);
            }
        };
        os.writeObject(classpath);
        os.flush();
    } catch (IOException e) {
        throw new ProjectConfigurationException(e);
    } finally {
        if (os != null) {
            try {
                os.close();
            } catch (IOException e) {
                throw new ProjectConfigurationException(e);
            }
        }
    }
}

From source file:net.kbserve.pyjdt.properties.models.CPEAbstractContainer.java

License:Open Source License

/**
 * Update the list of children to include the ICPEType contains the giveb IClasspathEntry
 * /*from   w ww.j a v  a  2 s .c o m*/
 * @param child
 *            the child
 * @param project
 *            the project
 * @return the iCPE type
 */
public synchronized ICPEType updateChild(IClasspathEntry child, IProject project) {

    String stringPath = makeStringPath(child.getPath());
    ICPEType icp = getChild(stringPath);
    if (icp == null) {
        switch (child.getEntryKind()) {
        case (IClasspathEntry.CPE_CONTAINER):
            icp = new CPEContainer();
            break;
        case (IClasspathEntry.CPE_LIBRARY):
            icp = new CPELibrary();
            break;
        case (IClasspathEntry.CPE_PROJECT):
            icp = new CPEProject();
            break;
        case (IClasspathEntry.CPE_SOURCE):
            icp = new CPESource();
            break;
        case (IClasspathEntry.CPE_VARIABLE):
            icp = new CPEVariable();
            break;
        default:
            throw new UnsupportedOperationException(
                    "Unsupported IClasspathEntry.getEntryKind() = '" + child.getEntryKind() + "' on " + child);
        }
        children.add(icp);
        icp.setPath(stringPath);
        icp.setParent(this.getPath());
    }

    return icp;
}

From source file:net.rim.ejde.internal.core.BasicClasspathElementChangedListener.java

License:Open Source License

static public boolean hasProjectDependencyProblem(IJavaProject javaProject) {
    IProject project = javaProject.getProject();
    try {/*from   www .j  a  v  a  2  s.  c  o m*/
        ResourceBuilderUtils.cleanProblemMarkers(project,
                new String[] { IRIMMarker.PROJECT_DEPENDENCY_PROBLEM_MARKER }, IResource.DEPTH_ONE);
    } catch (CoreException e) {
        _log.error(e);
    }
    IClasspathEntry[] classpathEntries = null;
    try {
        classpathEntries = javaProject.getRawClasspath();
    } catch (JavaModelException e) {
        _log.error(e);
        return true;
    }
    IProject dependentProject = null;
    String projectName = null;
    boolean hasDependencyError = false;
    for (IClasspathEntry entry : classpathEntries) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
            projectName = entry.getPath().lastSegment();
            dependentProject = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
            if (!isValidDependency(javaProject.getProject(), dependentProject) && !hasDependencyError) {
                hasDependencyError = true;
            }
        }
    }
    return hasDependencyError;
}