Example usage for org.eclipse.jdt.internal.core NameLookup findPackageFragments

List of usage examples for org.eclipse.jdt.internal.core NameLookup findPackageFragments

Introduction

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

Prototype

public IPackageFragment[] findPackageFragments(String name, boolean partialMatch) 

Source Link

Document

Returns the package fragments whose name matches the given (qualified) name, or null if none exist.

Usage

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

License:Open Source License

public IJavaElement findPackageFragment(String packageName) throws JavaModelException {
    NameLookup lookup = newNameLookup((WorkingCopyOwner) null/*no need to look at working copies for pkgs*/);
    IPackageFragment[] pkgFragments = lookup.findPackageFragments(packageName, false);
    if (pkgFragments == null) {
        return null;

    } else {//from w  w  w .  j  a va 2s.  c o  m
        // try to return one that is a child of this project
        for (int i = 0, length = pkgFragments.length; i < length; i++) {

            IPackageFragment pkgFragment = pkgFragments[i];
            if (equals(pkgFragment.getParent().getParent())) {
                return pkgFragment;
            }
        }
        // default to the first one
        return pkgFragments[0];
    }
}