langtools/src/share/classes/com/sun/tools/javac/comp/Enter.java
changeset 22163 3651128c74eb
parent 20235 7834123e35dc
child 22442 8fd30fc4e3a3
equal deleted inserted replaced
22162:3b3e23e67329 22163:3651128c74eb
    88  *  If you write code that depends on this, you do so at your own risk.
    88  *  If you write code that depends on this, you do so at your own risk.
    89  *  This code and its internal interfaces are subject to change or
    89  *  This code and its internal interfaces are subject to change or
    90  *  deletion without notice.</b>
    90  *  deletion without notice.</b>
    91  */
    91  */
    92 public class Enter extends JCTree.Visitor {
    92 public class Enter extends JCTree.Visitor {
    93     protected static final Context.Key<Enter> enterKey =
    93     protected static final Context.Key<Enter> enterKey = new Context.Key<>();
    94         new Context.Key<Enter>();
       
    95 
    94 
    96     Log log;
    95     Log log;
    97     Symtab syms;
    96     Symtab syms;
    98     Check chk;
    97     Check chk;
    99     TreeMaker make;
    98     TreeMaker make;
   145     }
   144     }
   146 
   145 
   147     /** A hashtable mapping classes and packages to the environments current
   146     /** A hashtable mapping classes and packages to the environments current
   148      *  at the points of their definitions.
   147      *  at the points of their definitions.
   149      */
   148      */
   150     Map<TypeSymbol,Env<AttrContext>> typeEnvs =
   149     Map<TypeSymbol,Env<AttrContext>> typeEnvs = new HashMap<>();
   151             new HashMap<TypeSymbol,Env<AttrContext>>();
       
   152 
   150 
   153     /** Accessor for typeEnvs
   151     /** Accessor for typeEnvs
   154      */
   152      */
   155     public Env<AttrContext> getEnv(TypeSymbol sym) {
   153     public Env<AttrContext> getEnv(TypeSymbol sym) {
   156         return typeEnvs.get(sym);
   154         return typeEnvs.get(sym);
   205 
   203 
   206     /** Create a fresh environment for toplevels.
   204     /** Create a fresh environment for toplevels.
   207      *  @param tree     The toplevel tree.
   205      *  @param tree     The toplevel tree.
   208      */
   206      */
   209     Env<AttrContext> topLevelEnv(JCCompilationUnit tree) {
   207     Env<AttrContext> topLevelEnv(JCCompilationUnit tree) {
   210         Env<AttrContext> localEnv = new Env<AttrContext>(tree, new AttrContext());
   208         Env<AttrContext> localEnv = new Env<>(tree, new AttrContext());
   211         localEnv.toplevel = tree;
   209         localEnv.toplevel = tree;
   212         localEnv.enclClass = predefClassDef;
   210         localEnv.enclClass = predefClassDef;
   213         tree.namedImportScope = new ImportScope(tree.packge);
   211         tree.namedImportScope = new ImportScope(tree.packge);
   214         tree.starImportScope = new StarImportScope(tree.packge);
   212         tree.starImportScope = new StarImportScope(tree.packge);
   215         localEnv.info.scope = tree.namedImportScope;
   213         localEnv.info.scope = tree.namedImportScope;
   216         localEnv.info.lint = lint;
   214         localEnv.info.lint = lint;
   217         return localEnv;
   215         return localEnv;
   218     }
   216     }
   219 
   217 
   220     public Env<AttrContext> getTopLevelEnv(JCCompilationUnit tree) {
   218     public Env<AttrContext> getTopLevelEnv(JCCompilationUnit tree) {
   221         Env<AttrContext> localEnv = new Env<AttrContext>(tree, new AttrContext());
   219         Env<AttrContext> localEnv = new Env<>(tree, new AttrContext());
   222         localEnv.toplevel = tree;
   220         localEnv.toplevel = tree;
   223         localEnv.enclClass = predefClassDef;
   221         localEnv.enclClass = predefClassDef;
   224         localEnv.info.scope = tree.namedImportScope;
   222         localEnv.info.scope = tree.namedImportScope;
   225         localEnv.info.lint = lint;
   223         localEnv.info.lint = lint;
   226         return localEnv;
   224         return localEnv;
   269     }
   267     }
   270 
   268 
   271     /** Visitor method: enter classes of a list of trees, returning a list of types.
   269     /** Visitor method: enter classes of a list of trees, returning a list of types.
   272      */
   270      */
   273     <T extends JCTree> List<Type> classEnter(List<T> trees, Env<AttrContext> env) {
   271     <T extends JCTree> List<Type> classEnter(List<T> trees, Env<AttrContext> env) {
   274         ListBuffer<Type> ts = new ListBuffer<Type>();
   272         ListBuffer<Type> ts = new ListBuffer<>();
   275         for (List<T> l = trees; l.nonEmpty(); l = l.tail) {
   273         for (List<T> l = trees; l.nonEmpty(); l = l.tail) {
   276             Type t = classEnter(l.head, env);
   274             Type t = classEnter(l.head, env);
   277             if (t != null)
   275             if (t != null)
   278                 ts.append(t);
   276                 ts.append(t);
   279         }
   277         }
   481      *  @param c          The class symbol to be processed.
   479      *  @param c          The class symbol to be processed.
   482      */
   480      */
   483     public void complete(List<JCCompilationUnit> trees, ClassSymbol c) {
   481     public void complete(List<JCCompilationUnit> trees, ClassSymbol c) {
   484         annotate.enterStart();
   482         annotate.enterStart();
   485         ListBuffer<ClassSymbol> prevUncompleted = uncompleted;
   483         ListBuffer<ClassSymbol> prevUncompleted = uncompleted;
   486         if (memberEnter.completionEnabled) uncompleted = new ListBuffer<ClassSymbol>();
   484         if (memberEnter.completionEnabled) uncompleted = new ListBuffer<>();
   487 
   485 
   488         try {
   486         try {
   489             // enter all classes, and construct uncompleted list
   487             // enter all classes, and construct uncompleted list
   490             classEnter(trees, null);
   488             classEnter(trees, null);
   491 
   489