langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TypeEnter.java
changeset 42407 f3702cff2933
parent 41932 b23b4712933b
child 42828 cce89649f958
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TypeEnter.java	Wed Nov 23 16:16:36 2016 +0000
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TypeEnter.java	Thu Dec 01 09:02:42 2016 +0000
@@ -160,8 +160,6 @@
         // if there remain any unimported toplevels (these must have
         // no classes at all), process their import statements as well.
         for (JCCompilationUnit tree : trees) {
-            if (tree.defs.nonEmpty() && tree.defs.head.hasTag(MODULEDEF))
-                continue;
             if (!tree.starImportScope.isFilled()) {
                 Env<AttrContext> topEnv = enter.topLevelEnv(tree);
                 finishImports(tree, () -> { completeClass.resolveImports(tree, topEnv); });
@@ -344,13 +342,22 @@
                     throw new FatalError(diags.fragment("fatal.err.no.java.lang"));
                 importAll(make.at(tree.pos()).Import(make.QualIdent(javaLang), false), javaLang, env);
 
+                JCModuleDecl decl = tree.getModuleDecl();
+
                 // Process the package def and all import clauses.
-                if (tree.getPackage() != null)
+                if (tree.getPackage() != null && decl == null)
                     checkClassPackageClash(tree.getPackage());
 
                 for (JCImport imp : tree.getImports()) {
                     doImport(imp);
                 }
+
+                if (decl != null) {
+                    //check @Deprecated:
+                    markDeprecated(decl.sym, decl.mods.annotations, env);
+                    // process module annotations
+                    annotate.annotateLater(decl.mods.annotations, env, env.toplevel.modle, null);
+                }
             } finally {
                 this.env = prevEnv;
                 chk.setLint(prevLint);
@@ -745,12 +752,7 @@
                 }
             }
 
-            // Annotations.
-            // In general, we cannot fully process annotations yet,  but we
-            // can attribute the annotation types and then check to see if the
-            // @Deprecated annotation is present.
-            attr.attribAnnotationTypes(tree.mods.annotations, baseEnv);
-            handleDeprecatedAnnotation(tree.mods.annotations, sym);
+            markDeprecated(sym, tree.mods.annotations, baseEnv);
 
             chk.checkNonCyclicDecl(tree);
         }
@@ -765,32 +767,6 @@
                 return superType;
             }
 
-            /**
-             * If a list of annotations contains a reference to java.lang.Deprecated,
-             * set the DEPRECATED flag.
-             * If the annotation is marked forRemoval=true, also set DEPRECATED_REMOVAL.
-             **/
-            private void handleDeprecatedAnnotation(List<JCAnnotation> annotations, Symbol sym) {
-                for (List<JCAnnotation> al = annotations; !al.isEmpty(); al = al.tail) {
-                    JCAnnotation a = al.head;
-                    if (a.annotationType.type == syms.deprecatedType) {
-                        sym.flags_field |= Flags.DEPRECATED;
-                        a.args.stream()
-                                .filter(e -> e.hasTag(ASSIGN))
-                                .map(e -> (JCAssign) e)
-                                .filter(assign -> TreeInfo.name(assign.lhs) == names.forRemoval)
-                                .findFirst()
-                                .ifPresent(assign -> {
-                                    JCExpression rhs = TreeInfo.skipParens(assign.rhs);
-                                    if (rhs.hasTag(LITERAL)
-                                            && Boolean.TRUE.equals(((JCLiteral) rhs).getValue())) {
-                                        sym.flags_field |= DEPRECATED_REMOVAL;
-                                    }
-                                });
-                    }
-                }
-            }
-
         @Override
         public void complete(Symbol sym) throws CompletionFailure {
             Assert.check((topLevelPhase instanceof ImportsPhase) ||
@@ -1135,4 +1111,41 @@
         List<JCExpression> typeargs = typarams.nonEmpty() ? make.Types(typarams) : null;
         return make.Exec(make.Apply(typeargs, meth, make.Idents(params)));
     }
+
+    /**
+     * Mark sym deprecated if annotations contain @Deprecated annotation.
+     */
+    public void markDeprecated(Symbol sym, List<JCAnnotation> annotations, Env<AttrContext> env) {
+        // In general, we cannot fully process annotations yet,  but we
+        // can attribute the annotation types and then check to see if the
+        // @Deprecated annotation is present.
+        attr.attribAnnotationTypes(annotations, env);
+        handleDeprecatedAnnotations(annotations, sym);
+    }
+
+    /**
+     * If a list of annotations contains a reference to java.lang.Deprecated,
+     * set the DEPRECATED flag.
+     * If the annotation is marked forRemoval=true, also set DEPRECATED_REMOVAL.
+     **/
+    private void handleDeprecatedAnnotations(List<JCAnnotation> annotations, Symbol sym) {
+        for (List<JCAnnotation> al = annotations; !al.isEmpty(); al = al.tail) {
+            JCAnnotation a = al.head;
+            if (a.annotationType.type == syms.deprecatedType) {
+                sym.flags_field |= (Flags.DEPRECATED | Flags.DEPRECATED_ANNOTATION);
+                a.args.stream()
+                        .filter(e -> e.hasTag(ASSIGN))
+                        .map(e -> (JCAssign) e)
+                        .filter(assign -> TreeInfo.name(assign.lhs) == names.forRemoval)
+                        .findFirst()
+                        .ifPresent(assign -> {
+                            JCExpression rhs = TreeInfo.skipParens(assign.rhs);
+                            if (rhs.hasTag(LITERAL)
+                                    && Boolean.TRUE.equals(((JCLiteral) rhs).getValue())) {
+                                sym.flags_field |= DEPRECATED_REMOVAL;
+                            }
+                        });
+            }
+        }
+    }
 }