1.1 --- a/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java Mon Dec 06 11:51:02 2010 +0000 1.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java Tue Dec 07 14:13:25 2010 -0800 1.3 @@ -32,6 +32,7 @@ 1.4 import java.util.Arrays; 1.5 import java.util.EnumSet; 1.6 import java.util.HashMap; 1.7 +import java.util.HashSet; 1.8 import java.util.Map; 1.9 import java.util.Set; 1.10 import javax.lang.model.SourceVersion; 1.11 @@ -44,11 +45,13 @@ 1.12 1.13 import com.sun.tools.javac.comp.Annotate; 1.14 import com.sun.tools.javac.code.*; 1.15 +import com.sun.tools.javac.code.Lint.LintCategory; 1.16 import com.sun.tools.javac.code.Type.*; 1.17 import com.sun.tools.javac.code.Symbol.*; 1.18 import com.sun.tools.javac.code.Symtab; 1.19 import com.sun.tools.javac.file.BaseFileObject; 1.20 import com.sun.tools.javac.util.*; 1.21 +import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; 1.22 1.23 import static com.sun.tools.javac.code.Flags.*; 1.24 import static com.sun.tools.javac.code.Kinds.*; 1.25 @@ -102,6 +105,10 @@ 1.26 */ 1.27 boolean allowAnnotations; 1.28 1.29 + /** Lint option: warn about classfile issues 1.30 + */ 1.31 + boolean lintClassfile; 1.32 + 1.33 /** Switch: preserve parameter names from the variable table. 1.34 */ 1.35 public boolean saveParameterNames; 1.36 @@ -207,6 +214,11 @@ 1.37 */ 1.38 boolean haveParameterNameIndices; 1.39 1.40 + /** 1.41 + * The set of attribute names for which warnings have been generated for the current class 1.42 + */ 1.43 + Set<Name> warnedAttrs = new HashSet<Name>(); 1.44 + 1.45 /** Get the ClassReader instance for this invocation. */ 1.46 public static ClassReader instance(Context context) { 1.47 ClassReader instance = context.get(classReaderKey); 1.48 @@ -279,6 +291,8 @@ 1.49 typevars = new Scope(syms.noSymbol); 1.50 debugJSR308 = options.isSet("TA:reader"); 1.51 1.52 + lintClassfile = Lint.instance(context).isEnabled(LintCategory.CLASSFILE); 1.53 + 1.54 initAttributeReaders(); 1.55 } 1.56 1.57 @@ -870,7 +884,22 @@ 1.58 } 1.59 1.60 boolean accepts(AttributeKind kind) { 1.61 - return kinds.contains(kind) && majorVersion >= version.major; 1.62 + if (kinds.contains(kind)) { 1.63 + if (majorVersion > version.major || (majorVersion == version.major && minorVersion >= version.minor)) 1.64 + return true; 1.65 + 1.66 + if (lintClassfile && !warnedAttrs.contains(name)) { 1.67 + JavaFileObject prev = log.useSource(currentClassFile); 1.68 + try { 1.69 + log.warning(LintCategory.CLASSFILE, (DiagnosticPosition) null, "future.attr", 1.70 + name, version.major, version.minor, majorVersion, minorVersion); 1.71 + } finally { 1.72 + log.useSource(prev); 1.73 + } 1.74 + warnedAttrs.add(name); 1.75 + } 1.76 + } 1.77 + return false; 1.78 } 1.79 1.80 abstract void read(Symbol sym, int attrLen); 1.81 @@ -889,7 +918,7 @@ 1.82 1.83 protected Map<Name, AttributeReader> attributeReaders = new HashMap<Name, AttributeReader>(); 1.84 1.85 - protected void initAttributeReaders() { 1.86 + private void initAttributeReaders() { 1.87 AttributeReader[] readers = { 1.88 // v45.3 attributes 1.89 1.90 @@ -1561,7 +1590,7 @@ 1.91 public void accept(Visitor v) { ((ProxyVisitor)v).visitCompoundAnnotationProxy(this); } 1.92 @Override 1.93 public String toString() { 1.94 - StringBuffer buf = new StringBuffer(); 1.95 + StringBuilder buf = new StringBuilder(); 1.96 buf.append("@"); 1.97 buf.append(type.tsym.getQualifiedName()); 1.98 buf.append("/*proxy*/{"); 1.99 @@ -2286,6 +2315,7 @@ 1.100 throw new CompletionFailure(c, "user-selected completion failure by class name"); 1.101 } 1.102 currentOwner = c; 1.103 + warnedAttrs.clear(); 1.104 JavaFileObject classfile = c.classfile; 1.105 if (classfile != null) { 1.106 JavaFileObject previousClassFile = currentClassFile;