< 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.

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) | FROM_SOURCE;
498         c.classfile = c.sourcefile = env.toplevel.sourcefile;
499         c.members_field = WriteableScope.create(c);
500         c.isPermittedExplicit = tree.permitting.nonEmpty();
501         c.clearAnnotationMetadata();
502 
503         ClassType ct = (ClassType)c.type;


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






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

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) | FROM_SOURCE;
499         c.classfile = c.sourcefile = env.toplevel.sourcefile;
500         c.members_field = WriteableScope.create(c);
501         c.isPermittedExplicit = tree.permitting.nonEmpty();
502         c.clearAnnotationMetadata();
503 
504         ClassType ct = (ClassType)c.type;
505         ct.flavor = ct.flavor.metamorphose((c.flags_field & PRIMITIVE_CLASS) != 0);
506 
507         if (owner.kind != PCK && (c.flags_field & STATIC) == 0) {
508             // We are seeing a local or inner class.
509             // Set outer_field of this class to closest enclosing class
510             // which contains this class in a non-static context
511             // (its "enclosing instance class"), provided such a class exists.
512             Symbol owner1 = owner;
513             while (owner1.kind.matches(KindSelector.VAL_MTH) &&
514                    (owner1.flags_field & STATIC) == 0) {
515                 owner1 = owner1.owner;
516             }
517             if (owner1.kind == TYP) {
518                 ct.setEnclosingType(owner1.type);
519             }
520         }
521 
522         // Enter type parameters.
523         ct.typarams_field = classEnter(tree.typarams, localEnv);
524         ct.allparams_field = null;
525         if (ct.isPrimitiveClass()) {
526             if (ct.projection != null) {
527                 ct.projection.typarams_field = ct.typarams_field;
528                 ct.projection.allparams_field = ct.allparams_field;
529             }
530         }
531 
532         // install further completer for this type.
533         c.completer = typeEnter;
534 
535         // Add non-local class to uncompleted, to make sure it will be
536         // completed later.
537         if (!c.isDirectlyOrIndirectlyLocal() && uncompleted != null) uncompleted.append(c);
538 //      System.err.println("entering " + c.fullname + " in " + c.owner);//DEBUG
539 
540         // Recursively enter all member classes.
541         classEnter(tree.defs, localEnv);
542 
543 //        Assert.checkNonNull(c.modle, c.sourcefile.toString());
544 
545         result = c.type;
546     }
547     //where
548         /** Does class have the same name as the file it appears in?
549          */
550         private static boolean classNameMatchesFileName(ClassSymbol c,
< prev index next >