src/share/classes/com/sun/tools/javac/comp/Lower.java

changeset 657
70ebdef189c9
parent 609
13354e1abba7
child 665
d3ead6731a91
equal deleted inserted replaced
656:6ef801fa38b7 657:70ebdef189c9
27 27
28 import java.util.*; 28 import java.util.*;
29 29
30 import com.sun.tools.javac.code.*; 30 import com.sun.tools.javac.code.*;
31 import com.sun.tools.javac.jvm.*; 31 import com.sun.tools.javac.jvm.*;
32 import com.sun.tools.javac.main.RecognizedOptions.PkgInfo;
32 import com.sun.tools.javac.tree.*; 33 import com.sun.tools.javac.tree.*;
33 import com.sun.tools.javac.util.*; 34 import com.sun.tools.javac.util.*;
34 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; 35 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
35 import com.sun.tools.javac.util.List; 36 import com.sun.tools.javac.util.List;
36 37
80 private boolean allowEnums; 81 private boolean allowEnums;
81 private final Name dollarAssertionsDisabled; 82 private final Name dollarAssertionsDisabled;
82 private final Name classDollar; 83 private final Name classDollar;
83 private Types types; 84 private Types types;
84 private boolean debugLower; 85 private boolean debugLower;
86 private PkgInfo pkginfoOpt;
85 87
86 protected Lower(Context context) { 88 protected Lower(Context context) {
87 context.put(lowerKey, this); 89 context.put(lowerKey, this);
88 names = Names.instance(context); 90 names = Names.instance(context);
89 log = Log.instance(context); 91 log = Log.instance(context);
104 fromString("class" + target.syntheticNameChar()); 106 fromString("class" + target.syntheticNameChar());
105 107
106 types = Types.instance(context); 108 types = Types.instance(context);
107 Options options = Options.instance(context); 109 Options options = Options.instance(context);
108 debugLower = options.get("debuglower") != null; 110 debugLower = options.get("debuglower") != null;
111 pkginfoOpt = PkgInfo.get(options);
109 } 112 }
110 113
111 /** The currently enclosing class. 114 /** The currently enclosing class.
112 */ 115 */
113 ClassSymbol currentClass; 116 ClassSymbol currentClass;
2159 l.head = translate(l.head, type); 2162 l.head = translate(l.head, type);
2160 return trees; 2163 return trees;
2161 } 2164 }
2162 2165
2163 public void visitTopLevel(JCCompilationUnit tree) { 2166 public void visitTopLevel(JCCompilationUnit tree) {
2164 if (tree.packageAnnotations.nonEmpty()) { 2167 if (needPackageInfoClass(tree)) {
2165 Name name = names.package_info; 2168 Name name = names.package_info;
2166 long flags = Flags.ABSTRACT | Flags.INTERFACE; 2169 long flags = Flags.ABSTRACT | Flags.INTERFACE;
2167 if (target.isPackageInfoSynthetic()) 2170 if (target.isPackageInfoSynthetic())
2168 // package-info is marked SYNTHETIC in JDK 1.6 and later releases 2171 // package-info is marked SYNTHETIC in JDK 1.6 and later releases
2169 flags = flags | Flags.SYNTHETIC; 2172 flags = flags | Flags.SYNTHETIC;
2180 ctype.interfaces_field = List.nil(); 2183 ctype.interfaces_field = List.nil();
2181 packageAnnotationsClass.sym = c; 2184 packageAnnotationsClass.sym = c;
2182 2185
2183 translated.append(packageAnnotationsClass); 2186 translated.append(packageAnnotationsClass);
2184 } 2187 }
2188 }
2189 // where
2190 private boolean needPackageInfoClass(JCCompilationUnit tree) {
2191 switch (pkginfoOpt) {
2192 case ALWAYS:
2193 return true;
2194 case LEGACY:
2195 return tree.packageAnnotations.nonEmpty();
2196 case NONEMPTY:
2197 for (Attribute.Compound a: tree.packge.attributes_field) {
2198 Attribute.RetentionPolicy p = types.getRetention(a);
2199 if (p != Attribute.RetentionPolicy.SOURCE)
2200 return true;
2201 }
2202 return false;
2203 }
2204 throw new AssertionError();
2185 } 2205 }
2186 2206
2187 public void visitClassDef(JCClassDecl tree) { 2207 public void visitClassDef(JCClassDecl tree) {
2188 ClassSymbol currentClassPrev = currentClass; 2208 ClassSymbol currentClassPrev = currentClass;
2189 MethodSymbol currentMethodSymPrev = currentMethodSym; 2209 MethodSymbol currentMethodSymPrev = currentMethodSym;

mercurial