com.sun.tools.javac.comp
Class Enter

java.lang.Object
  extended by com.sun.tools.javac.tree.JCTree.Visitor
      extended by com.sun.tools.javac.comp.Enter
Direct Known Subclasses:
JavadocEnter

public class Enter
extends JCTree.Visitor

This class enters symbols for all encountered definitions into the symbol table. The pass consists of two phases, organized as follows:

In the first phase, all class symbols are intered into their enclosing scope, descending recursively down the tree for classes which are members of other classes. The class symbols are given a MemberEnter object as completer.

In the second phase classes are completed using MemberEnter.complete(). Completion might occur on demand, but any classes that are not completed that way will be eventually completed by processing the `uncompleted' queue. Completion entails (1) determination of a class's parameters, supertype and interfaces, as well as (2) entering all symbols defined in the class into its scope, with the exception of class symbols which have been entered in phase 1. (2) depends on (1) having been completed for a class and all its superclasses and enclosing classes. That's why, after doing (1), we put classes in a `halfcompleted' queue. Only when we have performed (1) for a class and all it's superclasses and enclosing classes, we proceed to (2).

Whereas the first phase is organized as a sweep through all compiled syntax trees, the second phase is demand. Members of a class are entered when the contents of a class are first accessed. This is accomplished by installing completer objects in class symbols for compiled classes which invoke the member-enter phase for the corresponding class tree.

Classes migrate from one phase to the next via queues:

  class enter -> (Enter.uncompleted)         --> member enter (1)
              -> (MemberEnter.halfcompleted) --> member enter (2)
              -> (Todo)                      --> attribute
                                              (only for toplevel classes)
  

This is NOT part of any API supported by Sun Microsystems. If you write code that depends on this, you do so at your own risk. This code and its internal interfaces are subject to change or deletion without notice.


Field Summary
(package private)  Annotate annotate
           
(package private)  Check chk
           
protected static Context.Key<Enter> enterKey
           
protected  Env<AttrContext> env
          Visitor argument: the current environment.
(package private)  JavaFileManager fileManager
           
(package private)  Lint lint
           
(package private)  Log log
           
(package private)  TreeMaker make
           
(package private)  MemberEnter memberEnter
           
private  JCTree.JCClassDecl predefClassDef
          A dummy class to serve as enclClass for toplevel environments.
(package private)  ClassReader reader
           
(package private)  Type result
          Visitor result: the computed type.
(package private)  Symtab syms
           
private  Todo todo
           
(package private)  java.util.Map<Symbol.TypeSymbol,Env<AttrContext>> typeEnvs
          A hashtable mapping classes and packages to the environments current at the points of their definitions.
(package private)  Types types
           
(package private)  ListBuffer<Symbol.ClassSymbol> uncompleted
          The queue of all classes that might still need to be completed; saved and initialized by main().
 
Constructor Summary
protected Enter(Context context)
           
 
Method Summary
 Env<AttrContext> bracketEnv(JCTree.JCExpression tree, Env<AttrContext> env)
          Create a fresh environment for bracket bodies.
(package private)  Type classEnter(JCTree tree, Env<AttrContext> env)
          Visitor method: enter all classes in given tree, catching any completion failure exceptions.
(package private)
<T extends JCTree>
List<Type>
classEnter(List<T> trees, Env<AttrContext> env)
          Visitor method: enter classes of a list of trees, returning a list of types.
 Env<AttrContext> classEnv(JCTree.JCClassDecl tree, Env<AttrContext> env)
          Create a fresh environment for class bodies.
private static boolean classNameMatchesFileName(Symbol.ClassSymbol c, Env<AttrContext> env)
          Does class have the same name as the file it appears in?
 void complete(List<JCTree.JCCompilationUnit> trees, Symbol.ClassSymbol c)
          Main method: enter one class from a list of toplevel trees and place the rest on uncompleted for later processing.
protected  void duplicateClass(JCDiagnostic.DiagnosticPosition pos, Symbol.ClassSymbol c)
          Complain about a duplicate class.
(package private)  Scope enterScope(Env<AttrContext> env)
          The scope in which a member definition in environment env is to be entered This is usually the environment's scope, except for class environments, where the local scope is for type variables, and the this and super symbol only, and members go into the class member scope.
 Env<AttrContext> escapeEnv(JCTree tree, Env<AttrContext> env)
          Create a fresh environment for escape bodies.
 Env<AttrContext> getClassEnv(Symbol.TypeSymbol sym)
           
 Env<AttrContext> getEnv(Symbol.TypeSymbol sym)
          Accessor for typeEnvs
 Env<AttrContext> getTopLevelEnv(JCTree.JCCompilationUnit tree)
           
static Enter instance(Context context)
           
 void main(List<JCTree.JCCompilationUnit> trees)
          Main method: enter all classes in a list of toplevel trees.
(package private)  Env<AttrContext> topLevelEnv(JCTree.JCCompilationUnit tree)
          Create a fresh environment for toplevels.
 void visitClassDef(JCTree.JCClassDecl tree)
           
 void visitTopLevel(JCTree.JCCompilationUnit tree)
           
 void visitTree(JCTree tree)
          Default class enter visitor method: do nothing.
 void visitTypeParameter(JCTree.JCTypeParameter tree)
          Class enter visitor method for type parameters.
 
Methods inherited from class com.sun.tools.javac.tree.JCTree.Visitor
visitAnnotation, visitApply, visitAssert, visitAssign, visitAssignop, visitBinary, visitBlock, visitBracketExpr, visitBracketStat, visitBreak, visitCase, visitCatch, visitConditional, visitContinue, visitDoLoop, visitErroneous, visitEscapeExpr, visitEscapeStat, visitExec, visitForeachLoop, visitForLoop, visitIdent, visitIf, visitImport, visitIndexed, visitLabelled, visitLetExpr, visitLiteral, visitMethodDef, visitModifiers, visitNewArray, visitNewClass, visitParens, visitReturn, visitSelect, visitSkip, visitSwitch, visitSynchronized, visitThrow, visitTry, visitTypeApply, visitTypeArray, visitTypeBoundKind, visitTypeCast, visitTypeIdent, visitTypeTest, visitUnary, visitVarDef, visitWhileLoop, visitWildcard
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

enterKey

protected static final Context.Key<Enter> enterKey

log

Log log

syms

Symtab syms

chk

Check chk

make

TreeMaker make

reader

ClassReader reader

annotate

Annotate annotate

memberEnter

MemberEnter memberEnter

types

Types types

lint

Lint lint

fileManager

JavaFileManager fileManager

todo

private final Todo todo

typeEnvs

java.util.Map<Symbol.TypeSymbol,Env<AttrContext>> typeEnvs
A hashtable mapping classes and packages to the environments current at the points of their definitions.


uncompleted

ListBuffer<Symbol.ClassSymbol> uncompleted
The queue of all classes that might still need to be completed; saved and initialized by main().


predefClassDef

private JCTree.JCClassDecl predefClassDef
A dummy class to serve as enclClass for toplevel environments.


env

protected Env<AttrContext> env
Visitor argument: the current environment.


result

Type result
Visitor result: the computed type.

Constructor Detail

Enter

protected Enter(Context context)
Method Detail

instance

public static Enter instance(Context context)

getEnv

public Env<AttrContext> getEnv(Symbol.TypeSymbol sym)
Accessor for typeEnvs


getClassEnv

public Env<AttrContext> getClassEnv(Symbol.TypeSymbol sym)

classEnv

public Env<AttrContext> classEnv(JCTree.JCClassDecl tree,
                                 Env<AttrContext> env)
Create a fresh environment for class bodies. This will create a fresh scope for local symbols of a class, referred to by the environments info.scope field. This scope will contain - symbols for this and super - symbols for any type parameters In addition, it serves as an anchor for scopes of methods and initializers which are nested in this scope via Scope.dup(). This scope should not be confused with the members scope of a class.

Parameters:
tree - The class definition.
env - The environment current outside of the class definition.

topLevelEnv

Env<AttrContext> topLevelEnv(JCTree.JCCompilationUnit tree)
Create a fresh environment for toplevels.

Parameters:
tree - The toplevel tree.

getTopLevelEnv

public Env<AttrContext> getTopLevelEnv(JCTree.JCCompilationUnit tree)

enterScope

Scope enterScope(Env<AttrContext> env)
The scope in which a member definition in environment env is to be entered This is usually the environment's scope, except for class environments, where the local scope is for type variables, and the this and super symbol only, and members go into the class member scope.


bracketEnv

public Env<AttrContext> bracketEnv(JCTree.JCExpression tree,
                                   Env<AttrContext> env)
Create a fresh environment for bracket bodies.

Parameters:
tree - The bracket expression.
env - The environment current outside of the bracket.

escapeEnv

public Env<AttrContext> escapeEnv(JCTree tree,
                                  Env<AttrContext> env)
Create a fresh environment for escape bodies.

Parameters:
tree - The escape expression.
env - The environment current outside of the escape.

classEnter

Type classEnter(JCTree tree,
                Env<AttrContext> env)
Visitor method: enter all classes in given tree, catching any completion failure exceptions. Return the tree's type.

Parameters:
tree - The tree to be visited.
env - The environment visitor argument.

classEnter

<T extends JCTree> List<Type> classEnter(List<T> trees,
                                         Env<AttrContext> env)
Visitor method: enter classes of a list of trees, returning a list of types.


visitTopLevel

public void visitTopLevel(JCTree.JCCompilationUnit tree)
Overrides:
visitTopLevel in class JCTree.Visitor

visitClassDef

public void visitClassDef(JCTree.JCClassDecl tree)
Overrides:
visitClassDef in class JCTree.Visitor

classNameMatchesFileName

private static boolean classNameMatchesFileName(Symbol.ClassSymbol c,
                                                Env<AttrContext> env)
Does class have the same name as the file it appears in?


duplicateClass

protected void duplicateClass(JCDiagnostic.DiagnosticPosition pos,
                              Symbol.ClassSymbol c)
Complain about a duplicate class.


visitTypeParameter

public void visitTypeParameter(JCTree.JCTypeParameter tree)
Class enter visitor method for type parameters. Enter a symbol for type parameter in local scope, after checking that it is unique.

Overrides:
visitTypeParameter in class JCTree.Visitor

visitTree

public void visitTree(JCTree tree)
Default class enter visitor method: do nothing.

Overrides:
visitTree in class JCTree.Visitor

main

public void main(List<JCTree.JCCompilationUnit> trees)
Main method: enter all classes in a list of toplevel trees.

Parameters:
trees - The list of trees to be processed.

complete

public void complete(List<JCTree.JCCompilationUnit> trees,
                     Symbol.ClassSymbol c)
Main method: enter one class from a list of toplevel trees and place the rest on uncompleted for later processing.

Parameters:
trees - The list of trees to be processed.
c - The class symbol to be processed.