org.eclipse.jdt.internal.core
Class NameLookup

java.lang.Object
  extended by org.eclipse.jdt.internal.core.NameLookup
All Implemented Interfaces:
SuffixConstants

public class NameLookup
extends java.lang.Object
implements SuffixConstants

A NameLookup provides name resolution within a Java project. The name lookup facility uses the project's classpath to prioritize the order in which package fragments are searched when resolving a name.

Name lookup only returns a handle when the named element actually exists in the model; otherwise null is returned.

There are two logical sets of methods within this interface. Methods which start with find* are intended to be convenience methods for quickly finding an element within another element; for instance, for finding a class within a package. The other set of methods all begin with seek*. These methods do comprehensive searches of the IJavaProject returning hits in real time through an IJavaElementRequestor.


Nested Class Summary
static class NameLookup.Answer
           
 
Field Summary
static int ACCEPT_ALL
           
static int ACCEPT_ANNOTATIONS
          Accept flag for specifying annotations.
static int ACCEPT_CLASSES
          Accept flag for specifying classes.
static int ACCEPT_ENUMS
          Accept flag for specifying enums.
static int ACCEPT_INTERFACES
          Accept flag for specifying interfaces.
 long timeSpentInSeekTypesInBinaryPackage
           
 long timeSpentInSeekTypesInSourcePackage
           
static boolean VERBOSE
           
 
Fields inherited from interface org.eclipse.jdt.internal.compiler.util.SuffixConstants
EXTENSION_class, EXTENSION_CLASS, EXTENSION_java, EXTENSION_JAVA, SUFFIX_class, SUFFIX_CLASS, SUFFIX_java, SUFFIX_JAVA, SUFFIX_STRING_class, SUFFIX_STRING_CLASS, SUFFIX_STRING_java, SUFFIX_STRING_JAVA
 
Constructor Summary
NameLookup(IPackageFragmentRoot[] packageFragmentRoots, HashtableOfArrayToObject packageFragments, ICompilationUnit[] workingCopies, java.util.Map rootToResolvedEntries)
           
 
Method Summary
 ICompilationUnit findCompilationUnit(java.lang.String qualifiedTypeName)
          Returns the ICompilationUnit which defines the type named qualifiedTypeName, or null if none exists.
 IPackageFragment findPackageFragment(org.eclipse.core.runtime.IPath path)
          Returns the package fragment whose path matches the given (absolute) path, or null if none exist.
 IPackageFragment[] findPackageFragments(java.lang.String name, boolean partialMatch)
          Returns the package fragments whose name matches the given (qualified) name, or null if none exist.
 IPackageFragment[] findPackageFragments(java.lang.String name, boolean partialMatch, boolean patternMatch)
          Returns the package fragments whose name matches the given (qualified) name or pattern, or null if none exist.
 IType findType(java.lang.String name, boolean partialMatch, int acceptFlags)
          Returns the type specified by the qualified name, or null if none exist.
 NameLookup.Answer findType(java.lang.String name, boolean partialMatch, int acceptFlags, boolean checkRestrictions)
           
 NameLookup.Answer findType(java.lang.String name, boolean partialMatch, int acceptFlags, boolean considerSecondaryTypes, boolean waitForIndexes, boolean checkRestrictions, org.eclipse.core.runtime.IProgressMonitor monitor)
           
 IType findType(java.lang.String name, IPackageFragment pkg, boolean partialMatch, int acceptFlags)
          Returns the first type in the given package whose name matches the given (unqualified) name, or null if none exist.
 IType findType(java.lang.String name, IPackageFragment pkg, boolean partialMatch, int acceptFlags, boolean considerSecondaryTypes)
          Returns the first type in the given package whose name matches the given (unqualified) name, or null if none exist.
 NameLookup.Answer findType(java.lang.String typeName, java.lang.String packageName, boolean partialMatch, int acceptFlags, boolean checkRestrictions)
          Find type considering secondary types but without waiting for indexes.
 NameLookup.Answer findType(java.lang.String typeName, java.lang.String packageName, boolean partialMatch, int acceptFlags, boolean considerSecondaryTypes, boolean waitForIndexes, boolean checkRestrictions, org.eclipse.core.runtime.IProgressMonitor monitor)
          Find type.
 boolean isPackage(java.lang.String[] pkgName)
           
 void seekPackageFragments(java.lang.String name, boolean partialMatch, IJavaElementRequestor requestor)
          Notifies the given requestor of all package fragments with the given name.
 void seekTypes(java.lang.String name, IPackageFragment pkg, boolean partialMatch, int acceptFlags, IJavaElementRequestor requestor)
          Notifies the given requestor of all types (classes and interfaces) in the given package fragment with the given (unqualified) name.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ACCEPT_CLASSES

public static final int ACCEPT_CLASSES
Accept flag for specifying classes.

See Also:
Constant Field Values

ACCEPT_INTERFACES

public static final int ACCEPT_INTERFACES
Accept flag for specifying interfaces.

See Also:
Constant Field Values

ACCEPT_ENUMS

public static final int ACCEPT_ENUMS
Accept flag for specifying enums.

See Also:
Constant Field Values

ACCEPT_ANNOTATIONS

public static final int ACCEPT_ANNOTATIONS
Accept flag for specifying annotations.

See Also:
Constant Field Values

ACCEPT_ALL

public static final int ACCEPT_ALL
See Also:
Constant Field Values

VERBOSE

public static boolean VERBOSE

timeSpentInSeekTypesInSourcePackage

public long timeSpentInSeekTypesInSourcePackage

timeSpentInSeekTypesInBinaryPackage

public long timeSpentInSeekTypesInBinaryPackage
Constructor Detail

NameLookup

public NameLookup(IPackageFragmentRoot[] packageFragmentRoots,
                  HashtableOfArrayToObject packageFragments,
                  ICompilationUnit[] workingCopies,
                  java.util.Map rootToResolvedEntries)
Method Detail

findCompilationUnit

public ICompilationUnit findCompilationUnit(java.lang.String qualifiedTypeName)
Returns the ICompilationUnit which defines the type named qualifiedTypeName, or null if none exists. The domain of the search is bounded by the classpath of the IJavaProject this NameLookup was obtained from.

The name must be fully qualified (eg "java.lang.Object", "java.util.Hashtable$Entry")


findPackageFragment

public IPackageFragment findPackageFragment(org.eclipse.core.runtime.IPath path)
Returns the package fragment whose path matches the given (absolute) path, or null if none exist. The domain of the search is bounded by the classpath of the IJavaProject this NameLookup was obtained from. The path can be: - internal to the workbench: "/Project/src" - external to the workbench: "c:/jdk/classes.zip/java/lang"


findPackageFragments

public IPackageFragment[] findPackageFragments(java.lang.String name,
                                               boolean partialMatch)
Returns the package fragments whose name matches the given (qualified) name, or null if none exist. The name can be:

Parameters:
partialMatch - partial name matches qualify when true, only exact name matches qualify when false

findPackageFragments

public IPackageFragment[] findPackageFragments(java.lang.String name,
                                               boolean partialMatch,
                                               boolean patternMatch)
Returns the package fragments whose name matches the given (qualified) name or pattern, or null if none exist. The name can be:

Parameters:
partialMatch - partial name matches qualify when true,
patternMatch - true when the given name might be a pattern, false otherwise.

findType

public NameLookup.Answer findType(java.lang.String typeName,
                                  java.lang.String packageName,
                                  boolean partialMatch,
                                  int acceptFlags,
                                  boolean checkRestrictions)
Find type considering secondary types but without waiting for indexes. It means that secondary types may be not found under certain circumstances...

See Also:
"https://bugs.eclipse.org/bugs/show_bug.cgi?id=118789"

findType

public NameLookup.Answer findType(java.lang.String typeName,
                                  java.lang.String packageName,
                                  boolean partialMatch,
                                  int acceptFlags,
                                  boolean considerSecondaryTypes,
                                  boolean waitForIndexes,
                                  boolean checkRestrictions,
                                  org.eclipse.core.runtime.IProgressMonitor monitor)
Find type. Considering secondary types and waiting for indexes depends on given corresponding parameters.


findType

public IType findType(java.lang.String name,
                      IPackageFragment pkg,
                      boolean partialMatch,
                      int acceptFlags,
                      boolean considerSecondaryTypes)
Returns the first type in the given package whose name matches the given (unqualified) name, or null if none exist. Specifying a null package will result in no matches. The domain of the search is bounded by the Java project from which this name lookup was obtained.

Parameters:
name - the name of the type to find
pkg - the package to search
partialMatch - partial name matches qualify when true, only exact name matches qualify when false
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.
considerSecondaryTypes - flag to know whether secondary types has to be considered during the search
See Also:
ACCEPT_CLASSES, ACCEPT_INTERFACES, ACCEPT_ENUMS, ACCEPT_ANNOTATIONS

findType

public IType findType(java.lang.String name,
                      IPackageFragment pkg,
                      boolean partialMatch,
                      int acceptFlags)
Returns the first type in the given package whose name matches the given (unqualified) name, or null if none exist. Specifying a null package will result in no matches. The domain of the search is bounded by the Java project from which this name lookup was obtained.
Note that this method does not find secondary types.

Parameters:
name - the name of the type to find
pkg - the package to search
partialMatch - partial name matches qualify when true, only exact name matches qualify when false
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.
See Also:
ACCEPT_CLASSES, ACCEPT_INTERFACES, ACCEPT_ENUMS, ACCEPT_ANNOTATIONS

findType

public IType findType(java.lang.String name,
                      boolean partialMatch,
                      int acceptFlags)
Returns the type specified by the qualified name, or null if none exist. The domain of the search is bounded by the Java project from which this name lookup was obtained.

Parameters:
name - the name of the type to find
partialMatch - partial name matches qualify when true, only exact name matches qualify when false
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.
See Also:
ACCEPT_CLASSES, ACCEPT_INTERFACES, ACCEPT_ENUMS, ACCEPT_ANNOTATIONS

findType

public NameLookup.Answer findType(java.lang.String name,
                                  boolean partialMatch,
                                  int acceptFlags,
                                  boolean checkRestrictions)

findType

public NameLookup.Answer findType(java.lang.String name,
                                  boolean partialMatch,
                                  int acceptFlags,
                                  boolean considerSecondaryTypes,
                                  boolean waitForIndexes,
                                  boolean checkRestrictions,
                                  org.eclipse.core.runtime.IProgressMonitor monitor)

isPackage

public boolean isPackage(java.lang.String[] pkgName)

seekPackageFragments

public void seekPackageFragments(java.lang.String name,
                                 boolean partialMatch,
                                 IJavaElementRequestor requestor)
Notifies the given requestor of all package fragments with the given name. Checks the requestor at regular intervals to see if the requestor has canceled. The domain of the search is bounded by the IJavaProject this NameLookup was obtained from.

Parameters:
partialMatch - partial name matches qualify when true; only exact name matches qualify when false

seekTypes

public void seekTypes(java.lang.String name,
                      IPackageFragment pkg,
                      boolean partialMatch,
                      int acceptFlags,
                      IJavaElementRequestor requestor)
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 null, all types in the project whose simple name matches the given name are found.

Parameters:
name - The name to search
pkg - The corresponding package fragment
partialMatch - partial name matches qualify when true; only exact name matches qualify when false
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.
requestor - The requestor that collects the result
See Also:
ACCEPT_CLASSES, ACCEPT_INTERFACES, ACCEPT_ENUMS, ACCEPT_ANNOTATIONS