langtools/src/share/classes/com/sun/tools/javac/comp/Enter.java
author jjg
Thu, 10 Jul 2008 16:50:38 -0700
changeset 864 b1cf6afb8244
parent 10 06bc494ca11e
child 1206 3a05355982a9
permissions -rw-r--r--
6724551: Use Queues instead of Lists to link compiler phases Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
06bc494ca11e Initial load
duke
parents:
diff changeset
     2
 * Copyright 1999-2006 Sun Microsystems, Inc.  All Rights Reserved.
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
06bc494ca11e Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
 * have any questions.
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.javac.comp;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import java.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import java.util.Set;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import javax.tools.JavaFileObject;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import javax.tools.JavaFileManager;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import com.sun.tools.javac.code.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
import com.sun.tools.javac.jvm.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
import com.sun.tools.javac.tree.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
import com.sun.tools.javac.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
import com.sun.tools.javac.util.List;
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
import com.sun.tools.javac.code.Type.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
import com.sun.tools.javac.code.Symbol.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
import com.sun.tools.javac.tree.JCTree.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
import static com.sun.tools.javac.code.Flags.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
import static com.sun.tools.javac.code.Kinds.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
import static com.sun.tools.javac.code.TypeTags.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
/** This class enters symbols for all encountered definitions into
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
 *  the symbol table. The pass consists of two phases, organized as
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
 *  follows:
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
 *  <p>In the first phase, all class symbols are intered into their
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
 *  enclosing scope, descending recursively down the tree for classes
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
 *  which are members of other classes. The class symbols are given a
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
 *  MemberEnter object as completer.
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
 *  <p>In the second phase classes are completed using
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
 *  MemberEnter.complete().  Completion might occur on demand, but
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
 *  any classes that are not completed that way will be eventually
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
 *  completed by processing the `uncompleted' queue.  Completion
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
 *  entails (1) determination of a class's parameters, supertype and
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
 *  interfaces, as well as (2) entering all symbols defined in the
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
 *  class into its scope, with the exception of class symbols which
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
 *  have been entered in phase 1.  (2) depends on (1) having been
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
 *  completed for a class and all its superclasses and enclosing
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
 *  classes. That's why, after doing (1), we put classes in a
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
 *  `halfcompleted' queue. Only when we have performed (1) for a class
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
 *  and all it's superclasses and enclosing classes, we proceed to
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
 *  (2).
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
 *  <p>Whereas the first phase is organized as a sweep through all
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
 *  compiled syntax trees, the second phase is demand. Members of a
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
 *  class are entered when the contents of a class are first
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
 *  accessed. This is accomplished by installing completer objects in
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
 *  class symbols for compiled classes which invoke the member-enter
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
 *  phase for the corresponding class tree.
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
 *  <p>Classes migrate from one phase to the next via queues:
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
 *  <pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
 *  class enter -> (Enter.uncompleted)         --> member enter (1)
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
 *              -> (MemberEnter.halfcompleted) --> member enter (2)
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
 *              -> (Todo)                      --> attribute
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
 *                                              (only for toplevel classes)
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
 *  </pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
 *  <p><b>This is NOT part of any API supported by Sun Microsystems.  If
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
 *  you write code that depends on this, you do so at your own risk.
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
public class Enter extends JCTree.Visitor {
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
    protected static final Context.Key<Enter> enterKey =
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
        new Context.Key<Enter>();
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
    Log log;
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
    Symtab syms;
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
    Check chk;
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
    TreeMaker make;
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
    ClassReader reader;
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
    Annotate annotate;
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
    MemberEnter memberEnter;
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
    Lint lint;
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
    JavaFileManager fileManager;
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
    private final Todo todo;
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
    public static Enter instance(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
        Enter instance = context.get(enterKey);
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
        if (instance == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
            instance = new Enter(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
        return instance;
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
    protected Enter(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
        context.put(enterKey, this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
        log = Log.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
        reader = ClassReader.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
        make = TreeMaker.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
        syms = Symtab.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
        chk = Check.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
        memberEnter = MemberEnter.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
        annotate = Annotate.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
        lint = Lint.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
        predefClassDef = make.ClassDef(
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
            make.Modifiers(PUBLIC),
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
            syms.predefClass.name, null, null, null, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
        predefClassDef.sym = syms.predefClass;
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
        todo = Todo.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
        fileManager = context.get(JavaFileManager.class);
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
    /** A hashtable mapping classes and packages to the environments current
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
     *  at the points of their definitions.
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
    Map<TypeSymbol,Env<AttrContext>> typeEnvs =
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
            new HashMap<TypeSymbol,Env<AttrContext>>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
    /** Accessor for typeEnvs
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
    public Env<AttrContext> getEnv(TypeSymbol sym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
        return typeEnvs.get(sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
    public Env<AttrContext> getClassEnv(TypeSymbol sym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
        Env<AttrContext> localEnv = getEnv(sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
        Env<AttrContext> lintEnv = localEnv;
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
        while (lintEnv.info.lint == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
            lintEnv = lintEnv.next;
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
        localEnv.info.lint = lintEnv.info.lint.augment(sym.attributes_field, sym.flags());
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
        return localEnv;
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
    /** The queue of all classes that might still need to be completed;
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
     *  saved and initialized by main().
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
    ListBuffer<ClassSymbol> uncompleted;
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
    /** A dummy class to serve as enclClass for toplevel environments.
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
    private JCClassDecl predefClassDef;
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
/* ************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
 * environment construction
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
 *************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
    /** Create a fresh environment for class bodies.
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
     *  This will create a fresh scope for local symbols of a class, referred
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
     *  to by the environments info.scope field.
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
     *  This scope will contain
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
     *    - symbols for this and super
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
     *    - symbols for any type parameters
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
     *  In addition, it serves as an anchor for scopes of methods and initializers
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
     *  which are nested in this scope via Scope.dup().
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
     *  This scope should not be confused with the members scope of a class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
     *  @param tree     The class definition.
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
     *  @param env      The environment current outside of the class definition.
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
    public Env<AttrContext> classEnv(JCClassDecl tree, Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
        Env<AttrContext> localEnv =
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
            env.dup(tree, env.info.dup(new Scope(tree.sym)));
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
        localEnv.enclClass = tree;
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
        localEnv.outer = env;
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
        localEnv.info.isSelfCall = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
        localEnv.info.lint = null; // leave this to be filled in by Attr,
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
                                   // when annotations have been processed
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
        return localEnv;
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
    /** Create a fresh environment for toplevels.
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
     *  @param tree     The toplevel tree.
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
    Env<AttrContext> topLevelEnv(JCCompilationUnit tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
        Env<AttrContext> localEnv = new Env<AttrContext>(tree, new AttrContext());
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
        localEnv.toplevel = tree;
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
        localEnv.enclClass = predefClassDef;
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
        tree.namedImportScope = new Scope.ImportScope(tree.packge);
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
        tree.starImportScope = new Scope.ImportScope(tree.packge);
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
        localEnv.info.scope = tree.namedImportScope;
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
        localEnv.info.lint = lint;
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
        return localEnv;
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
    public Env<AttrContext> getTopLevelEnv(JCCompilationUnit tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
        Env<AttrContext> localEnv = new Env<AttrContext>(tree, new AttrContext());
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
        localEnv.toplevel = tree;
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
        localEnv.enclClass = predefClassDef;
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
        localEnv.info.scope = tree.namedImportScope;
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
        localEnv.info.lint = lint;
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
        return localEnv;
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
    /** The scope in which a member definition in environment env is to be entered
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
     *  This is usually the environment's scope, except for class environments,
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
     *  where the local scope is for type variables, and the this and super symbol
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
     *  only, and members go into the class member scope.
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
    Scope enterScope(Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
        return (env.tree.getTag() == JCTree.CLASSDEF)
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
            ? ((JCClassDecl) env.tree).sym.members_field
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
            : env.info.scope;
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
/* ************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
 * Visitor methods for phase 1: class enter
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
 *************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
    /** Visitor argument: the current environment.
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
    protected Env<AttrContext> env;
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
    /** Visitor result: the computed type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
    Type result;
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
    /** Visitor method: enter all classes in given tree, catching any
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
     *  completion failure exceptions. Return the tree's type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
     *  @param tree    The tree to be visited.
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
     *  @param env     The environment visitor argument.
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
    Type classEnter(JCTree tree, Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
        Env<AttrContext> prevEnv = this.env;
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
            this.env = env;
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
            tree.accept(this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
            return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
        }  catch (CompletionFailure ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
            return chk.completionError(tree.pos(), ex);
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
        } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
            this.env = prevEnv;
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
    /** Visitor method: enter classes of a list of trees, returning a list of types.
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
    <T extends JCTree> List<Type> classEnter(List<T> trees, Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
        ListBuffer<Type> ts = new ListBuffer<Type>();
864
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   263
        for (List<T> l = trees; l.nonEmpty(); l = l.tail) {
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   264
            Type t = classEnter(l.head, env);
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   265
            if (t != null)
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   266
                ts.append(t);
b1cf6afb8244 6724551: Use Queues instead of Lists to link compiler phases
jjg
parents: 10
diff changeset
   267
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
        return ts.toList();
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
    public void visitTopLevel(JCCompilationUnit tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
        JavaFileObject prev = log.useSource(tree.sourcefile);
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
        boolean addEnv = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
        boolean isPkgInfo = tree.sourcefile.isNameCompatible("package-info",
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
                                                             JavaFileObject.Kind.SOURCE);
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
        if (tree.pid != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
            tree.packge = reader.enterPackage(TreeInfo.fullName(tree.pid));
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
            if (tree.packageAnnotations.nonEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
                if (isPkgInfo) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
                    addEnv = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
                    log.error(tree.packageAnnotations.head.pos(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
                              "pkg.annotations.sb.in.package-info.java");
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
            tree.packge = syms.unnamedPackage;
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
        tree.packge.complete(); // Find all classes in package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
        Env<AttrContext> env = topLevelEnv(tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
        // Save environment of package-info.java file.
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
        if (isPkgInfo) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
            Env<AttrContext> env0 = typeEnvs.get(tree.packge);
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
            if (env0 == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
                typeEnvs.put(tree.packge, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
                JCCompilationUnit tree0 = env0.toplevel;
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
                if (!fileManager.isSameFile(tree.sourcefile, tree0.sourcefile)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
                    log.warning(tree.pid != null ? tree.pid.pos()
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
                                                 : null,
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
                                "pkg-info.already.seen",
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
                                tree.packge);
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
                    if (addEnv || (tree0.packageAnnotations.isEmpty() &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
                                   tree.docComments != null &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
                                   tree.docComments.get(tree) != null)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
                        typeEnvs.put(tree.packge, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
        classEnter(tree.defs, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
        if (addEnv) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
            todo.append(env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
        log.useSource(prev);
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
        result = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
    public void visitClassDef(JCClassDecl tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
        Symbol owner = env.info.scope.owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
        Scope enclScope = enterScope(env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
        ClassSymbol c;
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
        if (owner.kind == PCK) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
            // We are seeing a toplevel class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
            PackageSymbol packge = (PackageSymbol)owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
            for (Symbol q = packge; q != null && q.kind == PCK; q = q.owner)
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
                q.flags_field |= EXISTS;
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
            c = reader.enterClass(tree.name, packge);
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
            packge.members().enterIfAbsent(c);
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
            if ((tree.mods.flags & PUBLIC) != 0 && !classNameMatchesFileName(c, env)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
                log.error(tree.pos(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
                          "class.public.should.be.in.file", tree.name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
            if (tree.name.len != 0 &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
                !chk.checkUniqueClassName(tree.pos(), tree.name, enclScope)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
                result = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
                return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
            if (owner.kind == TYP) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
                // We are seeing a member class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
                c = reader.enterClass(tree.name, (TypeSymbol)owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
                if ((owner.flags_field & INTERFACE) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
                    tree.mods.flags |= PUBLIC | STATIC;
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
                // We are seeing a local class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
                c = reader.defineClass(tree.name, owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
                c.flatname = chk.localClassName(c);
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
                if (c.name.len != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
                    chk.checkTransparentClass(tree.pos(), c, env.info.scope);
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
        tree.sym = c;
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
        // Enter class into `compiled' table and enclosing scope.
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
        if (chk.compiled.get(c.flatname) != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
            duplicateClass(tree.pos(), c);
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
            result = new ErrorType(tree.name, (TypeSymbol)owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
            tree.sym = (ClassSymbol)result.tsym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
        chk.compiled.put(c.flatname, c);
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
        enclScope.enter(c);
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
        // Set up an environment for class block and store in `typeEnvs'
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
        // table, to be retrieved later in memberEnter and attribution.
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
        Env<AttrContext> localEnv = classEnv(tree, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
        typeEnvs.put(c, localEnv);
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
        // Fill out class fields.
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
        c.completer = memberEnter;
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
        c.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, c, tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
        c.sourcefile = env.toplevel.sourcefile;
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
        c.members_field = new Scope(c);
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
        ClassType ct = (ClassType)c.type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
        if (owner.kind != PCK && (c.flags_field & STATIC) == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
            // We are seeing a local or inner class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
            // Set outer_field of this class to closest enclosing class
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
            // which contains this class in a non-static context
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
            // (its "enclosing instance class"), provided such a class exists.
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
            Symbol owner1 = owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
            while ((owner1.kind & (VAR | MTH)) != 0 &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
                   (owner1.flags_field & STATIC) == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
                owner1 = owner1.owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
            if (owner1.kind == TYP) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
                ct.setEnclosingType(owner1.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
        // Enter type parameters.
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
        ct.typarams_field = classEnter(tree.typarams, localEnv);
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
        // Add non-local class to uncompleted, to make sure it will be
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
        // completed later.
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
        if (!c.isLocal() && uncompleted != null) uncompleted.append(c);
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
//      System.err.println("entering " + c.fullname + " in " + c.owner);//DEBUG
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
        // Recursively enter all member classes.
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
        classEnter(tree.defs, localEnv);
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
        result = c.type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
    //where
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
        /** Does class have the same name as the file it appears in?
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
        private static boolean classNameMatchesFileName(ClassSymbol c,
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
                                                        Env<AttrContext> env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
            return env.toplevel.sourcefile.isNameCompatible(c.name.toString(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
                                                            JavaFileObject.Kind.SOURCE);
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
    /** Complain about a duplicate class. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
    protected void duplicateClass(DiagnosticPosition pos, ClassSymbol c) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
        log.error(pos, "duplicate.class", c.fullname);
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   420
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
    /** Class enter visitor method for type parameters.
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
     *  Enter a symbol for type parameter in local scope, after checking that it
06bc494ca11e Initial load
duke
parents:
diff changeset
   423
     *  is unique.
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
    public void visitTypeParameter(JCTypeParameter tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   426
        TypeVar a = (tree.type != null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
            ? (TypeVar)tree.type
06bc494ca11e Initial load
duke
parents:
diff changeset
   428
            : new TypeVar(tree.name, env.info.scope.owner, syms.botType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   429
        tree.type = a;
06bc494ca11e Initial load
duke
parents:
diff changeset
   430
        if (chk.checkUnique(tree.pos(), a.tsym, env.info.scope)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   431
            env.info.scope.enter(a.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   432
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   433
        result = a;
06bc494ca11e Initial load
duke
parents:
diff changeset
   434
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   435
06bc494ca11e Initial load
duke
parents:
diff changeset
   436
    /** Default class enter visitor method: do nothing.
06bc494ca11e Initial load
duke
parents:
diff changeset
   437
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   438
    public void visitTree(JCTree tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   439
        result = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   440
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   441
06bc494ca11e Initial load
duke
parents:
diff changeset
   442
    /** Main method: enter all classes in a list of toplevel trees.
06bc494ca11e Initial load
duke
parents:
diff changeset
   443
     *  @param trees      The list of trees to be processed.
06bc494ca11e Initial load
duke
parents:
diff changeset
   444
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   445
    public void main(List<JCCompilationUnit> trees) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   446
        complete(trees, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   447
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   448
06bc494ca11e Initial load
duke
parents:
diff changeset
   449
    /** Main method: enter one class from a list of toplevel trees and
06bc494ca11e Initial load
duke
parents:
diff changeset
   450
     *  place the rest on uncompleted for later processing.
06bc494ca11e Initial load
duke
parents:
diff changeset
   451
     *  @param trees      The list of trees to be processed.
06bc494ca11e Initial load
duke
parents:
diff changeset
   452
     *  @param c          The class symbol to be processed.
06bc494ca11e Initial load
duke
parents:
diff changeset
   453
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   454
    public void complete(List<JCCompilationUnit> trees, ClassSymbol c) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   455
        annotate.enterStart();
06bc494ca11e Initial load
duke
parents:
diff changeset
   456
        ListBuffer<ClassSymbol> prevUncompleted = uncompleted;
06bc494ca11e Initial load
duke
parents:
diff changeset
   457
        if (memberEnter.completionEnabled) uncompleted = new ListBuffer<ClassSymbol>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   458
06bc494ca11e Initial load
duke
parents:
diff changeset
   459
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   460
            // enter all classes, and construct uncompleted list
06bc494ca11e Initial load
duke
parents:
diff changeset
   461
            classEnter(trees, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   462
06bc494ca11e Initial load
duke
parents:
diff changeset
   463
            // complete all uncompleted classes in memberEnter
06bc494ca11e Initial load
duke
parents:
diff changeset
   464
            if  (memberEnter.completionEnabled) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   465
                while (uncompleted.nonEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   466
                    ClassSymbol clazz = uncompleted.next();
06bc494ca11e Initial load
duke
parents:
diff changeset
   467
                    if (c == null || c == clazz || prevUncompleted == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   468
                        clazz.complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
   469
                    else
06bc494ca11e Initial load
duke
parents:
diff changeset
   470
                        // defer
06bc494ca11e Initial load
duke
parents:
diff changeset
   471
                        prevUncompleted.append(clazz);
06bc494ca11e Initial load
duke
parents:
diff changeset
   472
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   473
06bc494ca11e Initial load
duke
parents:
diff changeset
   474
                // if there remain any unimported toplevels (these must have
06bc494ca11e Initial load
duke
parents:
diff changeset
   475
                // no classes at all), process their import statements as well.
06bc494ca11e Initial load
duke
parents:
diff changeset
   476
                for (JCCompilationUnit tree : trees) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   477
                    if (tree.starImportScope.elems == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   478
                        JavaFileObject prev = log.useSource(tree.sourcefile);
06bc494ca11e Initial load
duke
parents:
diff changeset
   479
                        Env<AttrContext> env = typeEnvs.get(tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   480
                        if (env == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   481
                            env = topLevelEnv(tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   482
                        memberEnter.memberEnter(tree, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   483
                        log.useSource(prev);
06bc494ca11e Initial load
duke
parents:
diff changeset
   484
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   485
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   486
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   487
        } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
   488
            uncompleted = prevUncompleted;
06bc494ca11e Initial load
duke
parents:
diff changeset
   489
            annotate.enterDone();
06bc494ca11e Initial load
duke
parents:
diff changeset
   490
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   491
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   492
}