--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Lower.java Wed Aug 25 11:24:30 2010 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Lower.java Wed Aug 25 11:40:25 2010 -0700
@@ -29,6 +29,7 @@
import com.sun.tools.javac.code.*;
import com.sun.tools.javac.jvm.*;
+import com.sun.tools.javac.main.RecognizedOptions.PkgInfo;
import com.sun.tools.javac.tree.*;
import com.sun.tools.javac.util.*;
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
@@ -82,6 +83,7 @@
private final Name classDollar;
private Types types;
private boolean debugLower;
+ private PkgInfo pkginfoOpt;
protected Lower(Context context) {
context.put(lowerKey, this);
@@ -106,6 +108,7 @@
types = Types.instance(context);
Options options = Options.instance(context);
debugLower = options.get("debuglower") != null;
+ pkginfoOpt = PkgInfo.get(options);
}
/** The currently enclosing class.
@@ -2161,7 +2164,7 @@
}
public void visitTopLevel(JCCompilationUnit tree) {
- if (tree.packageAnnotations.nonEmpty()) {
+ if (needPackageInfoClass(tree)) {
Name name = names.package_info;
long flags = Flags.ABSTRACT | Flags.INTERFACE;
if (target.isPackageInfoSynthetic())
@@ -2183,6 +2186,23 @@
translated.append(packageAnnotationsClass);
}
}
+ // where
+ private boolean needPackageInfoClass(JCCompilationUnit tree) {
+ switch (pkginfoOpt) {
+ case ALWAYS:
+ return true;
+ case LEGACY:
+ return tree.packageAnnotations.nonEmpty();
+ case NONEMPTY:
+ for (Attribute.Compound a: tree.packge.attributes_field) {
+ Attribute.RetentionPolicy p = types.getRetention(a);
+ if (p != Attribute.RetentionPolicy.SOURCE)
+ return true;
+ }
+ return false;
+ }
+ throw new AssertionError();
+ }
public void visitClassDef(JCClassDecl tree) {
ClassSymbol currentClassPrev = currentClass;