JDT Core Programmer Guide/ECJ/Lookups
The central place where the following bindings are globally stored:
- ModuleBinding (
- PackageBinding (
- TypeBinding (
- TypeBinding (
Since Java 9, however, different instances of LookupEnvironment are used, to implement the perspective of one module each. In this situation
- the root lookup environment represents the unnamed module
- module-specific lookup environments are found via the
environmentfield of elements of
- each lookup environment has a back link
rootto the root environment
- fields of LookupEnvironment that are not module specific are documented as either ROOT_ONLY or SHARED (see javadoc of LookupEnvironment#root).
The root lookup environment also links a few unique instances:
globalOptions: all compiler options in effect
nameEnvironment: sometimes called the oracle, since it's an external/opaque entity that can answer sought types and packages.
typeRequestor: callback for newly discovered types
typeSystem: manages variants of known type bindings (parameterizations, arrays, annotations)
problemReporter: a fall-back problem reporter, which is used for reporting errors that cannot be associated to a particular AST node.
Since Java 9 also module bindings act as lookups.
In addition to the global lookup (which serves source and binary elements), the following AST nodes have their dedicated
Scope which performs the initial, location-aware part of name lookup:
- CompilationUnitDeclaration -> CompilationUnitScope
- ModuleDeclaration -> ModuleScope
- TypeDeclaration -> ClassScope
- AbstractMethodDeclaration -> MethodScope
- Block -> BlockScope (also used by block-like nodes like ForeachStatement)
A TypeDeclaration may hold additional scopes
staticInitializerScope for resolving field initializers (implementation uses MethodScope also here).