langtools/src/share/classes/com/sun/tools/javac/comp/Enter.java
changeset 24069 dfb8f11542fc
parent 23810 b92eb80925f0
child 24604 7f68545b5128
equal deleted inserted replaced
24068:d8a1180faaa9 24069:dfb8f11542fc
   286     public void visitTopLevel(JCCompilationUnit tree) {
   286     public void visitTopLevel(JCCompilationUnit tree) {
   287         JavaFileObject prev = log.useSource(tree.sourcefile);
   287         JavaFileObject prev = log.useSource(tree.sourcefile);
   288         boolean addEnv = false;
   288         boolean addEnv = false;
   289         boolean isPkgInfo = tree.sourcefile.isNameCompatible("package-info",
   289         boolean isPkgInfo = tree.sourcefile.isNameCompatible("package-info",
   290                                                              JavaFileObject.Kind.SOURCE);
   290                                                              JavaFileObject.Kind.SOURCE);
   291         if (tree.pid != null) {
   291         JCPackageDecl pd = tree.getPackage();
   292             tree.packge = syms.enterPackage(TreeInfo.fullName(tree.pid));
   292         if (pd != null) {
   293             if (tree.packageAnnotations.nonEmpty()
   293             tree.packge = pd.packge = syms.enterPackage(TreeInfo.fullName(pd.pid));
   294                     || pkginfoOpt == PkgInfo.ALWAYS
   294             if (   pd.annotations.nonEmpty()
   295                     || tree.docComments != null) {
   295                 || pkginfoOpt == PkgInfo.ALWAYS
       
   296                 || tree.docComments != null) {
   296                 if (isPkgInfo) {
   297                 if (isPkgInfo) {
   297                     addEnv = true;
   298                     addEnv = true;
   298                 } else if (tree.packageAnnotations.nonEmpty()){
   299                 } else if (pd.annotations.nonEmpty()) {
   299                     log.error(tree.packageAnnotations.head.pos(),
   300                     log.error(pd.annotations.head.pos(),
   300                               "pkg.annotations.sb.in.package-info.java");
   301                               "pkg.annotations.sb.in.package-info.java");
   301                 }
   302                 }
   302             }
   303             }
   303         } else {
   304         } else {
   304             tree.packge = syms.unnamedPackage;
   305             tree.packge = syms.unnamedPackage;
   305         }
   306         }
   306         tree.packge.complete(); // Find all classes in package.
   307         tree.packge.complete(); // Find all classes in package.
   307         Env<AttrContext> topEnv = topLevelEnv(tree);
   308         Env<AttrContext> topEnv = topLevelEnv(tree);
       
   309         Env<AttrContext> packageEnv = isPkgInfo ? topEnv.dup(pd) : null;
   308 
   310 
   309         // Save environment of package-info.java file.
   311         // Save environment of package-info.java file.
   310         if (isPkgInfo) {
   312         if (isPkgInfo) {
   311             Env<AttrContext> env0 = typeEnvs.get(tree.packge);
   313             Env<AttrContext> env0 = typeEnvs.get(tree.packge);
   312             if (env0 == null) {
   314             if (env0 != null) {
   313                 typeEnvs.put(tree.packge, topEnv);
       
   314             } else {
       
   315                 JCCompilationUnit tree0 = env0.toplevel;
   315                 JCCompilationUnit tree0 = env0.toplevel;
   316                 if (!fileManager.isSameFile(tree.sourcefile, tree0.sourcefile)) {
   316                 if (!fileManager.isSameFile(tree.sourcefile, tree0.sourcefile)) {
   317                     log.warning(tree.pid != null ? tree.pid.pos()
   317                     log.warning(pd != null ? pd.pid.pos() : null,
   318                                                  : null,
       
   319                                 "pkg-info.already.seen",
   318                                 "pkg-info.already.seen",
   320                                 tree.packge);
   319                                 tree.packge);
   321                     if (addEnv || (tree0.packageAnnotations.isEmpty() &&
       
   322                                    tree.docComments != null &&
       
   323                                    tree.docComments.hasComment(tree))) {
       
   324                         typeEnvs.put(tree.packge, topEnv);
       
   325                     }
       
   326                 }
   320                 }
   327             }
   321             }
       
   322             typeEnvs.put(tree.packge, packageEnv);
   328 
   323 
   329             for (Symbol q = tree.packge; q != null && q.kind == PCK; q = q.owner)
   324             for (Symbol q = tree.packge; q != null && q.kind == PCK; q = q.owner)
   330                 q.flags_field |= EXISTS;
   325                 q.flags_field |= EXISTS;
   331 
   326 
   332             Name name = names.package_info;
   327             Name name = names.package_info;
   337             c.members_field = new Scope(c);
   332             c.members_field = new Scope(c);
   338             tree.packge.package_info = c;
   333             tree.packge.package_info = c;
   339         }
   334         }
   340         classEnter(tree.defs, topEnv);
   335         classEnter(tree.defs, topEnv);
   341         if (addEnv) {
   336         if (addEnv) {
   342             todo.append(topEnv);
   337             todo.append(packageEnv);
   343         }
   338         }
   344         log.useSource(prev);
   339         log.useSource(prev);
   345         result = null;
   340         result = null;
   346     }
   341     }
   347 
   342