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

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

Introduction

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

Prototype

int CPE_LIBRARY

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

Click Source Link

Document

Entry kind constant describing a classpath entry identifying a library.

Usage

From source file:x10dt.ui.launch.core.utils.ProjectUtils.java

License:Open Source License

private static <T> void collectCpEntries(final Set<T> container, final IClasspathEntry cpEntry,
        final IWorkspaceRoot root, final IFilter<IPath> libFilter, final IFunctor<IPath, T> functor,
        final IProject project, StringBuffer pathBuffer) throws JavaModelException {
    final IJavaProject javaProject = JavaCore.create(project);
    switch (cpEntry.getEntryKind()) {
    case IClasspathEntry.CPE_SOURCE:
        if (isX10Project(javaProject)) {
            IPath outputPath = getOutputLocation(cpEntry, javaProject);
            if (outputPath.lastSegment().equals("bin-java")) {
                appendNew(functor, container, pathBuffer, makeAbsolutePath(root, outputPath));

            } else {
                appendNew(functor, container, pathBuffer, makeAbsolutePath(root, cpEntry.getPath()));
            }/* w w w.ja  v  a  2 s  .co m*/
        } else {
            appendNew(functor, container, pathBuffer,
                    makeAbsolutePath(root, getOutputLocation(cpEntry, javaProject)));
        }
        break;

    case IClasspathEntry.CPE_LIBRARY:
        IPath path = cpEntry.getPath();
        if (libFilter.accepts(path)) {
            IPath absolutePath = makeAbsolutePath(root, path);
            appendNew(functor, container, pathBuffer, absolutePath);
        }
        break;

    case IClasspathEntry.CPE_PROJECT:
        final IResource resource = root.findMember(cpEntry.getPath());
        if (resource == null) {
            LaunchCore.log(IStatus.WARNING, NLS.bind(Messages.JPU_ResourceErrorMsg, cpEntry.getPath()));
        } else {
            final IJavaProject refProject = JavaCore.create((IProject) resource);
            for (final IClasspathEntry newCPEntry : refProject.getResolvedClasspath(true)) {
                collectCpEntries(container, newCPEntry, root, libFilter, functor, (IProject) resource,
                        pathBuffer);
            }
        }
        break;

    default:
        throw new IllegalArgumentException(
                NLS.bind(Messages.JPU_UnexpectedEntryKindMsg, cpEntry.getEntryKind()));
    }
}

From source file:x10dt.ui.parser.CompilerDelegate.java

License:Open Source License

/**
 * @return a list of all project-relative CPE_SOURCE-type classpath entries.
 * @throws JavaModelException/*  www  .ja v  a2  s.  c o  m*/
 */
private List<IPath> getProjectSrcPath() throws CoreException {
    List<IPath> srcPath = new ArrayList<IPath>();

    // Produce a search path heuristically for files living outside the workspace,
    // and for workspace files living in non-X10-natured projects.
    if (fX10Project == null || !isX10Project()) {
        IPath pkgRootPath = determinePkgRootPath();

        if (pkgRootPath != null) {
            if (fX10Project != null && fX10Project.getProject().getName().equals("x10.runtime")) {
                // If the containing project happens to be x10.runtime,
                // don't add the runtime bound into the X10DT to the search path
                return Arrays.asList(pkgRootPath);
            } else {
                return Arrays.asList(pkgRootPath, new Path(getRuntimePath()));
            }
        } else {
            return Arrays.asList((IPath) new Path(getRuntimePath()));
        }
    }

    IClasspathEntry[] classPath = fX10Project.getResolvedClasspath(true);

    for (int i = 0; i < classPath.length; i++) {
        IClasspathEntry e = classPath[i];

        if (e.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            srcPath.add(e.getPath());
        } else if (e.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
            //PORT1.7 Compiler needs to see X10 source for all referenced compilation units,
            // so add source path entries of referenced projects to this project's sourcepath.
            // Assume that goal dependencies are such that Polyglot will not be compelled to
            // compile referenced X10 source down to Java source (causing duplication; see below).
            //
            // RMF 6/4/2008 - Don't add referenced projects to the source path:
            // 1) doing so should be unnecessary, since the classpath will include
            //    the project, and the class files should satisfy all references,
            // 2) doing so will cause Polyglot to compile the source files found in
            //    the other project to Java source files located in the *referencing*
            //    project, causing duplication, which is not what we want.
            //
            IProject refProject = ResourcesPlugin.getWorkspace().getRoot()
                    .getProject(e.getPath().toPortableString());
            IJavaProject refJavaProject = JavaCore.create(refProject);
            IClasspathEntry[] refJavaCPEntries = refJavaProject.getResolvedClasspath(true);
            for (int j = 0; j < refJavaCPEntries.length; j++) {
                if (refJavaCPEntries[j].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                    srcPath.add(refJavaCPEntries[j].getPath());
                }
            }
        } else if (e.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            // PORT1.7 Add the X10 runtime jar to the source path, since the compiler
            // needs to see the X10 source for the user-visible runtime classes (like
            // x10.lang.Region) to get the extra type information (for deptypes) that
            // can't be stored in Java class files, and for now, these source files
            // actually live in the X10 runtime jar.
            IPath path = e.getPath();
            if (path.toPortableString().contains(X10BundleUtils.X10_RUNTIME_BUNDLE_ID)) {
                srcPath.add(path);
            }
        }
    }
    if (srcPath.size() == 0)
        srcPath.add(fX10Project.getProject().getLocation());
    return srcPath;
}

From source file:x10dt.ui.parser.CompilerDelegate.java

License:Open Source License

/**
 * Build a class path string for a project
 * @param project The root project to start with
 * @param buff Accumulates the classpath into this buffer
 * @throws JavaModelException//  ww  w .  jav  a  2  s.c  o  m
 */
private static void buildClassPathSpec(final IWorkspaceRoot root, IJavaProject rootProject,
        IJavaProject project, Set<IPath> container) throws JavaModelException {
    if (project == null) {
        return;
    }

    IClasspathEntry[] classPath = project.getResolvedClasspath(true);
    for (IClasspathEntry cpEntry : classPath) {
        switch (cpEntry.getEntryKind()) {
        case IClasspathEntry.CPE_SOURCE:
            if (isX10Project(project)) {
                IPath outputPath = getOutputLocation(cpEntry, project);
                if (outputPath.lastSegment().equals("bin-java")) {
                    container.add(makeAbsolutePath(root, outputPath));
                } else {
                    container.add(makeAbsolutePath(root, cpEntry.getPath()));
                }
            } else {
                container.add(makeAbsolutePath(root, getOutputLocation(cpEntry, project)));
            }
            break;

        case IClasspathEntry.CPE_LIBRARY:
            IPath path = makeAbsolutePath(root, cpEntry.getPath());
            container.add(path);
            break;

        case IClasspathEntry.CPE_PROJECT:
            final IResource resource = root.findMember(cpEntry.getPath());
            if (resource == null) {
                X10DTCorePlugin.getInstance().writeErrorMsg("Error resolving class path: " + cpEntry.getPath());
            } else {
                final IJavaProject refProject = JavaCore.create((IProject) resource);
                for (final IClasspathEntry newCPEntry : refProject.getResolvedClasspath(true)) {
                    buildClassPathSpec(root, rootProject, refProject, container);
                }
            }
            break;

        default:
            X10DTCorePlugin.getInstance()
                    .writeErrorMsg("Error resolving class path kind: " + cpEntry.getEntryKind());
        }
    }
}

From source file:x10dt.ui.parser.PolyglotNodeLocator.java

License:Open Source License

private IClassFile resolveClassFile(final String path) throws JavaModelException {
    IJavaProject javaProject = JavaCore.create(fSrcProject.getRawProject());
    IClasspathEntry[] cpEntries = javaProject.getResolvedClasspath(true);

    for (int i = 0; i < cpEntries.length; i++) {
        IClasspathEntry entry = cpEntries[i];

        if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            IPath entryPath = entry.getPath();
            IPackageFragmentRoot pkgRoot = javaProject.findPackageFragmentRoot(entryPath);
            final int pkgEnd = path.lastIndexOf('/');
            String pkgName = path.substring(0, pkgEnd).replace('/', '.');
            IPackageFragment pkgFrag = pkgRoot.getPackageFragment(pkgName);

            return pkgFrag.getClassFile(path.substring(pkgEnd + 1));
        }/*  w w  w.java  2  s.c  o  m*/
    }
    return null;
}