< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java

Print this page

 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any
 23  * questions.
 24  */
 25 
 26 package com.sun.tools.javac.comp;
 27 
 28 import java.util.Map;
 29 import java.util.Optional;
 30 
 31 import javax.tools.JavaFileObject;
 32 import javax.tools.JavaFileManager;
 33 
 34 import com.sun.tools.javac.code.*;
 35 import com.sun.tools.javac.code.Kinds.KindName;
 36 import com.sun.tools.javac.code.Kinds.KindSelector;
 37 import com.sun.tools.javac.code.Scope.*;
 38 import com.sun.tools.javac.code.Symbol.*;
 39 import com.sun.tools.javac.code.Type.*;

 40 import com.sun.tools.javac.main.Option.PkgInfo;
 41 import com.sun.tools.javac.resources.CompilerProperties.Errors;
 42 import com.sun.tools.javac.resources.CompilerProperties.Warnings;
 43 import com.sun.tools.javac.tree.*;
 44 import com.sun.tools.javac.tree.JCTree.*;
 45 import com.sun.tools.javac.util.*;
 46 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
 47 import com.sun.tools.javac.util.List;
 48 
 49 import static com.sun.tools.javac.code.Flags.*;
 50 import static com.sun.tools.javac.code.Kinds.Kind.*;
 51 
 52 /** This class enters symbols for all encountered definitions into
 53  *  the symbol table. The pass consists of high-level two phases,
 54  *  organized as follows:
 55  *
 56  *  <p>In the first phase, all class symbols are entered into their
 57  *  enclosing scope, descending recursively down the tree for classes
 58  *  which are members of other classes. The class symbols are given a
 59  *  TypeEnter object as completer.

483             result = types.createErrorType(tree.name, (TypeSymbol)owner, Type.noType);
484             tree.sym = (ClassSymbol)result.tsym;
485             return;
486         }
487         chk.putCompiled(c);
488         enclScope.enter(c);
489 
490         // Set up an environment for class block and store in `typeEnvs'
491         // table, to be retrieved later in memberEnter and attribution.
492         Env<AttrContext> localEnv = classEnv(tree, env);
493         typeEnvs.put(c, localEnv);
494 
495         // Fill out class fields.
496         c.completer = Completer.NULL_COMPLETER; // do not allow the initial completer linger on.
497         c.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, c, tree);
498         c.sourcefile = env.toplevel.sourcefile;
499         c.members_field = WriteableScope.create(c);
500         c.clearAnnotationMetadata();
501 
502         ClassType ct = (ClassType)c.type;


503         if (owner.kind != PCK && (c.flags_field & STATIC) == 0) {
504             // We are seeing a local or inner class.
505             // Set outer_field of this class to closest enclosing class
506             // which contains this class in a non-static context
507             // (its "enclosing instance class"), provided such a class exists.
508             Symbol owner1 = owner;
509             while (owner1.kind.matches(KindSelector.VAL_MTH) &&
510                    (owner1.flags_field & STATIC) == 0) {
511                 owner1 = owner1.owner;
512             }
513             if (owner1.kind == TYP) {
514                 ct.setEnclosingType(owner1.type);
515             }
516         }
517 
518         // Enter type parameters.
519         ct.typarams_field = classEnter(tree.typarams, localEnv);
520         ct.allparams_field = null;






521 
522         // install further completer for this type.
523         c.completer = typeEnter;
524 
525         // Add non-local class to uncompleted, to make sure it will be
526         // completed later.
527         if (!c.isDirectlyOrIndirectlyLocal() && uncompleted != null) uncompleted.append(c);
528 //      System.err.println("entering " + c.fullname + " in " + c.owner);//DEBUG
529 
530         // Recursively enter all member classes.
531         classEnter(tree.defs, localEnv);
532 
533 //        Assert.checkNonNull(c.modle, c.sourcefile.toString());
534 
535         result = c.type;
536     }
537     //where
538         /** Does class have the same name as the file it appears in?
539          */
540         private static boolean classNameMatchesFileName(ClassSymbol c,

 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any
 23  * questions.
 24  */
 25 
 26 package com.sun.tools.javac.comp;
 27 
 28 import java.util.Map;
 29 import java.util.Optional;
 30 
 31 import javax.tools.JavaFileObject;
 32 import javax.tools.JavaFileManager;
 33 
 34 import com.sun.tools.javac.code.*;
 35 import com.sun.tools.javac.code.Kinds.KindName;
 36 import com.sun.tools.javac.code.Kinds.KindSelector;
 37 import com.sun.tools.javac.code.Scope.*;
 38 import com.sun.tools.javac.code.Symbol.*;
 39 import com.sun.tools.javac.code.Type.*;
 40 import com.sun.tools.javac.code.Type.ClassType.Flavor;
 41 import com.sun.tools.javac.main.Option.PkgInfo;
 42 import com.sun.tools.javac.resources.CompilerProperties.Errors;
 43 import com.sun.tools.javac.resources.CompilerProperties.Warnings;
 44 import com.sun.tools.javac.tree.*;
 45 import com.sun.tools.javac.tree.JCTree.*;
 46 import com.sun.tools.javac.util.*;
 47 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
 48 import com.sun.tools.javac.util.List;
 49 
 50 import static com.sun.tools.javac.code.Flags.*;
 51 import static com.sun.tools.javac.code.Kinds.Kind.*;
 52 
 53 /** This class enters symbols for all encountered definitions into
 54  *  the symbol table. The pass consists of high-level two phases,
 55  *  organized as follows:
 56  *
 57  *  <p>In the first phase, all class symbols are entered into their
 58  *  enclosing scope, descending recursively down the tree for classes
 59  *  which are members of other classes. The class symbols are given a
 60  *  TypeEnter object as completer.

484             result = types.createErrorType(tree.name, (TypeSymbol)owner, Type.noType);
485             tree.sym = (ClassSymbol)result.tsym;
486             return;
487         }
488         chk.putCompiled(c);
489         enclScope.enter(c);
490 
491         // Set up an environment for class block and store in `typeEnvs'
492         // table, to be retrieved later in memberEnter and attribution.
493         Env<AttrContext> localEnv = classEnv(tree, env);
494         typeEnvs.put(c, localEnv);
495 
496         // Fill out class fields.
497         c.completer = Completer.NULL_COMPLETER; // do not allow the initial completer linger on.
498         c.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, c, tree);
499         c.sourcefile = env.toplevel.sourcefile;
500         c.members_field = WriteableScope.create(c);
501         c.clearAnnotationMetadata();
502 
503         ClassType ct = (ClassType)c.type;
504         ct.flavor = ct.flavor.metamorphose(c.flags_field);
505 
506         if (owner.kind != PCK && (c.flags_field & STATIC) == 0) {
507             // We are seeing a local or inner class.
508             // Set outer_field of this class to closest enclosing class
509             // which contains this class in a non-static context
510             // (its "enclosing instance class"), provided such a class exists.
511             Symbol owner1 = owner;
512             while (owner1.kind.matches(KindSelector.VAL_MTH) &&
513                    (owner1.flags_field & STATIC) == 0) {
514                 owner1 = owner1.owner;
515             }
516             if (owner1.kind == TYP) {
517                 ct.setEnclosingType(owner1.type);
518             }
519         }
520 
521         // Enter type parameters.
522         ct.typarams_field = classEnter(tree.typarams, localEnv);
523         ct.allparams_field = null;
524         if (ct.isPrimitiveClass()) {
525             if (ct.projection != null) {
526                 ct.projection.typarams_field = ct.typarams_field;
527                 ct.projection.allparams_field = ct.allparams_field;
528             }
529         }
530 
531         // install further completer for this type.
532         c.completer = typeEnter;
533 
534         // Add non-local class to uncompleted, to make sure it will be
535         // completed later.
536         if (!c.isDirectlyOrIndirectlyLocal() && uncompleted != null) uncompleted.append(c);
537 //      System.err.println("entering " + c.fullname + " in " + c.owner);//DEBUG
538 
539         // Recursively enter all member classes.
540         classEnter(tree.defs, localEnv);
541 
542 //        Assert.checkNonNull(c.modle, c.sourcefile.toString());
543 
544         result = c.type;
545     }
546     //where
547         /** Does class have the same name as the file it appears in?
548          */
549         private static boolean classNameMatchesFileName(ClassSymbol c,
< prev index next >