public class NameLookup extends java.lang.Object implements SuffixConstants
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.
| Modifier and Type | Class and Description |
|---|---|
static class |
NameLookup.Answer |
| Modifier and Type | Field and Description |
|---|---|
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.
|
static int |
ACCEPT_RECORDS
Accept flag for specifying records.
|
protected IPackageFragmentRoot[] |
packageFragmentRoots
The
IPackageFragmentRoot's associated
with the classpath of this NameLookup facility's
project. |
protected HashtableOfArrayToObject |
packageFragments
Table that maps package names to lists of package fragment roots
that contain such a package known by this name lookup facility.
|
protected java.util.Map<IPackageFragmentRoot,IModuleDescription> |
rootToModule |
protected java.util.Map<IPackageFragmentRoot,IClasspathEntry> |
rootToResolvedEntries
Reverse map from root path to corresponding resolved CP entry
(so as to be able to figure inclusion/exclusion rules)
|
long |
timeSpentInSeekTypesInBinaryPackage |
long |
timeSpentInSeekTypesInSourcePackage |
protected java.util.HashMap |
typesInWorkingCopies
A map from package handles to a map from type name to an IType or an IType[].
|
static boolean |
VERBOSE |
EXTENSION_aj, EXTENSION_AJ, EXTENSION_class, EXTENSION_CLASS, EXTENSION_java, EXTENSION_JAVA, EXTENSION_jmod, EXTENSION_JMOD, SUFFIX_aj, SUFFIX_AJ, SUFFIX_class, SUFFIX_CLASS, SUFFIX_java, SUFFIX_JAVA, SUFFIX_STRING_aj, SUFFIX_STRING_AJ, SUFFIX_STRING_class, SUFFIX_STRING_CLASS, SUFFIX_STRING_java, SUFFIX_STRING_JAVA| Constructor and Description |
|---|
NameLookup(JavaProject rootProject,
IPackageFragmentRoot[] packageFragmentRoots,
HashtableOfArrayToObject packageFragments,
ICompilationUnit[] workingCopies,
java.util.Map rootToResolvedEntries) |
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
acceptType(IType type,
int acceptFlags,
boolean isSourceType)
Returns true if:
the given type is an existing class and the flag's
ACCEPT_CLASSES
bit is on
the given type is an existing interface and the ACCEPT_INTERFACES
bit is on
neither the ACCEPT_CLASSES or ACCEPT_INTERFACES
bit is on
Otherwise, false is returned. |
ICompilationUnit |
findCompilationUnit(java.lang.String qualifiedTypeName)
Returns the
ICompilationUnit which defines the type
named qualifiedTypeName, or null if
none exists. |
NameLookup.Answer |
findModule(char[] moduleName) |
IPackageFragment |
findPackageFragment(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,
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 waitForIndices,
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,
IProgressMonitor monitor)
Find type.
|
NameLookup.Answer |
findType(java.lang.String typeName,
java.lang.String packageName,
boolean partialMatch,
int acceptFlags,
boolean considerSecondaryTypes,
boolean waitForIndexes,
boolean checkRestrictions,
IProgressMonitor monitor,
IPackageFragmentRoot[] moduleContext)
Find type.
|
NameLookup.Answer |
findType(java.lang.String typeName,
java.lang.String packageName,
boolean partialMatch,
int acceptFlags,
boolean checkRestrictions,
IPackageFragmentRoot[] moduleContext)
Find type in the given modules considering secondary types but without waiting for indexes.
|
static IModule |
getModuleDescriptionInfo(IModuleDescription moduleDesc) |
IModule |
getModuleDescriptionInfo(PackageFragmentRoot root) |
boolean |
hasCompilationUnit(char[][] pkgName,
IPackageFragmentRoot[] moduleContext) |
boolean |
isPackage(java.lang.String[] pkgName) |
boolean |
isPackage(java.lang.String[] pkgName,
IPackageFragmentRoot[] moduleContext) |
protected boolean |
nameMatches(java.lang.String searchName,
ICompilationUnit cu,
boolean partialMatch)
Returns true if the given cu's name matches the
specified
searchName, otherwise false. |
protected boolean |
nameMatches(java.lang.String searchName,
IJavaElement element,
boolean partialMatch)
Returns true if the given element's name matches the
specified
searchName, otherwise false. |
void |
seekModule(char[] name,
boolean prefixMatch,
IJavaElementRequestor requestor) |
void |
seekModuleReferences(java.lang.String name,
IJavaElementRequestor requestor,
IJavaProject javaProject) |
void |
seekPackageFragments(java.lang.String name,
boolean partialMatch,
IJavaElementRequestor requestor)
Notifies the given requestor of all package fragments with the
given name.
|
void |
seekPackageFragments(java.lang.String name,
boolean partialMatch,
IJavaElementRequestor requestor,
IPackageFragmentRoot[] moduleContext)
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) |
void |
seekTypes(java.lang.String name,
IPackageFragment pkg,
boolean partialMatch,
int acceptFlags,
IJavaElementRequestor requestor,
boolean considerSecondaryTypes)
Notifies the given requestor of all types (classes and interfaces) in the
given package fragment with the given (unqualified) name.
|
void |
seekTypes(java.lang.String pkgName,
java.lang.String name,
boolean partialMatch,
IJavaElementRequestor requestor,
int acceptFlags,
IPackageFragmentRoot[] moduleContext,
java.lang.String moduleName)
Notifies the given requestor of all package fragments with the
given name.
|
protected void |
seekTypesInBinaryPackage(java.lang.String name,
IPackageFragment pkg,
boolean partialMatch,
int acceptFlags,
IJavaElementRequestor requestor)
Performs type search in a binary package.
|
protected void |
seekTypesInSourcePackage(java.lang.String name,
IPackageFragment pkg,
int firstDot,
boolean partialMatch,
java.lang.String topLevelTypeName,
int acceptFlags,
IJavaElementRequestor requestor)
Performs type search in a source package.
|
protected boolean |
seekTypesInTopLevelType(java.lang.String prefix,
int firstDot,
IType topLevelType,
IJavaElementRequestor requestor,
int acceptFlags) |
protected boolean |
seekTypesInType(java.lang.String prefix,
int firstDot,
IType type,
IJavaElementRequestor requestor,
int acceptFlags)
Notifies the given requestor of all types (classes and interfaces) in the
given type with the given (possibly qualified) name.
|
protected boolean |
seekTypesInWorkingCopies(java.lang.String name,
IPackageFragment pkg,
int firstDot,
boolean partialMatch,
java.lang.String topLevelTypeName,
int acceptFlags,
IJavaElementRequestor requestor,
boolean considerSecondaryTypes) |
public static final int ACCEPT_CLASSES
public static final int ACCEPT_INTERFACES
public static final int ACCEPT_ENUMS
public static final int ACCEPT_RECORDS
public static final int ACCEPT_ANNOTATIONS
public static final int ACCEPT_ALL
public static boolean VERBOSE
protected IPackageFragmentRoot[] packageFragmentRoots
IPackageFragmentRoot's associated
with the classpath of this NameLookup facility's
project.protected HashtableOfArrayToObject packageFragments
protected java.util.Map<IPackageFragmentRoot,IClasspathEntry> rootToResolvedEntries
protected java.util.Map<IPackageFragmentRoot,IModuleDescription> rootToModule
protected java.util.HashMap typesInWorkingCopies
public long timeSpentInSeekTypesInSourcePackage
public long timeSpentInSeekTypesInBinaryPackage
public NameLookup(JavaProject rootProject, IPackageFragmentRoot[] packageFragmentRoots, HashtableOfArrayToObject packageFragments, ICompilationUnit[] workingCopies, java.util.Map rootToResolvedEntries)
protected boolean acceptType(IType type, int acceptFlags, boolean isSourceType)
ACCEPT_CLASSES
bit is on
ACCEPT_INTERFACES
bit is on
ACCEPT_CLASSES or ACCEPT_INTERFACES
bit is on
public ICompilationUnit findCompilationUnit(java.lang.String qualifiedTypeName)
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")
public IPackageFragment findPackageFragment(IPath path)
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"public IPackageFragment[] findPackageFragments(java.lang.String name, boolean partialMatch)
null if none exist.
The name can be:
partialMatch - partial name matches qualify when true,
only exact name matches qualify when falsepublic IPackageFragment[] findPackageFragments(java.lang.String name, boolean partialMatch, boolean patternMatch)
null if none exist.
The name can be:
partialMatch - partial name matches qualify when true,patternMatch - true when the given name might be a pattern,
false otherwise.public NameLookup.Answer findType(java.lang.String typeName, java.lang.String packageName, boolean partialMatch, int acceptFlags, boolean checkRestrictions, IPackageFragmentRoot[] moduleContext)
public NameLookup.Answer findType(java.lang.String typeName, java.lang.String packageName, boolean partialMatch, int acceptFlags, boolean checkRestrictions)
public NameLookup.Answer findType(java.lang.String typeName, java.lang.String packageName, boolean partialMatch, int acceptFlags, boolean considerSecondaryTypes, boolean waitForIndexes, boolean checkRestrictions, IProgressMonitor monitor)
public NameLookup.Answer findType(java.lang.String typeName, java.lang.String packageName, boolean partialMatch, int acceptFlags, boolean considerSecondaryTypes, boolean waitForIndexes, boolean checkRestrictions, IProgressMonitor monitor, IPackageFragmentRoot[] moduleContext)
public static IModule getModuleDescriptionInfo(IModuleDescription moduleDesc)
public IModule getModuleDescriptionInfo(PackageFragmentRoot root)
public IType findType(java.lang.String name, IPackageFragment pkg, boolean partialMatch, int acceptFlags, boolean waitForIndices, boolean considerSecondaryTypes)
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.name - the name of the type to findpkg - the package to searchpartialMatch - partial name matches qualify when true,
only exact name matches qualify when falseacceptFlags - 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 searchACCEPT_CLASSES,
ACCEPT_INTERFACES,
ACCEPT_ENUMS,
ACCEPT_ANNOTATIONS,
ACCEPT_RECORDSpublic IType findType(java.lang.String name, IPackageFragment pkg, boolean partialMatch, int acceptFlags)
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.
name - the name of the type to findpkg - the package to searchpartialMatch - partial name matches qualify when true,
only exact name matches qualify when falseacceptFlags - a bit mask describing if classes, interfaces or both classes and interfaces
are desired results. If no flags are specified, all types are returned.ACCEPT_CLASSES,
ACCEPT_INTERFACES,
ACCEPT_ENUMS,
ACCEPT_ANNOTATIONS,
ACCEPT_RECORDSpublic IType findType(java.lang.String name, boolean partialMatch, int acceptFlags)
null
if none exist. The domain of
the search is bounded by the Java project from which this name lookup was obtained.name - the name of the type to findpartialMatch - partial name matches qualify when true,
only exact name matches qualify when falseacceptFlags - a bit mask describing if classes, interfaces or both classes and interfaces
are desired results. If no flags are specified, all types are returned.ACCEPT_CLASSES,
ACCEPT_INTERFACES,
ACCEPT_ENUMS,
ACCEPT_ANNOTATIONS,
ACCEPT_RECORDSpublic NameLookup.Answer findType(java.lang.String name, boolean partialMatch, int acceptFlags, boolean checkRestrictions)
public NameLookup.Answer findType(java.lang.String name, boolean partialMatch, int acceptFlags, boolean considerSecondaryTypes, boolean waitForIndexes, boolean checkRestrictions, IProgressMonitor monitor)
public NameLookup.Answer findModule(char[] moduleName)
public boolean isPackage(java.lang.String[] pkgName)
public boolean isPackage(java.lang.String[] pkgName,
IPackageFragmentRoot[] moduleContext)
protected boolean nameMatches(java.lang.String searchName,
IJavaElement element,
boolean partialMatch)
searchName, otherwise false.
The partialMatch argument indicates partial matches
should be considered.
NOTE: in partialMatch mode, the case will be ignored, and the searchName must already have
been lowercased.
protected boolean nameMatches(java.lang.String searchName,
ICompilationUnit cu,
boolean partialMatch)
searchName, otherwise false.
The partialMatch argument indicates partial matches
should be considered.
NOTE: in partialMatch mode, the case will be ignored, and the searchName must already have
been lowercased.
public void seekPackageFragments(java.lang.String name,
boolean partialMatch,
IJavaElementRequestor requestor,
IPackageFragmentRoot[] moduleContext)
IJavaProject
this NameLookup was obtained from.partialMatch - partial name matches qualify when true;
only exact name matches qualify when falsepublic void seekTypes(java.lang.String pkgName,
java.lang.String name,
boolean partialMatch,
IJavaElementRequestor requestor,
int acceptFlags,
IPackageFragmentRoot[] moduleContext,
java.lang.String moduleName)
IJavaProject
this NameLookup was obtained from.partialMatch - partial name matches qualify when true;
only exact name matches qualify when falsepublic void seekPackageFragments(java.lang.String name,
boolean partialMatch,
IJavaElementRequestor requestor)
IJavaProject
this NameLookup was obtained from.partialMatch - partial name matches qualify when true;
only exact name matches qualify when falsepublic void seekTypes(java.lang.String name,
IPackageFragment pkg,
boolean partialMatch,
int acceptFlags,
IJavaElementRequestor requestor)
public void seekModuleReferences(java.lang.String name,
IJavaElementRequestor requestor,
IJavaProject javaProject)
public void seekModule(char[] name,
boolean prefixMatch,
IJavaElementRequestor requestor)
public void seekTypes(java.lang.String name,
IPackageFragment pkg,
boolean partialMatch,
int acceptFlags,
IJavaElementRequestor requestor,
boolean considerSecondaryTypes)
null, all types in the
project whose simple name matches the given name are found.name - The name to searchpkg - The corresponding package fragmentpartialMatch - partial name matches qualify when true;
only exact name matches qualify when falseacceptFlags - 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 resultACCEPT_CLASSES,
ACCEPT_INTERFACES,
ACCEPT_ENUMS,
ACCEPT_ANNOTATIONS,
ACCEPT_RECORDSprotected void seekTypesInBinaryPackage(java.lang.String name,
IPackageFragment pkg,
boolean partialMatch,
int acceptFlags,
IJavaElementRequestor requestor)
protected void seekTypesInSourcePackage(java.lang.String name,
IPackageFragment pkg,
int firstDot,
boolean partialMatch,
java.lang.String topLevelTypeName,
int acceptFlags,
IJavaElementRequestor requestor)
protected boolean seekTypesInType(java.lang.String prefix,
int firstDot,
IType type,
IJavaElementRequestor requestor,
int acceptFlags)
protected boolean seekTypesInTopLevelType(java.lang.String prefix,
int firstDot,
IType topLevelType,
IJavaElementRequestor requestor,
int acceptFlags)
protected boolean seekTypesInWorkingCopies(java.lang.String name,
IPackageFragment pkg,
int firstDot,
boolean partialMatch,
java.lang.String topLevelTypeName,
int acceptFlags,
IJavaElementRequestor requestor,
boolean considerSecondaryTypes)
public boolean hasCompilationUnit(char[][] pkgName,
IPackageFragmentRoot[] moduleContext)