Example usage for org.eclipse.jdt.core IJavaProject findPackageFragmentRoots

List of usage examples for org.eclipse.jdt.core IJavaProject findPackageFragmentRoots

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IJavaProject findPackageFragmentRoots.

Prototype

IPackageFragmentRoot[] findPackageFragmentRoots(IClasspathEntry entry);

Source Link

Document

Returns the existing package fragment roots identified by the given entry.

Usage

From source file:org.springsource.ide.eclipse.commons.frameworks.core.internal.java.FrameworksJavaUtils.java

License:Open Source License

/**
 * Obtain the package fragment roots of the first encountered source class
 * path entry in the given java project. Return null if the java project is
 * null, or no source class path entries can be found.
 * /*from  w  w  w .ja  v a  2s.c o  m*/
 * @param javaProject
 *            containing source class path entries
 * @return package fragment roots of first encountered source class path
 *         entry, or null otherwise
 */
public static IPackageFragmentRoot[] getFirstEncounteredSourcePackageFragmentRoots(IJavaProject javaProject) {
    if (javaProject == null) {
        return null;
    }

    try {

        IClasspathEntry[] entries = javaProject.getRawClasspath();

        for (IClasspathEntry entry : entries) {

            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                return javaProject.findPackageFragmentRoots(entry);
            }
        }

    } catch (JavaModelException e) {
        FrameworkCoreActivator.logError(e.getLocalizedMessage(), e);
    }
    return null;

}