1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Lower.java Wed Aug 25 11:24:30 2010 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Lower.java Wed Aug 25 11:40:25 2010 -0700 1.3 @@ -29,6 +29,7 @@ 1.4 1.5 import com.sun.tools.javac.code.*; 1.6 import com.sun.tools.javac.jvm.*; 1.7 +import com.sun.tools.javac.main.RecognizedOptions.PkgInfo; 1.8 import com.sun.tools.javac.tree.*; 1.9 import com.sun.tools.javac.util.*; 1.10 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; 1.11 @@ -82,6 +83,7 @@ 1.12 private final Name classDollar; 1.13 private Types types; 1.14 private boolean debugLower; 1.15 + private PkgInfo pkginfoOpt; 1.16 1.17 protected Lower(Context context) { 1.18 context.put(lowerKey, this); 1.19 @@ -106,6 +108,7 @@ 1.20 types = Types.instance(context); 1.21 Options options = Options.instance(context); 1.22 debugLower = options.get("debuglower") != null; 1.23 + pkginfoOpt = PkgInfo.get(options); 1.24 } 1.25 1.26 /** The currently enclosing class. 1.27 @@ -2161,7 +2164,7 @@ 1.28 } 1.29 1.30 public void visitTopLevel(JCCompilationUnit tree) { 1.31 - if (tree.packageAnnotations.nonEmpty()) { 1.32 + if (needPackageInfoClass(tree)) { 1.33 Name name = names.package_info; 1.34 long flags = Flags.ABSTRACT | Flags.INTERFACE; 1.35 if (target.isPackageInfoSynthetic()) 1.36 @@ -2183,6 +2186,23 @@ 1.37 translated.append(packageAnnotationsClass); 1.38 } 1.39 } 1.40 + // where 1.41 + private boolean needPackageInfoClass(JCCompilationUnit tree) { 1.42 + switch (pkginfoOpt) { 1.43 + case ALWAYS: 1.44 + return true; 1.45 + case LEGACY: 1.46 + return tree.packageAnnotations.nonEmpty(); 1.47 + case NONEMPTY: 1.48 + for (Attribute.Compound a: tree.packge.attributes_field) { 1.49 + Attribute.RetentionPolicy p = types.getRetention(a); 1.50 + if (p != Attribute.RetentionPolicy.SOURCE) 1.51 + return true; 1.52 + } 1.53 + return false; 1.54 + } 1.55 + throw new AssertionError(); 1.56 + } 1.57 1.58 public void visitClassDef(JCClassDecl tree) { 1.59 ClassSymbol currentClassPrev = currentClass;