Example usage for org.eclipse.jdt.internal.core PackageFragmentRoot internalKind

List of usage examples for org.eclipse.jdt.internal.core PackageFragmentRoot internalKind

Introduction

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

Prototype

int internalKind() throws JavaModelException 

Source Link

Usage

From source file:com.codenvy.ide.ext.java.server.internal.core.NameLookup.java

License:Open Source License

/**
 * Notifies the given requestor of all types (classes and interfaces) in the
 * given package fragment with the given (unqualified) name.
 * Checks the requestor at regular intervals to see if the requestor
 * has canceled. If the given package fragment is <code>null</code>, all types in the
 * project whose simple name matches the given name are found.
 *
 * @param name//from w  w w  .  jav a  2  s  .c  o  m
 *         The name to search
 * @param pkg
 *         The corresponding package fragment
 * @param partialMatch
 *         partial name matches qualify when <code>true</code>;
 *         only exact name matches qualify when <code>false</code>
 * @param acceptFlags
 *         a bit mask describing if classes, interfaces or both classes and interfaces
 *         are desired results. If no flags are specified, all types are returned.
 * @param requestor
 *         The requestor that collects the result
 * @see #ACCEPT_CLASSES
 * @see #ACCEPT_INTERFACES
 * @see #ACCEPT_ENUMS
 * @see #ACCEPT_ANNOTATIONS
 */
public void seekTypes(String name, IPackageFragment pkg, boolean partialMatch, int acceptFlags,
        IJavaElementRequestor requestor, boolean considerSecondaryTypes) {
    /*      if (VERBOSE) {
             Util.verbose(" SEEKING TYPES");  //$NON-NLS-1$
             Util.verbose(" -> name: " + name);  //$NON-NLS-1$
             Util.verbose(" -> pkg: " + ((JavaElement) pkg).toStringWithAncestors());  //$NON-NLS-1$
             Util.verbose(" -> partial match:" + partialMatch);  //$NON-NLS-1$
          }
    */
    String matchName = partialMatch ? name.toLowerCase() : name;
    if (pkg == null) {
        findAllTypes(matchName, partialMatch, acceptFlags, requestor);
        return;
    }
    PackageFragmentRoot root = (PackageFragmentRoot) pkg.getParent();
    try {

        // look in working copies first
        int firstDot = -1;
        String topLevelTypeName = null;
        int packageFlavor = root.internalKind();
        if (this.typesInWorkingCopies != null || packageFlavor == IPackageFragmentRoot.K_SOURCE) {
            firstDot = matchName.indexOf('.');
            if (!partialMatch)
                topLevelTypeName = firstDot == -1 ? matchName : matchName.substring(0, firstDot);
        }
        if (this.typesInWorkingCopies != null) {
            if (seekTypesInWorkingCopies(matchName, pkg, firstDot, partialMatch, topLevelTypeName, acceptFlags,
                    requestor, considerSecondaryTypes))
                return;
        }

        // look in model
        switch (packageFlavor) {
        case IPackageFragmentRoot.K_BINARY:
            matchName = matchName.replace('.', '$');
            seekTypesInBinaryPackage(matchName, pkg, partialMatch, acceptFlags, requestor);
            break;
        case IPackageFragmentRoot.K_SOURCE:
            seekTypesInSourcePackage(matchName, pkg, firstDot, partialMatch, topLevelTypeName, acceptFlags,
                    requestor);
            if (matchName.indexOf('$') != -1) {
                matchName = matchName.replace('$', '.');
                firstDot = matchName.indexOf('.');
                if (!partialMatch)
                    topLevelTypeName = firstDot == -1 ? matchName : matchName.substring(0, firstDot);
                seekTypesInSourcePackage(matchName, pkg, firstDot, partialMatch, topLevelTypeName, acceptFlags,
                        requestor);
            }
            break;
        default:
            return;
        }
    } catch (JavaModelException e) {
        return;
    }
}