Fri, 24 Sep 2010 16:43:08 -0700
Merge
test/tools/javac/T6341023.java | file | annotate | diff | comparison | revisions | |
test/tools/javac/meth/MakeNegTests.sh | file | annotate | diff | comparison | revisions | |
test/tools/javac/quid/MakeNegTests.sh | file | annotate | diff | comparison | revisions | |
test/tools/javac/tree/TreeScannerTest.java | file | annotate | diff | comparison | revisions |
1.1 --- a/make/build.xml Thu Sep 23 17:33:52 2010 -0700 1.2 +++ b/make/build.xml Fri Sep 24 16:43:08 2010 -0700 1.3 @@ -275,6 +275,7 @@ 1.4 failOnError="false" 1.5 errorProperty="findbugs.all.errors" 1.6 warningsProperty="findbugs.all.warnings" 1.7 + jvm="${target.java.home}/bin/java" 1.8 jvmargs="-Xmx512M"> 1.9 <class location="${build.classes.dir}"/> 1.10 <sourcePath> 1.11 @@ -621,7 +622,7 @@ 1.12 <genstubs 1.13 srcdir="${import.jdk.src.dir}" destdir="${build.genstubs.dir}" 1.14 includes="${import.jdk.stub.files}" 1.15 - fork="true" classpath="${build.toolclasses.dir}:${build.bootstrap.dir}/classes:${ant.home}/lib/ant.jar" 1.16 + fork="true" classpath="${build.toolclasses.dir}:${build.bootstrap.dir}/classes:${ant.core.lib}" 1.17 /> 1.18 </target> 1.19 1.20 @@ -673,6 +674,7 @@ 1.21 <filterset begintoken="#" endtoken="#"> 1.22 <filter token="PROGRAM" value="@{name}"/> 1.23 <filter token="TARGET_JAVA" value="@{java}"/> 1.24 + <filter token="PS" value="${path.separator}"/> 1.25 </filterset> 1.26 </copy> 1.27 <chmod file="@{bin.dir}/@{name}" perm="ugo+rx"/> 1.28 @@ -812,7 +814,8 @@ 1.29 executable="${boot.java.home}/bin/javac" 1.30 srcdir="${make.tools.dir}/CompileProperties" 1.31 destdir="${build.toolclasses.dir}/" 1.32 - classpath="${ant.home}/lib/ant.jar"/> 1.33 + classpath="${ant.core.lib}" 1.34 + includeantruntime="false"/> 1.35 <taskdef name="pcompile" 1.36 classname="CompilePropertiesTask" 1.37 classpath="${build.toolclasses.dir}/"/> 1.38 @@ -826,7 +829,8 @@ 1.39 executable="${boot.java.home}/bin/javac" 1.40 srcdir="${make.tools.dir}/GenStubs" 1.41 destdir="${build.toolclasses.dir}/" 1.42 - classpath="${build.bootstrap.dir}/classes:${ant.home}/lib/ant.jar"/> 1.43 + classpath="${build.bootstrap.dir}/classes:${ant.core.lib}" 1.44 + includeantruntime="false"/> 1.45 <taskdef name="genstubs" 1.46 classname="GenStubs$$Ant" 1.47 classpath="${build.toolclasses.dir}/"/> 1.48 @@ -935,7 +939,8 @@ 1.49 <taskdef classpathref="cobertura.classpath" resource="tasks.properties"/> 1.50 </target> 1.51 1.52 - <target name="-def-findbugs" unless="findbugs.defined" depends="-check-findbugs.home"> 1.53 + <target name="-def-findbugs" unless="findbugs.defined" 1.54 + depends="-check-findbugs.home,-check-target.java.home"> 1.55 <taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask"> 1.56 <classpath> 1.57 <pathelement location="${findbugs.home}/lib/findbugs.jar"/> 1.58 @@ -955,6 +960,7 @@ 1.59 failOnError="false" 1.60 errorProperty="findbugs.@{name}.errors" 1.61 warningsProperty="findbugs.@{name}.warnings" 1.62 + jvm="${target.java.home}/bin/java" 1.63 jvmargs="-Xmx512M" > 1.64 <class location="${dist.dir}/lib/@{name}.jar"/> 1.65 <auxClasspath>
2.1 --- a/src/share/bin/launcher.sh-template Thu Sep 23 17:33:52 2010 -0700 2.2 +++ b/src/share/bin/launcher.sh-template Fri Sep 24 16:43:08 2010 -0700 2.3 @@ -40,8 +40,8 @@ 2.4 if [ "$LANGTOOLS_USE_BOOTCLASSPATH" != "no" ]; then 2.5 cp=`unzip -c "$mylib/#PROGRAM#.jar" META-INF/MANIFEST.MF | 2.6 grep "Class-Path:" | 2.7 - sed -e 's|Class-Path: *||' -e 's|\([a-z]*\.jar\) *|'"$mylib"'/\1:|g'` 2.8 - bcp="$mylib/#PROGRAM#.jar":$cp 2.9 + sed -e 's|Class-Path: *||' -e 's|\([a-z]*\.jar\) *|'"$mylib"'/\1#PS#|g'` 2.10 + bcp="$mylib/#PROGRAM#.jar#PS#$cp" 2.11 fi 2.12 2.13 # tools currently assumes that assertions are enabled in the launcher
3.1 --- a/src/share/classes/com/sun/source/tree/Tree.java Thu Sep 23 17:33:52 2010 -0700 3.2 +++ b/src/share/classes/com/sun/source/tree/Tree.java Fri Sep 24 16:43:08 2010 -0700 3.3 @@ -94,7 +94,7 @@ 3.4 CATCH(CatchTree.class), 3.5 3.6 /** 3.7 - * Used for instances of {@link ClassTree}. 3.8 + * Used for instances of {@link ClassTree} representing classes. 3.9 */ 3.10 CLASS(ClassTree.class), 3.11 3.12 @@ -558,6 +558,21 @@ 3.13 ERRONEOUS(ErroneousTree.class), 3.14 3.15 /** 3.16 + * Used for instances of {@link ClassTree} representing interfaces. 3.17 + */ 3.18 + INTERFACE(ClassTree.class), 3.19 + 3.20 + /** 3.21 + * Used for instances of {@link ClassTree} representing enums. 3.22 + */ 3.23 + ENUM(ClassTree.class), 3.24 + 3.25 + /** 3.26 + * Used for instances of {@link ClassTree} representing annotation types. 3.27 + */ 3.28 + ANNOTATION_TYPE(ClassTree.class), 3.29 + 3.30 + /** 3.31 * An implementation-reserved node. This is the not the node 3.32 * you are looking for. 3.33 */
4.1 --- a/src/share/classes/com/sun/source/util/TreeScanner.java Thu Sep 23 17:33:52 2010 -0700 4.2 +++ b/src/share/classes/com/sun/source/util/TreeScanner.java Fri Sep 24 16:43:08 2010 -0700 4.3 @@ -141,6 +141,7 @@ 4.4 r = scanAndReduce(node.getReceiverAnnotations(), p, r); 4.5 r = scanAndReduce(node.getThrows(), p, r); 4.6 r = scanAndReduce(node.getBody(), p, r); 4.7 + r = scanAndReduce(node.getDefaultValue(), p, r); 4.8 return r; 4.9 } 4.10
5.1 --- a/src/share/classes/com/sun/tools/javac/api/JavacTrees.java Thu Sep 23 17:33:52 2010 -0700 5.2 +++ b/src/share/classes/com/sun/tools/javac/api/JavacTrees.java Fri Sep 24 16:43:08 2010 -0700 5.3 @@ -45,6 +45,7 @@ 5.4 import com.sun.source.util.SourcePositions; 5.5 import com.sun.source.util.TreePath; 5.6 import com.sun.source.util.Trees; 5.7 +import com.sun.tools.javac.code.Flags; 5.8 import com.sun.tools.javac.code.Symbol.ClassSymbol; 5.9 import com.sun.tools.javac.code.Symbol.TypeSymbol; 5.10 import com.sun.tools.javac.code.Symbol; 5.11 @@ -189,8 +190,24 @@ 5.12 } 5.13 5.14 public Element getElement(TreePath path) { 5.15 - Tree t = path.getLeaf(); 5.16 - return TreeInfo.symbolFor((JCTree) t); 5.17 + JCTree tree = (JCTree) path.getLeaf(); 5.18 + Symbol sym = TreeInfo.symbolFor(tree); 5.19 + if (sym == null && TreeInfo.isDeclaration(tree)) { 5.20 + for (TreePath p = path; p != null; p = p.getParentPath()) { 5.21 + JCTree t = (JCTree) p.getLeaf(); 5.22 + if (t.getTag() == JCTree.CLASSDEF) { 5.23 + JCClassDecl ct = (JCClassDecl) t; 5.24 + if (ct.sym != null) { 5.25 + if ((ct.sym.flags_field & Flags.UNATTRIBUTED) != 0) { 5.26 + attr.attribClass(ct.pos(), ct.sym); 5.27 + sym = TreeInfo.symbolFor(tree); 5.28 + } 5.29 + break; 5.30 + } 5.31 + } 5.32 + } 5.33 + } 5.34 + return sym; 5.35 } 5.36 5.37 public TypeMirror getTypeMirror(TreePath path) { 5.38 @@ -258,6 +275,8 @@ 5.39 env = enter.getTopLevelEnv((JCCompilationUnit)tree); 5.40 break; 5.41 case CLASS: 5.42 + case INTERFACE: 5.43 + case ENUM: 5.44 // System.err.println("CLASS: " + ((JCClassDecl)tree).sym.getSimpleName()); 5.45 env = enter.getClassEnv(((JCClassDecl)tree).sym); 5.46 break;
6.1 --- a/src/share/classes/com/sun/tools/javac/code/Attribute.java Thu Sep 23 17:33:52 2010 -0700 6.2 +++ b/src/share/classes/com/sun/tools/javac/code/Attribute.java Fri Sep 24 16:43:08 2010 -0700 6.3 @@ -295,4 +295,11 @@ 6.4 void visitEnum(Attribute.Enum e); 6.5 void visitError(Attribute.Error e); 6.6 } 6.7 + 6.8 + /** A mirror of java.lang.annotation.RetentionPolicy. */ 6.9 + public static enum RetentionPolicy { 6.10 + SOURCE, 6.11 + CLASS, 6.12 + RUNTIME 6.13 + } 6.14 }
7.1 --- a/src/share/classes/com/sun/tools/javac/code/Flags.java Thu Sep 23 17:33:52 2010 -0700 7.2 +++ b/src/share/classes/com/sun/tools/javac/code/Flags.java Fri Sep 24 16:43:08 2010 -0700 7.3 @@ -241,6 +241,12 @@ 7.4 */ 7.5 public static final long POLYMORPHIC_SIGNATURE = 1L<<40; 7.6 7.7 + /** 7.8 + * Flag that marks a special kind of bridge methods (the ones that 7.9 + * come from restricted supertype bounds) 7.10 + */ 7.11 + public static final long OVERRIDE_BRIDGE = 1L<<41; 7.12 + 7.13 /** Modifier masks. 7.14 */ 7.15 public static final int
8.1 --- a/src/share/classes/com/sun/tools/javac/code/Scope.java Thu Sep 23 17:33:52 2010 -0700 8.2 +++ b/src/share/classes/com/sun/tools/javac/code/Scope.java Fri Sep 24 16:43:08 2010 -0700 8.3 @@ -272,6 +272,12 @@ 8.4 return false; 8.5 } 8.6 8.7 + static final Filter<Symbol> noFilter = new Filter<Symbol>() { 8.8 + public boolean accepts(Symbol s) { 8.9 + return true; 8.10 + } 8.11 + }; 8.12 + 8.13 /** Return the entry associated with given name, starting in 8.14 * this scope and proceeding outwards. If no entry was found, 8.15 * return the sentinel, which is characterized by having a null in 8.16 @@ -279,13 +285,20 @@ 8.17 * for regular entries. 8.18 */ 8.19 public Entry lookup(Name name) { 8.20 + return lookup(name, noFilter); 8.21 + } 8.22 + public Entry lookup(Name name, Filter<Symbol> sf) { 8.23 Entry e = table[name.hashCode() & hashMask]; 8.24 - while (e.scope != null && e.sym.name != name) 8.25 + while (e.scope != null && (e.sym.name != name || !sf.accepts(e.sym))) 8.26 e = e.shadowed; 8.27 return e; 8.28 } 8.29 8.30 public Iterable<Symbol> getElements() { 8.31 + return getElements(noFilter); 8.32 + } 8.33 + 8.34 + public Iterable<Symbol> getElements(final Filter<Symbol> sf) { 8.35 return new Iterable<Symbol>() { 8.36 public Iterator<Symbol> iterator() { 8.37 return new Iterator<Symbol>() { 8.38 @@ -301,7 +314,9 @@ 8.39 8.40 public Symbol next() { 8.41 Symbol sym = (currEntry == null ? null : currEntry.sym); 8.42 - currEntry = currEntry.sibling; 8.43 + if (currEntry != null) { 8.44 + currEntry = currEntry.sibling; 8.45 + } 8.46 update(); 8.47 return sym; 8.48 } 8.49 @@ -311,9 +326,17 @@ 8.50 } 8.51 8.52 private void update() { 8.53 + skipToNextMatchingEntry(); 8.54 while (currEntry == null && currScope.next != null) { 8.55 currScope = currScope.next; 8.56 currEntry = currScope.elems; 8.57 + skipToNextMatchingEntry(); 8.58 + } 8.59 + } 8.60 + 8.61 + void skipToNextMatchingEntry() { 8.62 + while (currEntry != null && !sf.accepts(currEntry.sym)) { 8.63 + currEntry = currEntry.sibling; 8.64 } 8.65 } 8.66 };
9.1 --- a/src/share/classes/com/sun/tools/javac/code/Source.java Thu Sep 23 17:33:52 2010 -0700 9.2 +++ b/src/share/classes/com/sun/tools/javac/code/Source.java Fri Sep 24 16:43:08 2010 -0700 9.3 @@ -171,11 +171,10 @@ 9.4 public boolean allowUnderscoresInLiterals() { 9.5 return compareTo(JDK1_7) >= 0; 9.6 } 9.7 - public boolean allowStringsInSwitch() { 9.8 + public boolean allowExoticIdentifiers() { 9.9 return compareTo(JDK1_7) >= 0; 9.10 } 9.11 - // JSR 292: recognize @PolymorphicSignature on java/dyn names 9.12 - public boolean allowPolymorphicSignature() { 9.13 + public boolean allowStringsInSwitch() { 9.14 return compareTo(JDK1_7) >= 0; 9.15 } 9.16 public static SourceVersion toSourceVersion(Source source) {
10.1 --- a/src/share/classes/com/sun/tools/javac/code/Symbol.java Thu Sep 23 17:33:52 2010 -0700 10.2 +++ b/src/share/classes/com/sun/tools/javac/code/Symbol.java Fri Sep 24 16:43:08 2010 -0700 10.3 @@ -214,6 +214,16 @@ 10.4 return (flags() & INTERFACE) != 0; 10.5 } 10.6 10.7 + /** Recognize if this symbol was marked @PolymorphicSignature in the source. */ 10.8 + public boolean isPolymorphicSignatureGeneric() { 10.9 + return (flags() & (POLYMORPHIC_SIGNATURE | HYPOTHETICAL)) == POLYMORPHIC_SIGNATURE; 10.10 + } 10.11 + 10.12 + /** Recognize if this symbol was split from a @PolymorphicSignature symbol in the source. */ 10.13 + public boolean isPolymorphicSignatureInstance() { 10.14 + return (flags() & (POLYMORPHIC_SIGNATURE | HYPOTHETICAL)) == (POLYMORPHIC_SIGNATURE | HYPOTHETICAL); 10.15 + } 10.16 + 10.17 /** Is this symbol declared (directly or indirectly) local 10.18 * to a method or variable initializer? 10.19 * Also includes fields of inner classes which are in 10.20 @@ -579,6 +589,9 @@ 10.21 10.22 public java.util.List<Symbol> getEnclosedElements() { 10.23 List<Symbol> list = List.nil(); 10.24 + if (kind == TYP && type.tag == TYPEVAR) { 10.25 + return list; 10.26 + } 10.27 for (Scope.Entry e = members().elems; e != null; e = e.sibling) { 10.28 if (e.sym != null && (e.sym.flags() & SYNTHETIC) == 0 && e.sym.owner == this) 10.29 list = list.prepend(e.sym); 10.30 @@ -1214,7 +1227,18 @@ 10.31 * as possible implementations. 10.32 */ 10.33 public MethodSymbol implementation(TypeSymbol origin, Types types, boolean checkResult) { 10.34 - MethodSymbol res = types.implementation(this, origin, types, checkResult); 10.35 + return implementation(origin, types, checkResult, implementation_filter); 10.36 + } 10.37 + // where 10.38 + private static final Filter<Symbol> implementation_filter = new Filter<Symbol>() { 10.39 + public boolean accepts(Symbol s) { 10.40 + return s.kind == Kinds.MTH && 10.41 + (s.flags() & SYNTHETIC) == 0; 10.42 + } 10.43 + }; 10.44 + 10.45 + public MethodSymbol implementation(TypeSymbol origin, Types types, boolean checkResult, Filter<Symbol> implFilter) { 10.46 + MethodSymbol res = types.implementation(this, origin, types, checkResult, implFilter); 10.47 if (res != null) 10.48 return res; 10.49 // if origin is derived from a raw type, we might have missed
11.1 --- a/src/share/classes/com/sun/tools/javac/code/Symtab.java Thu Sep 23 17:33:52 2010 -0700 11.2 +++ b/src/share/classes/com/sun/tools/javac/code/Symtab.java Fri Sep 24 16:43:08 2010 -0700 11.3 @@ -93,6 +93,10 @@ 11.4 */ 11.5 public final ClassSymbol errSymbol; 11.6 11.7 + /** The unknown symbol. 11.8 + */ 11.9 + public final ClassSymbol unknownSymbol; 11.10 + 11.11 /** A value for the errType, with a originalType of noType */ 11.12 public final Type errType; 11.13 11.14 @@ -354,6 +358,7 @@ 11.15 11.16 // create the error symbols 11.17 errSymbol = new ClassSymbol(PUBLIC|STATIC|ACYCLIC, names.any, null, rootPackage); 11.18 + unknownSymbol = new ClassSymbol(PUBLIC|STATIC|ACYCLIC, names.fromString("<any?>"), null, rootPackage); 11.19 errType = new ErrorType(errSymbol, Type.noType); 11.20 11.21 // initialize builtin types 11.22 @@ -368,7 +373,7 @@ 11.23 initType(voidType, "void", "Void"); 11.24 initType(botType, "<nulltype>"); 11.25 initType(errType, errSymbol); 11.26 - initType(unknownType, "<any?>"); 11.27 + initType(unknownType, unknownSymbol); 11.28 11.29 // the builtin class of all arrays 11.30 arrayClass = new ClassSymbol(PUBLIC|ACYCLIC, names.Array, noSymbol);
12.1 --- a/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java Thu Sep 23 17:33:52 2010 -0700 12.2 +++ b/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java Fri Sep 24 16:43:08 2010 -0700 12.3 @@ -114,6 +114,8 @@ 12.4 return p; 12.5 12.6 case CLASS: 12.7 + case INTERFACE: 12.8 + case ENUM: 12.9 p.pos = frame.pos; 12.10 if (((JCClassDecl)frame).extending == tree) { 12.11 p.type = TargetType.CLASS_EXTENDS;
13.1 --- a/src/share/classes/com/sun/tools/javac/code/Types.java Thu Sep 23 17:33:52 2010 -0700 13.2 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java Fri Sep 24 16:43:08 2010 -0700 13.3 @@ -32,6 +32,7 @@ 13.4 import com.sun.tools.javac.util.List; 13.5 13.6 import com.sun.tools.javac.jvm.ClassReader; 13.7 +import com.sun.tools.javac.code.Attribute.RetentionPolicy; 13.8 import com.sun.tools.javac.comp.Check; 13.9 13.10 import static com.sun.tools.javac.code.Type.*; 13.11 @@ -914,7 +915,7 @@ 13.12 return true; 13.13 13.14 if (t.isPrimitive() != s.isPrimitive()) 13.15 - return allowBoxing && isConvertible(t, s, warn); 13.16 + return allowBoxing && (isConvertible(t, s, warn) || isConvertible(s, t, warn)); 13.17 13.18 if (warn != warnStack.head) { 13.19 try { 13.20 @@ -1973,45 +1974,74 @@ 13.21 hasSameArgs(t, erasure(s)) || hasSameArgs(erasure(t), s); 13.22 } 13.23 13.24 - private WeakHashMap<MethodSymbol, SoftReference<Map<TypeSymbol, MethodSymbol>>> implCache_check = 13.25 - new WeakHashMap<MethodSymbol, SoftReference<Map<TypeSymbol, MethodSymbol>>>(); 13.26 - 13.27 - private WeakHashMap<MethodSymbol, SoftReference<Map<TypeSymbol, MethodSymbol>>> implCache_nocheck = 13.28 - new WeakHashMap<MethodSymbol, SoftReference<Map<TypeSymbol, MethodSymbol>>>(); 13.29 - 13.30 - public MethodSymbol implementation(MethodSymbol ms, TypeSymbol origin, Types types, boolean checkResult) { 13.31 - Map<MethodSymbol, SoftReference<Map<TypeSymbol, MethodSymbol>>> implCache = checkResult ? 13.32 - implCache_check : implCache_nocheck; 13.33 - SoftReference<Map<TypeSymbol, MethodSymbol>> ref_cache = implCache.get(ms); 13.34 - Map<TypeSymbol, MethodSymbol> cache = ref_cache != null ? ref_cache.get() : null; 13.35 - if (cache == null) { 13.36 - cache = new HashMap<TypeSymbol, MethodSymbol>(); 13.37 - implCache.put(ms, new SoftReference<Map<TypeSymbol, MethodSymbol>>(cache)); 13.38 + // <editor-fold defaultstate="collapsed" desc="Determining method implementation in given site"> 13.39 + class ImplementationCache { 13.40 + 13.41 + private WeakHashMap<MethodSymbol, SoftReference<Map<TypeSymbol, Entry>>> _map = 13.42 + new WeakHashMap<MethodSymbol, SoftReference<Map<TypeSymbol, Entry>>>(); 13.43 + 13.44 + class Entry { 13.45 + final MethodSymbol cachedImpl; 13.46 + final Filter<Symbol> implFilter; 13.47 + final boolean checkResult; 13.48 + 13.49 + public Entry(MethodSymbol cachedImpl, 13.50 + Filter<Symbol> scopeFilter, 13.51 + boolean checkResult) { 13.52 + this.cachedImpl = cachedImpl; 13.53 + this.implFilter = scopeFilter; 13.54 + this.checkResult = checkResult; 13.55 + } 13.56 + 13.57 + boolean matches(Filter<Symbol> scopeFilter, boolean checkResult) { 13.58 + return this.implFilter == scopeFilter && 13.59 + this.checkResult == checkResult; 13.60 + } 13.61 } 13.62 - MethodSymbol impl = cache.get(origin); 13.63 - if (impl == null) { 13.64 + 13.65 + MethodSymbol get(MethodSymbol ms, TypeSymbol origin, boolean checkResult, Filter<Symbol> implFilter) { 13.66 + SoftReference<Map<TypeSymbol, Entry>> ref_cache = _map.get(ms); 13.67 + Map<TypeSymbol, Entry> cache = ref_cache != null ? ref_cache.get() : null; 13.68 + if (cache == null) { 13.69 + cache = new HashMap<TypeSymbol, Entry>(); 13.70 + _map.put(ms, new SoftReference<Map<TypeSymbol, Entry>>(cache)); 13.71 + } 13.72 + Entry e = cache.get(origin); 13.73 + if (e == null || 13.74 + !e.matches(implFilter, checkResult)) { 13.75 + MethodSymbol impl = implementationInternal(ms, origin, Types.this, checkResult, implFilter); 13.76 + cache.put(origin, new Entry(impl, implFilter, checkResult)); 13.77 + return impl; 13.78 + } 13.79 + else { 13.80 + return e.cachedImpl; 13.81 + } 13.82 + } 13.83 + 13.84 + private MethodSymbol implementationInternal(MethodSymbol ms, TypeSymbol origin, Types types, boolean checkResult, Filter<Symbol> implFilter) { 13.85 for (Type t = origin.type; t.tag == CLASS || t.tag == TYPEVAR; t = types.supertype(t)) { 13.86 while (t.tag == TYPEVAR) 13.87 t = t.getUpperBound(); 13.88 TypeSymbol c = t.tsym; 13.89 - for (Scope.Entry e = c.members().lookup(ms.name); 13.90 + for (Scope.Entry e = c.members().lookup(ms.name, implFilter); 13.91 e.scope != null; 13.92 e = e.next()) { 13.93 - if (e.sym.kind == Kinds.MTH) { 13.94 - MethodSymbol m = (MethodSymbol) e.sym; 13.95 - if (m.overrides(ms, origin, types, checkResult) && 13.96 - (m.flags() & SYNTHETIC) == 0) { 13.97 - impl = m; 13.98 - cache.put(origin, m); 13.99 - return impl; 13.100 - } 13.101 - } 13.102 + if (e.sym != null && 13.103 + e.sym.overrides(ms, origin, types, checkResult)) 13.104 + return (MethodSymbol)e.sym; 13.105 } 13.106 } 13.107 + return null; 13.108 } 13.109 - return impl; 13.110 } 13.111 13.112 + private ImplementationCache implCache = new ImplementationCache(); 13.113 + 13.114 + public MethodSymbol implementation(MethodSymbol ms, TypeSymbol origin, Types types, boolean checkResult, Filter<Symbol> implFilter) { 13.115 + return implCache.get(ms, origin, checkResult, implFilter); 13.116 + } 13.117 + // </editor-fold> 13.118 + 13.119 /** 13.120 * Does t have the same arguments as s? It is assumed that both 13.121 * types are (possibly polymorphic) method types. Monomorphic 13.122 @@ -3554,4 +3584,24 @@ 13.123 public Type visitType(Type t, S s) { return t; } 13.124 } 13.125 // </editor-fold> 13.126 + 13.127 + 13.128 + // <editor-fold defaultstate="collapsed" desc="Annotation support"> 13.129 + 13.130 + public RetentionPolicy getRetention(Attribute.Compound a) { 13.131 + RetentionPolicy vis = RetentionPolicy.CLASS; // the default 13.132 + Attribute.Compound c = a.type.tsym.attribute(syms.retentionType.tsym); 13.133 + if (c != null) { 13.134 + Attribute value = c.member(names.value); 13.135 + if (value != null && value instanceof Attribute.Enum) { 13.136 + Name levelName = ((Attribute.Enum)value).value.name; 13.137 + if (levelName == names.SOURCE) vis = RetentionPolicy.SOURCE; 13.138 + else if (levelName == names.CLASS) vis = RetentionPolicy.CLASS; 13.139 + else if (levelName == names.RUNTIME) vis = RetentionPolicy.RUNTIME; 13.140 + else ;// /* fail soft */ throw new AssertionError(levelName); 13.141 + } 13.142 + } 13.143 + return vis; 13.144 + } 13.145 + // </editor-fold> 13.146 }
14.1 --- a/src/share/classes/com/sun/tools/javac/comp/Annotate.java Thu Sep 23 17:33:52 2010 -0700 14.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Annotate.java Fri Sep 24 16:43:08 2010 -0700 14.3 @@ -182,6 +182,7 @@ 14.4 if (!method.type.isErroneous()) 14.5 buf.append(new Pair<MethodSymbol,Attribute> 14.6 ((MethodSymbol)method, value)); 14.7 + t.type = result; 14.8 } 14.9 return new Attribute.Compound(a.type, buf.toList()); 14.10 } 14.11 @@ -234,6 +235,7 @@ 14.12 l.head, 14.13 env)); 14.14 } 14.15 + na.type = expected; 14.16 return new Attribute. 14.17 Array(expected, buf.toArray(new Attribute[buf.length()])); 14.18 }
15.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Thu Sep 23 17:33:52 2010 -0700 15.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Fri Sep 24 16:43:08 2010 -0700 15.3 @@ -328,6 +328,12 @@ 15.4 attribExpr(expr, env); 15.5 } catch (BreakAttr b) { 15.6 return b.env; 15.7 + } catch (AssertionError ae) { 15.8 + if (ae.getCause() instanceof BreakAttr) { 15.9 + return ((BreakAttr)(ae.getCause())).env; 15.10 + } else { 15.11 + throw ae; 15.12 + } 15.13 } finally { 15.14 breakTree = null; 15.15 log.useSource(prev); 15.16 @@ -342,6 +348,12 @@ 15.17 attribStat(stmt, env); 15.18 } catch (BreakAttr b) { 15.19 return b.env; 15.20 + } catch (AssertionError ae) { 15.21 + if (ae.getCause() instanceof BreakAttr) { 15.22 + return ((BreakAttr)(ae.getCause())).env; 15.23 + } else { 15.24 + throw ae; 15.25 + } 15.26 } finally { 15.27 breakTree = null; 15.28 log.useSource(prev); 15.29 @@ -578,6 +590,8 @@ 15.30 boolean classExpected, 15.31 boolean interfaceExpected, 15.32 boolean checkExtensible) { 15.33 + if (t.isErroneous()) 15.34 + return t; 15.35 if (t.tag == TYPEVAR && !classExpected && !interfaceExpected) { 15.36 // check that type variable is already visible 15.37 if (t.getUpperBound() == null) { 15.38 @@ -595,7 +609,7 @@ 15.39 } else if (checkExtensible && 15.40 classExpected && 15.41 (t.tsym.flags() & INTERFACE) != 0) { 15.42 - log.error(tree.pos(), "no.intf.expected.here"); 15.43 + log.error(tree.pos(), "no.intf.expected.here"); 15.44 return types.createErrorType(t); 15.45 } 15.46 if (checkExtensible && 15.47 @@ -1171,7 +1185,10 @@ 15.48 } 15.49 15.50 public void visitExec(JCExpressionStatement tree) { 15.51 - attribExpr(tree.expr, env); 15.52 + //a fresh environment is required for 292 inference to work properly --- 15.53 + //see Infer.instantiatePolymorphicSignatureInstance() 15.54 + Env<AttrContext> localEnv = env.dup(tree); 15.55 + attribExpr(tree.expr, localEnv); 15.56 result = null; 15.57 } 15.58 15.59 @@ -1429,23 +1446,19 @@ 15.60 restype.tsym); 15.61 } 15.62 15.63 - // as a special case, MethodHandle.<T>invoke(abc) and InvokeDynamic.<T>foo(abc) 15.64 - // has type <T>, and T can be a primitive type. 15.65 - if (tree.meth.getTag() == JCTree.SELECT && !typeargtypes.isEmpty()) { 15.66 - JCFieldAccess mfield = (JCFieldAccess) tree.meth; 15.67 - if ((mfield.selected.type.tsym != null && 15.68 - (mfield.selected.type.tsym.flags() & POLYMORPHIC_SIGNATURE) != 0) 15.69 - || 15.70 - (mfield.sym != null && 15.71 - (mfield.sym.flags() & POLYMORPHIC_SIGNATURE) != 0)) { 15.72 - assert types.isSameType(restype, typeargtypes.head) : mtype; 15.73 - assert mfield.selected.type == syms.methodHandleType 15.74 - || mfield.selected.type == syms.invokeDynamicType; 15.75 - typeargtypesNonRefOK = true; 15.76 - } 15.77 + // Special case logic for JSR 292 types. 15.78 + if (rs.allowTransitionalJSR292 && 15.79 + tree.meth.getTag() == JCTree.SELECT && 15.80 + !typeargtypes.isEmpty()) { 15.81 + JCFieldAccess mfield = (JCFieldAccess) tree.meth; 15.82 + // MethodHandle.<T>invoke(abc) and InvokeDynamic.<T>foo(abc) 15.83 + // has type <T>, and T can be a primitive type. 15.84 + if (mfield.sym != null && 15.85 + mfield.sym.isPolymorphicSignatureInstance()) 15.86 + typeargtypesNonRefOK = true; 15.87 } 15.88 15.89 - if (!typeargtypesNonRefOK) { 15.90 + if (!(rs.allowTransitionalJSR292 && typeargtypesNonRefOK)) { 15.91 chk.checkRefTypes(tree.typeargs, typeargtypes); 15.92 } 15.93 15.94 @@ -2009,7 +2022,10 @@ 15.95 public void visitTypeCast(JCTypeCast tree) { 15.96 Type clazztype = attribType(tree.clazz, env); 15.97 chk.validate(tree.clazz, env, false); 15.98 - Type exprtype = attribExpr(tree.expr, env, Infer.anyPoly); 15.99 + //a fresh environment is required for 292 inference to work properly --- 15.100 + //see Infer.instantiatePolymorphicSignatureInstance() 15.101 + Env<AttrContext> localEnv = env.dup(tree); 15.102 + Type exprtype = attribExpr(tree.expr, localEnv, Infer.anyPoly); 15.103 Type owntype = chk.checkCastable(tree.expr.pos(), exprtype, clazztype); 15.104 if (exprtype.constValue() != null) 15.105 owntype = cfolder.coerce(exprtype, owntype); 15.106 @@ -2845,7 +2861,6 @@ 15.107 if (tree.bounds.tail.nonEmpty()) { 15.108 log.error(tree.bounds.tail.head.pos(), 15.109 "type.var.may.not.be.followed.by.other.bounds"); 15.110 - log.unrecoverableError = true; 15.111 tree.bounds = List.of(tree.bounds.head); 15.112 a.bound = bs.head; 15.113 } 15.114 @@ -3186,4 +3201,104 @@ 15.115 super.visitMethodDef(tree); 15.116 } 15.117 }; 15.118 + 15.119 + // <editor-fold desc="post-attribution visitor"> 15.120 + 15.121 + /** 15.122 + * Handle missing types/symbols in an AST. This routine is useful when 15.123 + * the compiler has encountered some errors (which might have ended up 15.124 + * terminating attribution abruptly); if the compiler is used in fail-over 15.125 + * mode (e.g. by an IDE) and the AST contains semantic errors, this routine 15.126 + * prevents NPE to be progagated during subsequent compilation steps. 15.127 + */ 15.128 + public void postAttr(Env<AttrContext> env) { 15.129 + new PostAttrAnalyzer().scan(env.tree); 15.130 + } 15.131 + 15.132 + class PostAttrAnalyzer extends TreeScanner { 15.133 + 15.134 + private void initTypeIfNeeded(JCTree that) { 15.135 + if (that.type == null) { 15.136 + that.type = syms.unknownType; 15.137 + } 15.138 + } 15.139 + 15.140 + @Override 15.141 + public void scan(JCTree tree) { 15.142 + if (tree == null) return; 15.143 + if (tree instanceof JCExpression) { 15.144 + initTypeIfNeeded(tree); 15.145 + } 15.146 + super.scan(tree); 15.147 + } 15.148 + 15.149 + @Override 15.150 + public void visitIdent(JCIdent that) { 15.151 + if (that.sym == null) { 15.152 + that.sym = syms.unknownSymbol; 15.153 + } 15.154 + } 15.155 + 15.156 + @Override 15.157 + public void visitSelect(JCFieldAccess that) { 15.158 + if (that.sym == null) { 15.159 + that.sym = syms.unknownSymbol; 15.160 + } 15.161 + super.visitSelect(that); 15.162 + } 15.163 + 15.164 + @Override 15.165 + public void visitClassDef(JCClassDecl that) { 15.166 + initTypeIfNeeded(that); 15.167 + if (that.sym == null) { 15.168 + that.sym = new ClassSymbol(0, that.name, that.type, syms.noSymbol); 15.169 + } 15.170 + super.visitClassDef(that); 15.171 + } 15.172 + 15.173 + @Override 15.174 + public void visitMethodDef(JCMethodDecl that) { 15.175 + initTypeIfNeeded(that); 15.176 + if (that.sym == null) { 15.177 + that.sym = new MethodSymbol(0, that.name, that.type, syms.noSymbol); 15.178 + } 15.179 + super.visitMethodDef(that); 15.180 + } 15.181 + 15.182 + @Override 15.183 + public void visitVarDef(JCVariableDecl that) { 15.184 + initTypeIfNeeded(that); 15.185 + if (that.sym == null) { 15.186 + that.sym = new VarSymbol(0, that.name, that.type, syms.noSymbol); 15.187 + that.sym.adr = 0; 15.188 + } 15.189 + super.visitVarDef(that); 15.190 + } 15.191 + 15.192 + @Override 15.193 + public void visitNewClass(JCNewClass that) { 15.194 + if (that.constructor == null) { 15.195 + that.constructor = new MethodSymbol(0, names.init, syms.unknownType, syms.noSymbol); 15.196 + } 15.197 + if (that.constructorType == null) { 15.198 + that.constructorType = syms.unknownType; 15.199 + } 15.200 + super.visitNewClass(that); 15.201 + } 15.202 + 15.203 + @Override 15.204 + public void visitBinary(JCBinary that) { 15.205 + if (that.operator == null) 15.206 + that.operator = new OperatorSymbol(names.empty, syms.unknownType, -1, syms.noSymbol); 15.207 + super.visitBinary(that); 15.208 + } 15.209 + 15.210 + @Override 15.211 + public void visitUnary(JCUnary that) { 15.212 + if (that.operator == null) 15.213 + that.operator = new OperatorSymbol(names.empty, syms.unknownType, -1, syms.noSymbol); 15.214 + super.visitUnary(that); 15.215 + } 15.216 + } 15.217 + // </editor-fold> 15.218 }
16.1 --- a/src/share/classes/com/sun/tools/javac/comp/Enter.java Thu Sep 23 17:33:52 2010 -0700 16.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Enter.java Fri Sep 24 16:43:08 2010 -0700 16.3 @@ -38,6 +38,7 @@ 16.4 16.5 import com.sun.tools.javac.code.Type.*; 16.6 import com.sun.tools.javac.code.Symbol.*; 16.7 +import com.sun.tools.javac.main.RecognizedOptions.PkgInfo; 16.8 import com.sun.tools.javac.tree.JCTree.*; 16.9 16.10 import static com.sun.tools.javac.code.Flags.*; 16.11 @@ -102,6 +103,7 @@ 16.12 Lint lint; 16.13 Names names; 16.14 JavaFileManager fileManager; 16.15 + PkgInfo pkginfoOpt; 16.16 16.17 private final Todo todo; 16.18 16.19 @@ -132,6 +134,9 @@ 16.20 predefClassDef.sym = syms.predefClass; 16.21 todo = Todo.instance(context); 16.22 fileManager = context.get(JavaFileManager.class); 16.23 + 16.24 + Options options = Options.instance(context); 16.25 + pkginfoOpt = PkgInfo.get(options); 16.26 } 16.27 16.28 /** A hashtable mapping classes and packages to the environments current 16.29 @@ -278,7 +283,7 @@ 16.30 JavaFileObject.Kind.SOURCE); 16.31 if (tree.pid != null) { 16.32 tree.packge = reader.enterPackage(TreeInfo.fullName(tree.pid)); 16.33 - if (tree.packageAnnotations.nonEmpty()) { 16.34 + if (tree.packageAnnotations.nonEmpty() || pkginfoOpt == PkgInfo.ALWAYS) { 16.35 if (isPkgInfo) { 16.36 addEnv = true; 16.37 } else {
17.1 --- a/src/share/classes/com/sun/tools/javac/comp/Flow.java Thu Sep 23 17:33:52 2010 -0700 17.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Flow.java Fri Sep 24 16:43:08 2010 -0700 17.3 @@ -408,7 +408,9 @@ 17.4 tree = TreeInfo.skipParens(tree); 17.5 if (tree.getTag() == JCTree.IDENT || tree.getTag() == JCTree.SELECT) { 17.6 Symbol sym = TreeInfo.symbol(tree); 17.7 - letInit(tree.pos(), (VarSymbol)sym); 17.8 + if (sym.kind == VAR) { 17.9 + letInit(tree.pos(), (VarSymbol)sym); 17.10 + } 17.11 } 17.12 } 17.13 17.14 @@ -481,12 +483,13 @@ 17.15 17.16 /** Split (duplicate) inits/uninits into WhenTrue/WhenFalse sets 17.17 */ 17.18 - void split() { 17.19 + void split(boolean setToNull) { 17.20 initsWhenFalse = inits.dup(); 17.21 uninitsWhenFalse = uninits.dup(); 17.22 initsWhenTrue = inits; 17.23 uninitsWhenTrue = uninits; 17.24 - inits = uninits = null; 17.25 + if (setToNull) 17.26 + inits = uninits = null; 17.27 } 17.28 17.29 /** Merge (intersect) inits/uninits from WhenTrue/WhenFalse sets. 17.30 @@ -568,9 +571,11 @@ 17.31 uninitsWhenTrue = uninits; 17.32 } else { 17.33 scan(tree); 17.34 - if (inits != null) split(); 17.35 + if (inits != null) 17.36 + split(tree.type != syms.unknownType); 17.37 } 17.38 - inits = uninits = null; 17.39 + if (tree.type != syms.unknownType) 17.40 + inits = uninits = null; 17.41 } 17.42 17.43 /* ------------ Visitor methods for various sorts of trees -------------*/ 17.44 @@ -1007,7 +1012,7 @@ 17.45 List.of(resource.type); 17.46 for (Type sup : closeableSupertypes) { 17.47 if (types.asSuper(sup, syms.autoCloseableType.tsym) != null) { 17.48 - Symbol closeMethod = rs.resolveInternalMethod(tree, 17.49 + Symbol closeMethod = rs.resolveQualifiedMethod(tree, 17.50 attrEnv, 17.51 sup, 17.52 names.close, 17.53 @@ -1050,20 +1055,22 @@ 17.54 List<Type> rethrownTypes = chk.diff(thrownInTry, caughtInTry); 17.55 for (JCExpression ct : subClauses) { 17.56 Type exc = ct.type; 17.57 - ctypes = ctypes.append(exc); 17.58 - if (types.isSameType(exc, syms.objectType)) 17.59 - continue; 17.60 - if (chk.subset(exc, caughtInTry)) { 17.61 - log.error(l.head.pos(), 17.62 - "except.already.caught", exc); 17.63 - } else if (!chk.isUnchecked(l.head.pos(), exc) && 17.64 - exc.tsym != syms.throwableType.tsym && 17.65 - exc.tsym != syms.exceptionType.tsym && 17.66 - !chk.intersects(exc, thrownInTry)) { 17.67 - log.error(l.head.pos(), 17.68 - "except.never.thrown.in.try", exc); 17.69 + if (exc != syms.unknownType) { 17.70 + ctypes = ctypes.append(exc); 17.71 + if (types.isSameType(exc, syms.objectType)) 17.72 + continue; 17.73 + if (chk.subset(exc, caughtInTry)) { 17.74 + log.error(l.head.pos(), 17.75 + "except.already.caught", exc); 17.76 + } else if (!chk.isUnchecked(l.head.pos(), exc) && 17.77 + exc.tsym != syms.throwableType.tsym && 17.78 + exc.tsym != syms.exceptionType.tsym && 17.79 + !chk.intersects(exc, thrownInTry)) { 17.80 + log.error(l.head.pos(), 17.81 + "except.never.thrown.in.try", exc); 17.82 + } 17.83 + caughtInTry = chk.incl(exc, caughtInTry); 17.84 } 17.85 - caughtInTry = chk.incl(exc, caughtInTry); 17.86 } 17.87 inits = initsTry.dup(); 17.88 uninits = uninitsTry.dup();
18.1 --- a/src/share/classes/com/sun/tools/javac/comp/Infer.java Thu Sep 23 17:33:52 2010 -0700 18.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Infer.java Fri Sep 24 16:43:08 2010 -0700 18.3 @@ -25,6 +25,8 @@ 18.4 18.5 package com.sun.tools.javac.comp; 18.6 18.7 +import com.sun.tools.javac.tree.JCTree; 18.8 +import com.sun.tools.javac.tree.JCTree.JCTypeCast; 18.9 import com.sun.tools.javac.util.*; 18.10 import com.sun.tools.javac.util.List; 18.11 import com.sun.tools.javac.code.*; 18.12 @@ -543,4 +545,56 @@ 18.13 args.head, bounds); 18.14 } 18.15 } 18.16 + 18.17 + /** 18.18 + * Compute a synthetic method type corresponding to the requested polymorphic 18.19 + * method signature. If no explicit return type is supplied, a provisional 18.20 + * return type is computed (just Object in case of non-transitional 292) 18.21 + */ 18.22 + Type instantiatePolymorphicSignatureInstance(Env<AttrContext> env, Type site, 18.23 + Name name, 18.24 + MethodSymbol spMethod, // sig. poly. method or null if none 18.25 + List<Type> argtypes, 18.26 + List<Type> typeargtypes) { 18.27 + final Type restype; 18.28 + if (rs.allowTransitionalJSR292 && typeargtypes.nonEmpty()) { 18.29 + restype = typeargtypes.head; 18.30 + } else { 18.31 + //The return type for a polymorphic signature call is computed from 18.32 + //the enclosing tree E, as follows: if E is a cast, then use the 18.33 + //target type of the cast expression as a return type; if E is an 18.34 + //expression statement, the return type is 'void' - otherwise the 18.35 + //return type is simply 'Object'. 18.36 + switch (env.outer.tree.getTag()) { 18.37 + case JCTree.TYPECAST: 18.38 + restype = ((JCTypeCast)env.outer.tree).clazz.type; break; 18.39 + case JCTree.EXEC: 18.40 + restype = syms.voidType; break; 18.41 + default: 18.42 + restype = syms.objectType; 18.43 + } 18.44 + } 18.45 + 18.46 + List<Type> paramtypes = Type.map(argtypes, implicitArgType); 18.47 + List<Type> exType = spMethod != null ? 18.48 + spMethod.getThrownTypes() : 18.49 + List.of(syms.throwableType); // make it throw all exceptions 18.50 + 18.51 + MethodType mtype = new MethodType(paramtypes, 18.52 + restype, 18.53 + exType, 18.54 + syms.methodClass); 18.55 + return mtype; 18.56 + } 18.57 + //where 18.58 + Mapping implicitArgType = new Mapping ("implicitArgType") { 18.59 + public Type apply(Type t) { 18.60 + t = types.erasure(t); 18.61 + if (t.tag == BOT) 18.62 + // nulls type as the marker type Null (which has no instances) 18.63 + // infer as java.lang.Void for now 18.64 + t = types.boxedClass(syms.voidType).type; 18.65 + return t; 18.66 + } 18.67 + }; 18.68 }
19.1 --- a/src/share/classes/com/sun/tools/javac/comp/Lower.java Thu Sep 23 17:33:52 2010 -0700 19.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Lower.java Fri Sep 24 16:43:08 2010 -0700 19.3 @@ -29,6 +29,7 @@ 19.4 19.5 import com.sun.tools.javac.code.*; 19.6 import com.sun.tools.javac.jvm.*; 19.7 +import com.sun.tools.javac.main.RecognizedOptions.PkgInfo; 19.8 import com.sun.tools.javac.tree.*; 19.9 import com.sun.tools.javac.util.*; 19.10 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; 19.11 @@ -82,6 +83,7 @@ 19.12 private final Name classDollar; 19.13 private Types types; 19.14 private boolean debugLower; 19.15 + private PkgInfo pkginfoOpt; 19.16 19.17 protected Lower(Context context) { 19.18 context.put(lowerKey, this); 19.19 @@ -106,6 +108,7 @@ 19.20 types = Types.instance(context); 19.21 Options options = Options.instance(context); 19.22 debugLower = options.get("debuglower") != null; 19.23 + pkginfoOpt = PkgInfo.get(options); 19.24 } 19.25 19.26 /** The currently enclosing class. 19.27 @@ -2161,7 +2164,7 @@ 19.28 } 19.29 19.30 public void visitTopLevel(JCCompilationUnit tree) { 19.31 - if (tree.packageAnnotations.nonEmpty()) { 19.32 + if (needPackageInfoClass(tree)) { 19.33 Name name = names.package_info; 19.34 long flags = Flags.ABSTRACT | Flags.INTERFACE; 19.35 if (target.isPackageInfoSynthetic()) 19.36 @@ -2183,6 +2186,23 @@ 19.37 translated.append(packageAnnotationsClass); 19.38 } 19.39 } 19.40 + // where 19.41 + private boolean needPackageInfoClass(JCCompilationUnit tree) { 19.42 + switch (pkginfoOpt) { 19.43 + case ALWAYS: 19.44 + return true; 19.45 + case LEGACY: 19.46 + return tree.packageAnnotations.nonEmpty(); 19.47 + case NONEMPTY: 19.48 + for (Attribute.Compound a: tree.packge.attributes_field) { 19.49 + Attribute.RetentionPolicy p = types.getRetention(a); 19.50 + if (p != Attribute.RetentionPolicy.SOURCE) 19.51 + return true; 19.52 + } 19.53 + return false; 19.54 + } 19.55 + throw new AssertionError(); 19.56 + } 19.57 19.58 public void visitClassDef(JCClassDecl tree) { 19.59 ClassSymbol currentClassPrev = currentClass; 19.60 @@ -2869,8 +2889,17 @@ 19.61 /** Unbox an object to a primitive value. */ 19.62 JCExpression unbox(JCExpression tree, Type primitive) { 19.63 Type unboxedType = types.unboxedType(tree.type); 19.64 - // note: the "primitive" parameter is not used. There muse be 19.65 - // a conversion from unboxedType to primitive. 19.66 + if (unboxedType.tag == NONE) { 19.67 + unboxedType = primitive; 19.68 + if (!unboxedType.isPrimitive()) 19.69 + throw new AssertionError(unboxedType); 19.70 + make_at(tree.pos()); 19.71 + tree = make.TypeCast(types.boxedClass(unboxedType).type, tree); 19.72 + } else { 19.73 + // There must be a conversion from unboxedType to primitive. 19.74 + if (!types.isSubtype(unboxedType, primitive)) 19.75 + throw new AssertionError(tree); 19.76 + } 19.77 make_at(tree.pos()); 19.78 Symbol valueSym = lookupMethod(tree.pos(), 19.79 unboxedType.tsym.name.append(names.Value), // x.intValue()
20.1 --- a/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Thu Sep 23 17:33:52 2010 -0700 20.2 +++ b/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Fri Sep 24 16:43:08 2010 -0700 20.3 @@ -769,9 +769,17 @@ 20.4 && types.isSameType(c.type, syms.deprecatedType)) 20.5 s.flags_field |= Flags.DEPRECATED; 20.6 // Internally to java.dyn, a @PolymorphicSignature annotation 20.7 - // translates to a classfile attribute. 20.8 - if (!c.type.isErroneous() 20.9 - && types.isSameType(c.type, syms.polymorphicSignatureType)) { 20.10 + // acts like a classfile attribute. 20.11 + if (!c.type.isErroneous() && 20.12 + types.isSameType(c.type, syms.polymorphicSignatureType)) { 20.13 + if (!target.hasMethodHandles()) { 20.14 + // Somebody is compiling JDK7 source code to a JDK6 target. 20.15 + // Make it a strict warning, since it is unlikely but important. 20.16 + log.strictWarning(env.tree.pos(), 20.17 + "wrong.target.for.polymorphic.signature.definition", 20.18 + target.name); 20.19 + } 20.20 + // Pull the flag through for better diagnostics, even on a bad target. 20.21 s.flags_field |= Flags.POLYMORPHIC_SIGNATURE; 20.22 } 20.23 if (!annotated.add(a.type.tsym))
21.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java Thu Sep 23 17:33:52 2010 -0700 21.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java Fri Sep 24 16:43:08 2010 -0700 21.3 @@ -69,9 +69,13 @@ 21.4 JCDiagnostic.Factory diags; 21.5 public final boolean boxingEnabled; // = source.allowBoxing(); 21.6 public final boolean varargsEnabled; // = source.allowVarargs(); 21.7 - public final boolean allowPolymorphicSignature; 21.8 + public final boolean allowMethodHandles; 21.9 + public final boolean allowInvokeDynamic; 21.10 + public final boolean allowTransitionalJSR292; 21.11 private final boolean debugResolve; 21.12 21.13 + Scope polymorphicSignatureScope; 21.14 + 21.15 public static Resolve instance(Context context) { 21.16 Resolve instance = context.get(resolveKey); 21.17 if (instance == null) 21.18 @@ -107,7 +111,14 @@ 21.19 varargsEnabled = source.allowVarargs(); 21.20 Options options = Options.instance(context); 21.21 debugResolve = options.get("debugresolve") != null; 21.22 - allowPolymorphicSignature = source.allowPolymorphicSignature() || options.get("invokedynamic") != null; 21.23 + allowTransitionalJSR292 = options.get("allowTransitionalJSR292") != null; 21.24 + Target target = Target.instance(context); 21.25 + allowMethodHandles = allowTransitionalJSR292 || 21.26 + target.hasMethodHandles(); 21.27 + allowInvokeDynamic = (allowTransitionalJSR292 || 21.28 + target.hasInvokedynamic()) && 21.29 + options.get("invokedynamic") != null; 21.30 + polymorphicSignatureScope = new Scope(syms.noSymbol); 21.31 } 21.32 21.33 /** error symbols, which are returned when resolution fails 21.34 @@ -246,7 +257,8 @@ 21.35 /* `sym' is accessible only if not overridden by 21.36 * another symbol which is a member of `site' 21.37 * (because, if it is overridden, `sym' is not strictly 21.38 - * speaking a member of `site'.) 21.39 + * speaking a member of `site'). A polymorphic signature method 21.40 + * cannot be overridden (e.g. MH.invokeExact(Object[])). 21.41 */ 21.42 private boolean notOverriddenIn(Type site, Symbol sym) { 21.43 if (sym.kind != MTH || sym.isConstructor() || sym.isStatic()) 21.44 @@ -254,6 +266,7 @@ 21.45 else { 21.46 Symbol s2 = ((MethodSymbol)sym).implementation(site.tsym, types, true); 21.47 return (s2 == null || s2 == sym || 21.48 + s2.isPolymorphicSignatureGeneric() || 21.49 !types.isSubSignature(types.memberType(site, s2), types.memberType(site, sym))); 21.50 } 21.51 } 21.52 @@ -303,7 +316,8 @@ 21.53 boolean useVarargs, 21.54 Warner warn) 21.55 throws Infer.InferenceException { 21.56 - assert ((m.flags() & (POLYMORPHIC_SIGNATURE|HYPOTHETICAL)) != POLYMORPHIC_SIGNATURE); 21.57 + boolean polymorphicSignature = (m.isPolymorphicSignatureGeneric() && allowMethodHandles) || 21.58 + isTransitionalDynamicCallSite(site, m); 21.59 if (useVarargs && (m.flags() & VARARGS) == 0) return null; 21.60 Type mt = types.memberType(site, m); 21.61 21.62 @@ -311,7 +325,10 @@ 21.63 // need to inferred. 21.64 List<Type> tvars = env.info.tvars; 21.65 if (typeargtypes == null) typeargtypes = List.nil(); 21.66 - if (mt.tag != FORALL && typeargtypes.nonEmpty()) { 21.67 + if (allowTransitionalJSR292 && polymorphicSignature && typeargtypes.nonEmpty()) { 21.68 + //transitional 292 call sites might have wrong number of targs 21.69 + } 21.70 + else if (mt.tag != FORALL && typeargtypes.nonEmpty()) { 21.71 // This is not a polymorphic method, but typeargs are supplied 21.72 // which is fine, see JLS3 15.12.2.1 21.73 } else if (mt.tag == FORALL && typeargtypes.nonEmpty()) { 21.74 @@ -339,7 +356,8 @@ 21.75 } 21.76 21.77 // find out whether we need to go the slow route via infer 21.78 - boolean instNeeded = tvars.tail != null/*inlined: tvars.nonEmpty()*/; 21.79 + boolean instNeeded = tvars.tail != null || /*inlined: tvars.nonEmpty()*/ 21.80 + polymorphicSignature; 21.81 for (List<Type> l = argtypes; 21.82 l.tail != null/*inlined: l.nonEmpty()*/ && !instNeeded; 21.83 l = l.tail) { 21.84 @@ -347,8 +365,9 @@ 21.85 } 21.86 21.87 if (instNeeded) 21.88 - return 21.89 - infer.instantiateMethod(env, 21.90 + return polymorphicSignature ? 21.91 + infer.instantiatePolymorphicSignatureInstance(env, site, m.name, (MethodSymbol)m, argtypes, typeargtypes) : 21.92 + infer.instantiateMethod(env, 21.93 tvars, 21.94 (MethodType)mt, 21.95 m, 21.96 @@ -363,6 +382,14 @@ 21.97 : null; 21.98 } 21.99 21.100 + boolean isTransitionalDynamicCallSite(Type site, Symbol sym) { 21.101 + return allowTransitionalJSR292 && // old logic that doesn't use annotations 21.102 + !sym.isPolymorphicSignatureInstance() && 21.103 + ((allowMethodHandles && site == syms.methodHandleType && // invokeExact, invokeGeneric, invoke 21.104 + (sym.name == names.invoke && sym.isPolymorphicSignatureGeneric())) || 21.105 + (site == syms.invokeDynamicType && allowInvokeDynamic)); // InvokeDynamic.XYZ 21.106 + } 21.107 + 21.108 /** Same but returns null instead throwing a NoInstanceException 21.109 */ 21.110 Type instantiate(Env<AttrContext> env, 21.111 @@ -580,14 +607,6 @@ 21.112 if (sym.kind == ERR) return bestSoFar; 21.113 if (!sym.isInheritedIn(site.tsym, types)) return bestSoFar; 21.114 assert sym.kind < AMBIGUOUS; 21.115 - if ((sym.flags() & POLYMORPHIC_SIGNATURE) != 0 && allowPolymorphicSignature) { 21.116 - assert(site.tag == CLASS); 21.117 - // Never match a MethodHandle.invoke directly. 21.118 - if (useVarargs | allowBoxing | operator) 21.119 - return bestSoFar; 21.120 - // Supply an exactly-typed implicit method instead. 21.121 - sym = findPolymorphicSignatureInstance(env, sym.owner.type, sym.name, (MethodSymbol) sym, argtypes, typeargtypes); 21.122 - } 21.123 try { 21.124 if (rawInstantiate(env, site, sym, argtypes, typeargtypes, 21.125 allowBoxing, useVarargs, Warner.noWarnings) == null) { 21.126 @@ -759,13 +778,6 @@ 21.127 boolean useVarargs, 21.128 boolean operator) { 21.129 Symbol bestSoFar = methodNotFound; 21.130 - if ((site.tsym.flags() & POLYMORPHIC_SIGNATURE) != 0 && 21.131 - allowPolymorphicSignature && 21.132 - site.tag == CLASS && 21.133 - !(useVarargs | allowBoxing | operator)) { 21.134 - // supply an exactly-typed implicit method in java.dyn.InvokeDynamic 21.135 - bestSoFar = findPolymorphicSignatureInstance(env, site, name, null, argtypes, typeargtypes); 21.136 - } 21.137 return findMethod(env, 21.138 site, 21.139 name, 21.140 @@ -907,90 +919,6 @@ 21.141 return bestSoFar; 21.142 } 21.143 21.144 - /** Find or create an implicit method of exactly the given type (after erasure). 21.145 - * Searches in a side table, not the main scope of the site. 21.146 - * This emulates the lookup process required by JSR 292 in JVM. 21.147 - * @param env The current environment. 21.148 - * @param site The original type from where the selection 21.149 - * takes place. 21.150 - * @param name The method's name. 21.151 - * @param argtypes The method's value arguments. 21.152 - * @param typeargtypes The method's type arguments 21.153 - */ 21.154 - Symbol findPolymorphicSignatureInstance(Env<AttrContext> env, 21.155 - Type site, 21.156 - Name name, 21.157 - MethodSymbol spMethod, // sig. poly. method or null if none 21.158 - List<Type> argtypes, 21.159 - List<Type> typeargtypes) { 21.160 - assert allowPolymorphicSignature; 21.161 - //assert site == syms.invokeDynamicType || site == syms.methodHandleType : site; 21.162 - ClassSymbol c = (ClassSymbol) site.tsym; 21.163 - Scope implicit = c.members().next; 21.164 - if (implicit == null) { 21.165 - c.members().next = implicit = new Scope(c); 21.166 - } 21.167 - Type restype; 21.168 - if (typeargtypes.isEmpty()) { 21.169 - restype = syms.objectType; 21.170 - } else { 21.171 - restype = typeargtypes.head; 21.172 - if (!typeargtypes.tail.isEmpty()) 21.173 - return methodNotFound; 21.174 - } 21.175 - List<Type> paramtypes = Type.map(argtypes, implicitArgType); 21.176 - long flags; 21.177 - List<Type> exType; 21.178 - if (spMethod != null) { 21.179 - exType = spMethod.getThrownTypes(); 21.180 - flags = spMethod.flags() & AccessFlags; 21.181 - } else { 21.182 - // make it throw all exceptions 21.183 - //assert(site == syms.invokeDynamicType); 21.184 - exType = List.of(syms.throwableType); 21.185 - flags = PUBLIC | STATIC; 21.186 - } 21.187 - MethodType mtype = new MethodType(paramtypes, 21.188 - restype, 21.189 - exType, 21.190 - syms.methodClass); 21.191 - flags |= ABSTRACT | HYPOTHETICAL | POLYMORPHIC_SIGNATURE; 21.192 - Symbol m = null; 21.193 - for (Scope.Entry e = implicit.lookup(name); 21.194 - e.scope != null; 21.195 - e = e.next()) { 21.196 - Symbol sym = e.sym; 21.197 - assert sym.kind == MTH; 21.198 - if (types.isSameType(mtype, sym.type) 21.199 - && (sym.flags() & STATIC) == (flags & STATIC)) { 21.200 - m = sym; 21.201 - break; 21.202 - } 21.203 - } 21.204 - if (m == null) { 21.205 - // create the desired method 21.206 - m = new MethodSymbol(flags, name, mtype, c); 21.207 - implicit.enter(m); 21.208 - } 21.209 - assert argumentsAcceptable(argtypes, types.memberType(site, m).getParameterTypes(), 21.210 - false, false, Warner.noWarnings); 21.211 - assert null != instantiate(env, site, m, argtypes, typeargtypes, false, false, Warner.noWarnings); 21.212 - return m; 21.213 - } 21.214 - //where 21.215 - Mapping implicitArgType = new Mapping ("implicitArgType") { 21.216 - public Type apply(Type t) { return implicitArgType(t); } 21.217 - }; 21.218 - Type implicitArgType(Type argType) { 21.219 - argType = types.erasure(argType); 21.220 - if (argType.tag == BOT) 21.221 - // nulls type as the marker type Null (which has no instances) 21.222 - // TO DO: figure out how to access java.lang.Null safely, else throw nice error 21.223 - //argType = types.boxedClass(syms.botType).type; 21.224 - argType = types.boxedClass(syms.voidType).type; // REMOVE 21.225 - return argType; 21.226 - } 21.227 - 21.228 /** Load toplevel or member class with given fully qualified name and 21.229 * verify that it is accessible. 21.230 * @param env The current environment. 21.231 @@ -1369,16 +1297,77 @@ 21.232 methodResolutionCache.put(steps.head, sym); 21.233 steps = steps.tail; 21.234 } 21.235 - if (sym.kind >= AMBIGUOUS) {//if nothing is found return the 'first' error 21.236 - MethodResolutionPhase errPhase = 21.237 - firstErroneousResolutionPhase(); 21.238 - sym = access(methodResolutionCache.get(errPhase), 21.239 - pos, site, name, true, argtypes, typeargtypes); 21.240 - env.info.varArgs = errPhase.isVarargsRequired; 21.241 + if (sym.kind >= AMBIGUOUS) { 21.242 + if (site.tsym.isPolymorphicSignatureGeneric() || 21.243 + isTransitionalDynamicCallSite(site, sym)) { 21.244 + //polymorphic receiver - synthesize new method symbol 21.245 + env.info.varArgs = false; 21.246 + sym = findPolymorphicSignatureInstance(env, 21.247 + site, name, null, argtypes, typeargtypes); 21.248 + } 21.249 + else { 21.250 + //if nothing is found return the 'first' error 21.251 + MethodResolutionPhase errPhase = 21.252 + firstErroneousResolutionPhase(); 21.253 + sym = access(methodResolutionCache.get(errPhase), 21.254 + pos, site, name, true, argtypes, typeargtypes); 21.255 + env.info.varArgs = errPhase.isVarargsRequired; 21.256 + } 21.257 + } else if (allowMethodHandles && sym.isPolymorphicSignatureGeneric()) { 21.258 + //non-instantiated polymorphic signature - synthesize new method symbol 21.259 + env.info.varArgs = false; 21.260 + sym = findPolymorphicSignatureInstance(env, 21.261 + site, name, (MethodSymbol)sym, argtypes, typeargtypes); 21.262 } 21.263 return sym; 21.264 } 21.265 21.266 + /** Find or create an implicit method of exactly the given type (after erasure). 21.267 + * Searches in a side table, not the main scope of the site. 21.268 + * This emulates the lookup process required by JSR 292 in JVM. 21.269 + * @param env Attribution environment 21.270 + * @param site The original type from where the selection takes place. 21.271 + * @param name The method's name. 21.272 + * @param spMethod A template for the implicit method, or null. 21.273 + * @param argtypes The required argument types. 21.274 + * @param typeargtypes The required type arguments. 21.275 + */ 21.276 + Symbol findPolymorphicSignatureInstance(Env<AttrContext> env, Type site, 21.277 + Name name, 21.278 + MethodSymbol spMethod, // sig. poly. method or null if none 21.279 + List<Type> argtypes, 21.280 + List<Type> typeargtypes) { 21.281 + if (typeargtypes.nonEmpty() && (site.tsym.isPolymorphicSignatureGeneric() || 21.282 + (spMethod != null && spMethod.isPolymorphicSignatureGeneric()))) { 21.283 + log.warning(env.tree.pos(), "type.parameter.on.polymorphic.signature"); 21.284 + } 21.285 + 21.286 + Type mtype = infer.instantiatePolymorphicSignatureInstance(env, 21.287 + site, name, spMethod, argtypes, typeargtypes); 21.288 + long flags = ABSTRACT | HYPOTHETICAL | POLYMORPHIC_SIGNATURE | 21.289 + (spMethod != null ? 21.290 + spMethod.flags() & Flags.AccessFlags : 21.291 + Flags.PUBLIC | Flags.STATIC); 21.292 + Symbol m = null; 21.293 + for (Scope.Entry e = polymorphicSignatureScope.lookup(name); 21.294 + e.scope != null; 21.295 + e = e.next()) { 21.296 + Symbol sym = e.sym; 21.297 + if (types.isSameType(mtype, sym.type) && 21.298 + (sym.flags() & Flags.STATIC) == (flags & Flags.STATIC) && 21.299 + types.isSameType(sym.owner.type, site)) { 21.300 + m = sym; 21.301 + break; 21.302 + } 21.303 + } 21.304 + if (m == null) { 21.305 + // create the desired method 21.306 + m = new MethodSymbol(flags, name, mtype, site.tsym); 21.307 + polymorphicSignatureScope.enter(m); 21.308 + } 21.309 + return m; 21.310 + } 21.311 + 21.312 /** Resolve a qualified method identifier, throw a fatal error if not 21.313 * found. 21.314 * @param pos The position to use for error reporting.
22.1 --- a/src/share/classes/com/sun/tools/javac/comp/TransTypes.java Thu Sep 23 17:33:52 2010 -0700 22.2 +++ b/src/share/classes/com/sun/tools/javac/comp/TransTypes.java Fri Sep 24 16:43:08 2010 -0700 22.3 @@ -283,12 +283,13 @@ 22.4 ListBuffer<JCTree> bridges) { 22.5 if (sym.kind == MTH && 22.6 sym.name != names.init && 22.7 - (sym.flags() & (PRIVATE | SYNTHETIC | STATIC)) == 0 && 22.8 + (sym.flags() & (PRIVATE | STATIC)) == 0 && 22.9 + (sym.flags() & (SYNTHETIC | OVERRIDE_BRIDGE)) != SYNTHETIC && 22.10 sym.isMemberOf(origin, types)) 22.11 { 22.12 MethodSymbol meth = (MethodSymbol)sym; 22.13 MethodSymbol bridge = meth.binaryImplementation(origin, types); 22.14 - MethodSymbol impl = meth.implementation(origin, types, true); 22.15 + MethodSymbol impl = meth.implementation(origin, types, true, overrideBridgeFilter); 22.16 if (bridge == null || 22.17 bridge == meth || 22.18 (impl != null && !bridge.owner.isSubClass(impl.owner, types))) { 22.19 @@ -304,7 +305,7 @@ 22.20 // reflection design error. 22.21 addBridge(pos, meth, impl, origin, false, bridges); 22.22 } 22.23 - } else if ((bridge.flags() & SYNTHETIC) != 0) { 22.24 + } else if ((bridge.flags() & (SYNTHETIC | OVERRIDE_BRIDGE)) == SYNTHETIC) { 22.25 MethodSymbol other = overridden.get(bridge); 22.26 if (other != null && other != meth) { 22.27 if (impl == null || !impl.overrides(other, origin, types, true)) { 22.28 @@ -327,6 +328,11 @@ 22.29 } 22.30 } 22.31 // where 22.32 + Filter<Symbol> overrideBridgeFilter = new Filter<Symbol>() { 22.33 + public boolean accepts(Symbol s) { 22.34 + return (s.flags() & (SYNTHETIC | OVERRIDE_BRIDGE)) != SYNTHETIC; 22.35 + } 22.36 + }; 22.37 /** 22.38 * @param method The symbol for which a bridge might have to be added 22.39 * @param impl The implementation of method 22.40 @@ -754,6 +760,90 @@ 22.41 return types.erasure(t); 22.42 } 22.43 22.44 + private boolean boundsRestricted(ClassSymbol c) { 22.45 + Type st = types.supertype(c.type); 22.46 + if (st.isParameterized()) { 22.47 + List<Type> actuals = st.allparams(); 22.48 + List<Type> formals = st.tsym.type.allparams(); 22.49 + while (!actuals.isEmpty() && !formals.isEmpty()) { 22.50 + Type actual = actuals.head; 22.51 + Type formal = formals.head; 22.52 + 22.53 + if (!types.isSameType(types.erasure(actual), 22.54 + types.erasure(formal))) 22.55 + return true; 22.56 + 22.57 + actuals = actuals.tail; 22.58 + formals = formals.tail; 22.59 + } 22.60 + } 22.61 + return false; 22.62 + } 22.63 + 22.64 + private List<JCTree> addOverrideBridgesIfNeeded(DiagnosticPosition pos, 22.65 + final ClassSymbol c) { 22.66 + ListBuffer<JCTree> buf = ListBuffer.lb(); 22.67 + if (c.isInterface() || !boundsRestricted(c)) 22.68 + return buf.toList(); 22.69 + Type t = types.supertype(c.type); 22.70 + Scope s = t.tsym.members(); 22.71 + if (s.elems != null) { 22.72 + for (Symbol sym : s.getElements(new NeedsOverridBridgeFilter(c))) { 22.73 + 22.74 + MethodSymbol m = (MethodSymbol)sym; 22.75 + MethodSymbol member = (MethodSymbol)m.asMemberOf(c.type, types); 22.76 + MethodSymbol impl = m.implementation(c, types, false); 22.77 + 22.78 + if ((impl == null || impl.owner != c) && 22.79 + !types.isSameType(member.erasure(types), m.erasure(types))) { 22.80 + addOverrideBridges(pos, m, member, c, buf); 22.81 + } 22.82 + } 22.83 + } 22.84 + return buf.toList(); 22.85 + } 22.86 + // where 22.87 + class NeedsOverridBridgeFilter implements Filter<Symbol> { 22.88 + 22.89 + ClassSymbol c; 22.90 + 22.91 + NeedsOverridBridgeFilter(ClassSymbol c) { 22.92 + this.c = c; 22.93 + } 22.94 + public boolean accepts(Symbol s) { 22.95 + return s.kind == MTH && 22.96 + !s.isConstructor() && 22.97 + s.isInheritedIn(c, types) && 22.98 + (s.flags() & FINAL) == 0 && 22.99 + (s.flags() & (SYNTHETIC | OVERRIDE_BRIDGE)) != SYNTHETIC; 22.100 + } 22.101 + } 22.102 + 22.103 + private void addOverrideBridges(DiagnosticPosition pos, 22.104 + MethodSymbol impl, 22.105 + MethodSymbol member, 22.106 + ClassSymbol c, 22.107 + ListBuffer<JCTree> bridges) { 22.108 + Type implErasure = impl.erasure(types); 22.109 + long flags = (impl.flags() & AccessFlags) | SYNTHETIC | BRIDGE | OVERRIDE_BRIDGE; 22.110 + member = new MethodSymbol(flags, member.name, member.type, c); 22.111 + JCMethodDecl md = make.MethodDef(member, null); 22.112 + JCExpression receiver = make.Super(types.supertype(c.type).tsym.erasure(types), c); 22.113 + Type calltype = erasure(impl.type.getReturnType()); 22.114 + JCExpression call = 22.115 + make.Apply(null, 22.116 + make.Select(receiver, impl).setType(calltype), 22.117 + translateArgs(make.Idents(md.params), 22.118 + implErasure.getParameterTypes(), null)) 22.119 + .setType(calltype); 22.120 + JCStatement stat = (member.getReturnType().tag == VOID) 22.121 + ? make.Exec(call) 22.122 + : make.Return(coerce(call, member.erasure(types).getReturnType())); 22.123 + md.body = make.Block(0, List.of(stat)); 22.124 + c.members().enter(member); 22.125 + bridges.append(md); 22.126 + } 22.127 + 22.128 /************************************************************************** 22.129 * main method 22.130 *************************************************************************/ 22.131 @@ -786,6 +876,7 @@ 22.132 make.at(tree.pos); 22.133 if (addBridges) { 22.134 ListBuffer<JCTree> bridges = new ListBuffer<JCTree>(); 22.135 + bridges.appendList(addOverrideBridgesIfNeeded(tree, c)); 22.136 if ((tree.sym.flags() & INTERFACE) == 0) 22.137 addBridges(tree.pos(), tree.sym, bridges); 22.138 tree.defs = bridges.toList().prependList(tree.defs);
23.1 --- a/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java Thu Sep 23 17:33:52 2010 -0700 23.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java Fri Sep 24 16:43:08 2010 -0700 23.3 @@ -1098,12 +1098,6 @@ 23.4 } 23.5 }, 23.6 23.7 - new AttributeReader(names.PolymorphicSignature, V45_3/*S.B.V51*/, CLASS_OR_MEMBER_ATTRIBUTE) { 23.8 - void read(Symbol sym, int attrLen) { 23.9 - sym.flags_field |= POLYMORPHIC_SIGNATURE; 23.10 - } 23.11 - }, 23.12 - 23.13 23.14 // The following attributes for a Code attribute are not currently handled 23.15 // StackMapTable 23.16 @@ -1289,6 +1283,9 @@ 23.17 sym.flags_field |= PROPRIETARY; 23.18 else 23.19 proxies.append(proxy); 23.20 + if (majorVersion >= V51.major && proxy.type.tsym == syms.polymorphicSignatureType.tsym) { 23.21 + sym.flags_field |= POLYMORPHIC_SIGNATURE; 23.22 + } 23.23 } 23.24 annotate.later(new AnnotationCompleter(sym, proxies.toList())); 23.25 }
24.1 --- a/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java Thu Sep 23 17:33:52 2010 -0700 24.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java Fri Sep 24 16:43:08 2010 -0700 24.3 @@ -34,6 +34,7 @@ 24.4 import javax.tools.JavaFileObject; 24.5 24.6 import com.sun.tools.javac.code.*; 24.7 +import com.sun.tools.javac.code.Attribute.RetentionPolicy; 24.8 import com.sun.tools.javac.code.Symbol.*; 24.9 import com.sun.tools.javac.code.Type.*; 24.10 import com.sun.tools.javac.file.BaseFileObject; 24.11 @@ -651,13 +652,6 @@ 24.12 endAttr(alenIdx); 24.13 acount++; 24.14 } 24.15 - if ((flags & POLYMORPHIC_SIGNATURE) != 0) { 24.16 - if (target.majorVersion < 51) 24.17 - throw new AssertionError("PolymorphicSignature attributes in java/dyn must be written with -target 7 (required major version is 51, current is"+target.majorVersion+")"); 24.18 - int alenIdx = writeAttr(names.PolymorphicSignature); 24.19 - endAttr(alenIdx); 24.20 - acount++; 24.21 - } 24.22 return acount; 24.23 } 24.24 24.25 @@ -692,7 +686,7 @@ 24.26 boolean hasInvisible = false; 24.27 if (m.params != null) for (VarSymbol s : m.params) { 24.28 for (Attribute.Compound a : s.getAnnotationMirrors()) { 24.29 - switch (getRetention(a.type.tsym)) { 24.30 + switch (types.getRetention(a)) { 24.31 case SOURCE: break; 24.32 case CLASS: hasInvisible = true; break; 24.33 case RUNTIME: hasVisible = true; break; 24.34 @@ -708,7 +702,7 @@ 24.35 for (VarSymbol s : m.params) { 24.36 ListBuffer<Attribute.Compound> buf = new ListBuffer<Attribute.Compound>(); 24.37 for (Attribute.Compound a : s.getAnnotationMirrors()) 24.38 - if (getRetention(a.type.tsym) == RetentionPolicy.RUNTIME) 24.39 + if (types.getRetention(a) == RetentionPolicy.RUNTIME) 24.40 buf.append(a); 24.41 databuf.appendChar(buf.length()); 24.42 for (Attribute.Compound a : buf) 24.43 @@ -723,7 +717,7 @@ 24.44 for (VarSymbol s : m.params) { 24.45 ListBuffer<Attribute.Compound> buf = new ListBuffer<Attribute.Compound>(); 24.46 for (Attribute.Compound a : s.getAnnotationMirrors()) 24.47 - if (getRetention(a.type.tsym) == RetentionPolicy.CLASS) 24.48 + if (types.getRetention(a) == RetentionPolicy.CLASS) 24.49 buf.append(a); 24.50 databuf.appendChar(buf.length()); 24.51 for (Attribute.Compound a : buf) 24.52 @@ -747,7 +741,7 @@ 24.53 ListBuffer<Attribute.Compound> visibles = new ListBuffer<Attribute.Compound>(); 24.54 ListBuffer<Attribute.Compound> invisibles = new ListBuffer<Attribute.Compound>(); 24.55 for (Attribute.Compound a : attrs) { 24.56 - switch (getRetention(a.type.tsym)) { 24.57 + switch (types.getRetention(a)) { 24.58 case SOURCE: break; 24.59 case CLASS: invisibles.append(a); break; 24.60 case RUNTIME: visibles.append(a); break; 24.61 @@ -785,7 +779,7 @@ 24.62 if (tc.position.type == TargetType.UNKNOWN 24.63 || !tc.position.emitToClassfile()) 24.64 continue; 24.65 - switch (getRetention(tc.type.tsym)) { 24.66 + switch (types.getRetention(tc)) { 24.67 case SOURCE: break; 24.68 case CLASS: invisibles.append(tc); break; 24.69 case RUNTIME: visibles.append(tc); break; 24.70 @@ -815,29 +809,6 @@ 24.71 return attrCount; 24.72 } 24.73 24.74 - /** A mirror of java.lang.annotation.RetentionPolicy. */ 24.75 - enum RetentionPolicy { 24.76 - SOURCE, 24.77 - CLASS, 24.78 - RUNTIME 24.79 - } 24.80 - 24.81 - RetentionPolicy getRetention(TypeSymbol annotationType) { 24.82 - RetentionPolicy vis = RetentionPolicy.CLASS; // the default 24.83 - Attribute.Compound c = annotationType.attribute(syms.retentionType.tsym); 24.84 - if (c != null) { 24.85 - Attribute value = c.member(names.value); 24.86 - if (value != null && value instanceof Attribute.Enum) { 24.87 - Name levelName = ((Attribute.Enum)value).value.name; 24.88 - if (levelName == names.SOURCE) vis = RetentionPolicy.SOURCE; 24.89 - else if (levelName == names.CLASS) vis = RetentionPolicy.CLASS; 24.90 - else if (levelName == names.RUNTIME) vis = RetentionPolicy.RUNTIME; 24.91 - else ;// /* fail soft */ throw new AssertionError(levelName); 24.92 - } 24.93 - } 24.94 - return vis; 24.95 - } 24.96 - 24.97 /** A visitor to write an attribute including its leading 24.98 * single-character marker. 24.99 */
25.1 --- a/src/share/classes/com/sun/tools/javac/jvm/Target.java Thu Sep 23 17:33:52 2010 -0700 25.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/Target.java Fri Sep 24 16:43:08 2010 -0700 25.3 @@ -259,6 +259,14 @@ 25.4 return compareTo(JDK1_7) >= 0; 25.5 } 25.6 25.7 + /** Does the VM support polymorphic method handle invocation? 25.8 + * Affects the linkage information output to the classfile. 25.9 + * An alias for {@code hasInvokedynamic}, since all the JSR 292 features appear together. 25.10 + */ 25.11 + public boolean hasMethodHandles() { 25.12 + return hasInvokedynamic(); 25.13 + } 25.14 + 25.15 /** Although we may not have support for class literals, should we 25.16 * avoid initializing the class that the literal refers to? 25.17 * See 4468823
26.1 --- a/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java Thu Sep 23 17:33:52 2010 -0700 26.2 +++ b/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java Fri Sep 24 16:43:08 2010 -0700 26.3 @@ -59,6 +59,7 @@ 26.4 import javax.annotation.processing.Processor; 26.5 26.6 import static javax.tools.StandardLocation.CLASS_OUTPUT; 26.7 +import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*; 26.8 import static com.sun.tools.javac.util.ListBuffer.lb; 26.9 26.10 // TEMP, until we have a more efficient way to save doc comment info 26.11 @@ -579,10 +580,8 @@ 26.12 TaskEvent e = new TaskEvent(TaskEvent.Kind.PARSE, filename); 26.13 taskListener.started(e); 26.14 } 26.15 - int initialErrorCount = log.nerrors; 26.16 Parser parser = parserFactory.newParser(content, keepComments(), genEndPos, lineDebugInfo); 26.17 tree = parser.parseCompilationUnit(); 26.18 - log.unrecoverableError |= (log.nerrors > initialErrorCount); 26.19 if (verbose) { 26.20 printVerbose("parsing.done", Long.toString(elapsed(msec))); 26.21 } 26.22 @@ -608,7 +607,7 @@ 26.23 * @param filename The name of the file to be parsed. 26.24 */ 26.25 @Deprecated 26.26 - public JCTree.JCCompilationUnit parse(String filename) throws IOException { 26.27 + public JCTree.JCCompilationUnit parse(String filename) { 26.28 JavacFileManager fm = (JavacFileManager)fileManager; 26.29 return parse(fm.getJavaFileObjectsFromStrings(List.of(filename)).iterator().next()); 26.30 } 26.31 @@ -778,7 +777,6 @@ 26.32 public void compile(List<JavaFileObject> sourceFileObjects, 26.33 List<String> classnames, 26.34 Iterable<? extends Processor> processors) 26.35 - throws IOException // TODO: temp, from JavacProcessingEnvironment 26.36 { 26.37 if (processors != null && processors.iterator().hasNext()) 26.38 explicitAnnotationProcessingRequested = true; 26.39 @@ -868,14 +866,19 @@ 26.40 /** 26.41 * Parses a list of files. 26.42 */ 26.43 - public List<JCCompilationUnit> parseFiles(Iterable<JavaFileObject> fileObjects) throws IOException { 26.44 + public List<JCCompilationUnit> parseFiles(Iterable<JavaFileObject> fileObjects) { 26.45 if (shouldStop(CompileState.PARSE)) 26.46 return List.nil(); 26.47 26.48 //parse all files 26.49 ListBuffer<JCCompilationUnit> trees = lb(); 26.50 - for (JavaFileObject fileObject : fileObjects) 26.51 - trees.append(parse(fileObject)); 26.52 + Set<JavaFileObject> filesSoFar = new HashSet<JavaFileObject>(); 26.53 + for (JavaFileObject fileObject : fileObjects) { 26.54 + if (!filesSoFar.contains(fileObject)) { 26.55 + filesSoFar.add(fileObject); 26.56 + trees.append(parse(fileObject)); 26.57 + } 26.58 + } 26.59 return trees.toList(); 26.60 } 26.61 26.62 @@ -916,6 +919,15 @@ 26.63 } 26.64 rootClasses = cdefs.toList(); 26.65 } 26.66 + 26.67 + // Ensure the input files have been recorded. Although this is normally 26.68 + // done by readSource, it may not have been done if the trees were read 26.69 + // in a prior round of annotation processing, and the trees have been 26.70 + // cleaned and are being reused. 26.71 + for (JCCompilationUnit unit : roots) { 26.72 + inputFiles.add(unit.sourcefile); 26.73 + } 26.74 + 26.75 return roots; 26.76 } 26.77 26.78 @@ -941,8 +953,7 @@ 26.79 * @param processors user provided annotation processors to bypass 26.80 * discovery, {@code null} means that no processors were provided 26.81 */ 26.82 - public void initProcessAnnotations(Iterable<? extends Processor> processors) 26.83 - throws IOException { 26.84 + public void initProcessAnnotations(Iterable<? extends Processor> processors) { 26.85 // Process annotations if processing is not disabled and there 26.86 // is at least one Processor available. 26.87 Options options = Options.instance(context); 26.88 @@ -960,8 +971,7 @@ 26.89 keepComments = true; 26.90 if (taskListener != null) 26.91 taskListener.started(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING)); 26.92 - 26.93 - 26.94 + log.deferDiagnostics = true; 26.95 } else { // free resources 26.96 procEnvImpl.close(); 26.97 } 26.98 @@ -969,8 +979,7 @@ 26.99 } 26.100 26.101 // TODO: called by JavacTaskImpl 26.102 - public JavaCompiler processAnnotations(List<JCCompilationUnit> roots) 26.103 - throws IOException { 26.104 + public JavaCompiler processAnnotations(List<JCCompilationUnit> roots) { 26.105 return processAnnotations(roots, List.<String>nil()); 26.106 } 26.107 26.108 @@ -979,16 +988,23 @@ 26.109 * @param roots a list of compilation units 26.110 * @return an instance of the compiler in which to complete the compilation 26.111 */ 26.112 + // Implementation note: when this method is called, log.deferredDiagnostics 26.113 + // will have been set true by initProcessAnnotations, meaning that any diagnostics 26.114 + // that are reported will go into the log.deferredDiagnostics queue. 26.115 + // By the time this method exits, log.deferDiagnostics must be set back to false, 26.116 + // and all deferredDiagnostics must have been handled: i.e. either reported 26.117 + // or determined to be transient, and therefore suppressed. 26.118 public JavaCompiler processAnnotations(List<JCCompilationUnit> roots, 26.119 - List<String> classnames) 26.120 - throws IOException { // TODO: see TEMP note in JavacProcessingEnvironment 26.121 + List<String> classnames) { 26.122 if (shouldStop(CompileState.PROCESS)) { 26.123 // Errors were encountered. 26.124 - // If log.unrecoverableError is set, the errors were parse errors 26.125 + // Unless all the errors are resolve errors, the errors were parse errors 26.126 // or other errors during enter which cannot be fixed by running 26.127 // any annotation processors. 26.128 - if (log.unrecoverableError) 26.129 + if (unrecoverableError()) { 26.130 + log.reportDeferredDiagnostics(); 26.131 return this; 26.132 + } 26.133 } 26.134 26.135 // ASSERT: processAnnotations and procEnvImpl should have been set up by 26.136 @@ -1010,6 +1026,7 @@ 26.137 log.error("proc.no.explicit.annotation.processing.requested", 26.138 classnames); 26.139 } 26.140 + log.reportDeferredDiagnostics(); 26.141 return this; // continue regular compilation 26.142 } 26.143 26.144 @@ -1022,6 +1039,7 @@ 26.145 if (!explicitAnnotationProcessingRequested()) { 26.146 log.error("proc.no.explicit.annotation.processing.requested", 26.147 classnames); 26.148 + log.reportDeferredDiagnostics(); 26.149 return this; // TODO: Will this halt compilation? 26.150 } else { 26.151 boolean errors = false; 26.152 @@ -1036,7 +1054,6 @@ 26.153 if (sym.kind == Kinds.PCK) 26.154 sym.complete(); 26.155 if (sym.exists()) { 26.156 - Name name = names.fromString(nameStr); 26.157 if (sym.kind == Kinds.PCK) 26.158 pckSymbols = pckSymbols.prepend((PackageSymbol)sym); 26.159 else 26.160 @@ -1052,23 +1069,36 @@ 26.161 continue; 26.162 } 26.163 } 26.164 - if (errors) 26.165 + if (errors) { 26.166 + log.reportDeferredDiagnostics(); 26.167 return this; 26.168 + } 26.169 } 26.170 } 26.171 try { 26.172 JavaCompiler c = procEnvImpl.doProcessing(context, roots, classSymbols, pckSymbols); 26.173 if (c != this) 26.174 annotationProcessingOccurred = c.annotationProcessingOccurred = true; 26.175 + // doProcessing will have handled deferred diagnostics 26.176 + assert c.log.deferDiagnostics == false; 26.177 + assert c.log.deferredDiagnostics.size() == 0; 26.178 return c; 26.179 } finally { 26.180 procEnvImpl.close(); 26.181 } 26.182 } catch (CompletionFailure ex) { 26.183 log.error("cant.access", ex.sym, ex.getDetailValue()); 26.184 + log.reportDeferredDiagnostics(); 26.185 return this; 26.186 + } 26.187 + } 26.188 26.189 + private boolean unrecoverableError() { 26.190 + for (JCDiagnostic d: log.deferredDiagnostics) { 26.191 + if (d.getKind() == JCDiagnostic.Kind.ERROR && !d.isFlagSet(RESOLVE_ERROR)) 26.192 + return true; 26.193 } 26.194 + return false; 26.195 } 26.196 26.197 boolean explicitAnnotationProcessingRequested() { 26.198 @@ -1119,6 +1149,11 @@ 26.199 env.toplevel.sourcefile); 26.200 try { 26.201 attr.attribClass(env.tree.pos(), env.enclClass.sym); 26.202 + if (errorCount() > 0 && !shouldStop(CompileState.ATTR)) { 26.203 + //if in fail-over mode, ensure that AST expression nodes 26.204 + //are correctly initialized (e.g. they have a type/symbol) 26.205 + attr.postAttr(env); 26.206 + } 26.207 compileStates.put(env, CompileState.ATTR); 26.208 } 26.209 finally {
27.1 --- a/src/share/classes/com/sun/tools/javac/main/Main.java Thu Sep 23 17:33:52 2010 -0700 27.2 +++ b/src/share/classes/com/sun/tools/javac/main/Main.java Fri Sep 24 16:43:08 2010 -0700 27.3 @@ -282,6 +282,13 @@ 27.4 } 27.5 } 27.6 27.7 + // phase this out with JSR 292 PFD 27.8 + if ("no".equals(options.get("allowTransitionalJSR292"))) { 27.9 + options.put("allowTransitionalJSR292", null); 27.10 + } else if (target.hasInvokedynamic() && options.get("allowTransitionalJSR292") == null) { 27.11 + options.put("allowTransitionalJSR292", "allowTransitionalJSR292"); 27.12 + } 27.13 + 27.14 // handle this here so it works even if no other options given 27.15 String showClass = options.get("showClass"); 27.16 if (showClass != null) { 27.17 @@ -467,10 +474,13 @@ 27.18 ex.printStackTrace(out); 27.19 } 27.20 27.21 - /** Print a message reporting an fatal error. 27.22 + /** Print a message reporting a fatal error. 27.23 */ 27.24 void feMessage(Throwable ex) { 27.25 Log.printLines(out, ex.getMessage()); 27.26 + if (ex.getCause() != null && options.get("dev") != null) { 27.27 + ex.getCause().printStackTrace(out); 27.28 + } 27.29 } 27.30 27.31 /** Print a message reporting an input/output error.
28.1 --- a/src/share/classes/com/sun/tools/javac/main/OptionName.java Thu Sep 23 17:33:52 2010 -0700 28.2 +++ b/src/share/classes/com/sun/tools/javac/main/OptionName.java Fri Sep 24 16:43:08 2010 -0700 28.3 @@ -80,6 +80,7 @@ 28.4 XMAXERRS("-Xmaxerrs"), 28.5 XMAXWARNS("-Xmaxwarns"), 28.6 XSTDOUT("-Xstdout"), 28.7 + XPKGINFO("-Xpkginfo:"), 28.8 XPRINT("-Xprint"), 28.9 XPRINTROUNDS("-XprintRounds"), 28.10 XPRINTPROCESSORINFO("-XprintProcessorInfo"),
29.1 --- a/src/share/classes/com/sun/tools/javac/main/RecognizedOptions.java Thu Sep 23 17:33:52 2010 -0700 29.2 +++ b/src/share/classes/com/sun/tools/javac/main/RecognizedOptions.java Fri Sep 24 16:43:08 2010 -0700 29.3 @@ -160,6 +160,7 @@ 29.4 XMAXERRS, 29.5 XMAXWARNS, 29.6 XSTDOUT, 29.7 + XPKGINFO, 29.8 XPRINT, 29.9 XPRINTROUNDS, 29.10 XPRINTPROCESSORINFO, 29.11 @@ -217,6 +218,7 @@ 29.12 XMAXERRS, 29.13 XMAXWARNS, 29.14 // XSTDOUT, 29.15 + XPKGINFO, 29.16 XPRINT, 29.17 XPRINTROUNDS, 29.18 XPRINTPROCESSORINFO, 29.19 @@ -532,6 +534,9 @@ 29.20 new XOption(XPREFER, "opt.prefer", 29.21 Option.ChoiceKind.ONEOF, "source", "newer"), 29.22 29.23 + new XOption(XPKGINFO, "opt.pkginfo", 29.24 + Option.ChoiceKind.ONEOF, "always", "legacy", "nonempty"), 29.25 + 29.26 /* -O is a no-op, accepted for backward compatibility. */ 29.27 new HiddenOption(O), 29.28 29.29 @@ -598,6 +603,16 @@ 29.30 }; 29.31 } 29.32 29.33 + public enum PkgInfo { 29.34 + ALWAYS, LEGACY, NONEMPTY; 29.35 + public static PkgInfo get(Options options) { 29.36 + String v = options.get(XPKGINFO); 29.37 + return (v == null 29.38 + ? PkgInfo.LEGACY 29.39 + : PkgInfo.valueOf(v.toUpperCase())); 29.40 + } 29.41 + } 29.42 + 29.43 private static Map<String,Boolean> getXLintChoices() { 29.44 Map<String,Boolean> choices = new LinkedHashMap<String,Boolean>(); 29.45 choices.put("all", false);
30.1 --- a/src/share/classes/com/sun/tools/javac/model/JavacTypes.java Thu Sep 23 17:33:52 2010 -0700 30.2 +++ b/src/share/classes/com/sun/tools/javac/model/JavacTypes.java Fri Sep 24 16:43:08 2010 -0700 30.3 @@ -103,7 +103,7 @@ 30.4 public boolean contains(TypeMirror t1, TypeMirror t2) { 30.5 validateTypeNotIn(t1, EXEC_OR_PKG); 30.6 validateTypeNotIn(t2, EXEC_OR_PKG); 30.7 - return ((Type) t1).contains((Type) t2); 30.8 + return types.containsType((Type) t1, (Type) t2); 30.9 } 30.10 30.11 public boolean isSubsignature(ExecutableType m1, ExecutableType m2) {
31.1 --- a/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Thu Sep 23 17:33:52 2010 -0700 31.2 +++ b/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Fri Sep 24 16:43:08 2010 -0700 31.3 @@ -2781,7 +2781,7 @@ 31.4 List<JCTree> classOrInterfaceBodyDeclaration(Name className, boolean isInterface) { 31.5 if (S.token() == SEMI) { 31.6 S.nextToken(); 31.7 - return List.<JCTree>of(F.at(Position.NOPOS).Block(0, List.<JCStatement>nil())); 31.8 + return List.<JCTree>nil(); 31.9 } else { 31.10 String dc = S.docComment(); 31.11 int pos = S.pos();
32.1 --- a/src/share/classes/com/sun/tools/javac/parser/Scanner.java Thu Sep 23 17:33:52 2010 -0700 32.2 +++ b/src/share/classes/com/sun/tools/javac/parser/Scanner.java Fri Sep 24 16:43:08 2010 -0700 32.3 @@ -108,6 +108,10 @@ 32.4 */ 32.5 private boolean allowUnderscoresInLiterals; 32.6 32.7 + /** Allow exotic identifiers. 32.8 + */ 32.9 + private boolean allowExoticIdentifiers; 32.10 + 32.11 /** The source language setting. 32.12 */ 32.13 private Source source; 32.14 @@ -181,6 +185,7 @@ 32.15 allowBinaryLiterals = source.allowBinaryLiterals(); 32.16 allowHexFloats = source.allowHexFloats(); 32.17 allowUnderscoresInLiterals = source.allowBinaryLiterals(); 32.18 + allowExoticIdentifiers = source.allowExoticIdentifiers(); // for invokedynamic 32.19 } 32.20 32.21 private static final boolean hexFloatsWork = hexFloatsWork(); 32.22 @@ -1010,6 +1015,10 @@ 32.23 case '#': 32.24 scanChar(); 32.25 if (ch == '\"') { 32.26 + if (!allowExoticIdentifiers) { 32.27 + lexError("unsupported.exotic.id", source.name); 32.28 + allowExoticIdentifiers = true; 32.29 + } 32.30 scanChar(); 32.31 if (ch == '\"') 32.32 lexError(pos, "empty.bytecode.ident");
33.1 --- a/src/share/classes/com/sun/tools/javac/processing/JavacFiler.java Thu Sep 23 17:33:52 2010 -0700 33.2 +++ b/src/share/classes/com/sun/tools/javac/processing/JavacFiler.java Fri Sep 24 16:43:08 2010 -0700 33.3 @@ -34,6 +34,7 @@ 33.4 import java.util.*; 33.5 33.6 import java.io.Closeable; 33.7 +import java.io.FileNotFoundException; 33.8 import java.io.InputStream; 33.9 import java.io.OutputStream; 33.10 import java.io.FilterOutputStream; 33.11 @@ -450,10 +451,15 @@ 33.12 // TODO: Only support reading resources in selected output 33.13 // locations? Only allow reading of non-source, non-class 33.14 // files from the supported input locations? 33.15 - FileObject fileObject = fileManager.getFileForOutput(location, 33.16 - pkg.toString(), 33.17 - relativeName.toString(), 33.18 - null); 33.19 + FileObject fileObject = fileManager.getFileForInput(location, 33.20 + pkg.toString(), 33.21 + relativeName.toString()); 33.22 + if (fileObject == null) { 33.23 + String name = (pkg.length() == 0) 33.24 + ? relativeName.toString() : (pkg + "/" + relativeName); 33.25 + throw new FileNotFoundException(name); 33.26 + } 33.27 + 33.28 // If the path was already opened for writing, throw an exception. 33.29 checkFileReopening(fileObject, false); 33.30 return new FilerInputFileObject(fileObject);
34.1 --- a/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Thu Sep 23 17:33:52 2010 -0700 34.2 +++ b/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Fri Sep 24 16:43:08 2010 -0700 34.3 @@ -67,6 +67,8 @@ 34.4 import com.sun.tools.javac.util.Abort; 34.5 import com.sun.tools.javac.util.Context; 34.6 import com.sun.tools.javac.util.Convert; 34.7 +import com.sun.tools.javac.util.FatalError; 34.8 +import com.sun.tools.javac.util.JCDiagnostic; 34.9 import com.sun.tools.javac.util.List; 34.10 import com.sun.tools.javac.util.Log; 34.11 import com.sun.tools.javac.util.JavacMessages; 34.12 @@ -75,6 +77,7 @@ 34.13 import com.sun.tools.javac.util.Options; 34.14 34.15 import static javax.tools.StandardLocation.*; 34.16 +import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*; 34.17 34.18 /** 34.19 * Objects of this class hold and manage the state needed to support 34.20 @@ -95,6 +98,7 @@ 34.21 private final boolean procOnly; 34.22 private final boolean fatalErrors; 34.23 private final boolean werror; 34.24 + private final boolean showResolveErrors; 34.25 private boolean foundTypeProcessors; 34.26 34.27 private final JavacFiler filer; 34.28 @@ -131,6 +135,10 @@ 34.29 */ 34.30 Log log; 34.31 34.32 + /** Diagnostic factory. 34.33 + */ 34.34 + JCDiagnostic.Factory diags; 34.35 + 34.36 /** 34.37 * Source level of the compile. 34.38 */ 34.39 @@ -146,10 +154,11 @@ 34.40 private Context context; 34.41 34.42 public JavacProcessingEnvironment(Context context, Iterable<? extends Processor> processors) { 34.43 - options = Options.instance(context); 34.44 this.context = context; 34.45 log = Log.instance(context); 34.46 source = Source.instance(context); 34.47 + diags = JCDiagnostic.Factory.instance(context); 34.48 + options = Options.instance(context); 34.49 printProcessorInfo = options.get("-XprintProcessorInfo") != null; 34.50 printRounds = options.get("-XprintRounds") != null; 34.51 verbose = options.get("-verbose") != null; 34.52 @@ -157,6 +166,7 @@ 34.53 procOnly = options.get("-proc:only") != null || 34.54 options.get("-Xprint") != null; 34.55 fatalErrors = options.get("fatalEnterError") != null; 34.56 + showResolveErrors = options.get("showResolveErrors") != null; 34.57 werror = options.get("-Werror") != null; 34.58 platformAnnotations = initPlatformAnnotations(); 34.59 foundTypeProcessors = false; 34.60 @@ -818,6 +828,7 @@ 34.61 34.62 compiler = JavaCompiler.instance(context); 34.63 log = Log.instance(context); 34.64 + log.deferDiagnostics = true; 34.65 34.66 // the following is for the benefit of JavacProcessingEnvironment.getContext() 34.67 JavacProcessingEnvironment.this.context = context; 34.68 @@ -848,8 +859,7 @@ 34.69 34.70 /** Create a new round. */ 34.71 private Round(Round prev, 34.72 - Set<JavaFileObject> newSourceFiles, Map<String,JavaFileObject> newClassFiles) 34.73 - throws IOException { 34.74 + Set<JavaFileObject> newSourceFiles, Map<String,JavaFileObject> newClassFiles) { 34.75 this(prev.nextContext(), prev.number+1, prev.compiler.log.nwarnings); 34.76 this.genClassFiles = prev.genClassFiles; 34.77 34.78 @@ -882,8 +892,7 @@ 34.79 } 34.80 34.81 /** Create the next round to be used. */ 34.82 - Round next(Set<JavaFileObject> newSourceFiles, Map<String, JavaFileObject> newClassFiles) 34.83 - throws IOException { 34.84 + Round next(Set<JavaFileObject> newSourceFiles, Map<String, JavaFileObject> newClassFiles) { 34.85 try { 34.86 return new Round(this, newSourceFiles, newClassFiles); 34.87 } finally { 34.88 @@ -919,10 +928,24 @@ 34.89 34.90 /** Return whether or not an unrecoverable error has occurred. */ 34.91 boolean unrecoverableError() { 34.92 - return log.unrecoverableError 34.93 - || messager.errorRaised() 34.94 - || (werror && log.nwarnings > 0) 34.95 - || (fatalErrors && log.nerrors > 0); 34.96 + if (messager.errorRaised()) 34.97 + return true; 34.98 + 34.99 + for (JCDiagnostic d: log.deferredDiagnostics) { 34.100 + switch (d.getKind()) { 34.101 + case WARNING: 34.102 + if (werror) 34.103 + return true; 34.104 + break; 34.105 + 34.106 + case ERROR: 34.107 + if (fatalErrors || !d.isFlagSet(RESOLVE_ERROR)) 34.108 + return true; 34.109 + break; 34.110 + } 34.111 + } 34.112 + 34.113 + return false; 34.114 } 34.115 34.116 /** Find the set of annotations present in the set of top level 34.117 @@ -938,7 +961,7 @@ 34.118 } 34.119 34.120 /** Enter a set of generated class files. */ 34.121 - List<ClassSymbol> enterClassFiles(Map<String, JavaFileObject> classFiles) { 34.122 + private List<ClassSymbol> enterClassFiles(Map<String, JavaFileObject> classFiles) { 34.123 ClassReader reader = ClassReader.instance(context); 34.124 Names names = Names.instance(context); 34.125 List<ClassSymbol> list = List.nil(); 34.126 @@ -965,7 +988,7 @@ 34.127 } 34.128 34.129 /** Enter a set of syntax trees. */ 34.130 - void enterTrees(List<JCCompilationUnit> roots) { 34.131 + private void enterTrees(List<JCCompilationUnit> roots) { 34.132 compiler.enterTrees(roots); 34.133 } 34.134 34.135 @@ -995,6 +1018,15 @@ 34.136 } 34.137 } 34.138 34.139 + void showDiagnostics(boolean showAll) { 34.140 + Set<JCDiagnostic.Kind> kinds = EnumSet.allOf(JCDiagnostic.Kind.class); 34.141 + if (!showAll) { 34.142 + // suppress errors, which are all presumed to be transient resolve errors 34.143 + kinds.remove(JCDiagnostic.Kind.ERROR); 34.144 + } 34.145 + log.reportDeferredDiagnostics(kinds); 34.146 + } 34.147 + 34.148 /** Update the processing state for the current context. */ 34.149 private void updateProcessingState() { 34.150 filer.newRound(context); 34.151 @@ -1083,8 +1115,7 @@ 34.152 public JavaCompiler doProcessing(Context context, 34.153 List<JCCompilationUnit> roots, 34.154 List<ClassSymbol> classSymbols, 34.155 - Iterable<? extends PackageSymbol> pckSymbols) 34.156 - throws IOException { 34.157 + Iterable<? extends PackageSymbol> pckSymbols) { 34.158 34.159 TaskListener taskListener = context.get(TaskListener.class); 34.160 log = Log.instance(context); 34.161 @@ -1107,6 +1138,8 @@ 34.162 errorStatus = round.unrecoverableError(); 34.163 moreToDo = moreToDo(); 34.164 34.165 + round.showDiagnostics(errorStatus || showResolveErrors); 34.166 + 34.167 // Set up next round. 34.168 // Copy mutable collections returned from filer. 34.169 round = round.next( 34.170 @@ -1121,6 +1154,7 @@ 34.171 34.172 // run last round 34.173 round.run(true, errorStatus); 34.174 + round.showDiagnostics(true); 34.175 34.176 filer.warnIfUnclosedFiles(); 34.177 warnIfUnmatchedOptions(); 34.178 @@ -1184,13 +1218,19 @@ 34.179 /** 34.180 * Free resources related to annotation processing. 34.181 */ 34.182 - public void close() throws IOException { 34.183 + public void close() { 34.184 filer.close(); 34.185 if (discoveredProcs != null) // Make calling close idempotent 34.186 discoveredProcs.close(); 34.187 discoveredProcs = null; 34.188 - if (processorClassLoader != null && processorClassLoader instanceof Closeable) 34.189 - ((Closeable) processorClassLoader).close(); 34.190 + if (processorClassLoader != null && processorClassLoader instanceof Closeable) { 34.191 + try { 34.192 + ((Closeable) processorClassLoader).close(); 34.193 + } catch (IOException e) { 34.194 + JCDiagnostic msg = diags.fragment("fatal.err.cant.close.loader"); 34.195 + throw new FatalError(msg, e); 34.196 + } 34.197 + } 34.198 } 34.199 34.200 private List<ClassSymbol> getTopLevelClasses(List<? extends JCCompilationUnit> units) {
35.1 --- a/src/share/classes/com/sun/tools/javac/resources/compiler.properties Thu Sep 23 17:33:52 2010 -0700 35.2 +++ b/src/share/classes/com/sun/tools/javac/resources/compiler.properties Fri Sep 24 16:43:08 2010 -0700 35.3 @@ -128,6 +128,11 @@ 35.4 compiler.err.no.superclass=\ 35.5 {0} has no superclass 35.6 35.7 +compiler.warn.type.parameter.on.polymorphic.signature=\ 35.8 + change obsolete notation for MethodHandle invocations from x.<T>invoke(y) to (T)x.invoke(y) 35.9 +compiler.warn.wrong.target.for.polymorphic.signature.definition=\ 35.10 + MethodHandle API building requires -target 7 runtimes or better; current is -target {0} 35.11 + 35.12 compiler.err.concrete.inheritance.conflict=\ 35.13 methods {0} from {1} and {2} from {3} are inherited with the same signature 35.14 35.15 @@ -550,6 +555,8 @@ 35.16 Fatal Error: Unable to find field {0} 35.17 compiler.misc.fatal.err.cant.locate.ctor=\ 35.18 Fatal Error: Unable to find constructor for {0} 35.19 +compiler.misc.fatal.err.cant.close.loader=\ 35.20 + Fatal Error: Cannot close class loader for annotation processors 35.21 35.22 ##### 35.23 35.24 @@ -1240,6 +1247,10 @@ 35.25 underscores in literals are not supported in -source {0}\n\ 35.26 (use -source 7 or higher to enable underscores in literals) 35.27 35.28 +compiler.err.unsupported.exotic.id=\ 35.29 + exotic identifiers #"___" are not supported in -source {0}\n\ 35.30 +(use -source 7 or higher to enable exotic identifiers) 35.31 + 35.32 compiler.err.automatic.resource.management.not.supported.in.source=\ 35.33 automatic resource management is not supported in -source {0}\n\ 35.34 (use -source 7 or higher to enable automatic resource management)
36.1 --- a/src/share/classes/com/sun/tools/javac/resources/javac.properties Thu Sep 23 17:33:52 2010 -0700 36.2 +++ b/src/share/classes/com/sun/tools/javac/resources/javac.properties Fri Sep 24 16:43:08 2010 -0700 36.3 @@ -74,7 +74,9 @@ 36.4 javac.opt.A=\ 36.5 Options to pass to annotation processors 36.6 javac.opt.implicit=\ 36.7 - Specify whether or not to generate class files for implicitly referenced files 36.8 + Specify whether or not to generate class files for implicitly referenced files 36.9 +javac.opt.pkginfo=\ 36.10 + Specify handling of package-info files 36.11 javac.opt.arg.class=\ 36.12 <class> 36.13 javac.opt.arg.class.list=\ 36.14 @@ -189,7 +191,7 @@ 36.15 36.16 javac.msg.usage.nonstandard.footer=\ 36.17 These options are non-standard and subject to change without notice. 36.18 - 36.19 + 36.20 javac.msg.bug=\ 36.21 An exception has occurred in the compiler ({0}). \ 36.22 Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport) \
37.1 --- a/src/share/classes/com/sun/tools/javac/resources/legacy.properties Thu Sep 23 17:33:52 2010 -0700 37.2 +++ b/src/share/classes/com/sun/tools/javac/resources/legacy.properties Fri Sep 24 16:43:08 2010 -0700 37.3 @@ -565,6 +565,7 @@ 37.4 sun.tools.jar.resources = tiger legacy 37.5 sun.util = tiger legacy 37.6 sun.util.calendar = tiger legacy 37.7 +sun.util.locale = tiger legacy 37.8 sun.util.logging.resources = tiger legacy 37.9 sunw.io = tiger legacy 37.10 sunw.util = tiger legacy
38.1 --- a/src/share/classes/com/sun/tools/javac/tree/JCTree.java Thu Sep 23 17:33:52 2010 -0700 38.2 +++ b/src/share/classes/com/sun/tools/javac/tree/JCTree.java Fri Sep 24 16:43:08 2010 -0700 38.3 @@ -340,6 +340,7 @@ 38.4 public abstract int getTag(); 38.5 38.6 /** Convert a tree to a pretty-printed string. */ 38.7 + @Override 38.8 public String toString() { 38.9 StringWriter s = new StringWriter(); 38.10 try { 38.11 @@ -375,6 +376,7 @@ 38.12 38.13 /** Return a shallow copy of this tree. 38.14 */ 38.15 + @Override 38.16 public Object clone() { 38.17 try { 38.18 return super.clone(); 38.19 @@ -587,7 +589,17 @@ 38.20 @Override 38.21 public void accept(Visitor v) { v.visitClassDef(this); } 38.22 38.23 - public Kind getKind() { return Kind.CLASS; } 38.24 + public Kind getKind() { 38.25 + if ((mods.flags & Flags.ANNOTATION) != 0) 38.26 + return Kind.ANNOTATION_TYPE; 38.27 + else if ((mods.flags & Flags.INTERFACE) != 0) 38.28 + return Kind.INTERFACE; 38.29 + else if ((mods.flags & Flags.ENUM) != 0) 38.30 + return Kind.ENUM; 38.31 + else 38.32 + return Kind.CLASS; 38.33 + } 38.34 + 38.35 public JCModifiers getModifiers() { return mods; } 38.36 public Name getSimpleName() { return name; } 38.37 public List<JCTypeParameter> getTypeParameters() {
39.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java Thu Sep 23 17:33:52 2010 -0700 39.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java Fri Sep 24 16:43:08 2010 -0700 39.3 @@ -501,6 +501,10 @@ 39.4 if (that.sym == sym) result = that; 39.5 else super.visitVarDef(that); 39.6 } 39.7 + public void visitTypeParameter(JCTypeParameter that) { 39.8 + if (that.type.tsym == sym) result = that; 39.9 + else super.visitTypeParameter(that); 39.10 + } 39.11 } 39.12 DeclScanner s = new DeclScanner(); 39.13 tree.accept(s); 39.14 @@ -633,6 +637,18 @@ 39.15 } 39.16 } 39.17 39.18 + public static boolean isDeclaration(JCTree node) { 39.19 + node = skipParens(node); 39.20 + switch (node.getTag()) { 39.21 + case JCTree.CLASSDEF: 39.22 + case JCTree.METHODDEF: 39.23 + case JCTree.VARDEF: 39.24 + return true; 39.25 + default: 39.26 + return false; 39.27 + } 39.28 + } 39.29 + 39.30 /** If this tree is an identifier or a field, return its symbol, 39.31 * otherwise return null. 39.32 */
40.1 --- a/src/share/classes/com/sun/tools/javac/util/FatalError.java Thu Sep 23 17:33:52 2010 -0700 40.2 +++ b/src/share/classes/com/sun/tools/javac/util/FatalError.java Fri Sep 24 16:43:08 2010 -0700 40.3 @@ -37,12 +37,6 @@ 40.4 public class FatalError extends Error { 40.5 private static final long serialVersionUID = 0; 40.6 40.7 - /** Construct a <code>FatalError</code> with no detail message. 40.8 - */ 40.9 - public FatalError() { 40.10 - super(); 40.11 - } 40.12 - 40.13 /** Construct a <code>FatalError</code> with the specified detail message. 40.14 * @param d A diagnostic containing the reason for failure. 40.15 */ 40.16 @@ -50,6 +44,15 @@ 40.17 super(d.toString()); 40.18 } 40.19 40.20 + /** Construct a <code>FatalError</code> with the specified detail message 40.21 + * and cause. 40.22 + * @param d A diagnostic containing the reason for failure. 40.23 + * @param t An exception causing the error 40.24 + */ 40.25 + public FatalError(JCDiagnostic d, Throwable t) { 40.26 + super(d.toString(), t); 40.27 + } 40.28 + 40.29 /** Construct a <code>FatalError</code> with the specified detail message. 40.30 * @param s An English(!) string describing the failure, typically because 40.31 * the diagnostic resources are missing.
41.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 41.2 +++ b/src/share/classes/com/sun/tools/javac/util/Filter.java Fri Sep 24 16:43:08 2010 -0700 41.3 @@ -0,0 +1,39 @@ 41.4 +/* 41.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 41.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 41.7 + * 41.8 + * This code is free software; you can redistribute it and/or modify it 41.9 + * under the terms of the GNU General Public License version 2 only, as 41.10 + * published by the Free Software Foundation. Oracle designates this 41.11 + * particular file as subject to the "Classpath" exception as provided 41.12 + * by Oracle in the LICENSE file that accompanied this code. 41.13 + * 41.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 41.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 41.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 41.17 + * version 2 for more details (a copy is included in the LICENSE file that 41.18 + * accompanied this code). 41.19 + * 41.20 + * You should have received a copy of the GNU General Public License version 41.21 + * 2 along with this work; if not, write to the Free Software Foundation, 41.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 41.23 + * 41.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 41.25 + * or visit www.oracle.com if you need additional information or have any 41.26 + * questions. 41.27 + */ 41.28 + 41.29 +package com.sun.tools.javac.util; 41.30 + 41.31 +/** 41.32 + * Simple filter acting as a boolean predicate. Method accepts return true if 41.33 + * the supplied element matches against the filter. 41.34 + */ 41.35 +public interface Filter<T> { 41.36 + /** 41.37 + * Does this element match against the filter? 41.38 + * @param t element to be checked 41.39 + * @return true if the element satisfy constraints imposed by filter 41.40 + */ 41.41 + boolean accepts(T t); 41.42 +}
42.1 --- a/src/share/classes/com/sun/tools/javac/util/Log.java Thu Sep 23 17:33:52 2010 -0700 42.2 +++ b/src/share/classes/com/sun/tools/javac/util/Log.java Fri Sep 24 16:43:08 2010 -0700 42.3 @@ -27,8 +27,10 @@ 42.4 42.5 import java.io.*; 42.6 import java.util.Arrays; 42.7 +import java.util.EnumSet; 42.8 import java.util.HashSet; 42.9 import java.util.Map; 42.10 +import java.util.Queue; 42.11 import java.util.Set; 42.12 import javax.tools.DiagnosticListener; 42.13 import javax.tools.JavaFileObject; 42.14 @@ -110,6 +112,12 @@ 42.15 */ 42.16 private JavacMessages messages; 42.17 42.18 + /** 42.19 + * Deferred diagnostics 42.20 + */ 42.21 + public boolean deferDiagnostics; 42.22 + public Queue<JCDiagnostic> deferredDiagnostics = new ListBuffer<JCDiagnostic>(); 42.23 + 42.24 /** Construct a log with given I/O redirections. 42.25 */ 42.26 @Deprecated 42.27 @@ -204,12 +212,6 @@ 42.28 */ 42.29 public int nwarnings = 0; 42.30 42.31 - /** 42.32 - * Whether or not an unrecoverable error has been seen. 42.33 - * Unrecoverable errors prevent subsequent annotation processing. 42.34 - */ 42.35 - public boolean unrecoverableError; 42.36 - 42.37 /** A set of all errors generated so far. This is used to avoid printing an 42.38 * error message more than once. For each error, a pair consisting of the 42.39 * source file name and source code position of the error is added to the set. 42.40 @@ -347,12 +349,32 @@ 42.41 nwarnings++; 42.42 } 42.43 42.44 + /** Report all deferred diagnostics, and clear the deferDiagnostics flag. */ 42.45 + public void reportDeferredDiagnostics() { 42.46 + reportDeferredDiagnostics(EnumSet.allOf(JCDiagnostic.Kind.class)); 42.47 + } 42.48 + 42.49 + /** Report selected deferred diagnostics, and clear the deferDiagnostics flag. */ 42.50 + public void reportDeferredDiagnostics(Set<JCDiagnostic.Kind> kinds) { 42.51 + deferDiagnostics = false; 42.52 + JCDiagnostic d; 42.53 + while ((d = deferredDiagnostics.poll()) != null) { 42.54 + if (kinds.contains(d.getKind())) 42.55 + report(d); 42.56 + } 42.57 + } 42.58 + 42.59 /** 42.60 * Common diagnostic handling. 42.61 * The diagnostic is counted, and depending on the options and how many diagnostics have been 42.62 * reported so far, the diagnostic may be handed off to writeDiagnostic. 42.63 */ 42.64 public void report(JCDiagnostic diagnostic) { 42.65 + if (deferDiagnostics) { 42.66 + deferredDiagnostics.add(diagnostic); 42.67 + return; 42.68 + } 42.69 + 42.70 if (expectDiagKeys != null) 42.71 expectDiagKeys.remove(diagnostic.getCode()); 42.72
43.1 --- a/src/share/classes/com/sun/tools/javac/util/Names.java Thu Sep 23 17:33:52 2010 -0700 43.2 +++ b/src/share/classes/com/sun/tools/javac/util/Names.java Fri Sep 24 16:43:08 2010 -0700 43.3 @@ -103,7 +103,6 @@ 43.4 public final Name RuntimeInvisibleTypeAnnotations; 43.5 public final Name RuntimeVisibleParameterAnnotations; 43.6 public final Name RuntimeInvisibleParameterAnnotations; 43.7 - public final Name PolymorphicSignature; 43.8 public final Name Value; 43.9 public final Name EnclosingMethod; 43.10 public final Name desiredAssertionStatus; 43.11 @@ -116,6 +115,7 @@ 43.12 public final Name value; 43.13 public final Name getMessage; 43.14 public final Name getClass; 43.15 + public final Name invoke; //allowTransitionalJSR292 only 43.16 public final Name TYPE; 43.17 public final Name TYPE_USE; 43.18 public final Name TYPE_PARAMETER; 43.19 @@ -215,7 +215,6 @@ 43.20 RuntimeInvisibleTypeAnnotations = fromString("RuntimeInvisibleTypeAnnotations"); 43.21 RuntimeVisibleParameterAnnotations = fromString("RuntimeVisibleParameterAnnotations"); 43.22 RuntimeInvisibleParameterAnnotations = fromString("RuntimeInvisibleParameterAnnotations"); 43.23 - PolymorphicSignature = fromString("PolymorphicSignature"); 43.24 Value = fromString("Value"); 43.25 EnclosingMethod = fromString("EnclosingMethod"); 43.26 43.27 @@ -230,6 +229,7 @@ 43.28 value = fromString("value"); 43.29 getMessage = fromString("getMessage"); 43.30 getClass = fromString("getClass"); 43.31 + invoke = fromString("invoke"); //allowTransitionalJSR292 only 43.32 43.33 TYPE = fromString("TYPE"); 43.34 TYPE_USE = fromString("TYPE_USE");
44.1 --- a/src/share/classes/com/sun/tools/javap/CodeWriter.java Thu Sep 23 17:33:52 2010 -0700 44.2 +++ b/src/share/classes/com/sun/tools/javap/CodeWriter.java Fri Sep 24 16:43:08 2010 -0700 44.3 @@ -239,7 +239,10 @@ 44.4 new ArrayList<InstructionDetailWriter>(); 44.5 if (options.details.contains(InstructionDetailWriter.Kind.SOURCE)) { 44.6 sourceWriter.reset(classWriter.getClassFile(), attr); 44.7 - detailWriters.add(sourceWriter); 44.8 + if (sourceWriter.hasSource()) 44.9 + detailWriters.add(sourceWriter); 44.10 + else 44.11 + println("(Source code not available)"); 44.12 } 44.13 44.14 if (options.details.contains(InstructionDetailWriter.Kind.LOCAL_VARS)) {
45.1 --- a/src/share/classes/com/sun/tools/javap/SourceWriter.java Thu Sep 23 17:33:52 2010 -0700 45.2 +++ b/src/share/classes/com/sun/tools/javap/SourceWriter.java Fri Sep 24 16:43:08 2010 -0700 45.3 @@ -99,7 +99,10 @@ 45.4 } 45.5 } 45.6 } 45.7 + } 45.8 45.9 + public boolean hasSource() { 45.10 + return (sourceLines.length > 0); 45.11 } 45.12 45.13 private void setLineMap(Code_attribute attr) {
46.1 --- a/src/share/classes/javax/tools/ToolProvider.java Thu Sep 23 17:33:52 2010 -0700 46.2 +++ b/src/share/classes/javax/tools/ToolProvider.java Fri Sep 24 16:43:08 2010 -0700 46.3 @@ -26,10 +26,14 @@ 46.4 package javax.tools; 46.5 46.6 import java.io.File; 46.7 +import java.lang.ref.Reference; 46.8 +import java.lang.ref.WeakReference; 46.9 import java.net.URL; 46.10 import java.net.URLClassLoader; 46.11 import java.net.MalformedURLException; 46.12 +import java.util.HashMap; 46.13 import java.util.Locale; 46.14 +import java.util.Map; 46.15 import java.util.logging.Logger; 46.16 import java.util.logging.Level; 46.17 import static java.util.logging.Level.*; 46.18 @@ -44,8 +48,6 @@ 46.19 */ 46.20 public class ToolProvider { 46.21 46.22 - private ToolProvider() {} 46.23 - 46.24 private static final String propertyName = "sun.tools.ToolProvider"; 46.25 private static final String loggerName = "javax.tools"; 46.26 46.27 @@ -87,6 +89,9 @@ 46.28 return null; 46.29 } 46.30 46.31 + private static final String defaultJavaCompilerName 46.32 + = "com.sun.tools.javac.api.JavacTool"; 46.33 + 46.34 /** 46.35 * Gets the Java™ programming language compiler provided 46.36 * with this platform. 46.37 @@ -94,13 +99,7 @@ 46.38 * {@code null} if no compiler is provided 46.39 */ 46.40 public static JavaCompiler getSystemJavaCompiler() { 46.41 - if (Lazy.compilerClass == null) 46.42 - return trace(WARNING, "Lazy.compilerClass == null"); 46.43 - try { 46.44 - return Lazy.compilerClass.newInstance(); 46.45 - } catch (Throwable e) { 46.46 - return trace(WARNING, e); 46.47 - } 46.48 + return instance().getSystemTool(JavaCompiler.class, defaultJavaCompilerName); 46.49 } 46.50 46.51 /** 46.52 @@ -113,63 +112,109 @@ 46.53 * or {@code null} if no tools are provided 46.54 */ 46.55 public static ClassLoader getSystemToolClassLoader() { 46.56 - if (Lazy.compilerClass == null) 46.57 - return trace(WARNING, "Lazy.compilerClass == null"); 46.58 - return Lazy.compilerClass.getClassLoader(); 46.59 + try { 46.60 + Class<? extends JavaCompiler> c = 46.61 + instance().getSystemToolClass(JavaCompiler.class, defaultJavaCompilerName); 46.62 + return c.getClassLoader(); 46.63 + } catch (Throwable e) { 46.64 + return trace(WARNING, e); 46.65 + } 46.66 } 46.67 46.68 - /** 46.69 - * This class will not be initialized until one of the above 46.70 - * methods are called. This ensures that searching for the 46.71 - * compiler does not affect platform start up. 46.72 - */ 46.73 - static class Lazy { 46.74 - private static final String defaultJavaCompilerName 46.75 - = "com.sun.tools.javac.api.JavacTool"; 46.76 - private static final String[] defaultToolsLocation 46.77 - = { "lib", "tools.jar" }; 46.78 - static final Class<? extends JavaCompiler> compilerClass; 46.79 - static { 46.80 - Class<? extends JavaCompiler> c = null; 46.81 + 46.82 + private static ToolProvider instance; 46.83 + 46.84 + private static synchronized ToolProvider instance() { 46.85 + if (instance == null) 46.86 + instance = new ToolProvider(); 46.87 + return instance; 46.88 + } 46.89 + 46.90 + // Cache for tool classes. 46.91 + // Use weak references to avoid keeping classes around unnecessarily 46.92 + private Map<String, Reference<Class<?>>> toolClasses = new HashMap<String, Reference<Class<?>>>(); 46.93 + 46.94 + // Cache for tool classloader. 46.95 + // Use a weak reference to avoid keeping it around unnecessarily 46.96 + private Reference<ClassLoader> refToolClassLoader = null; 46.97 + 46.98 + 46.99 + private ToolProvider() { } 46.100 + 46.101 + private <T> T getSystemTool(Class<T> clazz, String name) { 46.102 + Class<? extends T> c = getSystemToolClass(clazz, name); 46.103 + try { 46.104 + return c.asSubclass(clazz).newInstance(); 46.105 + } catch (Throwable e) { 46.106 + trace(WARNING, e); 46.107 + return null; 46.108 + } 46.109 + } 46.110 + 46.111 + private <T> Class<? extends T> getSystemToolClass(Class<T> clazz, String name) { 46.112 + Reference<Class<?>> refClass = toolClasses.get(name); 46.113 + Class<?> c = (refClass == null ? null : refClass.get()); 46.114 + if (c == null) { 46.115 try { 46.116 - c = findClass().asSubclass(JavaCompiler.class); 46.117 - } catch (Throwable t) { 46.118 - trace(WARNING, t); 46.119 + c = findSystemToolClass(name); 46.120 + } catch (Throwable e) { 46.121 + return trace(WARNING, e); 46.122 } 46.123 - compilerClass = c; 46.124 + toolClasses.put(name, new WeakReference<Class<?>>(c)); 46.125 + } 46.126 + return c.asSubclass(clazz); 46.127 + } 46.128 + 46.129 + private static final String[] defaultToolsLocation = { "lib", "tools.jar" }; 46.130 + 46.131 + private Class<?> findSystemToolClass(String toolClassName) 46.132 + throws MalformedURLException, ClassNotFoundException 46.133 + { 46.134 + // try loading class directly, in case tool is on the bootclasspath 46.135 + try { 46.136 + return enableAsserts(Class.forName(toolClassName, false, null)); 46.137 + } catch (ClassNotFoundException e) { 46.138 + trace(FINE, e); 46.139 + 46.140 + // if tool not on bootclasspath, look in default tools location (tools.jar) 46.141 + ClassLoader cl = (refToolClassLoader == null ? null : refToolClassLoader.get()); 46.142 + if (cl == null) { 46.143 + File file = new File(System.getProperty("java.home")); 46.144 + if (file.getName().equalsIgnoreCase("jre")) 46.145 + file = file.getParentFile(); 46.146 + for (String name : defaultToolsLocation) 46.147 + file = new File(file, name); 46.148 + 46.149 + // if tools not found, no point in trying a URLClassLoader 46.150 + // so rethrow the original exception. 46.151 + if (!file.exists()) 46.152 + throw e; 46.153 + 46.154 + URL[] urls = { file.toURI().toURL() }; 46.155 + trace(FINE, urls[0].toString()); 46.156 + 46.157 + cl = URLClassLoader.newInstance(urls); 46.158 + cl.setPackageAssertionStatus("com.sun.tools.javac", true); 46.159 + refToolClassLoader = new WeakReference<ClassLoader>(cl); 46.160 + } 46.161 + 46.162 + return Class.forName(toolClassName, false, cl); 46.163 } 46.164 46.165 - private static Class<?> findClass() 46.166 - throws MalformedURLException, ClassNotFoundException 46.167 - { 46.168 - try { 46.169 - return enableAsserts(Class.forName(defaultJavaCompilerName, false, null)); 46.170 - } catch (ClassNotFoundException e) { 46.171 - trace(FINE, e); 46.172 - } 46.173 - File file = new File(System.getProperty("java.home")); 46.174 - if (file.getName().equalsIgnoreCase("jre")) 46.175 - file = file.getParentFile(); 46.176 - for (String name : defaultToolsLocation) 46.177 - file = new File(file, name); 46.178 - URL[] urls = {file.toURI().toURL()}; 46.179 - trace(FINE, urls[0].toString()); 46.180 - ClassLoader cl = URLClassLoader.newInstance(urls); 46.181 - cl.setPackageAssertionStatus("com.sun.tools.javac", true); 46.182 - return Class.forName(defaultJavaCompilerName, false, cl); 46.183 + } 46.184 + 46.185 + private static Class<?> enableAsserts(Class<?> cls) { 46.186 + try { 46.187 + ClassLoader loader = cls.getClassLoader(); 46.188 + if (loader != null) 46.189 + loader.setPackageAssertionStatus("com.sun.tools.javac", true); 46.190 + else 46.191 + trace(FINE, "loader == null"); 46.192 + } catch (SecurityException ex) { 46.193 + trace(FINE, ex); 46.194 } 46.195 + return cls; 46.196 + } 46.197 46.198 - private static Class<?> enableAsserts(Class<?> cls) { 46.199 - try { 46.200 - ClassLoader loader = cls.getClassLoader(); 46.201 - if (loader != null) 46.202 - loader.setPackageAssertionStatus("com.sun.tools.javac", true); 46.203 - else 46.204 - trace(FINE, "loader == null"); 46.205 - } catch (SecurityException ex) { 46.206 - trace(FINE, ex); 46.207 - } 46.208 - return cls; 46.209 - } 46.210 - } 46.211 + 46.212 }
47.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 47.2 +++ b/test/tools/javac/6979683/TestCast6979683_BAD34.java Fri Sep 24 16:43:08 2010 -0700 47.3 @@ -0,0 +1,40 @@ 47.4 +/* 47.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 47.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 47.7 + * 47.8 + * This code is free software; you can redistribute it and/or modify it 47.9 + * under the terms of the GNU General Public License version 2 only, as 47.10 + * published by the Free Software Foundation. 47.11 + * 47.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 47.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 47.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 47.15 + * version 2 for more details (a copy is included in the LICENSE file that 47.16 + * accompanied this code). 47.17 + * 47.18 + * You should have received a copy of the GNU General Public License version 47.19 + * 2 along with this work; if not, write to the Free Software Foundation, 47.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 47.21 + * 47.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 47.23 + * or visit www.oracle.com if you need additional information or have any 47.24 + * questions. 47.25 + */ 47.26 + 47.27 +/* 47.28 + * @test 47.29 + * @bug 6979683 47.30 + * @summary Verify that casts can narrow and unbox at the same time 47.31 + * @author jrose 47.32 + * 47.33 + * @compile/fail/ref=TestCast6979683_BAD34.java.errlog -XDrawDiagnostics TestCast6979683_BAD34.java 47.34 + */ 47.35 + 47.36 +public class TestCast6979683_BAD34 { 47.37 + static boolean zconvBAD1(Number o) { return o; } //BAD 47.38 + //... 47.39 + //... 47.40 + //... 47.41 + //... 47.42 + //... 47.43 +}
48.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 48.2 +++ b/test/tools/javac/6979683/TestCast6979683_BAD34.java.errlog Fri Sep 24 16:43:08 2010 -0700 48.3 @@ -0,0 +1,2 @@ 48.4 +TestCast6979683_BAD34.java:34:49: compiler.err.prob.found.req: (compiler.misc.incompatible.types), java.lang.Number, boolean 48.5 +1 error
49.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 49.2 +++ b/test/tools/javac/6979683/TestCast6979683_BAD35.java Fri Sep 24 16:43:08 2010 -0700 49.3 @@ -0,0 +1,40 @@ 49.4 +/* 49.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 49.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 49.7 + * 49.8 + * This code is free software; you can redistribute it and/or modify it 49.9 + * under the terms of the GNU General Public License version 2 only, as 49.10 + * published by the Free Software Foundation. 49.11 + * 49.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 49.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 49.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 49.15 + * version 2 for more details (a copy is included in the LICENSE file that 49.16 + * accompanied this code). 49.17 + * 49.18 + * You should have received a copy of the GNU General Public License version 49.19 + * 2 along with this work; if not, write to the Free Software Foundation, 49.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 49.21 + * 49.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 49.23 + * or visit www.oracle.com if you need additional information or have any 49.24 + * questions. 49.25 + */ 49.26 + 49.27 +/* 49.28 + * @test 49.29 + * @bug 6979683 49.30 + * @summary Verify that casts can narrow and unbox at the same time 49.31 + * @author jrose 49.32 + * 49.33 + * @compile/fail/ref=TestCast6979683_BAD35.java.errlog -XDrawDiagnostics TestCast6979683_BAD35.java 49.34 + */ 49.35 + 49.36 +public class TestCast6979683_BAD35 { 49.37 + //... 49.38 + static int iconvBAD1(Number o) { return o; } //BAD: cast needed 49.39 + //... 49.40 + //... 49.41 + //... 49.42 + //... 49.43 +}
50.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 50.2 +++ b/test/tools/javac/6979683/TestCast6979683_BAD35.java.errlog Fri Sep 24 16:43:08 2010 -0700 50.3 @@ -0,0 +1,2 @@ 50.4 +TestCast6979683_BAD35.java:35:45: compiler.err.prob.found.req: (compiler.misc.incompatible.types), java.lang.Number, int 50.5 +1 error
51.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 51.2 +++ b/test/tools/javac/6979683/TestCast6979683_BAD36.java Fri Sep 24 16:43:08 2010 -0700 51.3 @@ -0,0 +1,40 @@ 51.4 +/* 51.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 51.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 51.7 + * 51.8 + * This code is free software; you can redistribute it and/or modify it 51.9 + * under the terms of the GNU General Public License version 2 only, as 51.10 + * published by the Free Software Foundation. 51.11 + * 51.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 51.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 51.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 51.15 + * version 2 for more details (a copy is included in the LICENSE file that 51.16 + * accompanied this code). 51.17 + * 51.18 + * You should have received a copy of the GNU General Public License version 51.19 + * 2 along with this work; if not, write to the Free Software Foundation, 51.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 51.21 + * 51.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 51.23 + * or visit www.oracle.com if you need additional information or have any 51.24 + * questions. 51.25 + */ 51.26 + 51.27 +/* 51.28 + * @test 51.29 + * @bug 6979683 51.30 + * @summary Verify that casts can narrow and unbox at the same time 51.31 + * @author jrose 51.32 + * 51.33 + * @compile/fail/ref=TestCast6979683_BAD36.java.errlog -XDrawDiagnostics TestCast6979683_BAD36.java 51.34 + */ 51.35 + 51.36 +public class TestCast6979683_BAD36 { 51.37 + //... 51.38 + //... 51.39 + static int iconvBAD2(Comparable<Integer> o) { return o; } //BAD: cast needed 51.40 + //... 51.41 + //... 51.42 + //... 51.43 +}
52.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 52.2 +++ b/test/tools/javac/6979683/TestCast6979683_BAD36.java.errlog Fri Sep 24 16:43:08 2010 -0700 52.3 @@ -0,0 +1,2 @@ 52.4 +TestCast6979683_BAD36.java:36:58: compiler.err.prob.found.req: (compiler.misc.incompatible.types), java.lang.Comparable<java.lang.Integer>, int 52.5 +1 error
53.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 53.2 +++ b/test/tools/javac/6979683/TestCast6979683_BAD37.java Fri Sep 24 16:43:08 2010 -0700 53.3 @@ -0,0 +1,40 @@ 53.4 +/* 53.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 53.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 53.7 + * 53.8 + * This code is free software; you can redistribute it and/or modify it 53.9 + * under the terms of the GNU General Public License version 2 only, as 53.10 + * published by the Free Software Foundation. 53.11 + * 53.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 53.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 53.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 53.15 + * version 2 for more details (a copy is included in the LICENSE file that 53.16 + * accompanied this code). 53.17 + * 53.18 + * You should have received a copy of the GNU General Public License version 53.19 + * 2 along with this work; if not, write to the Free Software Foundation, 53.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 53.21 + * 53.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 53.23 + * or visit www.oracle.com if you need additional information or have any 53.24 + * questions. 53.25 + */ 53.26 + 53.27 +/* 53.28 + * @test 53.29 + * @bug 6979683 53.30 + * @summary Verify that casts can narrow and unbox at the same time 53.31 + * @author jrose 53.32 + * 53.33 + * @compile/fail/ref=TestCast6979683_BAD37.java.errlog -XDrawDiagnostics TestCast6979683_BAD37.java 53.34 + */ 53.35 + 53.36 +public class TestCast6979683_BAD37 { 53.37 + //... 53.38 + //... 53.39 + //... 53.40 + static int iconvBAD3(Comparable<Short> o) { return (int)o; } //BAD: wrong instance 53.41 + //... 53.42 + //... 53.43 +}
54.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 54.2 +++ b/test/tools/javac/6979683/TestCast6979683_BAD37.java.errlog Fri Sep 24 16:43:08 2010 -0700 54.3 @@ -0,0 +1,2 @@ 54.4 +TestCast6979683_BAD37.java:37:61: compiler.err.prob.found.req: (compiler.misc.inconvertible.types), java.lang.Comparable<java.lang.Short>, int 54.5 +1 error
55.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 55.2 +++ b/test/tools/javac/6979683/TestCast6979683_BAD38.java Fri Sep 24 16:43:08 2010 -0700 55.3 @@ -0,0 +1,40 @@ 55.4 +/* 55.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 55.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 55.7 + * 55.8 + * This code is free software; you can redistribute it and/or modify it 55.9 + * under the terms of the GNU General Public License version 2 only, as 55.10 + * published by the Free Software Foundation. 55.11 + * 55.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 55.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 55.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 55.15 + * version 2 for more details (a copy is included in the LICENSE file that 55.16 + * accompanied this code). 55.17 + * 55.18 + * You should have received a copy of the GNU General Public License version 55.19 + * 2 along with this work; if not, write to the Free Software Foundation, 55.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 55.21 + * 55.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 55.23 + * or visit www.oracle.com if you need additional information or have any 55.24 + * questions. 55.25 + */ 55.26 + 55.27 +/* 55.28 + * @test 55.29 + * @bug 6979683 55.30 + * @summary Verify that casts can narrow and unbox at the same time 55.31 + * @author jrose 55.32 + * 55.33 + * @compile/fail/ref=TestCast6979683_BAD38.java.errlog -XDrawDiagnostics TestCast6979683_BAD38.java 55.34 + */ 55.35 + 55.36 +public class TestCast6979683_BAD38 { 55.37 + //... 55.38 + //... 55.39 + //... 55.40 + //... 55.41 + static float cconvBAD1(Comparable<Character> o) { return o; } //BAD 55.42 + //... 55.43 +}
56.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 56.2 +++ b/test/tools/javac/6979683/TestCast6979683_BAD38.java.errlog Fri Sep 24 16:43:08 2010 -0700 56.3 @@ -0,0 +1,2 @@ 56.4 +TestCast6979683_BAD38.java:38:62: compiler.err.prob.found.req: (compiler.misc.incompatible.types), java.lang.Comparable<java.lang.Character>, float 56.5 +1 error
57.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 57.2 +++ b/test/tools/javac/6979683/TestCast6979683_BAD39.java Fri Sep 24 16:43:08 2010 -0700 57.3 @@ -0,0 +1,40 @@ 57.4 +/* 57.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 57.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 57.7 + * 57.8 + * This code is free software; you can redistribute it and/or modify it 57.9 + * under the terms of the GNU General Public License version 2 only, as 57.10 + * published by the Free Software Foundation. 57.11 + * 57.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 57.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 57.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 57.15 + * version 2 for more details (a copy is included in the LICENSE file that 57.16 + * accompanied this code). 57.17 + * 57.18 + * You should have received a copy of the GNU General Public License version 57.19 + * 2 along with this work; if not, write to the Free Software Foundation, 57.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 57.21 + * 57.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 57.23 + * or visit www.oracle.com if you need additional information or have any 57.24 + * questions. 57.25 + */ 57.26 + 57.27 +/* 57.28 + * @test 57.29 + * @bug 6979683 57.30 + * @summary Verify that casts can narrow and unbox at the same time 57.31 + * @author jrose 57.32 + * 57.33 + * @compile/fail/ref=TestCast6979683_BAD39.java.errlog -XDrawDiagnostics TestCast6979683_BAD39.java 57.34 + */ 57.35 + 57.36 +public class TestCast6979683_BAD39 { 57.37 + //... 57.38 + //... 57.39 + //... 57.40 + //... 57.41 + //... 57.42 + static float cconvBAD2(Number o) { return (char)o; } //BAD 57.43 +}
58.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 58.2 +++ b/test/tools/javac/6979683/TestCast6979683_BAD39.java.errlog Fri Sep 24 16:43:08 2010 -0700 58.3 @@ -0,0 +1,2 @@ 58.4 +TestCast6979683_BAD39.java:39:53: compiler.err.prob.found.req: (compiler.misc.inconvertible.types), java.lang.Number, char 58.5 +1 error
59.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 59.2 +++ b/test/tools/javac/6979683/TestCast6979683_GOOD.java Fri Sep 24 16:43:08 2010 -0700 59.3 @@ -0,0 +1,111 @@ 59.4 +/* 59.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 59.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 59.7 + * 59.8 + * This code is free software; you can redistribute it and/or modify it 59.9 + * under the terms of the GNU General Public License version 2 only, as 59.10 + * published by the Free Software Foundation. 59.11 + * 59.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 59.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 59.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 59.15 + * version 2 for more details (a copy is included in the LICENSE file that 59.16 + * accompanied this code). 59.17 + * 59.18 + * You should have received a copy of the GNU General Public License version 59.19 + * 2 along with this work; if not, write to the Free Software Foundation, 59.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 59.21 + * 59.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 59.23 + * or visit www.oracle.com if you need additional information or have any 59.24 + * questions. 59.25 + */ 59.26 + 59.27 +/* 59.28 + * @test 59.29 + * @bug 6979683 59.30 + * @summary Verify that casts can narrow and unbox at the same time 59.31 + * @author jrose 59.32 + * 59.33 + * @compile TestCast6979683_GOOD.java 59.34 + * @run main TestCast6979683_GOOD 59.35 + */ 59.36 + 59.37 +public class TestCast6979683_GOOD { 59.38 + public static void main(String... av) { 59.39 + bugReportExample(); 59.40 + for (int x = -1; x <= 2; x++) { 59.41 + zconvTests(x != 0); 59.42 + iconvTests(x); 59.43 + bconvTests((byte)x); 59.44 + cconvTests((char)x); 59.45 + } 59.46 + System.out.println("Successfully ran "+tests+" tests."); 59.47 + } 59.48 + 59.49 + static int tests; 59.50 + static void assertEquals(Object x, Object y) { 59.51 + if (!x.equals(y)) { 59.52 + throw new RuntimeException("assertEquals: "+x+" != "+y); 59.53 + } 59.54 + ++tests; 59.55 + } 59.56 + 59.57 + static void bugReportExample() { 59.58 + {} // example in bug report: 59.59 + Object x = (Object)1; 59.60 + int y = (int)x; 59.61 + {} // end example 59.62 + } 59.63 + 59.64 + static boolean zconv1(Boolean o) { return o; } 59.65 + static boolean zconv2(Object o) { return (boolean)o; } 59.66 + static boolean zconv3(Comparable<Boolean> o) { return (boolean)o; } 59.67 + 59.68 + static void zconvTests(boolean x) { 59.69 + assertEquals(x, zconv1(x)); 59.70 + assertEquals(x, zconv2(x)); 59.71 + assertEquals(x, zconv3(x)); 59.72 + } 59.73 + 59.74 + static int iconv1(Integer o) { return o; } 59.75 + static int iconv2(Object o) { return (int)o; } 59.76 + static int iconv3(java.io.Serializable o) { return (int)o; } 59.77 + static int iconv4(Number o) { return (int)o; } 59.78 + static int iconv5(Comparable<Integer> o) { return (int)o; } 59.79 + 59.80 + static void iconvTests(int x) { 59.81 + assertEquals(x, iconv1(x)); 59.82 + assertEquals(x, iconv2(x)); 59.83 + assertEquals(x, iconv3(x)); 59.84 + assertEquals(x, iconv4(x)); 59.85 + assertEquals(x, iconv5(x)); 59.86 + } 59.87 + 59.88 + static float bconv1(Byte o) { return o; } // note type "float" 59.89 + static float bconv2(Object o) { return (byte)o; } 59.90 + static float bconv3(java.io.Serializable o) { return (byte)o; } 59.91 + static float bconv4(Number o) { return (byte)o; } 59.92 + 59.93 + static void bconvTests(byte x) { 59.94 + float xf = x; 59.95 + assertEquals(xf, bconv1(x)); 59.96 + assertEquals(xf, bconv2(x)); 59.97 + assertEquals(xf, bconv3(x)); 59.98 + assertEquals(xf, bconv4(x)); 59.99 + } 59.100 + 59.101 + static float cconv1(Character o) { return o; } // note type "float" 59.102 + static float cconv2(Object o) { return (char)o; } 59.103 + static float cconv3(java.io.Serializable o) { return (char)o; } 59.104 + static float cconv4(Comparable<Character> o) { return (char)o; } 59.105 + 59.106 + static void cconvTests(char x) { 59.107 + float xf = x; 59.108 + assertEquals(xf, cconv1(x)); 59.109 + assertEquals(xf, cconv2(x)); 59.110 + assertEquals(xf, cconv3(x)); 59.111 + assertEquals(xf, cconv4(x)); 59.112 + } 59.113 + 59.114 +}
60.1 --- a/test/tools/javac/InterfaceAssert.java Thu Sep 23 17:33:52 2010 -0700 60.2 +++ b/test/tools/javac/InterfaceAssert.java Fri Sep 24 16:43:08 2010 -0700 60.3 @@ -23,9 +23,11 @@ 60.4 60.5 /* 60.6 * @test 60.7 - * @bug 4399129 60.8 + * @bug 4399129 6980724 60.9 * @summary Check that assertions compile properly when nested in an interface 60.10 * @author gafter 60.11 + * @compile InterfaceAssert.java 60.12 + * @run main InterfaceAssert 60.13 */ 60.14 60.15 /*
61.1 --- a/test/tools/javac/T6341023.java Thu Sep 23 17:33:52 2010 -0700 61.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 61.3 @@ -1,125 +0,0 @@ 61.4 -/* 61.5 - * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. 61.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 61.7 - * 61.8 - * This code is free software; you can redistribute it and/or modify it 61.9 - * under the terms of the GNU General Public License version 2 only, as 61.10 - * published by the Free Software Foundation. 61.11 - * 61.12 - * This code is distributed in the hope that it will be useful, but WITHOUT 61.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 61.14 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 61.15 - * version 2 for more details (a copy is included in the LICENSE file that 61.16 - * accompanied this code). 61.17 - * 61.18 - * You should have received a copy of the GNU General Public License version 61.19 - * 2 along with this work; if not, write to the Free Software Foundation, 61.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 61.21 - * 61.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 61.23 - * or visit www.oracle.com if you need additional information or have any 61.24 - * questions. 61.25 - */ 61.26 - 61.27 -/* 61.28 - * @test 61.29 - * @bug 6341023 61.30 - * @summary Tree API: Tree.Kind should have mapping to interface 61.31 - */ 61.32 - 61.33 -import com.sun.source.tree.*; 61.34 - 61.35 -public class T6341023 { 61.36 - public static void main(String... args) { 61.37 - boolean ok = true; 61.38 - 61.39 - for (Tree.Kind k: Tree.Kind.values()) { 61.40 - //System.err.println(k + " " + k.asInterface()); 61.41 - Class<? extends Tree> i = k.asInterface(); 61.42 - switch (k) { 61.43 - case POSTFIX_INCREMENT: 61.44 - case POSTFIX_DECREMENT: 61.45 - case PREFIX_INCREMENT: 61.46 - case PREFIX_DECREMENT: 61.47 - case UNARY_PLUS: 61.48 - case UNARY_MINUS: 61.49 - case BITWISE_COMPLEMENT: 61.50 - case LOGICAL_COMPLEMENT: 61.51 - ok = ok & verify(k, i, i == UnaryTree.class); 61.52 - break; 61.53 - 61.54 - case MULTIPLY: 61.55 - case DIVIDE: 61.56 - case REMAINDER: 61.57 - case PLUS: 61.58 - case MINUS: 61.59 - case LEFT_SHIFT: 61.60 - case RIGHT_SHIFT: 61.61 - case UNSIGNED_RIGHT_SHIFT: 61.62 - case LESS_THAN: 61.63 - case GREATER_THAN: 61.64 - case LESS_THAN_EQUAL: 61.65 - case GREATER_THAN_EQUAL: 61.66 - case EQUAL_TO: 61.67 - case NOT_EQUAL_TO: 61.68 - case AND: 61.69 - case XOR: 61.70 - case OR: 61.71 - case CONDITIONAL_AND: 61.72 - case CONDITIONAL_OR: 61.73 - ok = ok & verify(k, i, i == BinaryTree.class); 61.74 - break; 61.75 - 61.76 - case MULTIPLY_ASSIGNMENT: 61.77 - case DIVIDE_ASSIGNMENT: 61.78 - case REMAINDER_ASSIGNMENT: 61.79 - case PLUS_ASSIGNMENT: 61.80 - case MINUS_ASSIGNMENT: 61.81 - case LEFT_SHIFT_ASSIGNMENT: 61.82 - case RIGHT_SHIFT_ASSIGNMENT: 61.83 - case UNSIGNED_RIGHT_SHIFT_ASSIGNMENT: 61.84 - case AND_ASSIGNMENT: 61.85 - case XOR_ASSIGNMENT: 61.86 - case OR_ASSIGNMENT: 61.87 - ok = ok & verify(k, i, i == CompoundAssignmentTree.class); 61.88 - break; 61.89 - 61.90 - case INT_LITERAL: 61.91 - case LONG_LITERAL: 61.92 - case FLOAT_LITERAL: 61.93 - case DOUBLE_LITERAL: 61.94 - case BOOLEAN_LITERAL: 61.95 - case CHAR_LITERAL: 61.96 - case STRING_LITERAL: 61.97 - case NULL_LITERAL: 61.98 - ok = ok & verify(k, i, i == LiteralTree.class); 61.99 - break; 61.100 - 61.101 - case UNBOUNDED_WILDCARD: 61.102 - case EXTENDS_WILDCARD: 61.103 - case SUPER_WILDCARD: 61.104 - ok = ok & verify(k, i, i == WildcardTree.class); 61.105 - break; 61.106 - 61.107 - case OTHER: 61.108 - ok = ok & verify(k, i, i == null); 61.109 - break; 61.110 - 61.111 - default: 61.112 - String ks = k.toString().replace("_", "") + "tree"; 61.113 - String iName = i.getName(); 61.114 - String is = iName.substring(iName.lastIndexOf(".") + 1); 61.115 - ok = ok & verify(k, i, ks.equalsIgnoreCase(is)); 61.116 - } 61.117 - } 61.118 - 61.119 - if (!ok) 61.120 - throw new AssertionError("test failed"); 61.121 - } 61.122 - 61.123 - static boolean verify(Tree.Kind k, Class<?> c, boolean b) { 61.124 - if (!b) 61.125 - System.err.println("error: " + k + " " + c); 61.126 - return b; 61.127 - } 61.128 -}
62.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 62.2 +++ b/test/tools/javac/T6458749.java Fri Sep 24 16:43:08 2010 -0700 62.3 @@ -0,0 +1,62 @@ 62.4 +/* 62.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 62.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 62.7 + * 62.8 + * This code is free software; you can redistribute it and/or modify it 62.9 + * under the terms of the GNU General Public License version 2 only, as 62.10 + * published by the Free Software Foundation. 62.11 + * 62.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 62.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 62.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 62.15 + * version 2 for more details (a copy is included in the LICENSE file that 62.16 + * accompanied this code). 62.17 + * 62.18 + * You should have received a copy of the GNU General Public License version 62.19 + * 2 along with this work; if not, write to the Free Software Foundation, 62.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 62.21 + * 62.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 62.23 + * or visit www.oracle.com if you need additional information or have any 62.24 + * questions. 62.25 + */ 62.26 + 62.27 +/* 62.28 + * @test 62.29 + * @bug 6458749 62.30 + * @summary TypeParameterElement.getEnclosedElements() throws NPE within javac 62.31 + * @build T6458749 62.32 + * @compile -processor T6458749 -proc:only T6458749.java 62.33 + */ 62.34 + 62.35 +import java.util.Set; 62.36 +import javax.annotation.processing.*; 62.37 +import javax.lang.model.element.*; 62.38 +import javax.lang.model.util.ElementFilter; 62.39 +import javax.lang.model.SourceVersion; 62.40 + 62.41 +@SupportedAnnotationTypes("*") 62.42 +public class T6458749<T> extends AbstractProcessor { 62.43 + public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv) { 62.44 + if (!renv.processingOver()) { 62.45 + for(TypeElement e : ElementFilter.typesIn(renv.getRootElements())) { 62.46 + System.out.printf("Element %s:%n", e.toString()); 62.47 + try { 62.48 + for (TypeParameterElement tp : e.getTypeParameters()) { 62.49 + System.out.printf("Type param %s", tp.toString()); 62.50 + if (! tp.getEnclosedElements().isEmpty()) { 62.51 + throw new AssertionError("TypeParameterElement.getEnclosedElements() should return empty list"); 62.52 + } 62.53 + } 62.54 + } catch (NullPointerException npe) { 62.55 + throw new AssertionError("NPE from TypeParameterElement.getEnclosedElements()", npe); 62.56 + } 62.57 + } 62.58 + } 62.59 + return true; 62.60 + } 62.61 + 62.62 + public SourceVersion getSupportedSourceVersion() { 62.63 + return SourceVersion.latest(); 62.64 + } 62.65 +}
63.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 63.2 +++ b/test/tools/javac/T6458823/MyProcessor.java Fri Sep 24 16:43:08 2010 -0700 63.3 @@ -0,0 +1,55 @@ 63.4 + /* 63.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 63.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 63.7 + * 63.8 + * This code is free software; you can redistribute it and/or modify it 63.9 + * under the terms of the GNU General Public License version 2 only, as 63.10 + * published by the Free Software Foundation. 63.11 + * 63.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 63.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 63.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 63.15 + * version 2 for more details (a copy is included in the LICENSE file that 63.16 + * accompanied this code). 63.17 + * 63.18 + * You should have received a copy of the GNU General Public License version 63.19 + * 2 along with this work; if not, write to the Free Software Foundation, 63.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 63.21 + * 63.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 63.23 + * or visit www.oracle.com if you need additional information or have any 63.24 + * questions. 63.25 + */ 63.26 + 63.27 +import java.util.Set; 63.28 +import javax.annotation.processing.*; 63.29 +import javax.lang.model.element.*; 63.30 +import javax.lang.model.util.ElementFilter; 63.31 +import javax.lang.model.SourceVersion; 63.32 +import static javax.tools.Diagnostic.Kind.*; 63.33 + 63.34 +@SupportedAnnotationTypes("*") 63.35 +public class MyProcessor extends AbstractProcessor { 63.36 + private Messager messager; 63.37 + public void init(ProcessingEnvironment processingEnv) { 63.38 + this.messager = processingEnv.getMessager(); 63.39 + } 63.40 + 63.41 + public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv) { 63.42 + if (!renv.processingOver()) { 63.43 + for(TypeElement e : ElementFilter.typesIn(renv.getRootElements())) { 63.44 + for (TypeParameterElement tp : e.getTypeParameters()) { 63.45 + if (tp.getSimpleName().toString().length() > 1) { 63.46 + messager.printMessage(WARNING, 63.47 + "Type param names should be of length 1", tp); 63.48 + } 63.49 + } 63.50 + } 63.51 + } 63.52 + return true; 63.53 + } 63.54 + 63.55 + public SourceVersion getSupportedSourceVersion() { 63.56 + return SourceVersion.latest(); 63.57 + } 63.58 +}
64.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 64.2 +++ b/test/tools/javac/T6458823/T6458823.java Fri Sep 24 16:43:08 2010 -0700 64.3 @@ -0,0 +1,87 @@ 64.4 +/* 64.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 64.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 64.7 + * 64.8 + * This code is free software; you can redistribute it and/or modify it 64.9 + * under the terms of the GNU General Public License version 2 only, as 64.10 + * published by the Free Software Foundation. 64.11 + * 64.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 64.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 64.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 64.15 + * version 2 for more details (a copy is included in the LICENSE file that 64.16 + * accompanied this code). 64.17 + * 64.18 + * You should have received a copy of the GNU General Public License version 64.19 + * 2 along with this work; if not, write to the Free Software Foundation, 64.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 64.21 + * 64.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 64.23 + * or visit www.oracle.com if you need additional information or have any 64.24 + * questions. 64.25 + */ 64.26 + 64.27 +/* 64.28 + * @test 64.29 + * @bug 6458823 64.30 + * @summary Messager messages on TypeParamterElements to not include position information. 64.31 + * 64.32 + * @compile MyProcessor.java T6458823.java 64.33 + * @run main T6458823 64.34 + */ 64.35 + 64.36 +import java.io.File; 64.37 +import java.io.IOException; 64.38 +import java.io.Writer; 64.39 +import java.net.URISyntaxException; 64.40 +import java.util.ArrayList; 64.41 +import java.util.HashMap; 64.42 +import java.util.List; 64.43 +import java.util.Map; 64.44 +import java.util.Set; 64.45 +import javax.tools.Diagnostic; 64.46 +import javax.tools.DiagnosticCollector; 64.47 +import javax.tools.JavaCompiler; 64.48 +import javax.tools.JavaCompiler.CompilationTask; 64.49 +import javax.tools.JavaFileObject; 64.50 +import javax.tools.StandardJavaFileManager; 64.51 +import javax.tools.ToolProvider; 64.52 + 64.53 +public class T6458823 { 64.54 + public static void main(String[] args) throws Exception { 64.55 + JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); 64.56 + if (compiler == null) { 64.57 + throw new RuntimeException("can't get javax.tools.JavaCompiler!"); 64.58 + } 64.59 + DiagnosticCollector<JavaFileObject> diagColl = 64.60 + new DiagnosticCollector<JavaFileObject>(); 64.61 + StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null); 64.62 + List<String> options = new ArrayList<String>(); 64.63 + options.add("-processor"); 64.64 + options.add("MyProcessor"); 64.65 + options.add("-proc:only"); 64.66 + List<File> files = new ArrayList<File>(); 64.67 + files.add(new File(T6458823.class.getResource("TestClass.java").toURI())); 64.68 + final CompilationTask task = compiler.getTask(null, fm, diagColl, 64.69 + options, null, fm.getJavaFileObjectsFromFiles(files)); 64.70 + task.call(); 64.71 + int diagCount = 0; 64.72 + for (Diagnostic<? extends JavaFileObject> diag : diagColl.getDiagnostics()) { 64.73 + if (diag.getKind() != Diagnostic.Kind.WARNING) { 64.74 + throw new AssertionError("Only warnings expected"); 64.75 + } 64.76 + System.out.println(diag); 64.77 + if (diag.getPosition() == Diagnostic.NOPOS) { 64.78 + throw new AssertionError("No position info in message"); 64.79 + } 64.80 + if (diag.getSource() == null) { 64.81 + throw new AssertionError("No source info in message"); 64.82 + } 64.83 + diagCount++; 64.84 + } 64.85 + if (diagCount != 2) { 64.86 + throw new AssertionError("unexpected number of warnings: " + 64.87 + diagCount + ", expected: 2"); 64.88 + } 64.89 + } 64.90 +}
65.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 65.2 +++ b/test/tools/javac/T6458823/TestClass.java Fri Sep 24 16:43:08 2010 -0700 65.3 @@ -0,0 +1,25 @@ 65.4 +/* 65.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 65.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 65.7 + * 65.8 + * This code is free software; you can redistribute it and/or modify it 65.9 + * under the terms of the GNU General Public License version 2 only, as 65.10 + * published by the Free Software Foundation. 65.11 + * 65.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 65.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 65.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 65.15 + * version 2 for more details (a copy is included in the LICENSE file that 65.16 + * accompanied this code). 65.17 + * 65.18 + * You should have received a copy of the GNU General Public License version 65.19 + * 2 along with this work; if not, write to the Free Software Foundation, 65.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 65.21 + * 65.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 65.23 + * or visit www.oracle.com if you need additional information or have any 65.24 + * questions. 65.25 + */ 65.26 + 65.27 +class TestClass<XYZ, ABC> { 65.28 +}
66.1 --- a/test/tools/javac/T6855236.java Thu Sep 23 17:33:52 2010 -0700 66.2 +++ b/test/tools/javac/T6855236.java Fri Sep 24 16:43:08 2010 -0700 66.3 @@ -71,12 +71,10 @@ 66.4 66.5 @Override 66.6 public Object visitMethodInvocation(MethodInvocationTree node, Trees p) { 66.7 - System.out.print("current path: "); 66.8 + System.out.println("current path: "); 66.9 for (Tree t : getCurrentPath()) { 66.10 - System.out.print('/'); 66.11 - System.out.print(t); 66.12 - } 66.13 - System.out.println(); 66.14 + System.out.println(" " + t.getKind() + ": " + trim(t, 64)); 66.15 + } 66.16 System.out.println("parent path: " + getCurrentPath().getParentPath()); 66.17 System.out.println("method select: " + node.getMethodSelect().toString()); 66.18 for (ExpressionTree arg : node.getArguments()) { 66.19 @@ -88,12 +86,20 @@ 66.20 @Override 66.21 public Object visitExpressionStatement(ExpressionStatementTree node, Trees p) { 66.22 ExpressionTree t = node.getExpression(); 66.23 - System.out.println("expression statement: " + t.toString()); 66.24 + System.out.println(); 66.25 + System.out.println("expression statement: " + trim(t, 64)); 66.26 return super.visitExpressionStatement(node, p); 66.27 } 66.28 66.29 } 66.30 66.31 + private String trim(Tree t, int len) { 66.32 + String s = t.toString().trim().replaceAll("\\s+", " "); 66.33 + if (s.length() > len) 66.34 + s = s.substring(0, len) + "..."; 66.35 + return s; 66.36 + } 66.37 + 66.38 } 66.39 66.40
67.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 67.2 +++ b/test/tools/javac/T6900149.java Fri Sep 24 16:43:08 2010 -0700 67.3 @@ -0,0 +1,50 @@ 67.4 +/* 67.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 67.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 67.7 + * 67.8 + * This code is free software; you can redistribute it and/or modify it 67.9 + * under the terms of the GNU General Public License version 2 only, as 67.10 + * published by the Free Software Foundation. 67.11 + * 67.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 67.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 67.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 67.15 + * version 2 for more details (a copy is included in the LICENSE file that 67.16 + * accompanied this code). 67.17 + * 67.18 + * You should have received a copy of the GNU General Public License version 67.19 + * 2 along with this work; if not, write to the Free Software Foundation, 67.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 67.21 + * 67.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 67.23 + * or visit www.oracle.com if you need additional information or have any 67.24 + * questions. 67.25 + */ 67.26 + 67.27 +/* 67.28 + * @test 67.29 + * @bug 6900149 67.30 + * @summary IllegalStateException when compiling same files and DiagnosticListener is set 67.31 + */ 67.32 + 67.33 +import java.io.*; 67.34 +import java.util.*; 67.35 +import javax.tools.*; 67.36 +import javax.tools.JavaCompiler.CompilationTask; 67.37 + 67.38 +public class T6900149 { 67.39 + public static void main(String[] args) throws IOException { 67.40 + DiagnosticCollector<JavaFileObject> diag = 67.41 + new DiagnosticCollector<JavaFileObject>(); 67.42 + JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); 67.43 + StandardJavaFileManager fm = 67.44 + compiler.getStandardFileManager(null, null, null); 67.45 + File emptyFile = File.createTempFile("Empty", ".java"); 67.46 + File[] files = new File[] { emptyFile, emptyFile }; 67.47 + CompilationTask task = compiler.getTask(null, fm, diag, 67.48 + null, null, fm.getJavaFileObjects(files)); 67.49 + if (! task.call()) { 67.50 + throw new AssertionError("compilation failed"); 67.51 + } 67.52 + } 67.53 +}
68.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 68.2 +++ b/test/tools/javac/T6956462/T6956462.java Fri Sep 24 16:43:08 2010 -0700 68.3 @@ -0,0 +1,126 @@ 68.4 +/* 68.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 68.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 68.7 + * 68.8 + * This code is free software; you can redistribute it and/or modify it 68.9 + * under the terms of the GNU General Public License version 2 only, as 68.10 + * published by the Free Software Foundation. 68.11 + * 68.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 68.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 68.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 68.15 + * version 2 for more details (a copy is included in the LICENSE file that 68.16 + * accompanied this code). 68.17 + * 68.18 + * You should have received a copy of the GNU General Public License version 68.19 + * 2 along with this work; if not, write to the Free Software Foundation, 68.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 68.21 + * 68.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 68.23 + * or visit www.oracle.com if you need additional information or have any 68.24 + * questions. 68.25 + */ 68.26 + 68.27 +/* 68.28 + * @test 68.29 + * @bug 6956462 68.30 + * @summary AssertionError exception throws in the Compiler Tree API in JDK 7. 68.31 + * 68.32 + * @build TestClass T6956462 68.33 + * @run main T6956462 68.34 + */ 68.35 + 68.36 +import java.io.*; 68.37 +import java.net.URISyntaxException; 68.38 +import java.util.*; 68.39 +import javax.tools.*; 68.40 +import javax.tools.JavaCompiler.CompilationTask; 68.41 +import com.sun.source.tree.*; 68.42 +import com.sun.source.util.*; 68.43 + 68.44 +public class T6956462 { 68.45 + public static void main(String[] args) throws Exception { 68.46 + JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); 68.47 + if (compiler == null) { 68.48 + throw new RuntimeException("can't get javax.tools.JavaCompiler!"); 68.49 + } 68.50 + StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null); 68.51 + List<File> files = new ArrayList<File>(); 68.52 + files.add(new File(T6956462.class.getResource("TestClass.java").toURI())); 68.53 + final CompilationTask task = compiler.getTask(null, fm, null, 68.54 + null, null, fm.getJavaFileObjectsFromFiles(files)); 68.55 + JavacTask javacTask = (JavacTask) task; 68.56 + for (CompilationUnitTree cu : javacTask.parse()) { 68.57 + cu.accept(new MyVisitor(javacTask), null); 68.58 + } 68.59 + } 68.60 + 68.61 + private static class MyVisitor extends SimpleTreeVisitor<Tree, Void> { 68.62 + private final Trees trees; 68.63 + private CompilationUnitTree file; 68.64 + 68.65 + private MyVisitor(JavacTask javac) { 68.66 + this.trees = Trees.instance(javac); 68.67 + } 68.68 + 68.69 + @Override 68.70 + public Tree visitCompilationUnit(CompilationUnitTree file, Void v) { 68.71 + this.file = file; 68.72 + for (Tree typeDecl : file.getTypeDecls()) { 68.73 + typeDecl.accept(this, v); 68.74 + } 68.75 + return null; 68.76 + } 68.77 + 68.78 + @Override 68.79 + public Tree visitImport(ImportTree imp, Void v) { 68.80 + return null; 68.81 + } 68.82 + 68.83 + @Override 68.84 + public Tree visitMethodInvocation(MethodInvocationTree invoke, Void v) { 68.85 + invoke.getMethodSelect().accept(this, v); 68.86 + return null; 68.87 + } 68.88 + 68.89 + @Override 68.90 + public Tree visitBlock(BlockTree block, Void v) { 68.91 + for (StatementTree stat : block.getStatements()) { 68.92 + stat.accept(this, v); 68.93 + } 68.94 + return null; 68.95 + } 68.96 + 68.97 + @Override 68.98 + public Tree visitClass(ClassTree clazz, Void v) { 68.99 + for (Tree member : clazz.getMembers()) { 68.100 + member.accept(this, v); 68.101 + } 68.102 + return null; 68.103 + } 68.104 + 68.105 + @Override 68.106 + public Tree visitIdentifier(IdentifierTree ident, Void v) { 68.107 + trees.getScope(trees.getPath(file, ident)); 68.108 + return null; 68.109 + } 68.110 + 68.111 + @Override 68.112 + public Tree visitMethod(MethodTree method, Void v) { 68.113 + method.getBody().accept(this, v); 68.114 + return null; 68.115 + } 68.116 + 68.117 + @Override 68.118 + public Tree visitMemberSelect(MemberSelectTree select, Void v) { 68.119 + select.getExpression().accept(this, v); 68.120 + return null; 68.121 + } 68.122 + 68.123 + @Override 68.124 + public Tree visitVariable(VariableTree var, Void v) { 68.125 + var.getInitializer().accept(this, v); 68.126 + return null; 68.127 + } 68.128 + } 68.129 +}
69.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 69.2 +++ b/test/tools/javac/T6956462/TestClass.java Fri Sep 24 16:43:08 2010 -0700 69.3 @@ -0,0 +1,30 @@ 69.4 +/* 69.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 69.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 69.7 + * 69.8 + * This code is free software; you can redistribute it and/or modify it 69.9 + * under the terms of the GNU General Public License version 2 only, as 69.10 + * published by the Free Software Foundation. 69.11 + * 69.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 69.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 69.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 69.15 + * version 2 for more details (a copy is included in the LICENSE file that 69.16 + * accompanied this code). 69.17 + * 69.18 + * You should have received a copy of the GNU General Public License version 69.19 + * 2 along with this work; if not, write to the Free Software Foundation, 69.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 69.21 + * 69.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 69.23 + * or visit www.oracle.com if you need additional information or have any 69.24 + * questions. 69.25 + */ 69.26 + 69.27 +import java.io.PrintStream; 69.28 + 69.29 +abstract class TestClass { 69.30 + private void test() { 69.31 + final PrintStream out = System.out; 69.32 + } 69.33 +}
70.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 70.2 +++ b/test/tools/javac/T6985181.java Fri Sep 24 16:43:08 2010 -0700 70.3 @@ -0,0 +1,86 @@ 70.4 +/* 70.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 70.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 70.7 + * 70.8 + * This code is free software; you can redistribute it and/or modify it 70.9 + * under the terms of the GNU General Public License version 2 only, as 70.10 + * published by the Free Software Foundation. 70.11 + * 70.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 70.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 70.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 70.15 + * version 2 for more details (a copy is included in the LICENSE file that 70.16 + * accompanied this code). 70.17 + * 70.18 + * You should have received a copy of the GNU General Public License version 70.19 + * 2 along with this work; if not, write to the Free Software Foundation, 70.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 70.21 + * 70.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 70.23 + * or visit www.oracle.com if you need additional information or have any 70.24 + * questions. 70.25 + */ 70.26 + 70.27 +/* 70.28 + * @test 70.29 + * @bug 6985181 70.30 + * @summary Annotations lost from classfile 70.31 + */ 70.32 + 70.33 +import java.io.*; 70.34 +import java.util.*; 70.35 + 70.36 +public class T6985181 { 70.37 + public static void main(String... args) throws Exception{ 70.38 + new T6985181().run(); 70.39 + } 70.40 + 70.41 + public void run() throws Exception { 70.42 + String code = "@interface Simple { }\ninterface Test<@Simple T> { }"; 70.43 + 70.44 + File srcFile = writeFile("Test.java", code); 70.45 + File classesDir = new File("classes"); 70.46 + classesDir.mkdirs(); 70.47 + compile("-d", classesDir.getPath(), srcFile.getPath()); 70.48 + String out = javap(new File(classesDir, srcFile.getName().replace(".java", ".class"))); 70.49 + if (!out.contains("RuntimeInvisibleTypeAnnotations")) 70.50 + throw new Exception("RuntimeInvisibleTypeAnnotations not found"); 70.51 + } 70.52 + 70.53 + void compile(String... args) throws Exception { 70.54 + StringWriter sw = new StringWriter(); 70.55 + PrintWriter pw = new PrintWriter(sw); 70.56 + int rc = com.sun.tools.javac.Main.compile(args, pw); 70.57 + pw.close(); 70.58 + String out = sw.toString(); 70.59 + if (out.length() > 0) 70.60 + System.err.println(out); 70.61 + if (rc != 0) 70.62 + throw new Exception("Compilation failed: rc=" + rc); 70.63 + } 70.64 + 70.65 + String javap(File classFile) throws Exception { 70.66 + StringWriter sw = new StringWriter(); 70.67 + PrintWriter pw = new PrintWriter(sw); 70.68 + String[] args = { "-v", classFile.getPath() }; 70.69 + int rc = com.sun.tools.javap.Main.run(args, pw); 70.70 + pw.close(); 70.71 + String out = sw.toString(); 70.72 + if (out.length() > 0) 70.73 + System.err.println(out); 70.74 + if (rc != 0) 70.75 + throw new Exception("javap failed: rc=" + rc); 70.76 + return out; 70.77 + } 70.78 + 70.79 + File writeFile(String path, String body) throws IOException { 70.80 + File f = new File(path); 70.81 + FileWriter out = new FileWriter(f); 70.82 + try { 70.83 + out.write(body); 70.84 + } finally { 70.85 + out.close(); 70.86 + } 70.87 + return f; 70.88 + } 70.89 +}
71.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 71.2 +++ b/test/tools/javac/TestPkgInfo.java Fri Sep 24 16:43:08 2010 -0700 71.3 @@ -0,0 +1,174 @@ 71.4 +/* 71.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 71.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 71.7 + * 71.8 + * This code is free software; you can redistribute it and/or modify it 71.9 + * under the terms of the GNU General Public License version 2 only, as 71.10 + * published by the Free Software Foundation. 71.11 + * 71.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 71.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 71.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 71.15 + * version 2 for more details (a copy is included in the LICENSE file that 71.16 + * accompanied this code). 71.17 + * 71.18 + * You should have received a copy of the GNU General Public License version 71.19 + * 2 along with this work; if not, write to the Free Software Foundation, 71.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 71.21 + * 71.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 71.23 + * or visit www.oracle.com if you need additional information or have any 71.24 + * questions. 71.25 + */ 71.26 + 71.27 +/* 71.28 + * @test 71.29 + * @bug 6960424 71.30 + * @summary new option -Xpkginfo for better control of when package-info.class is generated 71.31 + */ 71.32 + 71.33 +import java.io.*; 71.34 +import java.util.*; 71.35 + 71.36 +public class TestPkgInfo { 71.37 + enum OptKind { 71.38 + NONE(null), 71.39 + ALWAYS("-Xpkginfo:always"), 71.40 + NONEMPTY("-Xpkginfo:nonempty"), 71.41 + LEGACY("-Xpkginfo:legacy"); 71.42 + OptKind(String opt) { this.opt = opt; } 71.43 + final String opt; 71.44 + }; 71.45 + 71.46 + public static void main(String... args) throws Exception { 71.47 + new TestPkgInfo().run(args); 71.48 + } 71.49 + 71.50 + public void run(String... args) throws Exception { 71.51 + boolean[] booleanValues = { false, true }; 71.52 + for (OptKind ok: OptKind.values()) { 71.53 + for (boolean sr: booleanValues) { 71.54 + for (boolean cr: booleanValues) { 71.55 + for (boolean rr: booleanValues) { 71.56 + try { 71.57 + test(ok, sr, cr, rr); 71.58 + } catch (Exception e) { 71.59 + error("Exception: " + e); 71.60 + } 71.61 + if (errors > 0) throw new AssertionError(); 71.62 + } 71.63 + } 71.64 + } 71.65 + } 71.66 + 71.67 + if (errors > 0) 71.68 + throw new Exception(errors + " errors occurred"); 71.69 + } 71.70 + 71.71 + void test(OptKind ok, boolean sr, boolean cr, boolean rr) throws Exception { 71.72 + count++; 71.73 + System.err.println("Test " + count + ": ok:" + ok + " sr:" + sr + " cr:" + cr + " rr:" + rr); 71.74 + 71.75 + StringBuilder sb = new StringBuilder(); 71.76 + 71.77 + // create annotated package statement with all combinations of retention policy 71.78 + if (sr) sb.append("@SR\n"); 71.79 + if (cr) sb.append("@CR\n"); 71.80 + if (rr) sb.append("@RR\n"); 71.81 + sb.append("package p;\n"); 71.82 + sb.append("\n"); 71.83 + 71.84 + sb.append("import java.lang.annotation.*;\n"); 71.85 + sb.append("@Retention(RetentionPolicy.SOURCE) @interface SR { }\n"); 71.86 + sb.append("@Retention(RetentionPolicy.CLASS) @interface CR { }\n"); 71.87 + sb.append("@Retention(RetentionPolicy.RUNTIME) @interface RR { }\n"); 71.88 + 71.89 + // test specific tmp directory 71.90 + File tmpDir = new File("tmp.test" + count); 71.91 + File classesDir = new File(tmpDir, "classes"); 71.92 + classesDir.mkdirs(); 71.93 + File pkginfo_java = new File(new File(tmpDir, "src"), "package-info.java"); 71.94 + writeFile(pkginfo_java, sb.toString()); 71.95 + 71.96 + // build up list of options and files to be compiled 71.97 + List<String> opts = new ArrayList<String>(); 71.98 + List<File> files = new ArrayList<File>(); 71.99 + 71.100 + opts.add("-d"); 71.101 + opts.add(classesDir.getPath()); 71.102 + if (ok.opt != null) 71.103 + opts.add(ok.opt); 71.104 + //opts.add("-verbose"); 71.105 + files.add(pkginfo_java); 71.106 + 71.107 + compile(opts, files); 71.108 + 71.109 + File pkginfo_class = new File(new File(classesDir, "p"), "package-info.class"); 71.110 + boolean exists = pkginfo_class.exists(); 71.111 + 71.112 + boolean expected; 71.113 + switch (ok) { 71.114 + case ALWAYS: 71.115 + expected = true; 71.116 + break; 71.117 + 71.118 + case LEGACY: 71.119 + case NONE: 71.120 + expected = (sr || cr || rr ); // any annotation 71.121 + break; 71.122 + 71.123 + case NONEMPTY: 71.124 + expected = (cr || rr ); // any annotation in class file 71.125 + break; 71.126 + 71.127 + default: 71.128 + throw new IllegalStateException(); 71.129 + } 71.130 + 71.131 + if (exists && !expected) 71.132 + error("package-info.class found but not expected"); 71.133 + if (!exists && expected) 71.134 + error("package-info.class expected but not found"); 71.135 + } 71.136 + 71.137 + /** Compile files with options provided. */ 71.138 + void compile(List<String> opts, List<File> files) throws Exception { 71.139 + System.err.println("javac: " + opts + " " + files); 71.140 + List<String> args = new ArrayList<String>(); 71.141 + args.addAll(opts); 71.142 + for (File f: files) 71.143 + args.add(f.getPath()); 71.144 + StringWriter sw = new StringWriter(); 71.145 + PrintWriter pw = new PrintWriter(sw); 71.146 + int rc = com.sun.tools.javac.Main.compile(args.toArray(new String[args.size()]), pw); 71.147 + pw.flush(); 71.148 + if (sw.getBuffer().length() > 0) 71.149 + System.err.println(sw.toString()); 71.150 + if (rc != 0) 71.151 + throw new Exception("compilation failed: rc=" + rc); 71.152 + } 71.153 + 71.154 + /** Write a file with a given body. */ 71.155 + void writeFile(File f, String body) throws Exception { 71.156 + if (f.getParentFile() != null) 71.157 + f.getParentFile().mkdirs(); 71.158 + Writer out = new FileWriter(f); 71.159 + try { 71.160 + out.write(body); 71.161 + } finally { 71.162 + out.close(); 71.163 + } 71.164 + } 71.165 + 71.166 + /** Report an error. */ 71.167 + void error(String msg) { 71.168 + System.err.println("Error: " + msg); 71.169 + errors++; 71.170 + } 71.171 + 71.172 + /** Test case counter. */ 71.173 + int count; 71.174 + 71.175 + /** Number of errors found. */ 71.176 + int errors; 71.177 +}
72.1 --- a/test/tools/javac/api/T6392782.java Thu Sep 23 17:33:52 2010 -0700 72.2 +++ b/test/tools/javac/api/T6392782.java Fri Sep 24 16:43:08 2010 -0700 72.3 @@ -47,12 +47,12 @@ 72.4 check(scanner, 6, scanner.scan(trees, null)); 72.5 72.6 CountNodes nodeCounter = new CountNodes(); 72.7 - // 383 nodes with the regular parser; 384 nodes with EndPosParser 72.8 - // We automatically swith to EndPosParser when calling JavacTask.parse() 72.9 - check(nodeCounter, 384, nodeCounter.scan(trees, null)); 72.10 + // 359 nodes with the regular parser; 360 nodes with EndPosParser 72.11 + // We automatically switch to EndPosParser when calling JavacTask.parse() 72.12 + check(nodeCounter, 360, nodeCounter.scan(trees, null)); 72.13 72.14 CountIdentifiers idCounter = new CountIdentifiers(); 72.15 - check(idCounter, 106, idCounter.scan(trees, null)); 72.16 + check(idCounter, 107, idCounter.scan(trees, null)); 72.17 } 72.18 72.19 private static void check(TreeScanner<?,?> scanner, int expect, int found) { 72.20 @@ -73,10 +73,11 @@ 72.21 } 72.22 } 72.23 72.24 - // example from TreeScanner javadoc 72.25 static class CountNodes extends TreeScanner<Integer,Void> { 72.26 @Override 72.27 public Integer scan(Tree node, Void p) { 72.28 + if (node == null) 72.29 + return 0; 72.30 Integer n = super.scan(node, p); 72.31 return (n == null ? 0 : n) + 1; 72.32 }
73.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 73.2 +++ b/test/tools/javac/api/TestContainTypes.java Fri Sep 24 16:43:08 2010 -0700 73.3 @@ -0,0 +1,216 @@ 73.4 +/* 73.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 73.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 73.7 + * 73.8 + * This code is free software; you can redistribute it and/or modify it 73.9 + * under the terms of the GNU General Public License version 2 only, as 73.10 + * published by the Free Software Foundation. 73.11 + * 73.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 73.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 73.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 73.15 + * version 2 for more details (a copy is included in the LICENSE file that 73.16 + * accompanied this code). 73.17 + * 73.18 + * You should have received a copy of the GNU General Public License version 73.19 + * 2 along with this work; if not, write to the Free Software Foundation, 73.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 73.21 + * 73.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 73.23 + * or visit www.oracle.com if you need additional information or have any 73.24 + * questions. 73.25 + */ 73.26 + 73.27 +/* 73.28 + * @test 73.29 + * @bug 6981185 73.30 + * @summary com.sun.tools.model.JavacTypes.contains() calls Type.contains instead of Types.containsType 73.31 + * @run main TestContainTypes 73.32 + */ 73.33 + 73.34 +import java.net.URI; 73.35 +import java.util.Arrays; 73.36 +import java.util.HashSet; 73.37 +import java.util.Set; 73.38 +import javax.annotation.processing.AbstractProcessor; 73.39 +import javax.annotation.processing.RoundEnvironment; 73.40 +import javax.lang.model.element.Element; 73.41 +import javax.lang.model.element.TypeElement; 73.42 +import javax.lang.model.element.ExecutableElement; 73.43 +import javax.lang.model.type.TypeMirror; 73.44 +import javax.lang.model.type.DeclaredType; 73.45 +import javax.tools.JavaCompiler; 73.46 +import javax.tools.JavaFileObject; 73.47 +import javax.tools.SimpleJavaFileObject; 73.48 +import javax.tools.ToolProvider; 73.49 + 73.50 +import com.sun.source.util.JavacTask; 73.51 +import javax.annotation.processing.SupportedSourceVersion; 73.52 +import javax.lang.model.SourceVersion; 73.53 + 73.54 +public class TestContainTypes { 73.55 + 73.56 + enum ClassType { 73.57 + OBJECT("Object"), 73.58 + NUMBER("Number"), 73.59 + INTEGER("Integer"), 73.60 + STRING("String"); 73.61 + 73.62 + String classStub; 73.63 + 73.64 + ClassType(String classStub) { 73.65 + this.classStub = classStub; 73.66 + } 73.67 + 73.68 + boolean subtypeOf(ClassType that) { 73.69 + switch (that) { 73.70 + case OBJECT: return true; 73.71 + case NUMBER: return this == NUMBER || this == INTEGER; 73.72 + case INTEGER: return this == INTEGER; 73.73 + case STRING: return this == STRING; 73.74 + default: throw new AssertionError("Bad type kind in subtyping test"); 73.75 + } 73.76 + } 73.77 + } 73.78 + 73.79 + enum ParameterType { 73.80 + INVARIANT("List<#1>"), 73.81 + COVARIANT("List<? extends #1>"), 73.82 + CONTRAVARIANT("List<? super #1>"), 73.83 + BIVARIANT("List<?>"); 73.84 + 73.85 + String paramTypeStub; 73.86 + 73.87 + ParameterType(String paramTypeStub) { 73.88 + this.paramTypeStub = paramTypeStub; 73.89 + } 73.90 + 73.91 + String instantiate(ClassType ct) { 73.92 + return paramTypeStub.replace("#1", ct.classStub); 73.93 + } 73.94 + 73.95 + static boolean contains(ParameterType pt1, ClassType ct1, 73.96 + ParameterType pt2, ClassType ct2) { 73.97 + switch (pt1) { 73.98 + case INVARIANT: return (pt2 == INVARIANT && ct1 == ct2) || 73.99 + (pt2 == CONTRAVARIANT && ct1 == ct2 && ct1 == ClassType.OBJECT); 73.100 + case COVARIANT: return ((pt2 == INVARIANT || pt2 == COVARIANT) && 73.101 + ct2.subtypeOf(ct1)) || 73.102 + (ct1 == ClassType.OBJECT); 73.103 + case CONTRAVARIANT: return (pt2 == INVARIANT || pt2 == CONTRAVARIANT) && 73.104 + ct1.subtypeOf(ct2); 73.105 + case BIVARIANT: return true; 73.106 + default: throw new AssertionError("Bad type kind in containment test"); 73.107 + } 73.108 + } 73.109 + } 73.110 + 73.111 + static class JavaSource extends SimpleJavaFileObject { 73.112 + 73.113 + final static String sourceStub = 73.114 + "import java.util.List;\n" + 73.115 + "@interface ToCheck {}\n" + 73.116 + "class Test {\n" + 73.117 + " @ToCheck void test(#A a, #B b) {}\n" + 73.118 + "}\n"; 73.119 + 73.120 + String source; 73.121 + 73.122 + public JavaSource(String typeA, String typeB) { 73.123 + super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); 73.124 + source = sourceStub.replace("#A", typeA).replace("#B", typeB); 73.125 + } 73.126 + 73.127 + @Override 73.128 + public CharSequence getCharContent(boolean ignoreEncodingErrors) { 73.129 + return source; 73.130 + } 73.131 + } 73.132 + 73.133 + public static void main(String... args) throws Exception { 73.134 + for (ClassType ctA : ClassType.values()) { 73.135 + for (ParameterType ptA : ParameterType.values()) { 73.136 + for (ClassType ctB : ClassType.values()) { 73.137 + for (ParameterType ptB : ParameterType.values()) { 73.138 + compileAndCheck(ptA, ctA, ptB, ctB); 73.139 + } 73.140 + } 73.141 + } 73.142 + } 73.143 + } 73.144 + 73.145 + static void compileAndCheck(ParameterType ptA, ClassType ctA, ParameterType ptB, ClassType ctB) throws Exception { 73.146 + JavaSource source = new JavaSource(ptA.instantiate(ctA), ptB.instantiate(ctB)); 73.147 + final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); 73.148 + JavacTask ct = (JavacTask)tool.getTask(null, null, null, 73.149 + null, null, Arrays.asList(source)); 73.150 + ct.setProcessors(Arrays.asList(new ContainTypesTester(ParameterType.contains(ptA, ctA, ptB, ctB), source))); 73.151 + System.err.println("A = " + ptA +" / " + ptA.instantiate(ctA)); 73.152 + System.err.println("B = " + ptB +" / " + ptB.instantiate(ctB)); 73.153 + System.err.println("Source = " + source.source); 73.154 + ct.analyze(); 73.155 + } 73.156 + 73.157 + @SupportedSourceVersion(SourceVersion.RELEASE_7) 73.158 + static class ContainTypesTester extends AbstractProcessor { 73.159 + 73.160 + boolean expected; 73.161 + JavaSource source; 73.162 + 73.163 + ContainTypesTester(boolean expected, JavaSource source) { 73.164 + this.expected = expected; 73.165 + this.source = source; 73.166 + } 73.167 + 73.168 + @Override 73.169 + public Set<String> getSupportedAnnotationTypes() { 73.170 + Set<String> supportedAnnos = new HashSet(); 73.171 + supportedAnnos.add("*"); 73.172 + return supportedAnnos; 73.173 + } 73.174 + 73.175 + private void error(String msg) { 73.176 + System.err.println(source.source); 73.177 + throw new AssertionError(msg); 73.178 + } 73.179 + 73.180 + @Override 73.181 + public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { 73.182 + if (roundEnv.getRootElements().size() == 0) { 73.183 + return true; 73.184 + } 73.185 + if (annotations.isEmpty() || annotations.size() > 1) { 73.186 + error("no anno found/wrong number of annotations found: " + annotations.size()); 73.187 + } 73.188 + TypeElement anno = (TypeElement)annotations.toArray()[0]; 73.189 + Set<? extends Element> annoElems = roundEnv.getElementsAnnotatedWith(anno); 73.190 + if (annoElems.isEmpty() || annoElems.size() > 1) { 73.191 + error("no annotated element found/wrong number of annotated elements found: " + annoElems.size()); 73.192 + } 73.193 + Element annoElement = (Element)annoElems.toArray()[0]; 73.194 + if (!(annoElement instanceof ExecutableElement)) { 73.195 + error("annotated element must be a method"); 73.196 + } 73.197 + ExecutableElement method = (ExecutableElement)annoElement; 73.198 + if (method.getParameters().size() != 2) { 73.199 + error("annotated method must have 2 arguments"); 73.200 + } 73.201 + DeclaredType d1 = (DeclaredType)method.getParameters().get(0).asType(); 73.202 + DeclaredType d2 = (DeclaredType)method.getParameters().get(1).asType(); 73.203 + if (d1.getTypeArguments().size() != 1 || 73.204 + d1.getTypeArguments().size() != 1) { 73.205 + error("parameter type must be generic in one type-variable"); 73.206 + } 73.207 + TypeMirror t1 = d1.getTypeArguments().get(0); 73.208 + TypeMirror t2 = d2.getTypeArguments().get(0); 73.209 + 73.210 + if (processingEnv.getTypeUtils().contains(t1, t2) != expected) { 73.211 + error("bad type containment result\n" + 73.212 + "t1 : " + t1 +"\n" + 73.213 + "t2 : " + t2 +"\n" + 73.214 + "expected answer : " + expected +"\n"); 73.215 + } 73.216 + return true; 73.217 + } 73.218 + } 73.219 +}
74.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 74.2 +++ b/test/tools/javac/api/TestGetElement.java Fri Sep 24 16:43:08 2010 -0700 74.3 @@ -0,0 +1,235 @@ 74.4 +/* 74.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 74.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 74.7 + * 74.8 + * This code is free software; you can redistribute it and/or modify it 74.9 + * under the terms of the GNU General Public License version 2 only, as 74.10 + * published by the Free Software Foundation. 74.11 + * 74.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 74.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 74.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 74.15 + * version 2 for more details (a copy is included in the LICENSE file that 74.16 + * accompanied this code). 74.17 + * 74.18 + * You should have received a copy of the GNU General Public License version 74.19 + * 2 along with this work; if not, write to the Free Software Foundation, 74.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 74.21 + * 74.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 74.23 + * or visit www.oracle.com if you need additional information or have any 74.24 + * questions. 74.25 + */ 74.26 + 74.27 +/* 74.28 + * @test 74.29 + * @bug 6930507 74.30 + * @summary Symbols for anonymous and local classes made too late for use by java tree API 74.31 + */ 74.32 + 74.33 +import java.io.*; 74.34 +import java.util.*; 74.35 +import javax.annotation.processing.*; 74.36 +import javax.lang.model.SourceVersion; 74.37 +import javax.lang.model.element.*; 74.38 +import javax.tools.Diagnostic; 74.39 +import static javax.lang.model.util.ElementFilter.*; 74.40 + 74.41 +import com.sun.source.tree.*; 74.42 +import com.sun.source.util.*; 74.43 + 74.44 +@SupportedOptions({"test", "last"}) 74.45 +@SupportedAnnotationTypes("*") 74.46 +public class TestGetElement extends AbstractProcessor { 74.47 + public static void main(String... args) throws Exception { 74.48 + new TestGetElement().run(); 74.49 + } 74.50 + 74.51 + public TestGetElement() { } 74.52 + 74.53 + public void run() throws Exception { 74.54 + final String testSrc = System.getProperty("test.src"); 74.55 + final String testClasses = System.getProperty("test.classes"); 74.56 + final String myClassName = getClass().getName(); 74.57 + final String mySrc = new File(testSrc, myClassName + ".java").getPath(); 74.58 + 74.59 + final int NUM_TESTS = 90; // #decls in this source file 74.60 + for (int i = 1; i <= NUM_TESTS; i++) { 74.61 + System.err.println("test " + i); 74.62 + File testDir = new File("test" + i); 74.63 + File classesDir = new File(testDir, "classes"); 74.64 + classesDir.mkdirs(); 74.65 + String[] args = { 74.66 + "-d", classesDir.getPath(), 74.67 + "-processorpath", testClasses, 74.68 + "-processor", myClassName, 74.69 + "-proc:only", 74.70 + "-Atest=" + i, 74.71 + "-Alast=" + (i == NUM_TESTS), 74.72 + mySrc 74.73 + }; 74.74 + 74.75 +// System.err.println("compile: " + Arrays.asList(args)); 74.76 + 74.77 + StringWriter sw = new StringWriter(); 74.78 + PrintWriter pw = new PrintWriter(sw); 74.79 + int rc = com.sun.tools.javac.Main.compile(args, pw); 74.80 + pw.close(); 74.81 + String out = sw.toString(); 74.82 + if (out != null) 74.83 + System.err.println(out); 74.84 + if (rc != 0) { 74.85 + System.err.println("compilation failed: rc=" + rc); 74.86 + errors++; 74.87 + } 74.88 + } 74.89 + 74.90 + if (errors > 0) 74.91 + throw new Exception(errors + " errors occurred"); 74.92 + } 74.93 + 74.94 + 74.95 + int errors; 74.96 + 74.97 + public boolean process(Set<? extends TypeElement> annotations, 74.98 + RoundEnvironment roundEnvironment) 74.99 + { 74.100 + if (roundEnvironment.processingOver()) 74.101 + return true; 74.102 + 74.103 + Map<String,String> options = processingEnv.getOptions(); 74.104 + int test = Integer.parseInt(options.get("test")); 74.105 + boolean _last = Boolean.parseBoolean(options.get("last")); 74.106 + 74.107 + Trees trees = Trees.instance(processingEnv); 74.108 + Scanner scanner = new Scanner(trees, _last); 74.109 + int nelems = 0; 74.110 + for (TypeElement e : typesIn(roundEnvironment.getRootElements())) { 74.111 + nelems += scanner.scan(trees.getPath(e), test); 74.112 + } 74.113 + 74.114 + Messager m = processingEnv.getMessager(); 74.115 + int EXPECT = 1; 74.116 + if (nelems != EXPECT) { 74.117 + m.printMessage(Diagnostic.Kind.ERROR, 74.118 + "Unexpected number of elements found: " + nelems + " expected: " + EXPECT); 74.119 + } 74.120 + return true; 74.121 + } 74.122 + 74.123 + @Override 74.124 + public SourceVersion getSupportedSourceVersion() { 74.125 + return SourceVersion.latest(); 74.126 + } 74.127 + 74.128 + class Scanner extends TreePathScanner<Integer,Integer> { 74.129 + final Trees trees; 74.130 + final boolean last; 74.131 + int count; 74.132 + 74.133 + Scanner(Trees trees, boolean last) { 74.134 + this.trees = trees; 74.135 + this.last = last; 74.136 + } 74.137 + 74.138 + @Override 74.139 + public Integer visitClass(ClassTree tree, Integer test) { 74.140 + return reduce(check(test), super.visitClass(tree, test)); 74.141 + } 74.142 + 74.143 + @Override 74.144 + public Integer visitMethod(MethodTree tree, Integer test) { 74.145 + return reduce(check(test), super.visitMethod(tree, test)); 74.146 + } 74.147 + 74.148 + @Override 74.149 + public Integer visitVariable(VariableTree tree, Integer test) { 74.150 + return reduce(check(test), super.visitVariable(tree, test)); 74.151 + } 74.152 + 74.153 + @Override 74.154 + public Integer reduce(Integer i1, Integer i2) { 74.155 + if (i1 == null || i1.intValue() == 0) 74.156 + return i2; 74.157 + if (i2 == null || i2.intValue() == 0) 74.158 + return i1; 74.159 + return (i1 + i2); 74.160 + } 74.161 + 74.162 + int check(int test) { 74.163 + count++; 74.164 + 74.165 + if (count != test) 74.166 + return 0; 74.167 + 74.168 + TreePath p = getCurrentPath(); 74.169 + Element e = trees.getElement(p); 74.170 + 74.171 + String text = p.getLeaf().toString().replaceAll("\\s+", " ").trim(); 74.172 + int MAXLEN = 40; 74.173 + if (text.length() > MAXLEN) 74.174 + text = text.substring(0, MAXLEN - 3) + "..."; 74.175 + 74.176 + System.err.println(String.format("%3d: %-" + MAXLEN + "s -- %s", 74.177 + count, text, 74.178 + (e == null ? "null" : e.getKind() + " " + e))); 74.179 + 74.180 + Messager m = processingEnv.getMessager(); 74.181 + if (e == null) { 74.182 + m.printMessage(Diagnostic.Kind.ERROR, "Null element found for " + text); 74.183 + return 0; 74.184 + } 74.185 + 74.186 + if (last && !e.getSimpleName().contentEquals("last")) { 74.187 + m.printMessage(Diagnostic.Kind.ERROR, "Unexpected name in last test: " 74.188 + + e.getSimpleName() + ", expected: last"); 74.189 + } 74.190 + 74.191 + return 1; 74.192 + } 74.193 + } 74.194 + 74.195 + // following are all fodder for the test 74.196 + 74.197 + class MemberClass { 74.198 + class NestedMemberClass { } 74.199 + } 74.200 + 74.201 + { 74.202 + class InnerClassInInit { } 74.203 + Object o = new Object() { }; 74.204 + } 74.205 + 74.206 + TestGetElement(TestGetElement unused) { 74.207 + class InnerClassInConstr { } 74.208 + Object o = new Object() { }; 74.209 + } 74.210 + 74.211 + void m() { 74.212 + class InnerClassInMethod { } 74.213 + Object o = new Object() { }; 74.214 + 74.215 + class C { 74.216 + class MemberClass { 74.217 + class NestedMemberClass { } 74.218 + } 74.219 + 74.220 + { 74.221 + class InnerClassInInit { } 74.222 + Object o = new Object() { }; 74.223 + } 74.224 + 74.225 + C(Object unused) { 74.226 + class InnerClassInConstr { } 74.227 + Object o = new Object() { }; 74.228 + } 74.229 + 74.230 + void m() { 74.231 + class InnerClassInMethod { } 74.232 + Object o = new Object() { }; 74.233 + } 74.234 + } 74.235 + } 74.236 + 74.237 + int last; // this name is verified by the test to make sure that all decls are checked 74.238 +}
75.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 75.2 +++ b/test/tools/javac/api/ToolProvider/HelloWorldTest.java Fri Sep 24 16:43:08 2010 -0700 75.3 @@ -0,0 +1,83 @@ 75.4 +/* 75.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 75.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 75.7 + * 75.8 + * This code is free software; you can redistribute it and/or modify it 75.9 + * under the terms of the GNU General Public License version 2 only, as 75.10 + * published by the Free Software Foundation. 75.11 + * 75.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 75.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 75.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 75.15 + * version 2 for more details (a copy is included in the LICENSE file that 75.16 + * accompanied this code). 75.17 + * 75.18 + * You should have received a copy of the GNU General Public License version 75.19 + * 2 along with this work; if not, write to the Free Software Foundation, 75.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 75.21 + * 75.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 75.23 + * or visit www.oracle.com if you need additional information or have any 75.24 + * questions. 75.25 + */ 75.26 + 75.27 +/* 75.28 + * @test 75.29 + * @bug 6604599 75.30 + * @summary ToolProvider should be less compiler-specific 75.31 + */ 75.32 + 75.33 +import java.io.*; 75.34 +import java.util.*; 75.35 + 75.36 +// verify that running a simple program, such as this one, does not trigger 75.37 +// the loading of ToolProvider or any com.sun.tools.javac class 75.38 +public class HelloWorldTest { 75.39 + public static void main(String... args) throws Exception { 75.40 + if (args.length > 0) { 75.41 + System.err.println(Arrays.asList(args)); 75.42 + return; 75.43 + } 75.44 + 75.45 + new HelloWorldTest().run(); 75.46 + } 75.47 + 75.48 + void run() throws Exception { 75.49 + File javaHome = new File(System.getProperty("java.home")); 75.50 + if (javaHome.getName().equals("jre")) 75.51 + javaHome = javaHome.getParentFile(); 75.52 + File javaExe = new File(new File(javaHome, "bin"), "java"); 75.53 + String classpath = System.getProperty("java.class.path"); 75.54 + 75.55 + String[] cmd = { 75.56 + javaExe.getPath(), 75.57 + "-verbose:class", 75.58 + "-classpath", classpath, 75.59 + HelloWorldTest.class.getName(), 75.60 + "Hello", "World" 75.61 + }; 75.62 + 75.63 + ProcessBuilder pb = new ProcessBuilder(cmd).redirectErrorStream(true); 75.64 + Process p = pb.start(); 75.65 + BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream())); 75.66 + String line; 75.67 + while ((line = r.readLine()) != null) { 75.68 + System.err.println(line); 75.69 + if (line.contains("javax.tools.ToolProvider") || line.contains("com.sun.tools.javac.")) 75.70 + error(">>> " + line); 75.71 + } 75.72 + int rc = p.waitFor(); 75.73 + if (rc != 0) 75.74 + error("Unexpected exit code: " + rc); 75.75 + 75.76 + if (errors > 0) 75.77 + throw new Exception(errors + " errors occurred"); 75.78 + } 75.79 + 75.80 + void error(String msg) { 75.81 + System.err.println(msg); 75.82 + errors++; 75.83 + } 75.84 + 75.85 + int errors; 75.86 +}
76.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 76.2 +++ b/test/tools/javac/api/ToolProvider/ToolProviderTest1.java Fri Sep 24 16:43:08 2010 -0700 76.3 @@ -0,0 +1,82 @@ 76.4 +/* 76.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 76.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 76.7 + * 76.8 + * This code is free software; you can redistribute it and/or modify it 76.9 + * under the terms of the GNU General Public License version 2 only, as 76.10 + * published by the Free Software Foundation. 76.11 + * 76.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 76.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 76.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 76.15 + * version 2 for more details (a copy is included in the LICENSE file that 76.16 + * accompanied this code). 76.17 + * 76.18 + * You should have received a copy of the GNU General Public License version 76.19 + * 2 along with this work; if not, write to the Free Software Foundation, 76.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 76.21 + * 76.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 76.23 + * or visit www.oracle.com if you need additional information or have any 76.24 + * questions. 76.25 + */ 76.26 + 76.27 +/* 76.28 + * @test 76.29 + * @bug 6604599 76.30 + * @summary ToolProvider should be less compiler-specific 76.31 + */ 76.32 + 76.33 +import java.io.*; 76.34 + 76.35 +// verify that running accessing ToolProvider by itself does not 76.36 +// trigger loading com.sun.tools.javac.* 76.37 +public class ToolProviderTest1 { 76.38 + public static void main(String... args) throws Exception { 76.39 + if (args.length > 0) { 76.40 + System.err.println(Class.forName(args[0], true, null)); 76.41 + return; 76.42 + } 76.43 + 76.44 + new ToolProviderTest1().run(); 76.45 + } 76.46 + 76.47 + void run() throws Exception { 76.48 + File javaHome = new File(System.getProperty("java.home")); 76.49 + if (javaHome.getName().equals("jre")) 76.50 + javaHome = javaHome.getParentFile(); 76.51 + File javaExe = new File(new File(javaHome, "bin"), "java"); 76.52 + String classpath = System.getProperty("java.class.path"); 76.53 + 76.54 + String[] cmd = { 76.55 + javaExe.getPath(), 76.56 + "-verbose:class", 76.57 + "-classpath", classpath, 76.58 + ToolProviderTest1.class.getName(), 76.59 + "javax.tools.ToolProvider" 76.60 + }; 76.61 + 76.62 + ProcessBuilder pb = new ProcessBuilder(cmd).redirectErrorStream(true); 76.63 + Process p = pb.start(); 76.64 + BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream())); 76.65 + String line; 76.66 + while ((line = r.readLine()) != null) { 76.67 + System.err.println(line); 76.68 + if (line.contains("com.sun.tools.javac.")) 76.69 + error(">>> " + line); 76.70 + } 76.71 + int rc = p.waitFor(); 76.72 + if (rc != 0) 76.73 + error("Unexpected exit code: " + rc); 76.74 + 76.75 + if (errors > 0) 76.76 + throw new Exception(errors + " errors occurred"); 76.77 + } 76.78 + 76.79 + void error(String msg) { 76.80 + System.err.println(msg); 76.81 + errors++; 76.82 + } 76.83 + 76.84 + int errors; 76.85 +}
77.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 77.2 +++ b/test/tools/javac/api/ToolProvider/ToolProviderTest2.java Fri Sep 24 16:43:08 2010 -0700 77.3 @@ -0,0 +1,87 @@ 77.4 +/* 77.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 77.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 77.7 + * 77.8 + * This code is free software; you can redistribute it and/or modify it 77.9 + * under the terms of the GNU General Public License version 2 only, as 77.10 + * published by the Free Software Foundation. 77.11 + * 77.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 77.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 77.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 77.15 + * version 2 for more details (a copy is included in the LICENSE file that 77.16 + * accompanied this code). 77.17 + * 77.18 + * You should have received a copy of the GNU General Public License version 77.19 + * 2 along with this work; if not, write to the Free Software Foundation, 77.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 77.21 + * 77.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 77.23 + * or visit www.oracle.com if you need additional information or have any 77.24 + * questions. 77.25 + */ 77.26 + 77.27 +/* 77.28 + * @test 77.29 + * @bug 6604599 77.30 + * @summary ToolProvider should be less compiler-specific 77.31 + */ 77.32 + 77.33 +import java.io.*; 77.34 +import javax.tools.*; 77.35 + 77.36 +// control for ToolProviderTest1 -- verify that using ToolProvider to 77.37 +// access the compiler does trigger loading com.sun.tools.javac.* 77.38 +public class ToolProviderTest2 { 77.39 + public static void main(String... args) throws Exception { 77.40 + if (args.length > 0) { 77.41 + System.err.println(ToolProvider.getSystemJavaCompiler()); 77.42 + return; 77.43 + } 77.44 + 77.45 + new ToolProviderTest2().run(); 77.46 + } 77.47 + 77.48 + void run() throws Exception { 77.49 + File javaHome = new File(System.getProperty("java.home")); 77.50 + if (javaHome.getName().equals("jre")) 77.51 + javaHome = javaHome.getParentFile(); 77.52 + File javaExe = new File(new File(javaHome, "bin"), "java"); 77.53 + String classpath = System.getProperty("java.class.path"); 77.54 + 77.55 + String[] cmd = { 77.56 + javaExe.getPath(), 77.57 + "-verbose:class", 77.58 + "-classpath", classpath, 77.59 + ToolProviderTest2.class.getName(), 77.60 + "javax.tools.ToolProvider" 77.61 + }; 77.62 + 77.63 + ProcessBuilder pb = new ProcessBuilder(cmd).redirectErrorStream(true); 77.64 + Process p = pb.start(); 77.65 + BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream())); 77.66 + String line; 77.67 + boolean found = false; 77.68 + while ((line = r.readLine()) != null) { 77.69 + System.err.println(line); 77.70 + if (line.contains("com.sun.tools.javac.")) 77.71 + found = true; 77.72 + } 77.73 + int rc = p.waitFor(); 77.74 + if (rc != 0) 77.75 + error("Unexpected exit code: " + rc); 77.76 + 77.77 + if (!found) 77.78 + System.err.println("expected class name not found"); 77.79 + 77.80 + if (errors > 0) 77.81 + throw new Exception(errors + " errors occurred"); 77.82 + } 77.83 + 77.84 + void error(String msg) { 77.85 + System.err.println(msg); 77.86 + errors++; 77.87 + } 77.88 + 77.89 + int errors; 77.90 +}
78.1 --- a/test/tools/javac/diags/examples.not-yet.txt Thu Sep 23 17:33:52 2010 -0700 78.2 +++ b/test/tools/javac/diags/examples.not-yet.txt Fri Sep 24 16:43:08 2010 -0700 78.3 @@ -62,6 +62,7 @@ 78.4 compiler.misc.fatal.err.cant.locate.ctor # Resolve, from Lower 78.5 compiler.misc.fatal.err.cant.locate.field # Resolve, from Lower 78.6 compiler.misc.fatal.err.cant.locate.meth # Resolve, from Lower 78.7 +compiler.misc.fatal.err.cant.close.loader # JavacProcessingEnvironment 78.8 compiler.misc.file.does.not.contain.package 78.9 compiler.misc.illegal.start.of.class.file 78.10 compiler.misc.inferred.do.not.conform.to.params # UNUSED (hard to see if very complex inference scenario might require this though, so leaving it in, as per JLS3) 78.11 @@ -113,3 +114,4 @@ 78.12 compiler.warn.unchecked.assign # DEAD, replaced by compiler.misc.unchecked.assign 78.13 compiler.warn.unchecked.cast.to.type # DEAD, replaced by compiler.misc.unchecked.cast.to.type 78.14 compiler.warn.unexpected.archive.file # Paths: zip file with unknown extn 78.15 +compiler.warn.wrong.target.for.polymorphic.signature.definition # Transitional 292
79.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 79.2 +++ b/test/tools/javac/diags/examples/TypeParameterOnPolymorphicSignature.java Fri Sep 24 16:43:08 2010 -0700 79.3 @@ -0,0 +1,31 @@ 79.4 +/* 79.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 79.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 79.7 + * 79.8 + * This code is free software; you can redistribute it and/or modify it 79.9 + * under the terms of the GNU General Public License version 2 only, as 79.10 + * published by the Free Software Foundation. 79.11 + * 79.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 79.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 79.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 79.15 + * version 2 for more details (a copy is included in the LICENSE file that 79.16 + * accompanied this code). 79.17 + * 79.18 + * You should have received a copy of the GNU General Public License version 79.19 + * 2 along with this work; if not, write to the Free Software Foundation, 79.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 79.21 + * 79.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 79.23 + * or visit www.oracle.com if you need additional information or have any 79.24 + * questions. 79.25 + */ 79.26 + 79.27 +// key: compiler.warn.type.parameter.on.polymorphic.signature 79.28 +// key: compiler.err.unreported.exception.need.to.catch.or.throw 79.29 + 79.30 +import java.dyn.InvokeDynamic; 79.31 + 79.32 +class TypeParameterOnPolymorphicSignature { 79.33 + { InvokeDynamic.<void>call("",123); } 79.34 +}
80.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 80.2 +++ b/test/tools/javac/diags/examples/UnsupportedExoticID.java Fri Sep 24 16:43:08 2010 -0700 80.3 @@ -0,0 +1,31 @@ 80.4 +/* 80.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 80.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 80.7 + * 80.8 + * This code is free software; you can redistribute it and/or modify it 80.9 + * under the terms of the GNU General Public License version 2 only, as 80.10 + * published by the Free Software Foundation. 80.11 + * 80.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 80.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 80.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 80.15 + * version 2 for more details (a copy is included in the LICENSE file that 80.16 + * accompanied this code). 80.17 + * 80.18 + * You should have received a copy of the GNU General Public License version 80.19 + * 2 along with this work; if not, write to the Free Software Foundation, 80.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 80.21 + * 80.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 80.23 + * or visit www.oracle.com if you need additional information or have any 80.24 + * questions. 80.25 + */ 80.26 + 80.27 +// key: compiler.err.unsupported.exotic.id 80.28 +// options: -source 6 80.29 + 80.30 +class UnsupportedExoticID { 80.31 + void m() { 80.32 + Object #"Hello!" = null; 80.33 + } 80.34 +}
81.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 81.2 +++ b/test/tools/javac/failover/CheckAttributedTree.java Fri Sep 24 16:43:08 2010 -0700 81.3 @@ -0,0 +1,775 @@ 81.4 +/* 81.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 81.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 81.7 + * 81.8 + * This code is free software; you can redistribute it and/or modify it 81.9 + * under the terms of the GNU General Public License version 2 only, as 81.10 + * published by the Free Software Foundation. 81.11 + * 81.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 81.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 81.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 81.15 + * version 2 for more details (a copy is included in the LICENSE file that 81.16 + * accompanied this code). 81.17 + * 81.18 + * You should have received a copy of the GNU General Public License version 81.19 + * 2 along with this work; if not, write to the Free Software Foundation, 81.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 81.21 + * 81.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 81.23 + * or visit www.oracle.com if you need additional information or have any 81.24 + * questions. 81.25 + */ 81.26 + 81.27 +import com.sun.source.util.TaskEvent; 81.28 +import java.awt.BorderLayout; 81.29 +import java.awt.Color; 81.30 +import java.awt.Dimension; 81.31 +import java.awt.EventQueue; 81.32 +import java.awt.Font; 81.33 +import java.awt.GridBagConstraints; 81.34 +import java.awt.GridBagLayout; 81.35 +import java.awt.Rectangle; 81.36 +import java.awt.event.ActionEvent; 81.37 +import java.awt.event.ActionListener; 81.38 +import java.awt.event.MouseAdapter; 81.39 +import java.awt.event.MouseEvent; 81.40 +import javax.swing.DefaultComboBoxModel; 81.41 +import javax.swing.JComboBox; 81.42 +import javax.swing.JComponent; 81.43 +import javax.swing.JFrame; 81.44 +import javax.swing.JLabel; 81.45 +import javax.swing.JPanel; 81.46 +import javax.swing.JScrollPane; 81.47 +import javax.swing.JTextArea; 81.48 +import javax.swing.JTextField; 81.49 +import javax.swing.SwingUtilities; 81.50 +import javax.swing.event.CaretEvent; 81.51 +import javax.swing.event.CaretListener; 81.52 +import javax.swing.text.BadLocationException; 81.53 +import javax.swing.text.DefaultHighlighter; 81.54 +import javax.swing.text.Highlighter; 81.55 +import java.io.File; 81.56 +import java.io.IOException; 81.57 +import java.io.PrintStream; 81.58 +import java.io.PrintWriter; 81.59 +import java.io.StringWriter; 81.60 +import java.lang.reflect.Field; 81.61 +import java.lang.reflect.Modifier; 81.62 +import java.nio.charset.Charset; 81.63 +import java.util.ArrayList; 81.64 +import java.util.HashMap; 81.65 +import java.util.List; 81.66 +import java.util.Map; 81.67 +import javax.tools.Diagnostic; 81.68 +import javax.tools.DiagnosticListener; 81.69 +import javax.tools.JavaFileObject; 81.70 +import javax.tools.StandardJavaFileManager; 81.71 + 81.72 +import com.sun.source.tree.CompilationUnitTree; 81.73 +import com.sun.source.util.JavacTask; 81.74 +import com.sun.source.util.TaskListener; 81.75 +import com.sun.tools.javac.api.JavacTool; 81.76 +import com.sun.tools.javac.code.Symbol; 81.77 +import com.sun.tools.javac.code.Type; 81.78 +import com.sun.tools.javac.tree.JCTree; 81.79 +import com.sun.tools.javac.tree.JCTree.JCClassDecl; 81.80 +import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; 81.81 +import com.sun.tools.javac.tree.JCTree.JCImport; 81.82 +import com.sun.tools.javac.tree.TreeInfo; 81.83 +import com.sun.tools.javac.tree.TreeScanner; 81.84 +import com.sun.tools.javac.util.Pair; 81.85 + 81.86 +import java.util.Arrays; 81.87 +import java.util.HashSet; 81.88 +import java.util.Set; 81.89 +import javax.lang.model.element.Element; 81.90 + 81.91 +/** 81.92 + * Utility and test program to check validity of tree positions for tree nodes. 81.93 + * The program can be run standalone, or as a jtreg test. In standalone mode, 81.94 + * errors can be displayed in a gui viewer. For info on command line args, 81.95 + * run program with no args. 81.96 + * 81.97 + * <p> 81.98 + * jtreg: Note that by using the -r switch in the test description below, this test 81.99 + * will process all java files in the langtools/test directory, thus implicitly 81.100 + * covering any new language features that may be tested in this test suite. 81.101 + */ 81.102 + 81.103 +/* 81.104 + * @test 81.105 + * @bug 6970584 81.106 + * @summary assorted position errors in compiler syntax trees 81.107 + * @run main CheckAttributedTree -q -r -et ERRONEOUS . 81.108 + */ 81.109 +public class CheckAttributedTree { 81.110 + /** 81.111 + * Main entry point. 81.112 + * If test.src is set, program runs in jtreg mode, and will throw an Error 81.113 + * if any errors arise, otherwise System.exit will be used, unless the gui 81.114 + * viewer is being used. In jtreg mode, the default base directory for file 81.115 + * args is the value of ${test.src}. In jtreg mode, the -r option can be 81.116 + * given to change the default base directory to the root test directory. 81.117 + */ 81.118 + public static void main(String... args) { 81.119 + String testSrc = System.getProperty("test.src"); 81.120 + File baseDir = (testSrc == null) ? null : new File(testSrc); 81.121 + boolean ok = new CheckAttributedTree().run(baseDir, args); 81.122 + if (!ok) { 81.123 + if (testSrc != null) // jtreg mode 81.124 + throw new Error("failed"); 81.125 + else 81.126 + System.exit(1); 81.127 + } 81.128 + } 81.129 + 81.130 + /** 81.131 + * Run the program. A base directory can be provided for file arguments. 81.132 + * In jtreg mode, the -r option can be given to change the default base 81.133 + * directory to the test root directory. For other options, see usage(). 81.134 + * @param baseDir base directory for any file arguments. 81.135 + * @param args command line args 81.136 + * @return true if successful or in gui mode 81.137 + */ 81.138 + boolean run(File baseDir, String... args) { 81.139 + if (args.length == 0) { 81.140 + usage(System.out); 81.141 + return true; 81.142 + } 81.143 + 81.144 + List<File> files = new ArrayList<File>(); 81.145 + for (int i = 0; i < args.length; i++) { 81.146 + String arg = args[i]; 81.147 + if (arg.equals("-encoding") && i + 1 < args.length) 81.148 + encoding = args[++i]; 81.149 + else if (arg.equals("-gui")) 81.150 + gui = true; 81.151 + else if (arg.equals("-q")) 81.152 + quiet = true; 81.153 + else if (arg.equals("-v")) 81.154 + verbose = true; 81.155 + else if (arg.equals("-t") && i + 1 < args.length) 81.156 + tags.add(args[++i]); 81.157 + else if (arg.equals("-ef") && i + 1 < args.length) 81.158 + excludeFiles.add(new File(baseDir, args[++i])); 81.159 + else if (arg.equals("-et") && i + 1 < args.length) 81.160 + excludeTags.add(args[++i]); 81.161 + else if (arg.equals("-r")) { 81.162 + if (excludeFiles.size() > 0) 81.163 + throw new Error("-r must be used before -ef"); 81.164 + File d = baseDir; 81.165 + while (!new File(d, "TEST.ROOT").exists()) { 81.166 + if (d == null) 81.167 + throw new Error("cannot find TEST.ROOT"); 81.168 + d = d.getParentFile(); 81.169 + } 81.170 + baseDir = d; 81.171 + } 81.172 + else if (arg.startsWith("-")) 81.173 + throw new Error("unknown option: " + arg); 81.174 + else { 81.175 + while (i < args.length) 81.176 + files.add(new File(baseDir, args[i++])); 81.177 + } 81.178 + } 81.179 + 81.180 + for (File file: files) { 81.181 + if (file.exists()) 81.182 + test(file); 81.183 + else 81.184 + error("File not found: " + file); 81.185 + } 81.186 + 81.187 + if (fileCount != 1) 81.188 + System.err.println(fileCount + " files read"); 81.189 + if (errors > 0) 81.190 + System.err.println(errors + " errors"); 81.191 + 81.192 + return (gui || errors == 0); 81.193 + } 81.194 + 81.195 + /** 81.196 + * Print command line help. 81.197 + * @param out output stream 81.198 + */ 81.199 + void usage(PrintStream out) { 81.200 + out.println("Usage:"); 81.201 + out.println(" java CheckAttributedTree options... files..."); 81.202 + out.println(""); 81.203 + out.println("where options include:"); 81.204 + out.println("-q Quiet: don't report on inapplicable files"); 81.205 + out.println("-gui Display returns in a GUI viewer"); 81.206 + out.println("-v Verbose: report on files as they are being read"); 81.207 + out.println("-t tag Limit checks to tree nodes with this tag"); 81.208 + out.println(" Can be repeated if desired"); 81.209 + out.println("-ef file Exclude file or directory"); 81.210 + out.println("-et tag Exclude tree nodes with given tag name"); 81.211 + out.println(""); 81.212 + out.println("files may be directories or files"); 81.213 + out.println("directories will be scanned recursively"); 81.214 + out.println("non java files, or java files which cannot be parsed, will be ignored"); 81.215 + out.println(""); 81.216 + } 81.217 + 81.218 + /** 81.219 + * Test a file. If the file is a directory, it will be recursively scanned 81.220 + * for java files. 81.221 + * @param file the file or directory to test 81.222 + */ 81.223 + void test(File file) { 81.224 + if (excludeFiles.contains(file)) { 81.225 + if (!quiet) 81.226 + error("File " + file + " excluded"); 81.227 + return; 81.228 + } 81.229 + 81.230 + if (file.isDirectory()) { 81.231 + for (File f: file.listFiles()) { 81.232 + test(f); 81.233 + } 81.234 + return; 81.235 + } 81.236 + 81.237 + if (file.isFile() && file.getName().endsWith(".java")) { 81.238 + try { 81.239 + if (verbose) 81.240 + System.err.println(file); 81.241 + fileCount++; 81.242 + NPETester p = new NPETester(); 81.243 + p.test(read(file)); 81.244 + } catch (AttributionException e) { 81.245 + if (!quiet) { 81.246 + error("Error attributing " + file + "\n" + e.getMessage()); 81.247 + } 81.248 + } catch (IOException e) { 81.249 + error("Error reading " + file + ": " + e); 81.250 + } 81.251 + return; 81.252 + } 81.253 + 81.254 + if (!quiet) 81.255 + error("File " + file + " ignored"); 81.256 + } 81.257 + 81.258 + /** 81.259 + * Read a file. 81.260 + * @param file the file to be read 81.261 + * @return the tree for the content of the file 81.262 + * @throws IOException if any IO errors occur 81.263 + * @throws TreePosTest.ParseException if any errors occur while parsing the file 81.264 + */ 81.265 + List<Pair<JCCompilationUnit, JCTree>> read(File file) throws IOException, AttributionException { 81.266 + StringWriter sw = new StringWriter(); 81.267 + PrintWriter pw = new PrintWriter(sw); 81.268 + Reporter r = new Reporter(pw); 81.269 + JavacTool tool = JavacTool.create(); 81.270 + Charset cs = (encoding == null ? null : Charset.forName(encoding)); 81.271 + StandardJavaFileManager fm = tool.getStandardFileManager(r, null, null); 81.272 + Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(file); 81.273 + String[] opts = { "-XDshouldStopPolicy=ATTR", "-XDverboseCompilePolicy" }; 81.274 + JavacTask task = tool.getTask(pw, fm, r, Arrays.asList(opts), null, files); 81.275 + final List<Element> analyzedElems = new ArrayList<>(); 81.276 + task.setTaskListener(new TaskListener() { 81.277 + public void started(TaskEvent e) { 81.278 + if (e.getKind() == TaskEvent.Kind.ANALYZE) 81.279 + analyzedElems.add(e.getTypeElement()); 81.280 + } 81.281 + public void finished(TaskEvent e) { } 81.282 + }); 81.283 + 81.284 + try { 81.285 + Iterable<? extends CompilationUnitTree> trees = task.parse(); 81.286 + task.analyze(); 81.287 + List<Pair<JCCompilationUnit, JCTree>> res = new ArrayList<>(); 81.288 + //System.out.println("Try to add pairs. Elems are " + analyzedElems); 81.289 + for (CompilationUnitTree t : trees) { 81.290 + JCCompilationUnit cu = (JCCompilationUnit)t; 81.291 + for (JCTree def : cu.defs) { 81.292 + if (def.getTag() == JCTree.CLASSDEF && 81.293 + analyzedElems.contains(((JCTree.JCClassDecl)def).sym)) { 81.294 + //System.out.println("Adding pair..."); 81.295 + res.add(new Pair<>(cu, def)); 81.296 + } 81.297 + } 81.298 + } 81.299 + return res; 81.300 + } 81.301 + catch (Throwable t) { 81.302 + throw new AttributionException("Exception while attributing file: " + file); 81.303 + } 81.304 + } 81.305 + 81.306 + /** 81.307 + * Report an error. When the program is complete, the program will either 81.308 + * exit or throw an Error if any errors have been reported. 81.309 + * @param msg the error message 81.310 + */ 81.311 + void error(String msg) { 81.312 + System.err.println(msg); 81.313 + errors++; 81.314 + } 81.315 + 81.316 + /** Number of files that have been analyzed. */ 81.317 + int fileCount; 81.318 + /** Number of errors reported. */ 81.319 + int errors; 81.320 + /** Flag: don't report irrelevant files. */ 81.321 + boolean quiet; 81.322 + /** Flag: show errors in GUI viewer. */ 81.323 + boolean gui; 81.324 + /** The GUI viewer for errors. */ 81.325 + Viewer viewer; 81.326 + /** Flag: report files as they are processed. */ 81.327 + boolean verbose; 81.328 + /** Option: encoding for test files. */ 81.329 + String encoding; 81.330 + /** The set of tags for tree nodes to be analyzed; if empty, all tree nodes 81.331 + * are analyzed. */ 81.332 + Set<String> tags = new HashSet<String>(); 81.333 + /** Set of files and directories to be excluded from analysis. */ 81.334 + Set<File> excludeFiles = new HashSet<File>(); 81.335 + /** Set of tag names to be excluded from analysis. */ 81.336 + Set<String> excludeTags = new HashSet<String>(); 81.337 + /** Utility class for trees */ 81.338 + TreeUtil treeUtil = new TreeUtil(); 81.339 + 81.340 + /** 81.341 + * Main class for testing assertions concerning types/symbol 81.342 + * left uninitialized after attribution 81.343 + */ 81.344 + private class NPETester extends TreeScanner { 81.345 + void test(List<Pair<JCCompilationUnit, JCTree>> trees) { 81.346 + for (Pair<JCCompilationUnit, JCTree> p : trees) { 81.347 + sourcefile = p.fst.sourcefile; 81.348 + endPosTable = p.fst.endPositions; 81.349 + encl = new Info(p.snd, endPosTable); 81.350 + p.snd.accept(this); 81.351 + } 81.352 + } 81.353 + 81.354 + @Override 81.355 + public void scan(JCTree tree) { 81.356 + if (tree == null || 81.357 + excludeTags.contains(treeUtil.nameFromTag(tree.getTag()))) { 81.358 + return; 81.359 + } 81.360 + 81.361 + Info self = new Info(tree, endPosTable); 81.362 + check(!mandatoryType(tree) || 81.363 + (tree.type != null && 81.364 + checkFields(tree)), 81.365 + "'null' found in tree ", 81.366 + self); 81.367 + 81.368 + Info prevEncl = encl; 81.369 + encl = self; 81.370 + tree.accept(this); 81.371 + encl = prevEncl; 81.372 + } 81.373 + 81.374 + private boolean mandatoryType(JCTree that) { 81.375 + return that instanceof JCTree.JCExpression || 81.376 + that.getTag() == JCTree.VARDEF || 81.377 + that.getTag() == JCTree.METHODDEF || 81.378 + that.getTag() == JCTree.CLASSDEF; 81.379 + } 81.380 + 81.381 + private final List<String> excludedFields = Arrays.asList("varargsElement"); 81.382 + 81.383 + void check(boolean ok, String label, Info self) { 81.384 + if (!ok) { 81.385 + if (gui) { 81.386 + if (viewer == null) 81.387 + viewer = new Viewer(); 81.388 + viewer.addEntry(sourcefile, label, encl, self); 81.389 + } 81.390 + error(label + self.toString() + " encl: " + encl.toString() + " in file: " + sourcefile + " " + self.tree); 81.391 + } 81.392 + } 81.393 + 81.394 + boolean checkFields(JCTree t) { 81.395 + List<Field> fieldsToCheck = treeUtil.getFieldsOfType(t, 81.396 + excludedFields, 81.397 + Symbol.class, 81.398 + Type.class); 81.399 + for (Field f : fieldsToCheck) { 81.400 + try { 81.401 + if (f.get(t) == null) { 81.402 + return false; 81.403 + } 81.404 + } 81.405 + catch (IllegalAccessException e) { 81.406 + System.err.println("Cannot read field: " + f); 81.407 + //swallow it 81.408 + } 81.409 + } 81.410 + return true; 81.411 + } 81.412 + 81.413 + @Override 81.414 + public void visitImport(JCImport tree) { } 81.415 + 81.416 + @Override 81.417 + public void visitTopLevel(JCCompilationUnit tree) { 81.418 + scan(tree.defs); 81.419 + } 81.420 + 81.421 + JavaFileObject sourcefile; 81.422 + Map<JCTree, Integer> endPosTable; 81.423 + Info encl; 81.424 + } 81.425 + 81.426 + /** 81.427 + * Utility class providing easy access to position and other info for a tree node. 81.428 + */ 81.429 + private class Info { 81.430 + Info() { 81.431 + tree = null; 81.432 + tag = JCTree.ERRONEOUS; 81.433 + start = 0; 81.434 + pos = 0; 81.435 + end = Integer.MAX_VALUE; 81.436 + } 81.437 + 81.438 + Info(JCTree tree, Map<JCTree, Integer> endPosTable) { 81.439 + this.tree = tree; 81.440 + tag = tree.getTag(); 81.441 + start = TreeInfo.getStartPos(tree); 81.442 + pos = tree.pos; 81.443 + end = TreeInfo.getEndPos(tree, endPosTable); 81.444 + } 81.445 + 81.446 + @Override 81.447 + public String toString() { 81.448 + return treeUtil.nameFromTag(tree.getTag()) + "[start:" + start + ",pos:" + pos + ",end:" + end + "]"; 81.449 + } 81.450 + 81.451 + final JCTree tree; 81.452 + final int tag; 81.453 + final int start; 81.454 + final int pos; 81.455 + final int end; 81.456 + } 81.457 + 81.458 + /** 81.459 + * Names for tree tags. 81.460 + * javac does not provide an API to convert tag values to strings, so this class uses 81.461 + * reflection to determine names of public static final int values in JCTree. 81.462 + */ 81.463 + private static class TreeUtil { 81.464 + String nameFromTag(int tag) { 81.465 + if (names == null) { 81.466 + names = new HashMap<Integer, String>(); 81.467 + Class c = JCTree.class; 81.468 + for (Field f : c.getDeclaredFields()) { 81.469 + if (f.getType().equals(int.class)) { 81.470 + int mods = f.getModifiers(); 81.471 + if (Modifier.isPublic(mods) && Modifier.isStatic(mods) && Modifier.isFinal(mods)) { 81.472 + try { 81.473 + names.put(f.getInt(null), f.getName()); 81.474 + } catch (IllegalAccessException e) { 81.475 + } 81.476 + } 81.477 + } 81.478 + } 81.479 + } 81.480 + String name = names.get(tag); 81.481 + return (name == null) ? "??" : name; 81.482 + } 81.483 + 81.484 + List<Field> getFieldsOfType(JCTree t, List<String> excludeNames, Class<?>... types) { 81.485 + List<Field> buf = new ArrayList<Field>(); 81.486 + for (Field f : t.getClass().getDeclaredFields()) { 81.487 + if (!excludeNames.contains(f.getName())) { 81.488 + for (Class<?> type : types) { 81.489 + if (type.isAssignableFrom(f.getType())) { 81.490 + f.setAccessible(true); 81.491 + buf.add(f); 81.492 + break; 81.493 + } 81.494 + } 81.495 + } 81.496 + } 81.497 + return buf; 81.498 + } 81.499 + 81.500 + private Map<Integer, String> names; 81.501 + } 81.502 + 81.503 + /** 81.504 + * Thrown when errors are found parsing a java file. 81.505 + */ 81.506 + private static class ParseException extends Exception { 81.507 + ParseException(String msg) { 81.508 + super(msg); 81.509 + } 81.510 + } 81.511 + 81.512 + private static class AttributionException extends Exception { 81.513 + AttributionException(String msg) { 81.514 + super(msg); 81.515 + } 81.516 + } 81.517 + 81.518 + /** 81.519 + * DiagnosticListener to report diagnostics and count any errors that occur. 81.520 + */ 81.521 + private static class Reporter implements DiagnosticListener<JavaFileObject> { 81.522 + Reporter(PrintWriter out) { 81.523 + this.out = out; 81.524 + } 81.525 + 81.526 + public void report(Diagnostic<? extends JavaFileObject> diagnostic) { 81.527 + out.println(diagnostic); 81.528 + switch (diagnostic.getKind()) { 81.529 + case ERROR: 81.530 + errors++; 81.531 + } 81.532 + } 81.533 + int errors; 81.534 + PrintWriter out; 81.535 + } 81.536 + 81.537 + /** 81.538 + * GUI viewer for issues found by TreePosTester. The viewer provides a drop 81.539 + * down list for selecting error conditions, a header area providing details 81.540 + * about an error, and a text area with the ranges of text highlighted as 81.541 + * appropriate. 81.542 + */ 81.543 + private class Viewer extends JFrame { 81.544 + /** 81.545 + * Create a viewer. 81.546 + */ 81.547 + Viewer() { 81.548 + initGUI(); 81.549 + } 81.550 + 81.551 + /** 81.552 + * Add another entry to the list of errors. 81.553 + * @param file The file containing the error 81.554 + * @param check The condition that was being tested, and which failed 81.555 + * @param encl the enclosing tree node 81.556 + * @param self the tree node containing the error 81.557 + */ 81.558 + void addEntry(JavaFileObject file, String check, Info encl, Info self) { 81.559 + Entry e = new Entry(file, check, encl, self); 81.560 + DefaultComboBoxModel m = (DefaultComboBoxModel) entries.getModel(); 81.561 + m.addElement(e); 81.562 + if (m.getSize() == 1) 81.563 + entries.setSelectedItem(e); 81.564 + } 81.565 + 81.566 + /** 81.567 + * Initialize the GUI window. 81.568 + */ 81.569 + private void initGUI() { 81.570 + JPanel head = new JPanel(new GridBagLayout()); 81.571 + GridBagConstraints lc = new GridBagConstraints(); 81.572 + GridBagConstraints fc = new GridBagConstraints(); 81.573 + fc.anchor = GridBagConstraints.WEST; 81.574 + fc.fill = GridBagConstraints.HORIZONTAL; 81.575 + fc.gridwidth = GridBagConstraints.REMAINDER; 81.576 + 81.577 + entries = new JComboBox(); 81.578 + entries.addActionListener(new ActionListener() { 81.579 + public void actionPerformed(ActionEvent e) { 81.580 + showEntry((Entry) entries.getSelectedItem()); 81.581 + } 81.582 + }); 81.583 + fc.insets.bottom = 10; 81.584 + head.add(entries, fc); 81.585 + fc.insets.bottom = 0; 81.586 + head.add(new JLabel("check:"), lc); 81.587 + head.add(checkField = createTextField(80), fc); 81.588 + fc.fill = GridBagConstraints.NONE; 81.589 + head.add(setBackground(new JLabel("encl:"), enclColor), lc); 81.590 + head.add(enclPanel = new InfoPanel(), fc); 81.591 + head.add(setBackground(new JLabel("self:"), selfColor), lc); 81.592 + head.add(selfPanel = new InfoPanel(), fc); 81.593 + add(head, BorderLayout.NORTH); 81.594 + 81.595 + body = new JTextArea(); 81.596 + body.setFont(Font.decode(Font.MONOSPACED)); 81.597 + body.addCaretListener(new CaretListener() { 81.598 + public void caretUpdate(CaretEvent e) { 81.599 + int dot = e.getDot(); 81.600 + int mark = e.getMark(); 81.601 + if (dot == mark) 81.602 + statusText.setText("dot: " + dot); 81.603 + else 81.604 + statusText.setText("dot: " + dot + ", mark:" + mark); 81.605 + } 81.606 + }); 81.607 + JScrollPane p = new JScrollPane(body, 81.608 + JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, 81.609 + JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); 81.610 + p.setPreferredSize(new Dimension(640, 480)); 81.611 + add(p, BorderLayout.CENTER); 81.612 + 81.613 + statusText = createTextField(80); 81.614 + add(statusText, BorderLayout.SOUTH); 81.615 + 81.616 + pack(); 81.617 + setLocationRelativeTo(null); // centered on screen 81.618 + setVisible(true); 81.619 + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 81.620 + } 81.621 + 81.622 + /** Show an entry that has been selected. */ 81.623 + private void showEntry(Entry e) { 81.624 + try { 81.625 + // update simple fields 81.626 + setTitle(e.file.getName()); 81.627 + checkField.setText(e.check); 81.628 + enclPanel.setInfo(e.encl); 81.629 + selfPanel.setInfo(e.self); 81.630 + // show file text with highlights 81.631 + body.setText(e.file.getCharContent(true).toString()); 81.632 + Highlighter highlighter = body.getHighlighter(); 81.633 + highlighter.removeAllHighlights(); 81.634 + addHighlight(highlighter, e.encl, enclColor); 81.635 + addHighlight(highlighter, e.self, selfColor); 81.636 + scroll(body, getMinPos(enclPanel.info, selfPanel.info)); 81.637 + } catch (IOException ex) { 81.638 + body.setText("Cannot read " + e.file.getName() + ": " + e); 81.639 + } 81.640 + } 81.641 + 81.642 + /** Create a test field. */ 81.643 + private JTextField createTextField(int width) { 81.644 + JTextField f = new JTextField(width); 81.645 + f.setEditable(false); 81.646 + f.setBorder(null); 81.647 + return f; 81.648 + } 81.649 + 81.650 + /** Add a highlighted region based on the positions in an Info object. */ 81.651 + private void addHighlight(Highlighter h, Info info, Color c) { 81.652 + int start = info.start; 81.653 + int end = info.end; 81.654 + if (start == -1 && end == -1) 81.655 + return; 81.656 + if (start == -1) 81.657 + start = end; 81.658 + if (end == -1) 81.659 + end = start; 81.660 + try { 81.661 + h.addHighlight(info.start, info.end, 81.662 + new DefaultHighlighter.DefaultHighlightPainter(c)); 81.663 + if (info.pos != -1) { 81.664 + Color c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int)(.4f * 255)); // 40% 81.665 + h.addHighlight(info.pos, info.pos + 1, 81.666 + new DefaultHighlighter.DefaultHighlightPainter(c2)); 81.667 + } 81.668 + } catch (BadLocationException e) { 81.669 + e.printStackTrace(); 81.670 + } 81.671 + } 81.672 + 81.673 + /** Get the minimum valid position in a set of info objects. */ 81.674 + private int getMinPos(Info... values) { 81.675 + int i = Integer.MAX_VALUE; 81.676 + for (Info info: values) { 81.677 + if (info.start >= 0) i = Math.min(i, info.start); 81.678 + if (info.pos >= 0) i = Math.min(i, info.pos); 81.679 + if (info.end >= 0) i = Math.min(i, info.end); 81.680 + } 81.681 + return (i == Integer.MAX_VALUE) ? 0 : i; 81.682 + } 81.683 + 81.684 + /** Set the background on a component. */ 81.685 + private JComponent setBackground(JComponent comp, Color c) { 81.686 + comp.setOpaque(true); 81.687 + comp.setBackground(c); 81.688 + return comp; 81.689 + } 81.690 + 81.691 + /** Scroll a text area to display a given position near the middle of the visible area. */ 81.692 + private void scroll(final JTextArea t, final int pos) { 81.693 + // Using invokeLater appears to give text a chance to sort itself out 81.694 + // before the scroll happens; otherwise scrollRectToVisible doesn't work. 81.695 + // Maybe there's a better way to sync with the text... 81.696 + EventQueue.invokeLater(new Runnable() { 81.697 + public void run() { 81.698 + try { 81.699 + Rectangle r = t.modelToView(pos); 81.700 + JScrollPane p = (JScrollPane) SwingUtilities.getAncestorOfClass(JScrollPane.class, t); 81.701 + r.y = Math.max(0, r.y - p.getHeight() * 2 / 5); 81.702 + r.height += p.getHeight() * 4 / 5; 81.703 + t.scrollRectToVisible(r); 81.704 + } catch (BadLocationException ignore) { 81.705 + } 81.706 + } 81.707 + }); 81.708 + } 81.709 + 81.710 + private JComboBox entries; 81.711 + private JTextField checkField; 81.712 + private InfoPanel enclPanel; 81.713 + private InfoPanel selfPanel; 81.714 + private JTextArea body; 81.715 + private JTextField statusText; 81.716 + 81.717 + private Color selfColor = new Color(0.f, 1.f, 0.f, 0.2f); // 20% green 81.718 + private Color enclColor = new Color(1.f, 0.f, 0.f, 0.2f); // 20% red 81.719 + 81.720 + /** Panel to display an Info object. */ 81.721 + private class InfoPanel extends JPanel { 81.722 + InfoPanel() { 81.723 + add(tagName = createTextField(20)); 81.724 + add(new JLabel("start:")); 81.725 + add(addListener(start = createTextField(6))); 81.726 + add(new JLabel("pos:")); 81.727 + add(addListener(pos = createTextField(6))); 81.728 + add(new JLabel("end:")); 81.729 + add(addListener(end = createTextField(6))); 81.730 + } 81.731 + 81.732 + void setInfo(Info info) { 81.733 + this.info = info; 81.734 + tagName.setText(treeUtil.nameFromTag(info.tag)); 81.735 + start.setText(String.valueOf(info.start)); 81.736 + pos.setText(String.valueOf(info.pos)); 81.737 + end.setText(String.valueOf(info.end)); 81.738 + } 81.739 + 81.740 + JTextField addListener(final JTextField f) { 81.741 + f.addMouseListener(new MouseAdapter() { 81.742 + @Override 81.743 + public void mouseClicked(MouseEvent e) { 81.744 + body.setCaretPosition(Integer.valueOf(f.getText())); 81.745 + body.getCaret().setVisible(true); 81.746 + } 81.747 + }); 81.748 + return f; 81.749 + } 81.750 + 81.751 + Info info; 81.752 + JTextField tagName; 81.753 + JTextField start; 81.754 + JTextField pos; 81.755 + JTextField end; 81.756 + } 81.757 + 81.758 + /** Object to record information about an error to be displayed. */ 81.759 + private class Entry { 81.760 + Entry(JavaFileObject file, String check, Info encl, Info self) { 81.761 + this.file = file; 81.762 + this.check = check; 81.763 + this.encl = encl; 81.764 + this.self= self; 81.765 + } 81.766 + 81.767 + @Override 81.768 + public String toString() { 81.769 + return file.getName() + " " + check + " " + getMinPos(encl, self); 81.770 + } 81.771 + 81.772 + final JavaFileObject file; 81.773 + final String check; 81.774 + final Info encl; 81.775 + final Info self; 81.776 + } 81.777 + } 81.778 +}
82.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 82.2 +++ b/test/tools/javac/failover/FailOver01.java Fri Sep 24 16:43:08 2010 -0700 82.3 @@ -0,0 +1,10 @@ 82.4 +/* 82.5 + * @test /nodynamiccopyright/ 82.6 + * @bug 6970584 82.7 + * @summary Flow.java should be more error-friendly 82.8 + * @author mcimadamore 82.9 + * 82.10 + * @compile/fail/ref=FailOver01.out -XDrawDiagnostics -XDshouldStopPolicy=FLOW -XDdev FailOver01.java 82.11 + */ 82.12 + 82.13 +class Test { { x = "" } }
83.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 83.2 +++ b/test/tools/javac/failover/FailOver01.out Fri Sep 24 16:43:08 2010 -0700 83.3 @@ -0,0 +1,3 @@ 83.4 +FailOver01.java:10:22: compiler.err.expected: ';' 83.5 +FailOver01.java:10:16: compiler.err.cant.resolve.location: kindname.variable, x, , , kindname.class, Test 83.6 +2 errors
84.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 84.2 +++ b/test/tools/javac/failover/FailOver02.java Fri Sep 24 16:43:08 2010 -0700 84.3 @@ -0,0 +1,14 @@ 84.4 +/* 84.5 + * @test /nodynamiccopyright/ 84.6 + * @bug 6970584 84.7 + * @summary Flow.java should be more error-friendly 84.8 + * @author mcimadamore 84.9 + * 84.10 + * @compile/fail/ref=FailOver02.out -XDrawDiagnostics -XDshouldStopPolicy=FLOW -XDdev FailOver02.java 84.11 + */ 84.12 + 84.13 +class Test implements AutoCloseable { 84.14 + void test() { 84.15 + try(Test t = null) {} 84.16 + } 84.17 +}
85.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 85.2 +++ b/test/tools/javac/failover/FailOver02.out Fri Sep 24 16:43:08 2010 -0700 85.3 @@ -0,0 +1,3 @@ 85.4 +FailOver02.java:10:1: compiler.err.does.not.override.abstract: Test, close(), java.lang.AutoCloseable 85.5 +FailOver02.java:12:9: compiler.err.cant.resolve.location.args: kindname.method, close, , , kindname.class, Test 85.6 +2 errors
86.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 86.2 +++ b/test/tools/javac/failover/FailOver03.java Fri Sep 24 16:43:08 2010 -0700 86.3 @@ -0,0 +1,12 @@ 86.4 +/* 86.5 + * @test /nodynamiccopyright/ 86.6 + * @bug 6970584 86.7 + * @summary Flow.java should be more error-friendly 86.8 + * @author mcimadamore 86.9 + * 86.10 + * @compile/fail/ref=FailOver03.out -XDrawDiagnostics -XDshouldStopPolicy=FLOW -XDdev FailOver03.java 86.11 + */ 86.12 + 86.13 +class Test extends Test { 86.14 + Test i; 86.15 +}
87.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 87.2 +++ b/test/tools/javac/failover/FailOver03.out Fri Sep 24 16:43:08 2010 -0700 87.3 @@ -0,0 +1,2 @@ 87.4 +FailOver03.java:10:1: compiler.err.cyclic.inheritance: Test 87.5 +1 error
88.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 88.2 +++ b/test/tools/javac/failover/FailOver04.java Fri Sep 24 16:43:08 2010 -0700 88.3 @@ -0,0 +1,12 @@ 88.4 +/* 88.5 + * @test /nodynamiccopyright/ 88.6 + * @bug 6970584 88.7 + * @summary Flow.java should be more error-friendly 88.8 + * @author mcimadamore 88.9 + * 88.10 + * @compile/fail/ref=FailOver04.out -XDrawDiagnostics -XDshouldStopPolicy=FLOW -XDdev FailOver04.java 88.11 + */ 88.12 + 88.13 +class Test { 88.14 + { new Unknown() {}; } 88.15 +}
89.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 89.2 +++ b/test/tools/javac/failover/FailOver04.out Fri Sep 24 16:43:08 2010 -0700 89.3 @@ -0,0 +1,2 @@ 89.4 +FailOver04.java:11:10: compiler.err.cant.resolve.location: kindname.class, Unknown, , , kindname.class, Test 89.5 +1 error
90.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 90.2 +++ b/test/tools/javac/failover/FailOver05.java Fri Sep 24 16:43:08 2010 -0700 90.3 @@ -0,0 +1,12 @@ 90.4 +/* 90.5 + * @test /nodynamiccopyright/ 90.6 + * @bug 6970584 90.7 + * @summary Flow.java should be more error-friendly 90.8 + * @author mcimadamore 90.9 + * 90.10 + * @compile/fail/ref=FailOver05.out -XDrawDiagnostics -XDshouldStopPolicy=FLOW -XDdev FailOver05.java 90.11 + */ 90.12 + 90.13 +class Test extends Test { 90.14 + { for ( Integer x : null) {} } 90.15 +}
91.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 91.2 +++ b/test/tools/javac/failover/FailOver05.out Fri Sep 24 16:43:08 2010 -0700 91.3 @@ -0,0 +1,2 @@ 91.4 +FailOver05.java:10:1: compiler.err.cyclic.inheritance: Test 91.5 +1 error
92.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 92.2 +++ b/test/tools/javac/failover/FailOver06.java Fri Sep 24 16:43:08 2010 -0700 92.3 @@ -0,0 +1,13 @@ 92.4 +/* 92.5 + * @test /nodynamiccopyright/ 92.6 + * @bug 6970584 92.7 + * @summary Flow.java should be more error-friendly 92.8 + * @author mcimadamore 92.9 + * 92.10 + * @compile/fail/ref=FailOver06.out -XDrawDiagnostics -XDshouldStopPolicy=FLOW -XDdev FailOver06.java 92.11 + */ 92.12 + 92.13 +class Test extends Test { 92.14 + Inference x = 1; 92.15 + { if (x == 1) { } else { } } 92.16 +}
93.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 93.2 +++ b/test/tools/javac/failover/FailOver06.out Fri Sep 24 16:43:08 2010 -0700 93.3 @@ -0,0 +1,2 @@ 93.4 +FailOver06.java:10:1: compiler.err.cyclic.inheritance: Test 93.5 +1 error
94.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 94.2 +++ b/test/tools/javac/failover/FailOver07.java Fri Sep 24 16:43:08 2010 -0700 94.3 @@ -0,0 +1,13 @@ 94.4 +/* 94.5 + * @test /nodynamiccopyright/ 94.6 + * @bug 6970584 94.7 + * @summary Flow.java should be more error-friendly 94.8 + * @author mcimadamore 94.9 + * 94.10 + * @compile/fail/ref=FailOver07.out -XDrawDiagnostics -XDshouldStopPolicy=FLOW -XDdev FailOver07.java 94.11 + */ 94.12 + 94.13 +class Test extends Test { 94.14 + Integer x = 1; 94.15 + { do {} while (x); } 94.16 +}
95.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 95.2 +++ b/test/tools/javac/failover/FailOver07.out Fri Sep 24 16:43:08 2010 -0700 95.3 @@ -0,0 +1,2 @@ 95.4 +FailOver07.java:10:1: compiler.err.cyclic.inheritance: Test 95.5 +1 error
96.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 96.2 +++ b/test/tools/javac/failover/FailOver08.java Fri Sep 24 16:43:08 2010 -0700 96.3 @@ -0,0 +1,13 @@ 96.4 +/* 96.5 + * @test /nodynamiccopyright/ 96.6 + * @bug 6970584 96.7 + * @summary Flow.java should be more error-friendly 96.8 + * @author mcimadamore 96.9 + * 96.10 + * @compile/fail/ref=FailOver08.out -XDrawDiagnostics -XDshouldStopPolicy=FLOW -XDdev FailOver08.java 96.11 + */ 96.12 + 96.13 +class Test extends Test { 96.14 + Integer x = 1; 96.15 + { while (x) {}; } 96.16 +}
97.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 97.2 +++ b/test/tools/javac/failover/FailOver08.out Fri Sep 24 16:43:08 2010 -0700 97.3 @@ -0,0 +1,2 @@ 97.4 +FailOver08.java:10:1: compiler.err.cyclic.inheritance: Test 97.5 +1 error
98.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 98.2 +++ b/test/tools/javac/failover/FailOver09.java Fri Sep 24 16:43:08 2010 -0700 98.3 @@ -0,0 +1,13 @@ 98.4 +/* 98.5 + * @test /nodynamiccopyright/ 98.6 + * @bug 6970584 98.7 + * @summary Flow.java should be more error-friendly 98.8 + * @author mcimadamore 98.9 + * 98.10 + * @compile/fail/ref=FailOver09.out -XDrawDiagnostics -XDshouldStopPolicy=FLOW -XDdev FailOver09.java 98.11 + */ 98.12 + 98.13 +class Test extends Test { 98.14 + Integer x = 1; 98.15 + { for (x = 0 ; x ; x++) {}; } 98.16 +}
99.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 99.2 +++ b/test/tools/javac/failover/FailOver09.out Fri Sep 24 16:43:08 2010 -0700 99.3 @@ -0,0 +1,2 @@ 99.4 +FailOver09.java:10:1: compiler.err.cyclic.inheritance: Test 99.5 +1 error
100.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 100.2 +++ b/test/tools/javac/failover/FailOver10.java Fri Sep 24 16:43:08 2010 -0700 100.3 @@ -0,0 +1,15 @@ 100.4 +/* 100.5 + * @test /nodynamiccopyright/ 100.6 + * @bug 6970584 100.7 + * @summary Flow.java should be more error-friendly 100.8 + * @author mcimadamore 100.9 + * 100.10 + * @compile/fail/ref=FailOver10.out -XDrawDiagnostics -XDshouldStopPolicy=FLOW -XDdev FailOver10.java 100.11 + */ 100.12 + 100.13 +class Test extends Test { 100.14 + 100.15 + boolean cond; 100.16 + 100.17 + { Object o = null; } 100.18 +}
101.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 101.2 +++ b/test/tools/javac/failover/FailOver10.out Fri Sep 24 16:43:08 2010 -0700 101.3 @@ -0,0 +1,2 @@ 101.4 +FailOver10.java:10:1: compiler.err.cyclic.inheritance: Test 101.5 +1 error
102.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 102.2 +++ b/test/tools/javac/failover/FailOver11.java Fri Sep 24 16:43:08 2010 -0700 102.3 @@ -0,0 +1,17 @@ 102.4 +/* 102.5 + * @test /nodynamiccopyright/ 102.6 + * @bug 6970584 102.7 + * @summary Flow.java should be more error-friendly 102.8 + * @author mcimadamore 102.9 + * 102.10 + * @compile/fail/ref=FailOver11.out -XDrawDiagnostics -XDshouldStopPolicy=FLOW -XDdev FailOver11.java 102.11 + */ 102.12 + 102.13 +class Test extends Test { 102.14 + 102.15 + boolean cond; 102.16 + 102.17 + void m(Object o) {} 102.18 + 102.19 + { m(cond ? null : null); } 102.20 +}
103.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 103.2 +++ b/test/tools/javac/failover/FailOver11.out Fri Sep 24 16:43:08 2010 -0700 103.3 @@ -0,0 +1,2 @@ 103.4 +FailOver11.java:10:1: compiler.err.cyclic.inheritance: Test 103.5 +1 error
104.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 104.2 +++ b/test/tools/javac/failover/FailOver12.java Fri Sep 24 16:43:08 2010 -0700 104.3 @@ -0,0 +1,15 @@ 104.4 +/* 104.5 + * @test /nodynamiccopyright/ 104.6 + * @bug 6970584 104.7 + * @summary Flow.java should be more error-friendly 104.8 + * @author mcimadamore 104.9 + * 104.10 + * @compile/fail/ref=FailOver12.out -XDrawDiagnostics -XDshouldStopPolicy=FLOW -XDdev FailOver12.java 104.11 + */ 104.12 + 104.13 +class Test extends Test { 104.14 + 104.15 + Integer x = 1; 104.16 + 104.17 + { try {} catch (Exception e) {} } 104.18 +}
105.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 105.2 +++ b/test/tools/javac/failover/FailOver12.out Fri Sep 24 16:43:08 2010 -0700 105.3 @@ -0,0 +1,2 @@ 105.4 +FailOver12.java:10:1: compiler.err.cyclic.inheritance: Test 105.5 +1 error
106.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 106.2 +++ b/test/tools/javac/failover/FailOver13.java Fri Sep 24 16:43:08 2010 -0700 106.3 @@ -0,0 +1,15 @@ 106.4 +/* 106.5 + * @test /nodynamiccopyright/ 106.6 + * @bug 6970584 106.7 + * @summary Flow.java should be more error-friendly 106.8 + * @author mcimadamore 106.9 + * 106.10 + * @compile/fail/ref=FailOver13.out -XDrawDiagnostics -XDshouldStopPolicy=FLOW -XDdev FailOver13.java 106.11 + */ 106.12 + 106.13 +class Test extends Test { 106.14 + 106.15 + Integer x = 1; 106.16 + 106.17 + { x = (Object)o; } 106.18 +}
107.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 107.2 +++ b/test/tools/javac/failover/FailOver13.out Fri Sep 24 16:43:08 2010 -0700 107.3 @@ -0,0 +1,2 @@ 107.4 +FailOver13.java:10:1: compiler.err.cyclic.inheritance: Test 107.5 +1 error
108.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 108.2 +++ b/test/tools/javac/failover/FailOver14.java Fri Sep 24 16:43:08 2010 -0700 108.3 @@ -0,0 +1,14 @@ 108.4 +/* 108.5 + * @test /nodynamiccopyright/ 108.6 + * @bug 6970584 108.7 + * @summary Flow.java should be more error-friendly 108.8 + * @author mcimadamore 108.9 + * 108.10 + * @compile/fail/ref=FailOver14.out -XDrawDiagnostics -XDshouldStopPolicy=FLOW -XDdev FailOver14.java 108.11 + */ 108.12 + 108.13 +class Test extends Test { 108.14 + 108.15 + { for (Integer x : !x) { } } 108.16 + 108.17 +}
109.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 109.2 +++ b/test/tools/javac/failover/FailOver14.out Fri Sep 24 16:43:08 2010 -0700 109.3 @@ -0,0 +1,2 @@ 109.4 +FailOver14.java:10:1: compiler.err.cyclic.inheritance: Test 109.5 +1 error
110.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 110.2 +++ b/test/tools/javac/generics/OverrideBridge.java Fri Sep 24 16:43:08 2010 -0700 110.3 @@ -0,0 +1,163 @@ 110.4 +/* 110.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 110.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 110.7 + * 110.8 + * This code is free software; you can redistribute it and/or modify it 110.9 + * under the terms of the GNU General Public License version 2 only, as 110.10 + * published by the Free Software Foundation. 110.11 + * 110.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 110.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 110.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 110.15 + * version 2 for more details (a copy is included in the LICENSE file that 110.16 + * accompanied this code). 110.17 + * 110.18 + * You should have received a copy of the GNU General Public License version 110.19 + * 2 along with this work; if not, write to the Free Software Foundation, 110.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 110.21 + * 110.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 110.23 + * or visit www.oracle.com if you need additional information or have any 110.24 + * questions. 110.25 + */ 110.26 + 110.27 +/* 110.28 + * @test 110.29 + * @bug 6337171 110.30 + * @summary javac should create bridge methods when type variable bounds restricted 110.31 + * @run main OverrideBridge 110.32 + */ 110.33 + 110.34 +import java.io.*; 110.35 +import java.net.URI; 110.36 +import java.util.ArrayList; 110.37 +import java.util.Arrays; 110.38 +import java.util.List; 110.39 +import java.util.Map; 110.40 +import java.util.HashMap; 110.41 +import javax.tools.JavaCompiler; 110.42 +import javax.tools.JavaFileObject; 110.43 +import javax.tools.SimpleJavaFileObject; 110.44 +import javax.tools.ToolProvider; 110.45 + 110.46 +import com.sun.source.util.JavacTask; 110.47 +import com.sun.tools.classfile.ClassFile; 110.48 +import com.sun.tools.classfile.ConstantPoolException; 110.49 +import com.sun.tools.classfile.Descriptor.InvalidDescriptor; 110.50 +import com.sun.tools.classfile.Method; 110.51 + 110.52 +public class OverrideBridge { 110.53 + 110.54 + enum Implementation { 110.55 + IMPLICIT(""), 110.56 + EXPLICIT("@Override public abstract X m(X x);"); 110.57 + 110.58 + String impl; 110.59 + 110.60 + Implementation(String impl) { 110.61 + this.impl = impl; 110.62 + } 110.63 + } 110.64 + 110.65 + static class JavaSource extends SimpleJavaFileObject { 110.66 + 110.67 + final static String sourceStub = 110.68 + "abstract class A<X> {\n" + 110.69 + " public abstract X m(X x);\n" + 110.70 + "}\n" + 110.71 + "interface I<X> {\n" + 110.72 + "X m(X x);\n" + 110.73 + "}\n" + 110.74 + "abstract class B<X extends B<X>> extends A<X> implements I<X> { #B }\n" + 110.75 + "abstract class C<X extends C<X>> extends B<X> { #C }\n" + 110.76 + "abstract class D<X extends D<X>> extends C<X> { #D }\n"; 110.77 + 110.78 + String source; 110.79 + 110.80 + public JavaSource(Implementation implB, Implementation implC, Implementation implD) { 110.81 + super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); 110.82 + source = sourceStub.replace("#B", implB.impl).replace("#C", implC.impl).replace("#D", implD.impl); 110.83 + } 110.84 + 110.85 + @Override 110.86 + public CharSequence getCharContent(boolean ignoreEncodingErrors) { 110.87 + return source; 110.88 + } 110.89 + } 110.90 + 110.91 + public static void main(String... args) throws Exception { 110.92 + Map<ClassFile, List<Method>> refMembers = 110.93 + compile(Implementation.EXPLICIT, Implementation.EXPLICIT, Implementation.EXPLICIT, "ref"); 110.94 + int i = 0; 110.95 + for (Implementation implB : Implementation.values()) { 110.96 + for (Implementation implC : Implementation.values()) { 110.97 + for (Implementation implD : Implementation.values()) { 110.98 + Map<ClassFile, List<Method>> membersToCheck = compile(implB, implC, implD, "out_" + i++); 110.99 + check(refMembers, membersToCheck); 110.100 + } 110.101 + } 110.102 + } 110.103 + } 110.104 + 110.105 + static String workDir = System.getProperty("user.dir"); 110.106 + 110.107 + static Map<ClassFile, List<Method>> compile(Implementation implB, Implementation implC, Implementation implD, String destPath) throws Exception { 110.108 + File destDir = new File(workDir, destPath); destDir.mkdir(); 110.109 + final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); 110.110 + JavaSource source = new JavaSource(implB, implC, implD); 110.111 + JavacTask ct = (JavacTask)tool.getTask(null, null, null, 110.112 + Arrays.asList("-d", destPath), null, Arrays.asList(source)); 110.113 + ct.generate(); 110.114 + Map<ClassFile, List<Method>> members = new HashMap<>(); 110.115 + addMembers(destDir, members); 110.116 + return members; 110.117 + } 110.118 + 110.119 + static void addMembers(File destDir, Map<ClassFile, List<Method>> members) { 110.120 + String[] names = { "B.class", "C.class", "D.class" }; 110.121 + try { 110.122 + for (String name : names) { 110.123 + File f = new File(destDir, name); 110.124 + ClassFile cf = ClassFile.read(f); 110.125 + members.put(cf, readMethod(cf, "m")); 110.126 + } 110.127 + } catch (Exception e) { 110.128 + e.printStackTrace(); 110.129 + throw new Error("error reading classes"); 110.130 + } 110.131 + } 110.132 + 110.133 + static List<Method> readMethod(ClassFile cf, String name) throws ConstantPoolException { 110.134 + List<Method> buf = new ArrayList<>(); 110.135 + for (Method m : cf.methods) { 110.136 + if (m.getName(cf.constant_pool).equals(name)) { 110.137 + buf.add(m); 110.138 + } 110.139 + } 110.140 + return buf; 110.141 + } 110.142 + 110.143 + static void check(Map<ClassFile, List<Method>> refMembers, Map<ClassFile, List<Method>> membersToCheck) throws ConstantPoolException, InvalidDescriptor { 110.144 + for (Map.Entry<ClassFile, List<Method>> ref : refMembers.entrySet()) { 110.145 + ClassFile cRef = ref.getKey(); 110.146 + for (Method mRef : ref.getValue()) { 110.147 + boolean ok = false; 110.148 + for (Map.Entry<ClassFile, List<Method>> toCheck : membersToCheck.entrySet()) { 110.149 + ClassFile cToCheck = toCheck.getKey(); 110.150 + for (Method mToCheck : toCheck.getValue()) { 110.151 + if (cRef.getName().equals(cToCheck.getName()) && 110.152 + mRef.descriptor.getReturnType(cRef.constant_pool).equals( 110.153 + mToCheck.descriptor.getReturnType(cToCheck.constant_pool)) && 110.154 + mRef.descriptor.getParameterTypes(cRef.constant_pool).equals( 110.155 + mToCheck.descriptor.getParameterTypes(cToCheck.constant_pool))) { 110.156 + ok = true; 110.157 + } 110.158 + } 110.159 + } 110.160 + if (!ok) { 110.161 + throw new AssertionError("Matching method descriptor for " + mRef.descriptor.getParameterTypes(cRef.constant_pool) + "not found"); 110.162 + } 110.163 + } 110.164 + } 110.165 + } 110.166 +}
111.1 --- a/test/tools/javac/meth/InvokeDyn.java Thu Sep 23 17:33:52 2010 -0700 111.2 +++ b/test/tools/javac/meth/InvokeDyn.java Fri Sep 24 16:43:08 2010 -0700 111.3 @@ -1,5 +1,5 @@ 111.4 /* 111.5 - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. 111.6 + * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. 111.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 111.8 * 111.9 * This code is free software; you can redistribute it and/or modify it 111.10 @@ -23,12 +23,12 @@ 111.11 111.12 /* 111.13 * @test 111.14 - * @bug 6754038 111.15 + * @bug 6754038 6979327 111.16 * @summary Generate call sites for method handle 111.17 * @author jrose 111.18 * 111.19 * @library .. 111.20 - * @compile -source 7 -target 7 InvokeDyn.java 111.21 + * @compile -source 7 -target 7 -XDinvokedynamic -XDallowTransitionalJSR292=no InvokeDyn.java 111.22 */ 111.23 //No: @run main/othervm -XX:+EnableInvokeDynamic meth.InvokeDyn 111.24 111.25 @@ -44,16 +44,21 @@ 111.26 111.27 package meth; 111.28 111.29 -import java.dyn.InvokeDynamic; 111.30 +import java.dyn.*; 111.31 111.32 public class InvokeDyn { 111.33 + class CS extends CallSite { 111.34 + CS(Object x, Object y, Object z) { throw new RuntimeException(); } 111.35 + } 111.36 + //@BootstrapMethod(CS.class) //note: requires 6964498 111.37 void test() throws Throwable { 111.38 Object x = "hello"; 111.39 - InvokeDynamic.greet(x, "world", 123); 111.40 - InvokeDynamic.greet(x, "mundus", 456); 111.41 - InvokeDynamic.greet(x, "kosmos", 789); 111.42 - InvokeDynamic.<String>cogitate(10.11121, 3.14); 111.43 - InvokeDynamic.<void>#"yow: what I mean to say is, please treat this one specially"(null); 111.44 - InvokeDynamic.<int>invoke("goodbye"); 111.45 + Object ojunk; int ijunk; 111.46 + ojunk = InvokeDynamic.greet(x, "world", 123); 111.47 + ojunk = InvokeDynamic.greet(x, "mundus", 456); 111.48 + ojunk = InvokeDynamic.greet(x, "kosmos", 789); 111.49 + ojunk = (String) InvokeDynamic.cogitate(10.11121, 3.14); 111.50 + InvokeDynamic.#"yow: what I mean to say is, please treat this one specially"(null); 111.51 + ijunk = (int) InvokeDynamic.invoke("goodbye"); 111.52 } 111.53 }
112.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 112.2 +++ b/test/tools/javac/meth/InvokeDynTrans.java Fri Sep 24 16:43:08 2010 -0700 112.3 @@ -0,0 +1,59 @@ 112.4 +/* 112.5 + * Copyright (c) 2008-2010, Oracle and/or its affiliates. All rights reserved. 112.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 112.7 + * 112.8 + * This code is free software; you can redistribute it and/or modify it 112.9 + * under the terms of the GNU General Public License version 2 only, as 112.10 + * published by the Free Software Foundation. 112.11 + * 112.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 112.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 112.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 112.15 + * version 2 for more details (a copy is included in the LICENSE file that 112.16 + * accompanied this code). 112.17 + * 112.18 + * You should have received a copy of the GNU General Public License version 112.19 + * 2 along with this work; if not, write to the Free Software Foundation, 112.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 112.21 + * 112.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 112.23 + * or visit www.oracle.com if you need additional information or have any 112.24 + * questions. 112.25 + */ 112.26 + 112.27 +/* 112.28 + * @test 112.29 + * @bug 6754038 6979327 112.30 + * @summary Generate call sites for method handle 112.31 + * @author jrose 112.32 + * 112.33 + * @library .. 112.34 + * @compile/fail/ref=InvokeDynTrans.out -Werror -XDrawDiagnostics -source 7 -target 7 InvokeDynTrans.java 112.35 + */ 112.36 +//No: @run main/othervm -XX:+EnableInvokeDynamic meth.InvokeDyn 112.37 + 112.38 +/* 112.39 + * Standalone testing: 112.40 + * <code> 112.41 + * $ cd $MY_REPO_DIR/langtools 112.42 + * $ (cd make; make) 112.43 + * $ ./dist/bootstrap/bin/javac -d dist test/tools/javac/meth/InvokeDyn.java 112.44 + * $ javap -c -classpath dist meth.InvokeDyn 112.45 + * </code> 112.46 + */ 112.47 + 112.48 +package meth; 112.49 + 112.50 +import java.dyn.InvokeDynamic; 112.51 + 112.52 +public class InvokeDynTrans { 112.53 + void test() throws Throwable { 112.54 + Object x = "hello"; 112.55 + InvokeDynamic.greet(x, "world", 123); 112.56 + InvokeDynamic.greet(x, "mundus", 456); 112.57 + InvokeDynamic.greet(x, "kosmos", 789); 112.58 + InvokeDynamic.<String>cogitate(10.11121, 3.14); 112.59 + InvokeDynamic.<void>#"yow: what I mean to say is, please treat this one specially"(null); 112.60 + InvokeDynamic.<int>invoke("goodbye"); 112.61 + } 112.62 +}
113.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 113.2 +++ b/test/tools/javac/meth/InvokeDynTrans.out Fri Sep 24 16:43:08 2010 -0700 113.3 @@ -0,0 +1,6 @@ 113.4 +InvokeDynTrans.java:55:39: compiler.warn.type.parameter.on.polymorphic.signature 113.5 +InvokeDynTrans.java:56:91: compiler.warn.type.parameter.on.polymorphic.signature 113.6 +InvokeDynTrans.java:57:34: compiler.warn.type.parameter.on.polymorphic.signature 113.7 +- compiler.err.warnings.and.werror 113.8 +1 error 113.9 +3 warnings
114.1 --- a/test/tools/javac/meth/InvokeMH.java Thu Sep 23 17:33:52 2010 -0700 114.2 +++ b/test/tools/javac/meth/InvokeMH.java Fri Sep 24 16:43:08 2010 -0700 114.3 @@ -1,5 +1,5 @@ 114.4 /* 114.5 - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. 114.6 + * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. 114.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 114.8 * 114.9 * This code is free software; you can redistribute it and/or modify it 114.10 @@ -23,11 +23,11 @@ 114.11 114.12 /* 114.13 * @test 114.14 - * @bug 6754038 114.15 + * @bug 6754038 6979327 114.16 * @summary Generate call sites for method handle 114.17 * @author jrose 114.18 * 114.19 - * @compile -source 7 -target 7 InvokeMH.java 114.20 + * @compile -source 7 -target 7 -XDallowTransitionalJSR292=no InvokeMH.java 114.21 */ 114.22 114.23 /* 114.24 @@ -57,20 +57,17 @@ 114.25 Object k = "kosmos"; 114.26 mh_SiO.invokeExact((String)k, 789); 114.27 o = mh_SiO.invokeExact((String)null, 000); 114.28 - o = mh_SiO.<Object>invokeExact("arda", -123); 114.29 + o = (Object) mh_SiO.invokeExact("arda", -123); 114.30 114.31 // sig = ()String 114.32 - s = mh_vS.<String>invokeExact(); 114.33 + s = (String) mh_vS.invokeExact(); 114.34 114.35 // sig = ()int 114.36 - i = mh_vi.<int>invokeExact(); 114.37 - o = mh_vi.<int>invokeExact(); 114.38 - //s = mh_vi.<int>invokeExact(); //BAD 114.39 - mh_vi.<int>invokeExact(); 114.40 + i = (int) mh_vi.invokeExact(); 114.41 + o = (int) mh_vi.invokeExact(); 114.42 114.43 // sig = ()void 114.44 - //o = mh_vv.<void>invokeExact(); //BAD 114.45 - mh_vv.<void>invokeExact(); 114.46 + mh_vv.invokeExact(); 114.47 } 114.48 114.49 void testGen(MethodHandle mh_SiO, 114.50 @@ -80,24 +77,23 @@ 114.51 Object o; String s; int i; // for return type testing 114.52 114.53 // next five must have sig = (*,*)* 114.54 - mh_SiO.invokeGeneric((Object)"world", (Object)123); 114.55 - mh_SiO.<void>invokeGeneric((Object)"mundus", (Object)456); 114.56 + o = mh_SiO.invokeGeneric((Object)"world", (Object)123); 114.57 + mh_SiO.invokeGeneric((Object)"mundus", (Object)456); 114.58 Object k = "kosmos"; 114.59 - mh_SiO.invokeGeneric(k, 789); 114.60 + o = mh_SiO.invokeGeneric(k, 789); 114.61 o = mh_SiO.invokeGeneric(null, 000); 114.62 - o = mh_SiO.<Object>invokeGeneric("arda", -123); 114.63 + o = mh_SiO.invokeGeneric("arda", -123); 114.64 114.65 // sig = ()String 114.66 o = mh_vS.invokeGeneric(); 114.67 114.68 // sig = ()int 114.69 - i = mh_vi.<int>invokeGeneric(); 114.70 - o = mh_vi.invokeGeneric(); 114.71 - //s = mh_vi.<int>invokeGeneric(); //BAD 114.72 - mh_vi.<void>invokeGeneric(); 114.73 + i = (int) mh_vi.invokeGeneric(); 114.74 + o = (int) mh_vi.invokeGeneric(); 114.75 + mh_vi.invokeGeneric(); 114.76 114.77 // sig = ()void 114.78 - //o = mh_vv.<void>invokeGeneric(); //BAD 114.79 + mh_vv.invokeGeneric(); 114.80 o = mh_vv.invokeGeneric(); 114.81 } 114.82 }
115.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 115.2 +++ b/test/tools/javac/meth/InvokeMHTrans.java Fri Sep 24 16:43:08 2010 -0700 115.3 @@ -0,0 +1,102 @@ 115.4 +/* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. 115.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 115.6 + * 115.7 + * This code is free software; you can redistribute it and/or modify it 115.8 + * under the terms of the GNU General Public License version 2 only, as 115.9 + * published by the Free Software Foundation. 115.10 + * 115.11 + * This code is distributed in the hope that it will be useful, but WITHOUT 115.12 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 115.13 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 115.14 + * version 2 for more details (a copy is included in the LICENSE file that 115.15 + * accompanied this code). 115.16 + * 115.17 + * You should have received a copy of the GNU General Public License version 115.18 + * 2 along with this work; if not, write to the Free Software Foundation, 115.19 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 115.20 + * 115.21 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 115.22 + * or visit www.oracle.com if you need additional information or have any 115.23 + * questions. 115.24 + */ 115.25 + 115.26 +/* 115.27 + * @test 115.28 + * @bug 6754038 6979327 115.29 + * @summary Generate call sites for method handle 115.30 + * @author jrose 115.31 + * 115.32 + * @compile/fail/ref=InvokeMHTrans.out -Werror -XDrawDiagnostics -source 7 -target 7 InvokeMHTrans.java 115.33 + */ 115.34 + 115.35 +/* 115.36 + * Standalone testing: 115.37 + * <code> 115.38 + * $ cd $MY_REPO_DIR/langtools 115.39 + * $ (cd make; make) 115.40 + * $ ./dist/bootstrap/bin/javac -d dist test/tools/javac/meth/InvokeMH.java 115.41 + * $ javap -c -classpath dist meth.InvokeMH 115.42 + * </code> 115.43 + */ 115.44 + 115.45 +package meth; 115.46 + 115.47 +import java.dyn.MethodHandle; 115.48 + 115.49 +public class InvokeMHTrans { 115.50 + void test(MethodHandle mh_SiO, 115.51 + MethodHandle mh_vS, 115.52 + MethodHandle mh_vi, 115.53 + MethodHandle mh_vv) throws Throwable { 115.54 + Object o; String s; int i; // for return type testing 115.55 + 115.56 + // next five must have sig = (String,int)Object 115.57 + mh_SiO.invokeExact("world", 123); 115.58 + mh_SiO.invokeExact("mundus", 456); 115.59 + Object k = "kosmos"; 115.60 + mh_SiO.invokeExact((String)k, 789); 115.61 + o = mh_SiO.invokeExact((String)null, 000); 115.62 + o = mh_SiO.<Object>invokeExact("arda", -123); 115.63 + 115.64 + // sig = ()String 115.65 + s = mh_vS.<String>invokeExact(); 115.66 + 115.67 + // sig = ()int 115.68 + i = mh_vi.<int>invokeExact(); 115.69 + o = mh_vi.<int>invokeExact(); 115.70 + //s = mh_vi.<int>invokeExact(); //BAD 115.71 + mh_vi.<int>invokeExact(); 115.72 + 115.73 + // sig = ()void 115.74 + //o = mh_vv.<void>invokeExact(); //BAD 115.75 + mh_vv.<void>invokeExact(); 115.76 + } 115.77 + 115.78 + void testGen(MethodHandle mh_SiO, 115.79 + MethodHandle mh_vS, 115.80 + MethodHandle mh_vi, 115.81 + MethodHandle mh_vv) throws Throwable { 115.82 + Object o; String s; int i; // for return type testing 115.83 + 115.84 + // next five must have sig = (*,*)* 115.85 + mh_SiO.invokeGeneric((Object)"world", (Object)123); 115.86 + mh_SiO.<void>invokeGeneric((Object)"mundus", (Object)456); 115.87 + Object k = "kosmos"; 115.88 + mh_SiO.invokeGeneric(k, 789); 115.89 + o = mh_SiO.invokeGeneric(null, 000); 115.90 + o = mh_SiO.<Object>invokeGeneric("arda", -123); 115.91 + 115.92 + // sig = ()String 115.93 + o = mh_vS.invokeGeneric(); 115.94 + 115.95 + // sig = ()int 115.96 + i = mh_vi.<int>invokeGeneric(); 115.97 + o = mh_vi.invokeGeneric(); 115.98 + //s = mh_vi.<int>invokeGeneric(); //BAD 115.99 + mh_vi.<void>invokeGeneric(); 115.100 + 115.101 + // sig = ()void 115.102 + //o = mh_vv.<void>invokeGeneric(); //BAD 115.103 + o = mh_vv.invokeGeneric(); 115.104 + } 115.105 +}
116.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 116.2 +++ b/test/tools/javac/meth/InvokeMHTrans.out Fri Sep 24 16:43:08 2010 -0700 116.3 @@ -0,0 +1,13 @@ 116.4 +InvokeMHTrans.java:59:39: compiler.warn.type.parameter.on.polymorphic.signature 116.5 +InvokeMHTrans.java:62:38: compiler.warn.type.parameter.on.polymorphic.signature 116.6 +InvokeMHTrans.java:65:35: compiler.warn.type.parameter.on.polymorphic.signature 116.7 +InvokeMHTrans.java:66:35: compiler.warn.type.parameter.on.polymorphic.signature 116.8 +InvokeMHTrans.java:68:31: compiler.warn.type.parameter.on.polymorphic.signature 116.9 +InvokeMHTrans.java:72:32: compiler.warn.type.parameter.on.polymorphic.signature 116.10 +InvokeMHTrans.java:83:35: compiler.warn.type.parameter.on.polymorphic.signature 116.11 +InvokeMHTrans.java:87:41: compiler.warn.type.parameter.on.polymorphic.signature 116.12 +InvokeMHTrans.java:93:37: compiler.warn.type.parameter.on.polymorphic.signature 116.13 +InvokeMHTrans.java:96:34: compiler.warn.type.parameter.on.polymorphic.signature 116.14 +- compiler.err.warnings.and.werror 116.15 +1 error 116.16 +10 warnings
117.1 --- a/test/tools/javac/meth/MakeNegTests.sh Thu Sep 23 17:33:52 2010 -0700 117.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 117.3 @@ -1,98 +0,0 @@ 117.4 -#!/bin/sh 117.5 - 117.6 -# 117.7 -# Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved. 117.8 -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 117.9 -# 117.10 -# This code is free software; you can redistribute it and/or modify it 117.11 -# under the terms of the GNU General Public License version 2 only, as 117.12 -# published by the Free Software Foundation. 117.13 -# 117.14 -# This code is distributed in the hope that it will be useful, but WITHOUT 117.15 -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 117.16 -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 117.17 -# version 2 for more details (a copy is included in the LICENSE file that 117.18 -# accompanied this code). 117.19 -# 117.20 -# You should have received a copy of the GNU General Public License version 117.21 -# 2 along with this work; if not, write to the Free Software Foundation, 117.22 -# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 117.23 -# 117.24 -# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 117.25 -# or visit www.oracle.com if you need additional information or have any 117.26 -# questions. 117.27 -# 117.28 - 117.29 -# @test 117.30 -# @bug 6754038 117.31 -# @summary Verify correct rejection of strongly typed return values 117.32 -# @run shell MakeNegTests.sh 117.33 - 117.34 -default_template=InvokeMH.java 117.35 -javacflags='-source 7 -target 7' 117.36 -# the rest of this file is a generic "//BAD"-line tester 117.37 - 117.38 -: ${TESTSRC=.} ${TESTCLASSES=.} 117.39 -javac="${TESTJAVA+${TESTJAVA}/bin/}javac" 117.40 - 117.41 -verbose=false quiet=false 117.42 - 117.43 -main() { 117.44 - case "${@-}" in 117.45 - *.java*) 117.46 - for template in "$@"; do 117.47 - expand_and_test "$template" 117.48 - done;; 117.49 - *) expand_and_test "${TESTSRC}/$default_template";; 117.50 - esac 117.51 -} 117.52 - 117.53 -expand_and_test() { 117.54 - template=$1 117.55 - expand "$@" 117.56 - testneg "$@" 117.57 -} 117.58 - 117.59 -expand() { 117.60 - template=$1 117.61 - badlines=` grep -n < "$template" '//BAD' ` 117.62 - badcount=` echo "$badlines" | wc -l ` 117.63 - [ $badcount -gt 0 ] || { echo "No negative test cases in $template"; exit 1; } 117.64 - $quiet || echo "Expanding $badcount negative test cases from $template:" 117.65 - $quiet || echo "$badlines" 117.66 - badnums=` echo "$badlines" | sed 's/:.*//' ` 117.67 - casestem=` getcasestem "$template" ` 117.68 - tclassname=` basename "$template" .java ` 117.69 - rm -f "$casestem"*.java 117.70 - for badnum in $badnums; do 117.71 - casefile="$casestem"${badnum}.java 117.72 - cclassname=` basename "$casefile" .java ` 117.73 - sed < "$template" > "$casefile" " 117.74 - s|@compile|@compile/fail| 117.75 - / @[a-z]/s|@|##| 117.76 - ${badnum}s:^ *[/*]*: : 117.77 - s/${tclassname}/${cclassname}/g 117.78 - " 117.79 - $verbose && diff -u "$template" "$casefile" 117.80 - done 117.81 -} 117.82 - 117.83 -getcasestem() { 117.84 - echo `basename $1` | sed 's/\.java$//;s/_BAD[0-9]*$//;s/$/_BAD/' 117.85 -} 117.86 - 117.87 -testneg() { 117.88 - template=$1 117.89 - for casefile in ` getcasestem "$template" `*.java; do 117.90 - $quiet || echo -------- $javac $javacflags "$casefile" 117.91 - $javac $javacflags "$casefile" > "$casefile".errlog 2>&1 && { 117.92 - echo "*** Compilation unexpectedly succeeded: $casefile" 117.93 - exit 1 117.94 - } 117.95 - $quiet || echo "Compilation failed as expected" 117.96 - $quiet || head ` $verbose || echo -3 ` < "$casefile".errlog 117.97 - rm "$casefile".errlog 117.98 - done 117.99 -} 117.100 - 117.101 -main "$@"
118.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 118.2 +++ b/test/tools/javac/parser/ExtraSemiTest.java Fri Sep 24 16:43:08 2010 -0700 118.3 @@ -0,0 +1,100 @@ 118.4 +/* 118.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 118.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 118.7 + * 118.8 + * This code is free software; you can redistribute it and/or modify it 118.9 + * under the terms of the GNU General Public License version 2 only, as 118.10 + * published by the Free Software Foundation. 118.11 + * 118.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 118.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 118.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 118.15 + * version 2 for more details (a copy is included in the LICENSE file that 118.16 + * accompanied this code). 118.17 + * 118.18 + * You should have received a copy of the GNU General Public License version 118.19 + * 2 along with this work; if not, write to the Free Software Foundation, 118.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 118.21 + * 118.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 118.23 + * or visit www.oracle.com if you need additional information or have any 118.24 + * questions. 118.25 + */ 118.26 + 118.27 +/* 118.28 + * @test 118.29 + * @bug 6921495 118.30 + * @summary spurious semicolons in class def cause empty NOPOS blocks 118.31 + */ 118.32 + 118.33 +import java.io.*; 118.34 +import java.net.*; 118.35 +import java.util.*; 118.36 +import javax.tools.*; 118.37 +import com.sun.source.util.*; 118.38 + 118.39 +public class ExtraSemiTest { 118.40 + 118.41 + static class JavaSource extends SimpleJavaFileObject { 118.42 + 118.43 + final static String source = 118.44 + "class C {\n" + 118.45 + " int x;;\n" + 118.46 + " class X { int i;; };\n" + 118.47 + "}"; 118.48 + 118.49 + JavaSource() { 118.50 + super(URI.create("myfo:/C.java"), JavaFileObject.Kind.SOURCE); 118.51 + } 118.52 + 118.53 + @Override 118.54 + public CharSequence getCharContent(boolean ignoreEncodingErrors) { 118.55 + return source; 118.56 + } 118.57 + } 118.58 + 118.59 + public static void main(String... args) throws IOException { 118.60 + new ExtraSemiTest().run(); 118.61 + } 118.62 + 118.63 + void run() throws IOException { 118.64 + File destDir = new File("classes"); destDir.mkdir(); 118.65 + final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); 118.66 + JavaSource source = new JavaSource(); 118.67 + JavacTask ct = (JavacTask)tool.getTask(null, null, null, 118.68 + Arrays.asList("-d", destDir.getPath(), "-XD-printsource"), 118.69 + null, 118.70 + Arrays.asList(source)); 118.71 + Boolean ok = ct.call(); 118.72 + if (!ok) throw new AssertionError("compilation failed"); 118.73 + 118.74 + String text = readFile(new File(destDir, "C.java")); 118.75 + System.out.println(text); 118.76 + 118.77 + // compress/canonicalize all whitespace 118.78 + String canon = text.replaceAll("\\s+", " "); 118.79 + System.out.println("canon: " + canon); 118.80 + 118.81 + // There are no empty blocks in the original text. 118.82 + // C will be given a default constructor "C() { super(); }" which 118.83 + // does not have any empty blocks. 118.84 + // The bug is that spurious semicolons in the class defn are parsed 118.85 + // into redundant empty blocks in the tree, so verify there are 118.86 + // no empty blocks in the -printsource output 118.87 + 118.88 + if (canon.contains("{ }")) 118.89 + throw new AssertionError("unexpected empty block found"); 118.90 + } 118.91 + 118.92 + String readFile(File f) throws IOException { 118.93 + int len = (int) f.length(); 118.94 + byte[] data = new byte[len]; 118.95 + DataInputStream in = new DataInputStream(new FileInputStream(f)); 118.96 + try { 118.97 + in.readFully(data); 118.98 + return new String(data); 118.99 + } finally { 118.100 + in.close(); 118.101 + } 118.102 + } 118.103 +}
119.1 --- a/test/tools/javac/processing/6430209/b6341534.java Thu Sep 23 17:33:52 2010 -0700 119.2 +++ b/test/tools/javac/processing/6430209/b6341534.java Fri Sep 24 16:43:08 2010 -0700 119.3 @@ -51,7 +51,8 @@ 119.4 try { 119.5 PackageElement PE = E.getPackageElement("dir1"); 119.6 List<? extends Element> LEE = PE.getEnclosedElements(); /* <=This line elicits the error message. */ 119.7 - for(Element e : LEE) System.out.println("found " + e.toString() + " in dir1."); 119.8 + for(Element e : LEE) 119.9 + System.out.println("found " + e.toString() + " in dir1."); 119.10 } 119.11 catch(NullPointerException npe) { 119.12 msgr.printMessage(ERROR,npe.toString()); 119.13 @@ -59,7 +60,11 @@ 119.14 return false; 119.15 } 119.16 } 119.17 - if( renv.errorRaised() ) { msgr.printMessage(ERROR, "FAILED");} 119.18 + // on round 1, expect errorRaised == false && processingOver == false 119.19 + // on round 2, expect errorRaised == true && processingOver == true 119.20 + if( renv.errorRaised() != renv.processingOver()) { 119.21 + msgr.printMessage(ERROR, "FAILED"); 119.22 + } 119.23 return true; 119.24 } 119.25
120.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 120.2 +++ b/test/tools/javac/processing/errors/TestSuppression.java Fri Sep 24 16:43:08 2010 -0700 120.3 @@ -0,0 +1,232 @@ 120.4 +/* 120.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 120.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 120.7 + * 120.8 + * This code is free software; you can redistribute it and/or modify it 120.9 + * under the terms of the GNU General Public License version 2 only, as 120.10 + * published by the Free Software Foundation. 120.11 + * 120.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 120.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 120.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 120.15 + * version 2 for more details (a copy is included in the LICENSE file that 120.16 + * accompanied this code). 120.17 + * 120.18 + * You should have received a copy of the GNU General Public License version 120.19 + * 2 along with this work; if not, write to the Free Software Foundation, 120.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 120.21 + * 120.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 120.23 + * or visit www.oracle.com if you need additional information or have any 120.24 + * questions. 120.25 + */ 120.26 + 120.27 +/* 120.28 + * @test 120.29 + * @bug 6403465 120.30 + * @summary javac should defer diagnostics until it can be determined they are persistent 120.31 + */ 120.32 + 120.33 +import java.io.*; 120.34 +import java.util.*; 120.35 +import javax.annotation.processing.*; 120.36 +import javax.lang.model.*; 120.37 +import javax.lang.model.element.TypeElement; 120.38 +import javax.tools.*; 120.39 + 120.40 +import com.sun.source.util.JavacTask; 120.41 +import com.sun.tools.javac.api.JavacTool; 120.42 +import com.sun.tools.javac.util.JCDiagnostic; 120.43 + 120.44 +import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*; 120.45 + 120.46 + 120.47 +public class TestSuppression { 120.48 + public static void main(String... args) throws Exception { 120.49 + new TestSuppression().run(args); 120.50 + } 120.51 + 120.52 + enum WarningKind { NO, YES }; 120.53 + 120.54 + String[] cases = { 120.55 + // missing class C 120.56 + "class X { C c; }", 120.57 + "class X { C foo() { return null; } }", 120.58 + "class X { void foo(C c) { } }", 120.59 + "class X extends C { }", 120.60 + "class X<T extends C> { }", 120.61 + // missing interface I 120.62 + "class X implements I { }", 120.63 + "interface X extends I { }", 120.64 + // missing exception E 120.65 + "class X { void m() throws E { } }", 120.66 + // missing method m 120.67 + "class X extends C { int i = m(); }", 120.68 + // missing field f 120.69 + "class X extends C { int i = f; }" 120.70 + }; 120.71 + 120.72 + void run(String... args) throws Exception { 120.73 + for (String c: cases) { 120.74 + for (WarningKind wk: WarningKind.values()) { 120.75 + for (int g = 1; g <= 3; g++) { 120.76 + try { 120.77 + test(c, wk, g); 120.78 + } catch (Throwable t) { 120.79 + error("caught: " + t); 120.80 + } 120.81 + if (errors > 0) throw new AssertionError(); 120.82 + } 120.83 + } 120.84 + } 120.85 + 120.86 + System.err.println(count + " test cases"); 120.87 + 120.88 + if (errors > 0) 120.89 + throw new Exception(errors + " errors occurred"); 120.90 + } 120.91 + 120.92 + void test(String src, WarningKind wk, int gen) throws Exception { 120.93 + count++; 120.94 + System.err.println("Test " + count + ": wk:" + wk + " gen:" + gen + " src:" +src); 120.95 + 120.96 + File testDir = new File("test" + count); 120.97 + File srcDir = createDir(testDir, "src"); 120.98 + File gensrcDir = createDir(testDir, "gensrc"); 120.99 + File classesDir = createDir(testDir, "classes"); 120.100 + 120.101 + File x = writeFile(new File(srcDir, "X.java"), src); 120.102 + 120.103 + DiagListener dl = new DiagListener(); 120.104 + JavacTool tool = JavacTool.create(); 120.105 + StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null); 120.106 + fm.setLocation(StandardLocation.CLASS_PATH, 120.107 + Arrays.asList(classesDir, new File(System.getProperty("test.classes")))); 120.108 + fm.setLocation(StandardLocation.CLASS_OUTPUT, Collections.singleton(classesDir)); 120.109 + fm.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singleton(gensrcDir)); 120.110 + List<String> args = new ArrayList<String>(); 120.111 +// args.add("-XprintProcessorInfo"); 120.112 + args.add("-XprintRounds"); 120.113 + args.add("-Agen=" + gen); 120.114 + if (wk == WarningKind.YES) 120.115 + args.add("-Xlint:serial"); 120.116 + Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(x); 120.117 + 120.118 + StringWriter sw = new StringWriter(); 120.119 + PrintWriter pw = new PrintWriter(sw); 120.120 + JavacTask task = tool.getTask(pw, fm, dl, args, null, files); 120.121 + task.setProcessors(Arrays.asList(new AnnoProc())); 120.122 + boolean ok = task.call(); 120.123 + pw.close(); 120.124 + 120.125 + System.err.println("ok:" + ok + " diags:" + dl.counts); 120.126 + if (sw.toString().length() > 0) { 120.127 + System.err.println("output:\n" + sw.toString()); 120.128 + } 120.129 + 120.130 + for (Diagnostic.Kind dk: Diagnostic.Kind.values()) { 120.131 + Integer v = dl.counts.get(dk); 120.132 + int found = (v == null) ? 0 : v; 120.133 + int expect = (dk == Diagnostic.Kind.WARNING && wk == WarningKind.YES) ? gen : 0; 120.134 + if (found != expect) { 120.135 + error("Unexpected value for " + dk + ": expected: " + expect + " found: " + found); 120.136 + } 120.137 + } 120.138 + 120.139 + System.err.println(); 120.140 + } 120.141 + 120.142 + File createDir(File parent, String name) { 120.143 + File dir = new File(parent, name); 120.144 + dir.mkdirs(); 120.145 + return dir; 120.146 + } 120.147 + 120.148 + File writeFile(File f, String content) throws IOException { 120.149 + FileWriter out = new FileWriter(f); 120.150 + try { 120.151 + out.write(content); 120.152 + } finally { 120.153 + out.close(); 120.154 + } 120.155 + return f; 120.156 + } 120.157 + 120.158 + <T> void add(List<T> list, T... values) { 120.159 + for (T v: values) 120.160 + list.add(v); 120.161 + } 120.162 + 120.163 + void error(String msg) { 120.164 + System.err.println("Error: " + msg); 120.165 + errors++; 120.166 + } 120.167 + 120.168 + int count; 120.169 + int errors; 120.170 + 120.171 + static class DiagListener implements DiagnosticListener<JavaFileObject> { 120.172 + int total; 120.173 + Map<Diagnostic.Kind,Integer> counts = new TreeMap<Diagnostic.Kind,Integer>(); 120.174 + 120.175 + public void report(Diagnostic<? extends JavaFileObject> diagnostic) { 120.176 + System.err.println((++total) + ": " 120.177 + + "resolveError:" + isResolveError((JCDiagnostic) diagnostic) + "\n" 120.178 + + diagnostic); 120.179 + Diagnostic.Kind dk = diagnostic.getKind(); 120.180 + Integer c = counts.get(dk); 120.181 + counts.put(dk, (c == null ? 1 : c + 1)); 120.182 + } 120.183 + 120.184 + private static boolean isResolveError(JCDiagnostic d) { 120.185 + return d.isFlagSet(RESOLVE_ERROR); 120.186 + } 120.187 + } 120.188 + 120.189 + @SupportedAnnotationTypes("*") 120.190 + @SupportedOptions("gen") 120.191 + public static class AnnoProc extends AbstractProcessor { 120.192 + Filer f; 120.193 + Messager m; 120.194 + int gen; 120.195 + 120.196 + @Override 120.197 + public void init(ProcessingEnvironment processingEnv) { 120.198 + f = processingEnv.getFiler(); 120.199 + m = processingEnv.getMessager(); 120.200 + Map<String,String> options = processingEnv.getOptions(); 120.201 + gen = Integer.parseInt(options.get("gen")); 120.202 + } 120.203 + 120.204 + @Override 120.205 + public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { 120.206 + round++; 120.207 + if (round < gen) 120.208 + writeSource("Dummy" + round, "class Dummy" + round + " extends java.util.ArrayList{ }"); 120.209 + else if (round == gen) { 120.210 + writeSource("C", "class C { int f; int m() { return 0; } }"); 120.211 + writeSource("I", "interface I { }"); 120.212 + writeSource("E", "class E extends Exception { }"); 120.213 + } 120.214 + return true; 120.215 + } 120.216 + 120.217 + @Override 120.218 + public SourceVersion getSupportedSourceVersion() { 120.219 + return SourceVersion.latest(); 120.220 + } 120.221 + 120.222 + private void writeSource(String name, String text) { 120.223 + try { 120.224 + JavaFileObject fo = f.createSourceFile(name); 120.225 + Writer out = fo.openWriter(); 120.226 + out.write(text); 120.227 + out.close(); 120.228 + } catch (IOException e) { 120.229 + m.printMessage(Diagnostic.Kind.ERROR, e.toString()); 120.230 + } 120.231 + } 120.232 + 120.233 + int round = 0; 120.234 + } 120.235 +}
121.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 121.2 +++ b/test/tools/javac/processing/filer/TestGetResource2.java Fri Sep 24 16:43:08 2010 -0700 121.3 @@ -0,0 +1,172 @@ 121.4 +/* 121.5 + * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. 121.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 121.7 + * 121.8 + * This code is free software; you can redistribute it and/or modify it 121.9 + * under the terms of the GNU General Public License version 2 only, as 121.10 + * published by the Free Software Foundation. 121.11 + * 121.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 121.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 121.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 121.15 + * version 2 for more details (a copy is included in the LICENSE file that 121.16 + * accompanied this code). 121.17 + * 121.18 + * You should have received a copy of the GNU General Public License version 121.19 + * 2 along with this work; if not, write to the Free Software Foundation, 121.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 121.21 + * 121.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 121.23 + * or visit www.oracle.com if you need additional information or have any 121.24 + * questions. 121.25 + */ 121.26 + 121.27 +/* @test 121.28 + * @bug 6929404 121.29 + * @summary Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry 121.30 + */ 121.31 + 121.32 +import java.io.*; 121.33 +import java.security.*; 121.34 +import java.util.*; 121.35 +import javax.annotation.processing.*; 121.36 +import javax.lang.model.*; 121.37 +import javax.lang.model.element.*; 121.38 +import javax.tools.*; 121.39 +import javax.tools.Diagnostic.Kind; 121.40 +import javax.tools.JavaCompiler.CompilationTask; 121.41 + 121.42 +public class TestGetResource2 { 121.43 + 121.44 + public static void main(String[] args) throws Exception { 121.45 + new TestGetResource2().run(); 121.46 + } 121.47 + 121.48 + void run() throws Exception { 121.49 + JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); 121.50 + CodeSource cs = javac.getClass().getProtectionDomain().getCodeSource(); 121.51 + if (cs == null) { 121.52 + System.err.println("got compiler from " + 121.53 + ClassLoader.getSystemResource(javac.getClass().getName().replace(".", "/")+".class")); 121.54 + } else { 121.55 + System.err.println("got compiler from " + cs.getLocation()); 121.56 + } 121.57 + 121.58 + testSingleSourceDir(javac); 121.59 + testCompositeSourcePath(javac); 121.60 + testMissingResource(javac); 121.61 + } 121.62 + 121.63 + private void testSingleSourceDir(JavaCompiler javac) throws Exception { 121.64 + System.err.println("testSingleSourceDir"); 121.65 + File tmpdir = new File("testSingleSourceDir"); 121.66 + File srcdir = new File(tmpdir, "src"); 121.67 + File destdir = new File(tmpdir, "dest"); 121.68 + write(srcdir, "pkg/X.java", "package pkg; class X {}"); 121.69 + write(srcdir, "resources/file.txt", "hello"); 121.70 + destdir.mkdirs(); 121.71 + 121.72 + CompilationTask task = javac.getTask(null, null, null, 121.73 + Arrays.asList("-sourcepath", srcdir.toString(), "-d", destdir.toString()), 121.74 + Collections.singleton("pkg.X"), null); 121.75 + task.setProcessors(Collections.singleton(new AnnoProc())); 121.76 + boolean result = task.call(); 121.77 + System.err.println("javac result with single source dir: " + result); 121.78 + expect(result, true); 121.79 + } 121.80 + 121.81 + private void testCompositeSourcePath(JavaCompiler javac) throws Exception { 121.82 + System.err.println("testCompositeSearchPath"); 121.83 + File tmpdir = new File("testCompositeSourcePath"); 121.84 + File srcdir = new File(tmpdir, "src"); 121.85 + File rsrcdir = new File(tmpdir, "rsrc"); 121.86 + File destdir = new File(tmpdir, "dest"); 121.87 + write(srcdir, "pkg/X.java", "package pkg; class X {}"); 121.88 + write(rsrcdir, "resources/file.txt", "hello"); 121.89 + destdir.mkdirs(); 121.90 + 121.91 + CompilationTask task = javac.getTask(null, null, null, 121.92 + Arrays.asList("-sourcepath", srcdir + File.pathSeparator + rsrcdir, "-d", destdir.toString()), 121.93 + Collections.singleton("pkg.X"), null); 121.94 + task.setProcessors(Collections.singleton(new AnnoProc())); 121.95 + boolean result = task.call(); 121.96 + System.err.println("javac result with composite source path: " + result); 121.97 + expect(result, true); 121.98 + } 121.99 + 121.100 + private void testMissingResource(JavaCompiler javac) throws Exception { 121.101 + System.err.println("testMissingResource"); 121.102 + File tmpdir = new File("testMissingResource"); 121.103 + File srcdir = new File(tmpdir, "src"); 121.104 + File destdir = new File(tmpdir, "dest"); 121.105 + write(srcdir, "pkg/X.java", "package pkg; class X {}"); 121.106 + destdir.mkdirs(); 121.107 + 121.108 + CompilationTask task = javac.getTask(null, null, null, 121.109 + Arrays.asList("-sourcepath", srcdir.toString(), "-d", destdir.toString()), 121.110 + Collections.singleton("pkg.X"), null); 121.111 + task.setProcessors(Collections.singleton(new AnnoProc())); 121.112 + boolean result = task.call(); 121.113 + System.err.println("javac result when missing resource: " + result); 121.114 + expect(result, false); 121.115 + 121.116 + if (errors > 0) 121.117 + throw new Exception(errors + " errors occurred"); 121.118 + } 121.119 + 121.120 + @SupportedAnnotationTypes("*") 121.121 + static class AnnoProc extends AbstractProcessor { 121.122 + 121.123 + public @Override boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { 121.124 + if (roundEnv.processingOver()) { 121.125 + return false; 121.126 + } 121.127 + 121.128 + try { 121.129 + FileObject resource = processingEnv.getFiler().getResource(StandardLocation.SOURCE_PATH, "resources", "file.txt"); 121.130 + try { 121.131 + resource.openInputStream().close(); 121.132 + processingEnv.getMessager().printMessage(Kind.NOTE, "found: " + resource.toUri()); 121.133 + return true; 121.134 + } catch (IOException x) { 121.135 + processingEnv.getMessager().printMessage(Kind.ERROR, "could not read: " + resource.toUri()); 121.136 + x.printStackTrace(); 121.137 + } 121.138 + } catch (IOException x) { 121.139 + processingEnv.getMessager().printMessage(Kind.ERROR, "did not find resource"); 121.140 + x.printStackTrace(); 121.141 + } 121.142 + 121.143 + return false; 121.144 + } 121.145 + 121.146 + @Override 121.147 + public SourceVersion getSupportedSourceVersion() { 121.148 + return SourceVersion.latest(); 121.149 + } 121.150 + } 121.151 + 121.152 + private File write(File dir, String path, String contents) throws IOException { 121.153 + File f = new File(dir, path); 121.154 + f.getParentFile().mkdirs(); 121.155 + Writer w = new FileWriter(f); 121.156 + try { 121.157 + w.write(contents); 121.158 + } finally { 121.159 + w.close(); 121.160 + } 121.161 + return f; 121.162 + } 121.163 + 121.164 + void expect(boolean val, boolean expect) { 121.165 + if (val != expect) 121.166 + error("Unexpected value: " + val + "; expected: " + expect); 121.167 + } 121.168 + 121.169 + void error(String msg) { 121.170 + System.err.println(msg); 121.171 + errors++; 121.172 + } 121.173 + 121.174 + int errors = 0; 121.175 +}
122.1 --- a/test/tools/javac/processing/model/element/TestAnonClassNames.java Thu Sep 23 17:33:52 2010 -0700 122.2 +++ b/test/tools/javac/processing/model/element/TestAnonClassNames.java Fri Sep 24 16:43:08 2010 -0700 122.3 @@ -27,8 +27,7 @@ 122.4 * @summary Test that reported names of anonymous classes are non-null. 122.5 * @author Joseph D. Darcy 122.6 * @build TestAnonSourceNames 122.7 - * @compile/fail -processor TestAnonSourceNames TestAnonClassNames.java 122.8 - * @build TestAnonClassNames 122.9 + * @compile -processor TestAnonSourceNames TestAnonClassNames.java 122.10 * @run main TestAnonClassNames 122.11 */ 122.12 122.13 @@ -40,10 +39,6 @@ 122.14 * 122.15 * Source files will be tested by the @compile line which runs 122.16 * TestAnonSourceNames as an annotation processor over this file. 122.17 - * This compile line is expected to fail until 6930507 is fixed. Once 122.18 - * bug 6930507 is fixed, the "@compile/fail -processor ..." and 122.19 - * following "@build..." steps can be replaced with a single "@compile 122.20 - * -processor ..." directive. 122.21 * 122.22 * Class files are tested by the @run command on this type. This 122.23 * class gets the names of classes with different nesting kinds,
123.1 --- a/test/tools/javac/processing/model/element/TestAnonSourceNames.java Thu Sep 23 17:33:52 2010 -0700 123.2 +++ b/test/tools/javac/processing/model/element/TestAnonSourceNames.java Fri Sep 24 16:43:08 2010 -0700 123.3 @@ -67,7 +67,7 @@ 123.4 Element element = trees.getElement(trees.getPath(cu, node)); 123.5 if (element == null) { 123.6 processingEnv.getMessager().printMessage(ERROR, 123.7 - "No element retreived for node named ''" + 123.8 + "No element retrieved for node named ''" + 123.9 node.getSimpleName() + "''."); 123.10 } else { 123.11
124.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 124.2 +++ b/test/tools/javac/processing/options/TestImplicitNone.java Fri Sep 24 16:43:08 2010 -0700 124.3 @@ -0,0 +1,109 @@ 124.4 +/* 124.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 124.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 124.7 + * 124.8 + * This code is free software; you can redistribute it and/or modify it 124.9 + * under the terms of the GNU General Public License version 2 only, as 124.10 + * published by the Free Software Foundation. 124.11 + * 124.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 124.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 124.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 124.15 + * version 2 for more details (a copy is included in the LICENSE file that 124.16 + * accompanied this code). 124.17 + * 124.18 + * You should have received a copy of the GNU General Public License version 124.19 + * 2 along with this work; if not, write to the Free Software Foundation, 124.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 124.21 + * 124.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 124.23 + * or visit www.oracle.com if you need additional information or have any 124.24 + * questions. 124.25 + */ 124.26 + 124.27 +/* 124.28 + * @test 124.29 + * @bug 6935638 124.30 + * @summary -implicit:none prevents compilation with annotation processing 124.31 + */ 124.32 + 124.33 +import java.io.*; 124.34 +import java.util.*; 124.35 +import javax.annotation.processing.*; 124.36 +import javax.lang.model.*; 124.37 +import javax.lang.model.element.*; 124.38 + 124.39 + 124.40 +@SupportedAnnotationTypes("*") 124.41 +public class TestImplicitNone extends AbstractProcessor { 124.42 + public static void main(String... args) throws Exception { 124.43 + new TestImplicitNone().run(); 124.44 + } 124.45 + 124.46 + void run() throws Exception { 124.47 + File classesDir = new File("tmp", "classes"); 124.48 + classesDir.mkdirs(); 124.49 + File test_java = new File(new File("tmp", "src"), "Test.java"); 124.50 + writeFile(test_java, "class Test { }"); 124.51 + 124.52 + // build up list of options and files to be compiled 124.53 + List<String> opts = new ArrayList<String>(); 124.54 + List<File> files = new ArrayList<File>(); 124.55 + 124.56 + opts.add("-d"); 124.57 + opts.add(classesDir.getPath()); 124.58 + opts.add("-processorpath"); 124.59 + opts.add(System.getProperty("test.classes")); 124.60 + opts.add("-implicit:none"); 124.61 + opts.add("-processor"); 124.62 + opts.add(TestImplicitNone.class.getName()); 124.63 + files.add(test_java); 124.64 + 124.65 + compile(opts, files); 124.66 + 124.67 + File test_class = new File(classesDir, "Test.class"); 124.68 + if (!test_class.exists()) 124.69 + throw new Exception("Test.class not generated"); 124.70 + } 124.71 + 124.72 + /** Compile files with options provided. */ 124.73 + void compile(List<String> opts, List<File> files) throws Exception { 124.74 + System.err.println("javac: " + opts + " " + files); 124.75 + List<String> args = new ArrayList<String>(); 124.76 + args.addAll(opts); 124.77 + for (File f: files) 124.78 + args.add(f.getPath()); 124.79 + StringWriter sw = new StringWriter(); 124.80 + PrintWriter pw = new PrintWriter(sw); 124.81 + int rc = com.sun.tools.javac.Main.compile(args.toArray(new String[args.size()]), pw); 124.82 + pw.flush(); 124.83 + if (sw.getBuffer().length() > 0) 124.84 + System.err.println(sw.toString()); 124.85 + if (rc != 0) 124.86 + throw new Exception("compilation failed: rc=" + rc); 124.87 + } 124.88 + 124.89 + /** Write a file with a given body. */ 124.90 + void writeFile(File f, String body) throws Exception { 124.91 + if (f.getParentFile() != null) 124.92 + f.getParentFile().mkdirs(); 124.93 + Writer out = new FileWriter(f); 124.94 + try { 124.95 + out.write(body); 124.96 + } finally { 124.97 + out.close(); 124.98 + } 124.99 + } 124.100 + 124.101 + //----- annotation processor methods ----- 124.102 + 124.103 + public boolean process(Set<? extends TypeElement> annotations, 124.104 + RoundEnvironment roundEnv) { 124.105 + return true; 124.106 + } 124.107 + 124.108 + @Override 124.109 + public SourceVersion getSupportedSourceVersion() { 124.110 + return SourceVersion.latest(); 124.111 + } 124.112 +}
125.1 --- a/test/tools/javac/quid/MakeNegTests.sh Thu Sep 23 17:33:52 2010 -0700 125.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 125.3 @@ -1,97 +0,0 @@ 125.4 -#!/bin/sh 125.5 - 125.6 -# 125.7 -# Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved. 125.8 -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 125.9 -# 125.10 -# This code is free software; you can redistribute it and/or modify it 125.11 -# under the terms of the GNU General Public License version 2 only, as 125.12 -# published by the Free Software Foundation. 125.13 -# 125.14 -# This code is distributed in the hope that it will be useful, but WITHOUT 125.15 -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 125.16 -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 125.17 -# version 2 for more details (a copy is included in the LICENSE file that 125.18 -# accompanied this code). 125.19 -# 125.20 -# You should have received a copy of the GNU General Public License version 125.21 -# 2 along with this work; if not, write to the Free Software Foundation, 125.22 -# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 125.23 -# 125.24 -# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 125.25 -# or visit www.oracle.com if you need additional information or have any 125.26 -# questions. 125.27 -# 125.28 - 125.29 -# @test 125.30 -# @bug 6746458 125.31 -# @summary Verify correct rejection of illegal quoted identifiers. 125.32 -# @run shell MakeNegTests.sh 125.33 - 125.34 -default_template=QuotedIdent.java 125.35 -# the rest of this file is a generic "//BAD"-line tester 125.36 - 125.37 -: ${TESTSRC=.} ${TESTCLASSES=.} 125.38 -javac="${TESTJAVA+${TESTJAVA}/bin/}javac" 125.39 - 125.40 -verbose=false quiet=false 125.41 - 125.42 -main() { 125.43 - case "${@-}" in 125.44 - *.java*) 125.45 - for template in "$@"; do 125.46 - expand_and_test "$template" 125.47 - done;; 125.48 - *) expand_and_test "${TESTSRC}/$default_template";; 125.49 - esac 125.50 -} 125.51 - 125.52 -expand_and_test() { 125.53 - template=$1 125.54 - expand "$@" 125.55 - testneg "$@" 125.56 -} 125.57 - 125.58 -expand() { 125.59 - template=$1 125.60 - badlines=` grep -n < "$template" '//BAD' ` 125.61 - badcount=` echo "$badlines" | wc -l ` 125.62 - [ $badcount -gt 0 ] || { echo "No negative test cases in $template"; exit 1; } 125.63 - $quiet || echo "Expanding $badcount negative test cases from $template:" 125.64 - $quiet || echo "$badlines" 125.65 - badnums=` echo "$badlines" | sed 's/:.*//' ` 125.66 - casestem=` getcasestem "$template" ` 125.67 - tclassname=` basename "$template" .java ` 125.68 - rm "$casestem"*.java 125.69 - for badnum in $badnums; do 125.70 - casefile="$casestem"${badnum}.java 125.71 - cclassname=` basename "$casefile" .java ` 125.72 - sed < "$template" > "$casefile" " 125.73 - s|@compile|@compile/fail| 125.74 - / @[a-z]/s|@|##| 125.75 - ${badnum}s:^ *[/*]*: : 125.76 - s/${tclassname}/${cclassname}/g 125.77 - " 125.78 - $verbose && diff -u "$template" "$casefile" 125.79 - done 125.80 -} 125.81 - 125.82 -getcasestem() { 125.83 - echo `basename $1` | sed 's/.*\///;s/\.java$//;s/_BAD[0-9]*$//;s/$/_BAD/' 125.84 -} 125.85 - 125.86 -testneg() { 125.87 - template=$1 125.88 - for casefile in ` getcasestem "$template" `*.java; do 125.89 - $quiet || echo -------- $javac "$casefile" 125.90 - $javac "$casefile" > "$casefile".errlog 2>&1 && { 125.91 - echo "*** Compilation unexpectedly succeeded: $casefile" 125.92 - exit 1 125.93 - } 125.94 - $quiet || echo "Compilation failed as expected" 125.95 - $quiet || head ` $verbose || echo -3 ` < "$casefile".errlog 125.96 - rm "$casefile".errlog 125.97 - done 125.98 -} 125.99 - 125.100 -main "$@"
126.1 --- a/test/tools/javac/quid/QuotedIdent.java Thu Sep 23 17:33:52 2010 -0700 126.2 +++ b/test/tools/javac/quid/QuotedIdent.java Fri Sep 24 16:43:08 2010 -0700 126.3 @@ -1,5 +1,5 @@ 126.4 /* 126.5 - * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved. 126.6 + * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. 126.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 126.8 * 126.9 * This code is free software; you can redistribute it and/or modify it 126.10 @@ -31,6 +31,7 @@ 126.11 * (The filename, directory name, or volume label syntax is incorrect) 126.12 * 126.13 * @library .. 126.14 + * @compile -source 7 -target 7 -XDinvokedynamic QuotedIdent.java 126.15 * @run main quid.QuotedIdent 126.16 */ 126.17 126.18 @@ -119,7 +120,7 @@ 126.19 s = #"int".class.getName(); 126.20 check(31, s, QuotedIdent.class.getName()+"$int"); 126.21 126.22 - Class x86 = Class.forName(QuotedIdent.class.getName()+"$*86"); 126.23 + Class<?> x86 = Class.forName(QuotedIdent.class.getName()+"$*86"); 126.24 if (x86 != #"*86".class) 126.25 check(32, "reflected "+x86, "static "+#"*86".class); 126.26
127.1 --- a/test/tools/javac/quid/QuotedIdent2.java Thu Sep 23 17:33:52 2010 -0700 127.2 +++ b/test/tools/javac/quid/QuotedIdent2.java Fri Sep 24 16:43:08 2010 -0700 127.3 @@ -1,5 +1,5 @@ 127.4 /* 127.5 - * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved. 127.6 + * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. 127.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 127.8 * 127.9 * This code is free software; you can redistribute it and/or modify it 127.10 @@ -31,6 +31,7 @@ 127.11 * (The filename, directory name, or volume label syntax is incorrect) 127.12 * 127.13 * @library .. 127.14 + * @compile -source 7 -target 7 -XDinvokedynamic QuotedIdent.java 127.15 * @run main quid.QuotedIdent2 127.16 */ 127.17 /* 127.18 @@ -72,7 +73,7 @@ 127.19 s = QuotedIdent.#"int".class.getName(); 127.20 check(31, s, QuotedIdent.class.getName()+"$int"); 127.21 127.22 - Class x86 = Class.forName(QuotedIdent.class.getName()+"$*86"); 127.23 + Class<?> x86 = Class.forName(QuotedIdent.class.getName()+"$*86"); 127.24 if (x86 != #"*86".class) 127.25 check(32, "reflected "+x86, "static "+#"*86".class); 127.26
128.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 128.2 +++ b/test/tools/javac/tree/AbstractTreeScannerTest.java Fri Sep 24 16:43:08 2010 -0700 128.3 @@ -0,0 +1,294 @@ 128.4 +/* 128.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 128.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 128.7 + * 128.8 + * This code is free software; you can redistribute it and/or modify it 128.9 + * under the terms of the GNU General Public License version 2 only, as 128.10 + * published by the Free Software Foundation. 128.11 + * 128.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 128.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 128.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 128.15 + * version 2 for more details (a copy is included in the LICENSE file that 128.16 + * accompanied this code). 128.17 + * 128.18 + * You should have received a copy of the GNU General Public License version 128.19 + * 2 along with this work; if not, write to the Free Software Foundation, 128.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 128.21 + * 128.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 128.23 + * or visit www.oracle.com if you need additional information or have any 128.24 + * questions. 128.25 + */ 128.26 + 128.27 +import java.io.*; 128.28 +import java.lang.reflect.*; 128.29 +import java.util.*; 128.30 +import javax.tools.*; 128.31 + 128.32 +import com.sun.source.tree.CompilationUnitTree; 128.33 +import com.sun.source.tree.Tree; 128.34 +import com.sun.source.util.JavacTask; 128.35 +import com.sun.tools.javac.api.JavacTool; 128.36 +import com.sun.tools.javac.tree.JCTree; 128.37 +import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; 128.38 +import com.sun.tools.javac.util.List; 128.39 + 128.40 +public abstract class AbstractTreeScannerTest { 128.41 + 128.42 + /** 128.43 + * Run the program. A base directory can be provided for file arguments. 128.44 + * In jtreg mode, the -r option can be given to change the default base 128.45 + * directory to the test root directory. For other options, see usage(). 128.46 + * @param baseDir base directory for any file arguments. 128.47 + * @param args command line args 128.48 + * @return true if successful or in gui mode 128.49 + */ 128.50 + boolean run(File baseDir, String... args) { 128.51 + if (args.length == 0) { 128.52 + usage(System.out); 128.53 + return true; 128.54 + } 128.55 + 128.56 + ArrayList<File> files = new ArrayList<File>(); 128.57 + for (int i = 0; i < args.length; i++) { 128.58 + String arg = args[i]; 128.59 + if (arg.equals("-q")) 128.60 + quiet = true; 128.61 + else if (arg.equals("-v")) 128.62 + verbose = true; 128.63 + else if (arg.equals("-r")) { 128.64 + File d = baseDir; 128.65 + while (!new File(d, "TEST.ROOT").exists()) { 128.66 + d = d.getParentFile(); 128.67 + if (d == null) 128.68 + throw new Error("cannot find TEST.ROOT"); 128.69 + } 128.70 + baseDir = d; 128.71 + } 128.72 + else if (arg.startsWith("-")) 128.73 + throw new Error("unknown option: " + arg); 128.74 + else { 128.75 + while (i < args.length) 128.76 + files.add(new File(baseDir, args[i++])); 128.77 + } 128.78 + } 128.79 + 128.80 + for (File file: files) { 128.81 + if (file.exists()) 128.82 + test(file); 128.83 + else 128.84 + error("File not found: " + file); 128.85 + } 128.86 + 128.87 + if (fileCount != 1) 128.88 + System.err.println(fileCount + " files read"); 128.89 + System.err.println(treeCount + " tree nodes compared"); 128.90 + if (errors > 0) 128.91 + System.err.println(errors + " errors"); 128.92 + 128.93 + return (errors == 0); 128.94 + } 128.95 + 128.96 + /** 128.97 + * Print command line help. 128.98 + * @param out output stream 128.99 + */ 128.100 + void usage(PrintStream out) { 128.101 + out.println("Usage:"); 128.102 + out.println(" java " + getClass().getName() + " options... files..."); 128.103 + out.println(""); 128.104 + out.println("where options include:"); 128.105 + out.println("-q Quiet: don't report on inapplicable files"); 128.106 + out.println("-v Verbose: report on files as they are being read"); 128.107 + out.println(""); 128.108 + out.println("files may be directories or files"); 128.109 + out.println("directories will be scanned recursively"); 128.110 + out.println("non java files, or java files which cannot be parsed, will be ignored"); 128.111 + out.println(""); 128.112 + } 128.113 + 128.114 + /** 128.115 + * Test a file. If the file is a directory, it will be recursively scanned 128.116 + * for java files. 128.117 + * @param file the file or directory to test 128.118 + */ 128.119 + void test(File file) { 128.120 + if (file.isDirectory()) { 128.121 + for (File f: file.listFiles()) { 128.122 + test(f); 128.123 + } 128.124 + return; 128.125 + } 128.126 + 128.127 + if (file.isFile() && file.getName().endsWith(".java")) { 128.128 + try { 128.129 + if (verbose) 128.130 + System.err.println(file); 128.131 + fileCount++; 128.132 + treeCount += test(read(file)); 128.133 + } catch (ParseException e) { 128.134 + if (!quiet) { 128.135 + error("Error parsing " + file + "\n" + e.getMessage()); 128.136 + } 128.137 + } catch (IOException e) { 128.138 + error("Error reading " + file + ": " + e); 128.139 + } 128.140 + return; 128.141 + } 128.142 + 128.143 + if (!quiet) 128.144 + error("File " + file + " ignored"); 128.145 + } 128.146 + 128.147 + abstract int test(JCCompilationUnit t); 128.148 + 128.149 + /** 128.150 + * Read a file. 128.151 + * @param file the file to be read 128.152 + * @return the tree for the content of the file 128.153 + * @throws IOException if any IO errors occur 128.154 + * @throws TreePosTest.ParseException if any errors occur while parsing the file 128.155 + */ 128.156 + JCCompilationUnit read(File file) throws IOException, ParseException { 128.157 + StringWriter sw = new StringWriter(); 128.158 + PrintWriter pw = new PrintWriter(sw); 128.159 + Reporter r = new Reporter(pw); 128.160 + JavacTool tool = JavacTool.create(); 128.161 + StandardJavaFileManager fm = tool.getStandardFileManager(r, null, null); 128.162 + Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(file); 128.163 + JavacTask task = tool.getTask(pw, fm, r, Collections.<String>emptyList(), null, files); 128.164 + Iterable<? extends CompilationUnitTree> trees = task.parse(); 128.165 + pw.flush(); 128.166 + if (r.errors > 0) 128.167 + throw new ParseException(sw.toString()); 128.168 + Iterator<? extends CompilationUnitTree> iter = trees.iterator(); 128.169 + if (!iter.hasNext()) 128.170 + throw new Error("no trees found"); 128.171 + JCCompilationUnit t = (JCCompilationUnit) iter.next(); 128.172 + if (iter.hasNext()) 128.173 + throw new Error("too many trees found"); 128.174 + return t; 128.175 + } 128.176 + 128.177 + /** 128.178 + * Report an error. When the program is complete, the program will either 128.179 + * exit or throw an Error if any errors have been reported. 128.180 + * @param msg the error message 128.181 + */ 128.182 + void error(String msg) { 128.183 + System.err.println(msg); 128.184 + errors++; 128.185 + } 128.186 + 128.187 + /** 128.188 + * Report an error. When the program is complete, the program will either 128.189 + * exit or throw an Error if any errors have been reported. 128.190 + * @param msg the error message 128.191 + */ 128.192 + void error(JavaFileObject file, String msg) { 128.193 + System.err.println(file.getName() + ": " + msg); 128.194 + errors++; 128.195 + } 128.196 + 128.197 + /** 128.198 + * Report an error for a specific tree node. 128.199 + * @param file the source file for the tree 128.200 + * @param t the tree node 128.201 + * @param label an indication of the error 128.202 + */ 128.203 + void error(JavaFileObject file, Tree tree, String msg) { 128.204 + JCTree t = (JCTree) tree; 128.205 + error(file.getName() + ":" + getLine(file, t) + ": " + msg + " " + trim(t, 64)); 128.206 + } 128.207 + 128.208 + /** 128.209 + * Get a trimmed string for a tree node, with normalized white space and limited length. 128.210 + */ 128.211 + String trim(Tree tree, int len) { 128.212 + JCTree t = (JCTree) tree; 128.213 + String s = t.toString().replaceAll("\\s+", " "); 128.214 + return (s.length() < len) ? s : s.substring(0, len); 128.215 + } 128.216 + 128.217 + /** Number of files that have been analyzed. */ 128.218 + int fileCount; 128.219 + /** Number of trees that have been successfully compared. */ 128.220 + int treeCount; 128.221 + /** Number of errors reported. */ 128.222 + int errors; 128.223 + /** Flag: don't report irrelevant files. */ 128.224 + boolean quiet; 128.225 + /** Flag: report files as they are processed. */ 128.226 + boolean verbose; 128.227 + 128.228 + 128.229 + /** 128.230 + * Thrown when errors are found parsing a java file. 128.231 + */ 128.232 + private static class ParseException extends Exception { 128.233 + ParseException(String msg) { 128.234 + super(msg); 128.235 + } 128.236 + } 128.237 + 128.238 + /** 128.239 + * DiagnosticListener to report diagnostics and count any errors that occur. 128.240 + */ 128.241 + private static class Reporter implements DiagnosticListener<JavaFileObject> { 128.242 + Reporter(PrintWriter out) { 128.243 + this.out = out; 128.244 + } 128.245 + 128.246 + public void report(Diagnostic<? extends JavaFileObject> diagnostic) { 128.247 + out.println(diagnostic); 128.248 + switch (diagnostic.getKind()) { 128.249 + case ERROR: 128.250 + errors++; 128.251 + } 128.252 + } 128.253 + int errors; 128.254 + PrintWriter out; 128.255 + } 128.256 + 128.257 + /** 128.258 + * Get the set of fields for a tree node that may contain child tree nodes. 128.259 + * These are the fields that are subtypes of JCTree or List. 128.260 + * The results are cached, based on the tree's tag. 128.261 + */ 128.262 + Set<Field> getFields(JCTree tree) { 128.263 + Set<Field> fields = map.get(tree.getTag()); 128.264 + if (fields == null) { 128.265 + fields = new HashSet<Field>(); 128.266 + for (Field f: tree.getClass().getFields()) { 128.267 + Class<?> fc = f.getType(); 128.268 + if (JCTree.class.isAssignableFrom(fc) || List.class.isAssignableFrom(fc)) 128.269 + fields.add(f); 128.270 + } 128.271 + map.put(tree.getTag(), fields); 128.272 + } 128.273 + return fields; 128.274 + } 128.275 + // where 128.276 + Map<Integer, Set<Field>> map = new HashMap<Integer,Set<Field>>(); 128.277 + 128.278 + /** Get the line number for the primary position for a tree. 128.279 + * The code is intended to be simple, although not necessarily efficient. 128.280 + * However, note that a file manager such as JavacFileManager is likely 128.281 + * to cache the results of file.getCharContent, avoiding the need to read 128.282 + * the bits from disk each time this method is called. 128.283 + */ 128.284 + int getLine(JavaFileObject file, JCTree tree) { 128.285 + try { 128.286 + CharSequence cs = file.getCharContent(true); 128.287 + int line = 1; 128.288 + for (int i = 0; i < tree.pos; i++) { 128.289 + if (cs.charAt(i) == '\n') // jtreg tests always use Unix line endings 128.290 + line++; 128.291 + } 128.292 + return line; 128.293 + } catch (IOException e) { 128.294 + return -1; 128.295 + } 128.296 + } 128.297 +}
129.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 129.2 +++ b/test/tools/javac/tree/ClassTreeTest.java Fri Sep 24 16:43:08 2010 -0700 129.3 @@ -0,0 +1,102 @@ 129.4 +/* 129.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 129.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 129.7 + * 129.8 + * This code is free software; you can redistribute it and/or modify it 129.9 + * under the terms of the GNU General Public License version 2 only, as 129.10 + * published by the Free Software Foundation. 129.11 + * 129.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 129.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 129.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 129.15 + * version 2 for more details (a copy is included in the LICENSE file that 129.16 + * accompanied this code). 129.17 + * 129.18 + * You should have received a copy of the GNU General Public License version 129.19 + * 2 along with this work; if not, write to the Free Software Foundation, 129.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 129.21 + * 129.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 129.23 + * or visit www.oracle.com if you need additional information or have any 129.24 + * questions. 129.25 + */ 129.26 + 129.27 +/* 129.28 + * @test 129.29 + * @bug 6570730 129.30 + * @summary com.sun.source.tree.ModifiersTree.getFlags() should return class type 129.31 + */ 129.32 + 129.33 +import java.io.*; 129.34 +import java.util.*; 129.35 +import javax.tools.*; 129.36 +import com.sun.source.tree.*; 129.37 +import com.sun.source.util.*; 129.38 +import com.sun.tools.javac.api.*; 129.39 + 129.40 +public class ClassTreeTest { 129.41 + public static void main(String... args) throws Exception { 129.42 + new ClassTreeTest().run(); 129.43 + } 129.44 + 129.45 + void run() throws Exception { 129.46 + JavacTool tool = JavacTool.create(); 129.47 + StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); 129.48 + List<String> opts = Collections.<String>emptyList(); 129.49 + File testSrc = new File(System.getProperty("test.src")); 129.50 + File thisFile = new File(testSrc, ClassTreeTest.class.getSimpleName() + ".java"); 129.51 + Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjects(thisFile); 129.52 + JavacTask task = tool.getTask(null, fm, null, opts, null, fos); 129.53 + for (CompilationUnitTree cu: task.parse()) { 129.54 + check(cu, "CLASS", Tree.Kind.CLASS); 129.55 + check(cu, "INTERFACE", Tree.Kind.INTERFACE); 129.56 + check(cu, "ENUM", Tree.Kind.ENUM); 129.57 + check(cu, "ANNOTATION_TYPE", Tree.Kind.ANNOTATION_TYPE); 129.58 + } 129.59 + 129.60 + int expected = 4; 129.61 + if (checks != expected) 129.62 + error("Unexpected number of checks performed; expected: " + expected + ", found: " + checks); 129.63 + 129.64 + if (errors > 0) 129.65 + throw new Exception(errors + " errors found"); 129.66 + } 129.67 + 129.68 + void check(CompilationUnitTree cu, String name, Tree.Kind k) { 129.69 + checks++; 129.70 + 129.71 + TreeScanner<ClassTree,String> s = new TreeScanner<ClassTree,String>() { 129.72 + @Override 129.73 + public ClassTree visitClass(ClassTree c, String name) { 129.74 + if (c.getSimpleName().toString().equals(name)) 129.75 + return c; 129.76 + else 129.77 + return super.visitClass(c, name); 129.78 + } 129.79 + 129.80 + @Override 129.81 + public ClassTree reduce(ClassTree t1, ClassTree t2) { 129.82 + return (t1 != null ? t1 : t2); 129.83 + } 129.84 + }; 129.85 + 129.86 + ClassTree c = s.scan(cu, name); 129.87 + if (c == null) 129.88 + error("Can't find node named " + name); 129.89 + else if (c.getKind() != k) 129.90 + error("Unexpected kind for node named " + name + ": expected: " + k + ", found: " + c.getKind()); 129.91 + } 129.92 + 129.93 + void error(String msg) { 129.94 + System.err.println("Error: " + msg); 129.95 + errors++; 129.96 + } 129.97 + 129.98 + int checks; 129.99 + int errors; 129.100 + 129.101 + class CLASS { } 129.102 + interface INTERFACE { } 129.103 + enum ENUM { } 129.104 + @interface ANNOTATION_TYPE { } 129.105 +}
130.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 130.2 +++ b/test/tools/javac/tree/JavacTreeScannerTest.java Fri Sep 24 16:43:08 2010 -0700 130.3 @@ -0,0 +1,156 @@ 130.4 +/* 130.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 130.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 130.7 + * 130.8 + * This code is free software; you can redistribute it and/or modify it 130.9 + * under the terms of the GNU General Public License version 2 only, as 130.10 + * published by the Free Software Foundation. 130.11 + * 130.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 130.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 130.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 130.15 + * version 2 for more details (a copy is included in the LICENSE file that 130.16 + * accompanied this code). 130.17 + * 130.18 + * You should have received a copy of the GNU General Public License version 130.19 + * 2 along with this work; if not, write to the Free Software Foundation, 130.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 130.21 + * 130.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 130.23 + * or visit www.oracle.com if you need additional information or have any 130.24 + * questions. 130.25 + */ 130.26 + 130.27 + 130.28 +/** 130.29 + * Utility and test program to check javac's internal TreeScanner class. 130.30 + * The program can be run standalone, or as a jtreg test. For info on 130.31 + * command line args, run program with no args. 130.32 + * 130.33 + * <p> 130.34 + * jtreg: Note that by using the -r switch in the test description below, this test 130.35 + * will process all java files in the langtools/test directory, thus implicitly 130.36 + * covering any new language features that may be tested in this test suite. 130.37 + */ 130.38 + 130.39 +/* 130.40 + * @test 130.41 + * @bug 6923080 130.42 + * @summary TreeScanner.visitNewClass should scan tree.typeargs 130.43 + * @build AbstractTreeScannerTest JavacTreeScannerTest 130.44 + * @run main JavacTreeScannerTest -q -r . 130.45 + */ 130.46 + 130.47 +import java.io.*; 130.48 +import java.lang.reflect.*; 130.49 +import java.util.*; 130.50 +import javax.tools.*; 130.51 + 130.52 +import com.sun.tools.javac.tree.JCTree; 130.53 +import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; 130.54 +import com.sun.tools.javac.tree.TreeScanner; 130.55 +import com.sun.tools.javac.util.List; 130.56 + 130.57 +public class JavacTreeScannerTest extends AbstractTreeScannerTest { 130.58 + /** 130.59 + * Main entry point. 130.60 + * If test.src is set, program runs in jtreg mode, and will throw an Error 130.61 + * if any errors arise, otherwise System.exit will be used. In jtreg mode, 130.62 + * the default base directory for file args is the value of ${test.src}. 130.63 + * In jtreg mode, the -r option can be given to change the default base 130.64 + * directory to the root test directory. 130.65 + */ 130.66 + public static void main(String... args) { 130.67 + String testSrc = System.getProperty("test.src"); 130.68 + File baseDir = (testSrc == null) ? null : new File(testSrc); 130.69 + boolean ok = new JavacTreeScannerTest().run(baseDir, args); 130.70 + if (!ok) { 130.71 + if (testSrc != null) // jtreg mode 130.72 + throw new Error("failed"); 130.73 + else 130.74 + System.exit(1); 130.75 + } 130.76 + } 130.77 + 130.78 + int test(JCCompilationUnit tree) { 130.79 + return new ScanTester().test(tree); 130.80 + } 130.81 + 130.82 + /** 130.83 + * Main class for testing operation of tree scanner. 130.84 + * The set of nodes found by the scanner are compared 130.85 + * against the set of nodes found by reflection. 130.86 + */ 130.87 + private class ScanTester extends TreeScanner { 130.88 + /** Main entry method for the class. */ 130.89 + int test(JCCompilationUnit tree) { 130.90 + sourcefile = tree.sourcefile; 130.91 + found = new HashSet<JCTree>(); 130.92 + scan(tree); 130.93 + expect = new HashSet<JCTree>(); 130.94 + reflectiveScan(tree); 130.95 + 130.96 + if (found.equals(expect)) { 130.97 + //System.err.println(sourcefile.getName() + ": trees compared OK"); 130.98 + return found.size(); 130.99 + } 130.100 + 130.101 + error(sourcefile, "differences found"); 130.102 + 130.103 + if (found.size() != expect.size()) 130.104 + error("Size mismatch; found: " + found.size() + ", expected: " + expect.size()); 130.105 + 130.106 + Set<JCTree> missing = new HashSet<JCTree>(); 130.107 + missing.addAll(expect); 130.108 + missing.removeAll(found); 130.109 + for (JCTree t: missing) 130.110 + error(sourcefile, t, "missing"); 130.111 + 130.112 + Set<JCTree> excess = new HashSet<JCTree>(); 130.113 + excess.addAll(found); 130.114 + excess.removeAll(expect); 130.115 + for (JCTree t: excess) 130.116 + error(sourcefile, t, "unexpected"); 130.117 + 130.118 + return 0; 130.119 + } 130.120 + 130.121 + /** Record all tree nodes found by scanner. */ 130.122 + @Override 130.123 + public void scan(JCTree tree) { 130.124 + if (tree == null) 130.125 + return; 130.126 + //System.err.println("FOUND: " + tree.getTag() + " " + trim(tree, 64)); 130.127 + found.add(tree); 130.128 + super.scan(tree); 130.129 + } 130.130 + 130.131 + /** record all tree nodes found by reflection. */ 130.132 + public void reflectiveScan(Object o) { 130.133 + if (o == null) 130.134 + return; 130.135 + if (o instanceof JCTree) { 130.136 + JCTree tree = (JCTree) o; 130.137 + //System.err.println("EXPECT: " + tree.getTag() + " " + trim(tree, 64)); 130.138 + expect.add(tree); 130.139 + for (Field f: getFields(tree)) { 130.140 + try { 130.141 + //System.err.println("FIELD: " + f.getName()); 130.142 + reflectiveScan(f.get(tree)); 130.143 + } catch (IllegalAccessException e) { 130.144 + error(e.toString()); 130.145 + } 130.146 + } 130.147 + } else if (o instanceof List) { 130.148 + List<?> list = (List<?>) o; 130.149 + for (Object item: list) 130.150 + reflectiveScan(item); 130.151 + } else 130.152 + error("unexpected item: " + o); 130.153 + } 130.154 + 130.155 + JavaFileObject sourcefile; 130.156 + Set<JCTree> found; 130.157 + Set<JCTree> expect; 130.158 + } 130.159 +}
131.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 131.2 +++ b/test/tools/javac/tree/SourceTreeScannerTest.java Fri Sep 24 16:43:08 2010 -0700 131.3 @@ -0,0 +1,169 @@ 131.4 +/* 131.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 131.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 131.7 + * 131.8 + * This code is free software; you can redistribute it and/or modify it 131.9 + * under the terms of the GNU General Public License version 2 only, as 131.10 + * published by the Free Software Foundation. 131.11 + * 131.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 131.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 131.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 131.15 + * version 2 for more details (a copy is included in the LICENSE file that 131.16 + * accompanied this code). 131.17 + * 131.18 + * You should have received a copy of the GNU General Public License version 131.19 + * 2 along with this work; if not, write to the Free Software Foundation, 131.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 131.21 + * 131.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 131.23 + * or visit www.oracle.com if you need additional information or have any 131.24 + * questions. 131.25 + */ 131.26 + 131.27 + 131.28 +/** 131.29 + * Utility and test program to check javac's internal TreeScanner class. 131.30 + * The program can be run standalone, or as a jtreg test. For info on 131.31 + * command line args, run program with no args. 131.32 + * 131.33 + * <p> 131.34 + * jtreg: Note that by using the -r switch in the test description below, this test 131.35 + * will process all java files in the langtools/test directory, thus implicitly 131.36 + * covering any new language features that may be tested in this test suite. 131.37 + */ 131.38 + 131.39 +/* 131.40 + * @test 131.41 + * @bug 6923080 131.42 + * @summary TreeScanner.visitNewClass should scan tree.typeargs 131.43 + * @build AbstractTreeScannerTest SourceTreeScannerTest 131.44 + * @run main SourceTreeScannerTest -q -r . 131.45 + */ 131.46 + 131.47 +import java.io.*; 131.48 +import java.lang.reflect.*; 131.49 +import java.util.*; 131.50 +import javax.tools.*; 131.51 + 131.52 +import com.sun.source.tree.Tree; 131.53 +import com.sun.source.util.TreeScanner; 131.54 +import com.sun.tools.javac.tree.JCTree; 131.55 +import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; 131.56 +import com.sun.tools.javac.tree.JCTree.TypeBoundKind; 131.57 +import com.sun.tools.javac.util.List; 131.58 + 131.59 +public class SourceTreeScannerTest extends AbstractTreeScannerTest { 131.60 + /** 131.61 + * Main entry point. 131.62 + * If test.src is set, program runs in jtreg mode, and will throw an Error 131.63 + * if any errors arise, otherwise System.exit will be used. In jtreg mode, 131.64 + * the default base directory for file args is the value of ${test.src}. 131.65 + * In jtreg mode, the -r option can be given to change the default base 131.66 + * directory to the root test directory. 131.67 + */ 131.68 + public static void main(String... args) { 131.69 + String testSrc = System.getProperty("test.src"); 131.70 + File baseDir = (testSrc == null) ? null : new File(testSrc); 131.71 + boolean ok = new SourceTreeScannerTest().run(baseDir, args); 131.72 + if (!ok) { 131.73 + if (testSrc != null) // jtreg mode 131.74 + throw new Error("failed"); 131.75 + else 131.76 + System.exit(1); 131.77 + } 131.78 + } 131.79 + 131.80 + int test(JCCompilationUnit tree) { 131.81 + return new ScanTester().test(tree); 131.82 + } 131.83 + 131.84 + /** 131.85 + * Main class for testing operation of tree scanner. 131.86 + * The set of nodes found by the scanner are compared 131.87 + * against the set of nodes found by reflection. 131.88 + */ 131.89 + private class ScanTester extends TreeScanner<Void,Void> { 131.90 + /** Main entry method for the class. */ 131.91 + int test(JCCompilationUnit tree) { 131.92 + sourcefile = tree.sourcefile; 131.93 + found = new HashSet<Tree>(); 131.94 + scan(tree, null); 131.95 + expect = new HashSet<Tree>(); 131.96 + reflectiveScan(tree); 131.97 + 131.98 + if (found.equals(expect)) { 131.99 + //System.err.println(sourcefile.getName() + ": trees compared OK"); 131.100 + return found.size(); 131.101 + } 131.102 + 131.103 + error(sourcefile.getName() + ": differences found"); 131.104 + 131.105 + if (found.size() != expect.size()) 131.106 + error("Size mismatch; found: " + found.size() + ", expected: " + expect.size()); 131.107 + 131.108 + Set<Tree> missing = new HashSet<Tree>(); 131.109 + missing.addAll(expect); 131.110 + missing.removeAll(found); 131.111 + for (Tree t: missing) 131.112 + error(sourcefile, t, "missing"); 131.113 + 131.114 + Set<Tree> excess = new HashSet<Tree>(); 131.115 + excess.addAll(found); 131.116 + excess.removeAll(expect); 131.117 + for (Tree t: excess) 131.118 + error(sourcefile, t, "unexpected"); 131.119 + 131.120 + return 0; 131.121 + } 131.122 + 131.123 + /** Record all tree nodes found by scanner. */ 131.124 + @Override 131.125 + public Void scan(Tree tree, Void ignore) { 131.126 + if (tree == null) 131.127 + return null; 131.128 + //System.err.println("FOUND: " + tree.getKind() + " " + trim(tree, 64)); 131.129 + found.add(tree); 131.130 + return super.scan(tree, ignore); 131.131 + } 131.132 + 131.133 + /** record all tree nodes found by reflection. */ 131.134 + public void reflectiveScan(Object o) { 131.135 + if (o == null) 131.136 + return; 131.137 + if (o instanceof JCTree) { 131.138 + JCTree tree = (JCTree) o; 131.139 + //System.err.println("EXPECT: " + tree.getKind() + " " + trim(tree, 64)); 131.140 + expect.add(tree); 131.141 + for (Field f: getFields(tree)) { 131.142 + if (TypeBoundKind.class.isAssignableFrom(f.getType())) { 131.143 + // not part of public API 131.144 + continue; 131.145 + } 131.146 + if (JCTree.JCNewArray.class.isAssignableFrom(tree.getClass()) 131.147 + && (f.getName().equals("annotations") 131.148 + || f.getName().equals("dimAnnotations"))) { 131.149 + // these fields are incorrectly missing from the public API 131.150 + // (CR 6983297) 131.151 + continue; 131.152 + } 131.153 + try { 131.154 + //System.err.println("FIELD: " + f.getName()); 131.155 + reflectiveScan(f.get(tree)); 131.156 + } catch (IllegalAccessException e) { 131.157 + error(e.toString()); 131.158 + } 131.159 + } 131.160 + } else if (o instanceof List) { 131.161 + List<?> list = (List<?>) o; 131.162 + for (Object item: list) 131.163 + reflectiveScan(item); 131.164 + } else 131.165 + error("unexpected item: " + o); 131.166 + } 131.167 + 131.168 + JavaFileObject sourcefile; 131.169 + Set<Tree> found; 131.170 + Set<Tree> expect; 131.171 + } 131.172 +}
132.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 132.2 +++ b/test/tools/javac/tree/TreeKindTest.java Fri Sep 24 16:43:08 2010 -0700 132.3 @@ -0,0 +1,132 @@ 132.4 +/* 132.5 + * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. 132.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 132.7 + * 132.8 + * This code is free software; you can redistribute it and/or modify it 132.9 + * under the terms of the GNU General Public License version 2 only, as 132.10 + * published by the Free Software Foundation. 132.11 + * 132.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 132.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 132.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 132.15 + * version 2 for more details (a copy is included in the LICENSE file that 132.16 + * accompanied this code). 132.17 + * 132.18 + * You should have received a copy of the GNU General Public License version 132.19 + * 2 along with this work; if not, write to the Free Software Foundation, 132.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 132.21 + * 132.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 132.23 + * or visit www.oracle.com if you need additional information or have any 132.24 + * questions. 132.25 + */ 132.26 + 132.27 +/* 132.28 + * @test 132.29 + * @bug 6341023 132.30 + * @summary Tree API: Tree.Kind should have mapping to interface 132.31 + */ 132.32 + 132.33 +import com.sun.source.tree.*; 132.34 + 132.35 +public class TreeKindTest{ 132.36 + public static void main(String... args) { 132.37 + boolean ok = true; 132.38 + 132.39 + for (Tree.Kind k: Tree.Kind.values()) { 132.40 + //System.err.println(k + " " + k.asInterface()); 132.41 + Class<? extends Tree> i = k.asInterface(); 132.42 + switch (k) { 132.43 + case POSTFIX_INCREMENT: 132.44 + case POSTFIX_DECREMENT: 132.45 + case PREFIX_INCREMENT: 132.46 + case PREFIX_DECREMENT: 132.47 + case UNARY_PLUS: 132.48 + case UNARY_MINUS: 132.49 + case BITWISE_COMPLEMENT: 132.50 + case LOGICAL_COMPLEMENT: 132.51 + ok = ok & verify(k, i, i == UnaryTree.class); 132.52 + break; 132.53 + 132.54 + case MULTIPLY: 132.55 + case DIVIDE: 132.56 + case REMAINDER: 132.57 + case PLUS: 132.58 + case MINUS: 132.59 + case LEFT_SHIFT: 132.60 + case RIGHT_SHIFT: 132.61 + case UNSIGNED_RIGHT_SHIFT: 132.62 + case LESS_THAN: 132.63 + case GREATER_THAN: 132.64 + case LESS_THAN_EQUAL: 132.65 + case GREATER_THAN_EQUAL: 132.66 + case EQUAL_TO: 132.67 + case NOT_EQUAL_TO: 132.68 + case AND: 132.69 + case XOR: 132.70 + case OR: 132.71 + case CONDITIONAL_AND: 132.72 + case CONDITIONAL_OR: 132.73 + ok = ok & verify(k, i, i == BinaryTree.class); 132.74 + break; 132.75 + 132.76 + case MULTIPLY_ASSIGNMENT: 132.77 + case DIVIDE_ASSIGNMENT: 132.78 + case REMAINDER_ASSIGNMENT: 132.79 + case PLUS_ASSIGNMENT: 132.80 + case MINUS_ASSIGNMENT: 132.81 + case LEFT_SHIFT_ASSIGNMENT: 132.82 + case RIGHT_SHIFT_ASSIGNMENT: 132.83 + case UNSIGNED_RIGHT_SHIFT_ASSIGNMENT: 132.84 + case AND_ASSIGNMENT: 132.85 + case XOR_ASSIGNMENT: 132.86 + case OR_ASSIGNMENT: 132.87 + ok = ok & verify(k, i, i == CompoundAssignmentTree.class); 132.88 + break; 132.89 + 132.90 + case INT_LITERAL: 132.91 + case LONG_LITERAL: 132.92 + case FLOAT_LITERAL: 132.93 + case DOUBLE_LITERAL: 132.94 + case BOOLEAN_LITERAL: 132.95 + case CHAR_LITERAL: 132.96 + case STRING_LITERAL: 132.97 + case NULL_LITERAL: 132.98 + ok = ok & verify(k, i, i == LiteralTree.class); 132.99 + break; 132.100 + 132.101 + case UNBOUNDED_WILDCARD: 132.102 + case EXTENDS_WILDCARD: 132.103 + case SUPER_WILDCARD: 132.104 + ok = ok & verify(k, i, i == WildcardTree.class); 132.105 + break; 132.106 + 132.107 + case INTERFACE: 132.108 + case ANNOTATION_TYPE: 132.109 + case ENUM: 132.110 + case CLASS: 132.111 + ok = ok & verify(k, i, i == ClassTree.class); 132.112 + break; 132.113 + 132.114 + case OTHER: 132.115 + ok = ok & verify(k, i, i == null); 132.116 + break; 132.117 + 132.118 + default: 132.119 + String ks = k.toString().replace("_", "") + "tree"; 132.120 + String iName = i.getName(); 132.121 + String is = iName.substring(iName.lastIndexOf(".") + 1); 132.122 + ok = ok & verify(k, i, ks.equalsIgnoreCase(is)); 132.123 + } 132.124 + } 132.125 + 132.126 + if (!ok) 132.127 + throw new AssertionError("test failed"); 132.128 + } 132.129 + 132.130 + static boolean verify(Tree.Kind k, Class<?> c, boolean b) { 132.131 + if (!b) 132.132 + System.err.println("error: " + k + " " + c); 132.133 + return b; 132.134 + } 132.135 +}
133.1 --- a/test/tools/javac/tree/TreeScannerTest.java Thu Sep 23 17:33:52 2010 -0700 133.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 133.3 @@ -1,387 +0,0 @@ 133.4 -/* 133.5 - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 133.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 133.7 - * 133.8 - * This code is free software; you can redistribute it and/or modify it 133.9 - * under the terms of the GNU General Public License version 2 only, as 133.10 - * published by the Free Software Foundation. 133.11 - * 133.12 - * This code is distributed in the hope that it will be useful, but WITHOUT 133.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 133.14 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 133.15 - * version 2 for more details (a copy is included in the LICENSE file that 133.16 - * accompanied this code). 133.17 - * 133.18 - * You should have received a copy of the GNU General Public License version 133.19 - * 2 along with this work; if not, write to the Free Software Foundation, 133.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 133.21 - * 133.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 133.23 - * or visit www.oracle.com if you need additional information or have any 133.24 - * questions. 133.25 - */ 133.26 - 133.27 - 133.28 -/** 133.29 - * Utility and test program to check javac's internal TreeScanner class. 133.30 - * The program can be run standalone, or as a jtreg test. For info on 133.31 - * command line args, run program with no args. 133.32 - * 133.33 - * <p> 133.34 - * jtreg: Note that by using the -r switch in the test description below, this test 133.35 - * will process all java files in the langtools/test directory, thus implicitly 133.36 - * covering any new language features that may be tested in this test suite. 133.37 - */ 133.38 - 133.39 -/* 133.40 - * @test 133.41 - * @bug 6923080 133.42 - * @summary TreeScanner.visitNewClass should scan tree.typeargs 133.43 - * @run main TreeScannerTest -q -r . 133.44 - */ 133.45 - 133.46 -import java.io.*; 133.47 -import java.lang.reflect.*; 133.48 -import java.util.*; 133.49 -import javax.tools.*; 133.50 - 133.51 -import com.sun.source.tree.CompilationUnitTree; 133.52 -import com.sun.source.util.JavacTask; 133.53 -import com.sun.tools.javac.api.JavacTool; 133.54 -import com.sun.tools.javac.tree.*; 133.55 -import com.sun.tools.javac.tree.JCTree.*; 133.56 -import com.sun.tools.javac.util.List; 133.57 - 133.58 -public class TreeScannerTest { 133.59 - /** 133.60 - * Main entry point. 133.61 - * If test.src is set, program runs in jtreg mode, and will throw an Error 133.62 - * if any errors arise, otherwise System.exit will be used. In jtreg mode, 133.63 - * the default base directory for file args is the value of ${test.src}. 133.64 - * In jtreg mode, the -r option can be given to change the default base 133.65 - * directory to the root test directory. 133.66 - */ 133.67 - public static void main(String... args) { 133.68 - String testSrc = System.getProperty("test.src"); 133.69 - File baseDir = (testSrc == null) ? null : new File(testSrc); 133.70 - boolean ok = new TreeScannerTest().run(baseDir, args); 133.71 - if (!ok) { 133.72 - if (testSrc != null) // jtreg mode 133.73 - throw new Error("failed"); 133.74 - else 133.75 - System.exit(1); 133.76 - } 133.77 - } 133.78 - 133.79 - /** 133.80 - * Run the program. A base directory can be provided for file arguments. 133.81 - * In jtreg mode, the -r option can be given to change the default base 133.82 - * directory to the test root directory. For other options, see usage(). 133.83 - * @param baseDir base directory for any file arguments. 133.84 - * @param args command line args 133.85 - * @return true if successful or in gui mode 133.86 - */ 133.87 - boolean run(File baseDir, String... args) { 133.88 - if (args.length == 0) { 133.89 - usage(System.out); 133.90 - return true; 133.91 - } 133.92 - 133.93 - ArrayList<File> files = new ArrayList<File>(); 133.94 - for (int i = 0; i < args.length; i++) { 133.95 - String arg = args[i]; 133.96 - if (arg.equals("-q")) 133.97 - quiet = true; 133.98 - else if (arg.equals("-v")) 133.99 - verbose = true; 133.100 - else if (arg.equals("-r")) { 133.101 - File d = baseDir; 133.102 - while (!new File(d, "TEST.ROOT").exists()) { 133.103 - d = d.getParentFile(); 133.104 - if (d == null) 133.105 - throw new Error("cannot find TEST.ROOT"); 133.106 - } 133.107 - baseDir = d; 133.108 - } 133.109 - else if (arg.startsWith("-")) 133.110 - throw new Error("unknown option: " + arg); 133.111 - else { 133.112 - while (i < args.length) 133.113 - files.add(new File(baseDir, args[i++])); 133.114 - } 133.115 - } 133.116 - 133.117 - for (File file: files) { 133.118 - if (file.exists()) 133.119 - test(file); 133.120 - else 133.121 - error("File not found: " + file); 133.122 - } 133.123 - 133.124 - if (fileCount != 1) 133.125 - System.err.println(fileCount + " files read"); 133.126 - if (errors > 0) 133.127 - System.err.println(errors + " errors"); 133.128 - 133.129 - return (errors == 0); 133.130 - } 133.131 - 133.132 - /** 133.133 - * Print command line help. 133.134 - * @param out output stream 133.135 - */ 133.136 - void usage(PrintStream out) { 133.137 - out.println("Usage:"); 133.138 - out.println(" java TreeScannerTest options... files..."); 133.139 - out.println(""); 133.140 - out.println("where options include:"); 133.141 - out.println("-q Quiet: don't report on inapplicable files"); 133.142 - out.println("-v Verbose: report on files as they are being read"); 133.143 - out.println(""); 133.144 - out.println("files may be directories or files"); 133.145 - out.println("directories will be scanned recursively"); 133.146 - out.println("non java files, or java files which cannot be parsed, will be ignored"); 133.147 - out.println(""); 133.148 - } 133.149 - 133.150 - /** 133.151 - * Test a file. If the file is a directory, it will be recursively scanned 133.152 - * for java files. 133.153 - * @param file the file or directory to test 133.154 - */ 133.155 - void test(File file) { 133.156 - if (file.isDirectory()) { 133.157 - for (File f: file.listFiles()) { 133.158 - test(f); 133.159 - } 133.160 - return; 133.161 - } 133.162 - 133.163 - if (file.isFile() && file.getName().endsWith(".java")) { 133.164 - try { 133.165 - if (verbose) 133.166 - System.err.println(file); 133.167 - fileCount++; 133.168 - ScanTester t = new ScanTester(); 133.169 - t.test(read(file)); 133.170 - } catch (ParseException e) { 133.171 - if (!quiet) { 133.172 - error("Error parsing " + file + "\n" + e.getMessage()); 133.173 - } 133.174 - } catch (IOException e) { 133.175 - error("Error reading " + file + ": " + e); 133.176 - } 133.177 - return; 133.178 - } 133.179 - 133.180 - if (!quiet) 133.181 - error("File " + file + " ignored"); 133.182 - } 133.183 - 133.184 - /** 133.185 - * Read a file. 133.186 - * @param file the file to be read 133.187 - * @return the tree for the content of the file 133.188 - * @throws IOException if any IO errors occur 133.189 - * @throws TreePosTest.ParseException if any errors occur while parsing the file 133.190 - */ 133.191 - JCCompilationUnit read(File file) throws IOException, ParseException { 133.192 - StringWriter sw = new StringWriter(); 133.193 - PrintWriter pw = new PrintWriter(sw); 133.194 - Reporter r = new Reporter(pw); 133.195 - JavacTool tool = JavacTool.create(); 133.196 - StandardJavaFileManager fm = tool.getStandardFileManager(r, null, null); 133.197 - Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(file); 133.198 - JavacTask task = tool.getTask(pw, fm, r, Collections.<String>emptyList(), null, files); 133.199 - Iterable<? extends CompilationUnitTree> trees = task.parse(); 133.200 - pw.flush(); 133.201 - if (r.errors > 0) 133.202 - throw new ParseException(sw.toString()); 133.203 - Iterator<? extends CompilationUnitTree> iter = trees.iterator(); 133.204 - if (!iter.hasNext()) 133.205 - throw new Error("no trees found"); 133.206 - JCCompilationUnit t = (JCCompilationUnit) iter.next(); 133.207 - if (iter.hasNext()) 133.208 - throw new Error("too many trees found"); 133.209 - return t; 133.210 - } 133.211 - 133.212 - /** 133.213 - * Report an error. When the program is complete, the program will either 133.214 - * exit or throw an Error if any errors have been reported. 133.215 - * @param msg the error message 133.216 - */ 133.217 - void error(String msg) { 133.218 - System.err.println(msg); 133.219 - errors++; 133.220 - } 133.221 - 133.222 - /** 133.223 - * Report an error for a specific tree node. 133.224 - * @param file the source file for the tree 133.225 - * @param t the tree node 133.226 - * @param label an indication of the error 133.227 - */ 133.228 - void error(JavaFileObject file, JCTree t, String msg) { 133.229 - error(file.getName() + ":" + getLine(file, t) + ": " + msg + " " + trim(t, 64)); 133.230 - } 133.231 - 133.232 - /** 133.233 - * Get a trimmed string for a tree node, with normalized white space and limited length. 133.234 - */ 133.235 - String trim(JCTree t, int len) { 133.236 - String s = t.toString().replaceAll("[\r\n]+", " ").replaceAll(" +", " "); 133.237 - return (s.length() < len) ? s : s.substring(0, len); 133.238 - } 133.239 - 133.240 - /** Number of files that have been analyzed. */ 133.241 - int fileCount; 133.242 - /** Number of errors reported. */ 133.243 - int errors; 133.244 - /** Flag: don't report irrelevant files. */ 133.245 - boolean quiet; 133.246 - /** Flag: report files as they are processed. */ 133.247 - boolean verbose; 133.248 - 133.249 - /** 133.250 - * Main class for testing operation of tree scanner. 133.251 - * The set of nodes found by the scanner are compared 133.252 - * against the set of nodes found by reflection. 133.253 - */ 133.254 - private class ScanTester extends TreeScanner { 133.255 - /** Main entry method for the class. */ 133.256 - void test(JCCompilationUnit tree) { 133.257 - sourcefile = tree.sourcefile; 133.258 - found = new HashSet<JCTree>(); 133.259 - scan(tree); 133.260 - expect = new HashSet<JCTree>(); 133.261 - reflectiveScan(tree); 133.262 - if (found.equals(expect)) 133.263 - return; 133.264 - 133.265 - error("Differences found for " + tree.sourcefile.getName()); 133.266 - 133.267 - if (found.size() != expect.size()) 133.268 - error("Size mismatch; found: " + found.size() + ", expected: " + expect.size()); 133.269 - 133.270 - Set<JCTree> missing = new HashSet<JCTree>(); 133.271 - missing.addAll(expect); 133.272 - missing.removeAll(found); 133.273 - for (JCTree t: missing) 133.274 - error(tree.sourcefile, t, "missing"); 133.275 - 133.276 - Set<JCTree> excess = new HashSet<JCTree>(); 133.277 - excess.addAll(found); 133.278 - excess.removeAll(expect); 133.279 - for (JCTree t: excess) 133.280 - error(tree.sourcefile, t, "unexpected"); 133.281 - } 133.282 - 133.283 - /** Record all tree nodes found by scanner. */ 133.284 - @Override 133.285 - public void scan(JCTree tree) { 133.286 - if (tree == null) 133.287 - return; 133.288 - System.err.println("FOUND: " + tree.getTag() + " " + trim(tree, 64)); 133.289 - found.add(tree); 133.290 - super.scan(tree); 133.291 - } 133.292 - 133.293 - /** record all tree nodes found by reflection. */ 133.294 - public void reflectiveScan(Object o) { 133.295 - if (o == null) 133.296 - return; 133.297 - if (o instanceof JCTree) { 133.298 - JCTree tree = (JCTree) o; 133.299 - System.err.println("EXPECT: " + tree.getTag() + " " + trim(tree, 64)); 133.300 - expect.add(tree); 133.301 - for (Field f: getFields(tree)) { 133.302 - try { 133.303 - //System.err.println("FIELD: " + f.getName()); 133.304 - reflectiveScan(f.get(tree)); 133.305 - } catch (IllegalAccessException e) { 133.306 - error(e.toString()); 133.307 - } 133.308 - } 133.309 - } else if (o instanceof List) { 133.310 - List<?> list = (List<?>) o; 133.311 - for (Object item: list) 133.312 - reflectiveScan(item); 133.313 - } else 133.314 - error("unexpected item: " + o); 133.315 - } 133.316 - 133.317 - JavaFileObject sourcefile; 133.318 - Set<JCTree> found; 133.319 - Set<JCTree> expect; 133.320 - } 133.321 - 133.322 - /** 133.323 - * Thrown when errors are found parsing a java file. 133.324 - */ 133.325 - private static class ParseException extends Exception { 133.326 - ParseException(String msg) { 133.327 - super(msg); 133.328 - } 133.329 - } 133.330 - 133.331 - /** 133.332 - * DiagnosticListener to report diagnostics and count any errors that occur. 133.333 - */ 133.334 - private static class Reporter implements DiagnosticListener<JavaFileObject> { 133.335 - Reporter(PrintWriter out) { 133.336 - this.out = out; 133.337 - } 133.338 - 133.339 - public void report(Diagnostic<? extends JavaFileObject> diagnostic) { 133.340 - out.println(diagnostic); 133.341 - switch (diagnostic.getKind()) { 133.342 - case ERROR: 133.343 - errors++; 133.344 - } 133.345 - } 133.346 - int errors; 133.347 - PrintWriter out; 133.348 - } 133.349 - 133.350 - /** 133.351 - * Get the set of fields for a tree node that may contain child tree nodes. 133.352 - * These are the fields that are subtypes of JCTree or List. 133.353 - * The results are cached, based on the tree's tag. 133.354 - */ 133.355 - Set<Field> getFields(JCTree tree) { 133.356 - Set<Field> fields = map.get(tree.getTag()); 133.357 - if (fields == null) { 133.358 - fields = new HashSet<Field>(); 133.359 - for (Field f: tree.getClass().getFields()) { 133.360 - Class<?> fc = f.getType(); 133.361 - if (JCTree.class.isAssignableFrom(fc) || List.class.isAssignableFrom(fc)) 133.362 - fields.add(f); 133.363 - } 133.364 - map.put(tree.getTag(), fields); 133.365 - } 133.366 - return fields; 133.367 - } 133.368 - // where 133.369 - Map<Integer, Set<Field>> map = new HashMap<Integer,Set<Field>>(); 133.370 - 133.371 - /** Get the line number for the primary position for a tree. 133.372 - * The code is intended to be simple, although not necessarily efficient. 133.373 - * However, note that a file manager such as JavacFileManager is likely 133.374 - * to cache the results of file.getCharContent, avoiding the need to read 133.375 - * the bits from disk each time this method is called. 133.376 - */ 133.377 - int getLine(JavaFileObject file, JCTree tree) { 133.378 - try { 133.379 - CharSequence cs = file.getCharContent(true); 133.380 - int line = 1; 133.381 - for (int i = 0; i < tree.pos; i++) { 133.382 - if (cs.charAt(i) == '\n') // jtreg tests always use Unix line endings 133.383 - line++; 133.384 - } 133.385 - return line; 133.386 - } catch (IOException e) { 133.387 - return -1; 133.388 - } 133.389 - } 133.390 -}
134.1 --- a/test/tools/javap/T6868539.java Thu Sep 23 17:33:52 2010 -0700 134.2 +++ b/test/tools/javap/T6868539.java Fri Sep 24 16:43:08 2010 -0700 134.3 @@ -39,25 +39,25 @@ 134.4 } 134.5 134.6 void run() { 134.7 - verify("T6868539", "Utf8 +java/lang/String"); // 1: Utf8 134.8 + String output = javap("T6868539"); 134.9 + verify(output, "Utf8 +java/lang/String"); // 1: Utf8 134.10 // 2: currently unused 134.11 - verify("T6868539", "Integer +123456"); // 3: Integer 134.12 - verify("T6868539", "Float +123456.0f"); // 4: Float 134.13 - verify("T6868539", "Long +123456l"); // 5: Long 134.14 - verify("T6868539", "Double +123456.0d"); // 6: Double 134.15 - verify("T6868539", "Class +#[0-9]+ +// + T6868539"); // 7: Class 134.16 - verify("T6868539", "String +#[0-9]+ +// + not found"); // 8: String 134.17 - verify("T6868539", "Fieldref +#[0-9]+\\.#[0-9]+ +// +T6868539.errors:I"); // 9: Fieldref 134.18 - verify("T6868539", "Methodref +#[0-9]+\\.#[0-9]+ +// +T6868539.run:\\(\\)V"); // 10: Methodref 134.19 - verify("T6868539", "InterfaceMethodref +#[0-9]+\\.#[0-9]+ +// +java/lang/Runnable\\.run:\\(\\)V"); 134.20 + verify(output, "Integer +123456"); // 3: Integer 134.21 + verify(output, "Float +123456.0f"); // 4: Float 134.22 + verify(output, "Long +123456l"); // 5: Long 134.23 + verify(output, "Double +123456.0d"); // 6: Double 134.24 + verify(output, "Class +#[0-9]+ +// + T6868539"); // 7: Class 134.25 + verify(output, "String +#[0-9]+ +// + not found"); // 8: String 134.26 + verify(output, "Fieldref +#[0-9]+\\.#[0-9]+ +// +T6868539.errors:I"); // 9: Fieldref 134.27 + verify(output, "Methodref +#[0-9]+\\.#[0-9]+ +// +T6868539.run:\\(\\)V"); // 10: Methodref 134.28 + verify(output, "InterfaceMethodref +#[0-9]+\\.#[0-9]+ +// +java/lang/Runnable\\.run:\\(\\)V"); 134.29 // 11: InterfaceMethodref 134.30 - verify("T6868539", "NameAndType +#[0-9]+:#[0-9]+ +// +run:\\(\\)V"); // 12: NameAndType 134.31 + verify(output, "NameAndType +#[0-9]+:#[0-9]+ +// +run:\\(\\)V"); // 12: NameAndType 134.32 if (errors > 0) 134.33 throw new Error(errors + " found."); 134.34 } 134.35 134.36 - void verify(String className, String... expects) { 134.37 - String output = javap(className); 134.38 + void verify(String output, String... expects) { 134.39 for (String expect: expects) { 134.40 if (!output.matches("(?s).*" + expect + ".*")) 134.41 error(expect + " not found");
135.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 135.2 +++ b/test/tools/javap/T6980017.java Fri Sep 24 16:43:08 2010 -0700 135.3 @@ -0,0 +1,78 @@ 135.4 +/* 135.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 135.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 135.7 + * 135.8 + * This code is free software; you can redistribute it and/or modify it 135.9 + * under the terms of the GNU General Public License version 2 only, as 135.10 + * published by the Free Software Foundation. 135.11 + * 135.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 135.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 135.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 135.15 + * version 2 for more details (a copy is included in the LICENSE file that 135.16 + * accompanied this code). 135.17 + * 135.18 + * You should have received a copy of the GNU General Public License version 135.19 + * 2 along with this work; if not, write to the Free Software Foundation, 135.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 135.21 + * 135.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 135.23 + * or visit www.oracle.com if you need additional information or have any 135.24 + * questions. 135.25 + */ 135.26 + 135.27 +/* 135.28 + * @test 135.29 + * @bug 6980017 135.30 + * @summary javap -XDdetail:source behaves badly if source not available. 135.31 + */ 135.32 + 135.33 +import java.io.*; 135.34 + 135.35 +public class T6980017 { 135.36 + public static void main(String... args) throws Exception { 135.37 + new T6980017().run(); 135.38 + } 135.39 + 135.40 + void run() throws Exception { 135.41 + 135.42 + String[] args = { 135.43 + "-v", 135.44 + "-XDdetails:source", 135.45 + "java.lang.Object" 135.46 + }; 135.47 + 135.48 + StringWriter sw = new StringWriter(); 135.49 + PrintWriter pw = new PrintWriter(sw); 135.50 + int rc = com.sun.tools.javap.Main.run(args, pw); 135.51 + pw.close(); 135.52 + if (rc != 0) 135.53 + error("Unexpected exit code: " + rc); 135.54 + 135.55 + boolean foundBlankSourceLine = false; 135.56 + boolean foundNoSourceLine = false; 135.57 + for (String line: sw.toString().split("[\r\n]+")) { 135.58 + System.err.println(line); 135.59 + if (line.contains("Source code not available")) 135.60 + foundNoSourceLine = true; 135.61 + if (line.matches("\\s*\\( *[0-9]+\\)\\s*")) 135.62 + foundBlankSourceLine = true; 135.63 + } 135.64 + 135.65 + if (foundBlankSourceLine) 135.66 + error("found blank source lines"); 135.67 + 135.68 + if (!foundNoSourceLine) 135.69 + error("did not find \"Source code not available\" message"); 135.70 + 135.71 + if (errors > 0) 135.72 + throw new Exception(errors + " errors occurred"); 135.73 + } 135.74 + 135.75 + void error(String msg) { 135.76 + System.err.println(msg); 135.77 + errors++; 135.78 + } 135.79 + 135.80 + int errors; 135.81 +}