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

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
protected static Context.Key<Enter> enterKey
           
protected  Env<AttrContext> env
          Visitor argument: the current environment.
 
Constructor Summary
protected Enter(Context context)
           
 
Method Summary
 Env<AttrContext> classEnv(JCTree.JCClassDecl tree, Env<AttrContext> env)
          Create a fresh environment for class bodies.
 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.
 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.
 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, visitBreak, visitCase, visitCatch, visitConditional, visitContinue, visitDoLoop, visitErroneous, 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

env

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

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.

getTopLevelEnv

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

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

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.


Copyright © 2009. All Rights Reserved.