com.sun.tools.javac.comp
Class MemberEnter

java.lang.Object
  extended by com.sun.tools.javac.tree.JCTree.Visitor
      extended by com.sun.tools.javac.comp.MemberEnter
All Implemented Interfaces:
Symbol.Completer
Direct Known Subclasses:
JavadocMemberEnter

public class MemberEnter
extends JCTree.Visitor
implements Symbol.Completer

This is the second phase of Enter, in which classes are completed by entering their members into the class scope using MemberEnter.complete(). See Enter for an overview.

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
private  Annotate annotate
           
private  Attr attr
           
(package private) static boolean checkClash
          A switch to determine whether we check for package/class conflicts
private  Check chk
           
(package private)  boolean completionEnabled
          A flag to disable completion from time to time during member enter, as we only need to look up types.
private  JCDiagnostic.Factory diags
           
private  Enter enter
           
protected  Env<AttrContext> env
          Visitor argument: the current environment
(package private)  ListBuffer<Env<AttrContext>> halfcompleted
          A queue for classes whose members still need to be entered into the symbol table.
(package private)  boolean isFirst
          Set to true only when the first of a set of classes is processed from the halfcompleted queue.
private  Log log
           
private  TreeMaker make
           
protected static Context.Key<MemberEnter> memberEnterKey
           
private  Names names
           
private  ClassReader reader
           
private  boolean skipAnnotations
           
private  Symtab syms
           
private  Target target
           
private  Todo todo
           
private  Types types
           
 
Constructor Summary
protected MemberEnter(Context context)
           
 
Method Summary
private  void addEnumMembers(JCTree.JCClassDecl tree, Env<AttrContext> env)
          Add the implicit members for an enum type to the symbol table.
(package private)  void annotateDefaultValueLater(JCTree.JCExpression defaultValue, Env<AttrContext> localEnv, Symbol.MethodSymbol m)
          Queue processing of an attribute default value.
(package private)  void annotateLater(List<JCTree.JCAnnotation> annotations, Env<AttrContext> localEnv, Symbol s)
          Queue annotations for later processing.
(package private)  Type attribImportType(JCTree tree, Env<AttrContext> env)
           
private  Env<AttrContext> baseEnv(JCTree.JCClassDecl tree, Env<AttrContext> env)
           
 void complete(Symbol sym)
          Complete entering a class.
(package private)  JCTree DefaultConstructor(TreeMaker make, Symbol.ClassSymbol c, List<Type> typarams, List<Type> argtypes, List<Type> thrown, long flags, boolean based)
          Generate default constructor for given class.
private  void enterAnnotations(List<JCTree.JCAnnotation> annotations, Env<AttrContext> env, Symbol s)
          Enter a set of annotations.
private  void enterDefaultValue(JCTree.JCExpression defaultValue, Env<AttrContext> localEnv, Symbol.MethodSymbol m)
          Enter a default value for an attribute method.
private  JCTree.JCExpression enumBase(int pos, Symbol.ClassSymbol c)
          Generate a base clause for an enum type.
private  void finish(Env<AttrContext> env)
          Enter member fields and methods of a class
(package private)  void finishClass(JCTree.JCClassDecl tree, Env<AttrContext> env)
          Enter members for a class.
 Env<AttrContext> getInitEnv(JCTree.JCVariableDecl tree, Env<AttrContext> env)
           
 Env<AttrContext> getMethodEnv(JCTree.JCMethodDecl tree, Env<AttrContext> env)
           
private  boolean hasDeprecatedAnnotation(List<JCTree.JCAnnotation> annotations)
          Check if a list of annotations contains a reference to java.lang.Deprecated.
private  void importAll(int pos, Symbol.TypeSymbol tsym, Env<AttrContext> env)
          Import all classes of a class or package on demand.
private  void importNamed(JCDiagnostic.DiagnosticPosition pos, Symbol tsym, Env<AttrContext> env)
          Import given class.
private  void importNamedStatic(JCDiagnostic.DiagnosticPosition pos, Symbol.TypeSymbol tsym, Name name, Env<AttrContext> env)
          Import statics types of a given name.
private  void importStaticAll(int pos, Symbol.TypeSymbol tsym, Env<AttrContext> env)
          Import all static members of a class or package on demand.
(package private)  Env<AttrContext> initEnv(JCTree.JCVariableDecl tree, Env<AttrContext> env)
          Create a fresh environment for a variable's initializer.
static MemberEnter instance(Context context)
           
protected  void memberEnter(JCTree tree, Env<AttrContext> env)
          Enter field and method definitions and process import clauses, catching any completion failure exceptions.
(package private)  void memberEnter(List<? extends JCTree> trees, Env<AttrContext> env)
          Enter members from a list of trees.
(package private)  Env<AttrContext> methodEnv(JCTree.JCMethodDecl tree, Env<AttrContext> env)
          Create a fresh environment for method bodies.
(package private)  Type signature(List<JCTree.JCTypeParameter> typarams, List<JCTree.JCVariableDecl> params, JCTree res, List<JCTree.JCExpression> thrown, Env<AttrContext> env)
          Construct method type from method signature.
(package private)  boolean staticImportAccessible(Symbol sym, Symbol.PackageSymbol packge)
           
(package private)  JCTree.JCExpressionStatement SuperCall(TreeMaker make, List<Type> typarams, List<JCTree.JCVariableDecl> params, boolean based)
          Generate call to superclass constructor.
 void visitErroneous(JCTree.JCErroneous tree)
           
 void visitImport(JCTree.JCImport tree)
           
 void visitMethodDef(JCTree.JCMethodDecl tree)
           
 void visitTopLevel(JCTree.JCCompilationUnit tree)
           
 void visitTree(JCTree tree)
          Default member enter visitor method: do nothing
 void visitVarDef(JCTree.JCVariableDecl tree)
           
 
Methods inherited from class com.sun.tools.javac.tree.JCTree.Visitor
visitAnnotation, visitApply, visitAssert, visitAssign, visitAssignop, visitBinary, visitBlock, visitBracketExpr, visitBracketStat, visitBreak, visitCase, visitCatch, visitClassDef, visitConditional, visitContinue, visitDoLoop, visitEscapeExpr, visitEscapeStat, visitExec, visitForeachLoop, visitForLoop, visitIdent, visitIf, visitIndexed, visitLabelled, visitLetExpr, visitLiteral, visitModifiers, visitNewArray, visitNewClass, visitParens, visitReturn, visitSelect, visitSkip, visitSwitch, visitSynchronized, visitThrow, visitTry, visitTypeApply, visitTypeArray, visitTypeBoundKind, visitTypeCast, visitTypeIdent, visitTypeParameter, visitTypeTest, visitUnary, visitWhileLoop, visitWildcard
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

memberEnterKey

protected static final Context.Key<MemberEnter> memberEnterKey

checkClash

static final boolean checkClash
A switch to determine whether we check for package/class conflicts

See Also:
Constant Field Values

names

private final Names names

enter

private final Enter enter

log

private final Log log

chk

private final Check chk

attr

private final Attr attr

syms

private final Symtab syms

make

private final TreeMaker make

reader

private final ClassReader reader

todo

private final Todo todo

annotate

private final Annotate annotate

types

private final Types types

diags

private final JCDiagnostic.Factory diags

target

private final Target target

skipAnnotations

private final boolean skipAnnotations

halfcompleted

ListBuffer<Env<AttrContext>> halfcompleted
A queue for classes whose members still need to be entered into the symbol table.


isFirst

boolean isFirst
Set to true only when the first of a set of classes is processed from the halfcompleted queue.


completionEnabled

boolean completionEnabled
A flag to disable completion from time to time during member enter, as we only need to look up types. This avoids unnecessarily deep recursion.


env

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

Constructor Detail

MemberEnter

protected MemberEnter(Context context)
Method Detail

instance

public static MemberEnter instance(Context context)

importAll

private void importAll(int pos,
                       Symbol.TypeSymbol tsym,
                       Env<AttrContext> env)
Import all classes of a class or package on demand.

Parameters:
pos - Position to be used for error reporting.
tsym - The class or package the members of which are imported.
toScope - The (import) scope in which imported classes are entered.

importStaticAll

private void importStaticAll(int pos,
                             Symbol.TypeSymbol tsym,
                             Env<AttrContext> env)
Import all static members of a class or package on demand.

Parameters:
pos - Position to be used for error reporting.
tsym - The class or package the members of which are imported.
toScope - The (import) scope in which imported classes are entered.

staticImportAccessible

boolean staticImportAccessible(Symbol sym,
                               Symbol.PackageSymbol packge)

importNamedStatic

private void importNamedStatic(JCDiagnostic.DiagnosticPosition pos,
                               Symbol.TypeSymbol tsym,
                               Name name,
                               Env<AttrContext> env)
Import statics types of a given name. Non-types are handled in Attr.

Parameters:
pos - Position to be used for error reporting.
tsym - The class from which the name is imported.
name - The (simple) name being imported.
env - The environment containing the named import scope to add to.

importNamed

private void importNamed(JCDiagnostic.DiagnosticPosition pos,
                         Symbol tsym,
                         Env<AttrContext> env)
Import given class.

Parameters:
pos - Position to be used for error reporting.
tsym - The class to be imported.
env - The environment containing the named import scope to add to.

signature

Type signature(List<JCTree.JCTypeParameter> typarams,
               List<JCTree.JCVariableDecl> params,
               JCTree res,
               List<JCTree.JCExpression> thrown,
               Env<AttrContext> env)
Construct method type from method signature.

Parameters:
typarams - The method's type parameters.
params - The method's value parameters.
res - The method's result type, null if it is a constructor.
thrown - The method's thrown exceptions.
env - The method's (local) environment.

memberEnter

protected void memberEnter(JCTree tree,
                           Env<AttrContext> env)
Enter field and method definitions and process import clauses, catching any completion failure exceptions.


memberEnter

void memberEnter(List<? extends JCTree> trees,
                 Env<AttrContext> env)
Enter members from a list of trees.


finishClass

void finishClass(JCTree.JCClassDecl tree,
                 Env<AttrContext> env)
Enter members for a class.


addEnumMembers

private void addEnumMembers(JCTree.JCClassDecl tree,
                            Env<AttrContext> env)
Add the implicit members for an enum type to the symbol table.


visitTopLevel

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

visitImport

public void visitImport(JCTree.JCImport tree)
Overrides:
visitImport in class JCTree.Visitor

visitMethodDef

public void visitMethodDef(JCTree.JCMethodDecl tree)
Overrides:
visitMethodDef in class JCTree.Visitor

methodEnv

Env<AttrContext> methodEnv(JCTree.JCMethodDecl tree,
                           Env<AttrContext> env)
Create a fresh environment for method bodies.

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

visitVarDef

public void visitVarDef(JCTree.JCVariableDecl tree)
Overrides:
visitVarDef in class JCTree.Visitor

initEnv

Env<AttrContext> initEnv(JCTree.JCVariableDecl tree,
                         Env<AttrContext> env)
Create a fresh environment for a variable's initializer. If the variable is a field, the owner of the environment's scope is be the variable itself, otherwise the owner is the method enclosing the variable definition.

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

visitTree

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

Overrides:
visitTree in class JCTree.Visitor

visitErroneous

public void visitErroneous(JCTree.JCErroneous tree)
Overrides:
visitErroneous in class JCTree.Visitor

getMethodEnv

public Env<AttrContext> getMethodEnv(JCTree.JCMethodDecl tree,
                                     Env<AttrContext> env)

getInitEnv

public Env<AttrContext> getInitEnv(JCTree.JCVariableDecl tree,
                                   Env<AttrContext> env)

attribImportType

Type attribImportType(JCTree tree,
                      Env<AttrContext> env)

annotateLater

void annotateLater(List<JCTree.JCAnnotation> annotations,
                   Env<AttrContext> localEnv,
                   Symbol s)
Queue annotations for later processing.


hasDeprecatedAnnotation

private boolean hasDeprecatedAnnotation(List<JCTree.JCAnnotation> annotations)
Check if a list of annotations contains a reference to java.lang.Deprecated.


enterAnnotations

private void enterAnnotations(List<JCTree.JCAnnotation> annotations,
                              Env<AttrContext> env,
                              Symbol s)
Enter a set of annotations.


annotateDefaultValueLater

void annotateDefaultValueLater(JCTree.JCExpression defaultValue,
                               Env<AttrContext> localEnv,
                               Symbol.MethodSymbol m)
Queue processing of an attribute default value.


enterDefaultValue

private void enterDefaultValue(JCTree.JCExpression defaultValue,
                               Env<AttrContext> localEnv,
                               Symbol.MethodSymbol m)
Enter a default value for an attribute method.


complete

public void complete(Symbol sym)
              throws Symbol.CompletionFailure
Complete entering a class.

Specified by:
complete in interface Symbol.Completer
Parameters:
sym - The symbol of the class to be completed.
Throws:
Symbol.CompletionFailure

baseEnv

private Env<AttrContext> baseEnv(JCTree.JCClassDecl tree,
                                 Env<AttrContext> env)

finish

private void finish(Env<AttrContext> env)
Enter member fields and methods of a class

Parameters:
env - the environment current for the class block.

enumBase

private JCTree.JCExpression enumBase(int pos,
                                     Symbol.ClassSymbol c)
Generate a base clause for an enum type.

Parameters:
pos - The position for trees and diagnostics, if any
c - The class symbol of the enum

DefaultConstructor

JCTree DefaultConstructor(TreeMaker make,
                          Symbol.ClassSymbol c,
                          List<Type> typarams,
                          List<Type> argtypes,
                          List<Type> thrown,
                          long flags,
                          boolean based)
Generate default constructor for given class. For classes different from java.lang.Object, this is: c(argtype_0 x_0, ..., argtype_n x_n) throws thrown { super(x_0, ..., x_n) } or, if based == true: c(argtype_0 x_0, ..., argtype_n x_n) throws thrown { x_0.super(x_1, ..., x_n) }

Parameters:
make - The tree factory.
c - The class owning the default constructor.
argtypes - The parameter types of the constructor.
thrown - The thrown exceptions of the constructor.
based - Is first parameter a this$n?

SuperCall

JCTree.JCExpressionStatement SuperCall(TreeMaker make,
                                       List<Type> typarams,
                                       List<JCTree.JCVariableDecl> params,
                                       boolean based)
Generate call to superclass constructor. This is: super(id_0, ..., id_n) or, if based == true id_0.super(id_1,...,id_n) where id_0, ..., id_n are the names of the given parameters.

Parameters:
make - The tree factory
params - The parameters that need to be passed to super
typarams - The type parameters that need to be passed to super
based - Is first parameter a this$n?