Wed, 21 Aug 2013 16:13:50 -0700
8023515: import type-annotations updates
Reviewed-by: jjg
Contributed-by: wdietl@gmail.com
1.1 --- a/src/share/classes/com/sun/source/tree/MethodTree.java Tue Aug 20 15:12:16 2013 -0700 1.2 +++ b/src/share/classes/com/sun/source/tree/MethodTree.java Wed Aug 21 16:13:50 2013 -0700 1.3 @@ -53,7 +53,15 @@ 1.4 Tree getReturnType(); 1.5 List<? extends TypeParameterTree> getTypeParameters(); 1.6 List<? extends VariableTree> getParameters(); 1.7 + 1.8 + /** 1.9 + * Return an explicit receiver parameter ("this" parameter). 1.10 + * 1.11 + * @return an explicit receiver parameter ("this" parameter) 1.12 + * @since 1.8 1.13 + */ 1.14 VariableTree getReceiverParameter(); 1.15 + 1.16 List<? extends ExpressionTree> getThrows(); 1.17 BlockTree getBody(); 1.18 Tree getDefaultValue(); // for annotation types
2.1 --- a/src/share/classes/com/sun/source/tree/TypeParameterTree.java Tue Aug 20 15:12:16 2013 -0700 2.2 +++ b/src/share/classes/com/sun/source/tree/TypeParameterTree.java Wed Aug 21 16:13:50 2013 -0700 2.3 @@ -36,6 +36,8 @@ 2.4 * <em>name</em> 2.5 * 2.6 * <em>name</em> extends <em>bounds</em> 2.7 + * 2.8 + * <em>annotations</em> <em>name</em> 2.9 * </pre> 2.10 * 2.11 * @jls section 4.4 2.12 @@ -48,5 +50,17 @@ 2.13 public interface TypeParameterTree extends Tree { 2.14 Name getName(); 2.15 List<? extends Tree> getBounds(); 2.16 + 2.17 + /** 2.18 + * Return annotations on the type parameter declaration. 2.19 + * 2.20 + * Annotations need Target meta-annotations of 2.21 + * {@link java.lang.annotation.ElementType#TYPE_PARAMETER} or 2.22 + * {@link java.lang.annotation.ElementType#TYPE_USE} 2.23 + * to appear in this position. 2.24 + * 2.25 + * @return annotations on the type parameter declaration 2.26 + * @since 1.8 2.27 + */ 2.28 List<? extends AnnotationTree> getAnnotations(); 2.29 }
3.1 --- a/src/share/classes/com/sun/tools/javac/code/Printer.java Tue Aug 20 15:12:16 2013 -0700 3.2 +++ b/src/share/classes/com/sun/tools/javac/code/Printer.java Wed Aug 21 16:13:50 2013 -0700 3.3 @@ -27,8 +27,6 @@ 3.4 3.5 import java.util.Locale; 3.6 3.7 -import javax.lang.model.type.TypeKind; 3.8 - 3.9 import com.sun.tools.javac.api.Messages; 3.10 import com.sun.tools.javac.code.Type.AnnotatedType; 3.11 import com.sun.tools.javac.code.Type.ArrayType; 3.12 @@ -191,7 +189,7 @@ 3.13 3.14 void printBaseElementType(Type t, StringBuilder sb, Locale locale) { 3.15 Type arrel = t; 3.16 - while (arrel.getKind() == TypeKind.ARRAY) { 3.17 + while (arrel.hasTag(TypeTag.ARRAY)) { 3.18 arrel = arrel.unannotatedType(); 3.19 arrel = ((ArrayType) arrel).elemtype; 3.20 } 3.21 @@ -200,7 +198,7 @@ 3.22 3.23 void printBrackets(Type t, StringBuilder sb, Locale locale) { 3.24 Type arrel = t; 3.25 - while (arrel.getKind() == TypeKind.ARRAY) { 3.26 + while (arrel.hasTag(TypeTag.ARRAY)) { 3.27 if (arrel.isAnnotated()) { 3.28 sb.append(' '); 3.29 sb.append(arrel.getAnnotationMirrors()); 3.30 @@ -264,12 +262,12 @@ 3.31 public String visitAnnotatedType(AnnotatedType t, Locale locale) { 3.32 if (t.typeAnnotations != null && 3.33 t.typeAnnotations.nonEmpty()) { 3.34 - if (t.underlyingType.getKind() == TypeKind.ARRAY) { 3.35 + if (t.underlyingType.hasTag(TypeTag.ARRAY)) { 3.36 StringBuilder res = new StringBuilder(); 3.37 printBaseElementType(t, res, locale); 3.38 printBrackets(t, res, locale); 3.39 return res.toString(); 3.40 - } else if (t.underlyingType.getKind() == TypeKind.DECLARED && 3.41 + } else if (t.underlyingType.hasTag(TypeTag.CLASS) && 3.42 t.underlyingType.getEnclosingType() != Type.noType) { 3.43 return visit(t.underlyingType.getEnclosingType(), locale) + 3.44 ". " + 3.45 @@ -348,7 +346,7 @@ 3.46 args = args.tail; 3.47 buf.append(','); 3.48 } 3.49 - if (args.head.unannotatedType().getKind() == TypeKind.ARRAY) { 3.50 + if (args.head.unannotatedType().hasTag(TypeTag.ARRAY)) { 3.51 buf.append(visit(((ArrayType) args.head.unannotatedType()).elemtype, locale)); 3.52 if (args.head.getAnnotationMirrors().nonEmpty()) { 3.53 buf.append(' ');
4.1 --- a/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java Tue Aug 20 15:12:16 2013 -0700 4.2 +++ b/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java Wed Aug 21 16:13:50 2013 -0700 4.3 @@ -29,6 +29,8 @@ 4.4 import javax.lang.model.element.ElementKind; 4.5 import javax.lang.model.type.TypeKind; 4.6 4.7 +import javax.tools.JavaFileObject; 4.8 + 4.9 import com.sun.tools.javac.code.Attribute; 4.10 import com.sun.tools.javac.code.Attribute.TypeCompound; 4.11 import com.sun.tools.javac.code.Flags; 4.12 @@ -52,12 +54,16 @@ 4.13 import com.sun.tools.javac.code.Symbol.MethodSymbol; 4.14 import com.sun.tools.javac.comp.Annotate; 4.15 import com.sun.tools.javac.comp.Annotate.Annotator; 4.16 +import com.sun.tools.javac.comp.AttrContext; 4.17 +import com.sun.tools.javac.comp.Env; 4.18 import com.sun.tools.javac.tree.JCTree; 4.19 +import com.sun.tools.javac.tree.TreeInfo; 4.20 import com.sun.tools.javac.tree.JCTree.JCBlock; 4.21 import com.sun.tools.javac.tree.JCTree.JCClassDecl; 4.22 import com.sun.tools.javac.tree.JCTree.JCExpression; 4.23 import com.sun.tools.javac.tree.JCTree.JCLambda; 4.24 import com.sun.tools.javac.tree.JCTree.JCMethodDecl; 4.25 +import com.sun.tools.javac.tree.JCTree.JCMethodInvocation; 4.26 import com.sun.tools.javac.tree.JCTree.JCNewClass; 4.27 import com.sun.tools.javac.tree.JCTree.JCTypeApply; 4.28 import com.sun.tools.javac.tree.JCTree.JCVariableDecl; 4.29 @@ -90,11 +96,17 @@ 4.30 * later processing. 4.31 */ 4.32 public static void organizeTypeAnnotationsSignatures(final Symtab syms, final Names names, 4.33 - final Log log, final JCClassDecl tree, Annotate annotate) { 4.34 + final Log log, final Env<AttrContext> env, final JCClassDecl tree, final Annotate annotate) { 4.35 annotate.afterRepeated( new Annotator() { 4.36 @Override 4.37 public void enterAnnotation() { 4.38 - new TypeAnnotationPositions(syms, names, log, true).scan(tree); 4.39 + JavaFileObject oldSource = log.useSource(env.toplevel.sourcefile); 4.40 + 4.41 + try { 4.42 + new TypeAnnotationPositions(syms, names, log, true).scan(tree); 4.43 + } finally { 4.44 + log.useSource(oldSource); 4.45 + } 4.46 } 4.47 } ); 4.48 } 4.49 @@ -906,7 +918,14 @@ 4.50 if (!invocation.typeargs.contains(tree)) { 4.51 Assert.error("{" + tree + "} is not an argument in the invocation: " + invocation); 4.52 } 4.53 - p.type = TargetType.METHOD_INVOCATION_TYPE_ARGUMENT; 4.54 + MethodSymbol exsym = (MethodSymbol) TreeInfo.symbol(invocation.getMethodSelect()); 4.55 + if (exsym == null) { 4.56 + Assert.error("could not determine symbol for {" + invocation + "}"); 4.57 + } else if (exsym.isConstructor()) { 4.58 + p.type = TargetType.CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT; 4.59 + } else { 4.60 + p.type = TargetType.METHOD_INVOCATION_TYPE_ARGUMENT; 4.61 + } 4.62 p.pos = invocation.pos; 4.63 p.type_index = invocation.typeargs.indexOf(tree); 4.64 return;
5.1 --- a/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java Tue Aug 20 15:12:16 2013 -0700 5.2 +++ b/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java Wed Aug 21 16:13:50 2013 -0700 5.3 @@ -249,7 +249,7 @@ 5.4 MethodType lambdaType = (MethodType) sym.type; 5.5 5.6 { 5.7 - MethodSymbol owner = (MethodSymbol) localContext.owner; 5.8 + Symbol owner = localContext.owner; 5.9 ListBuffer<Attribute.TypeCompound> ownerTypeAnnos = new ListBuffer<Attribute.TypeCompound>(); 5.10 ListBuffer<Attribute.TypeCompound> lambdaTypeAnnos = new ListBuffer<Attribute.TypeCompound>(); 5.11
6.1 --- a/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Tue Aug 20 15:12:16 2013 -0700 6.2 +++ b/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Wed Aug 21 16:13:50 2013 -0700 6.3 @@ -1089,7 +1089,7 @@ 6.4 } 6.5 } 6.6 if (allowTypeAnnos) { 6.7 - TypeAnnotations.organizeTypeAnnotationsSignatures(syms, names, log, tree, annotate); 6.8 + TypeAnnotations.organizeTypeAnnotationsSignatures(syms, names, log, env, tree, annotate); 6.9 } 6.10 } 6.11
7.1 --- a/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Tue Aug 20 15:12:16 2013 -0700 7.2 +++ b/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Wed Aug 21 16:13:50 2013 -0700 7.3 @@ -89,7 +89,7 @@ 7.4 * deletion without notice.</b> 7.5 */ 7.6 public class JavacProcessingEnvironment implements ProcessingEnvironment, Closeable { 7.7 - Options options; 7.8 + private final Options options; 7.9 7.10 private final boolean printProcessorInfo; 7.11 private final boolean printRounds;
8.1 --- a/src/share/classes/com/sun/tools/javac/resources/compiler.properties Tue Aug 20 15:12:16 2013 -0700 8.2 +++ b/src/share/classes/com/sun/tools/javac/resources/compiler.properties Wed Aug 21 16:13:50 2013 -0700 8.3 @@ -2248,7 +2248,7 @@ 8.4 # TODO 308: make a better error message 8.5 # 0: unused 8.6 compiler.err.cant.annotate.nested.type=\ 8.7 - nested type cannot be annotated 8.8 + scoping construct for static nested type cannot be annotated 8.9 8.10 # 0: type, 1: type 8.11 compiler.err.incorrect.receiver.name=\
9.1 --- a/src/share/classes/com/sun/tools/javac/tree/Pretty.java Tue Aug 20 15:12:16 2013 -0700 9.2 +++ b/src/share/classes/com/sun/tools/javac/tree/Pretty.java Wed Aug 21 16:13:50 2013 -0700 9.3 @@ -944,10 +944,17 @@ 9.4 try { 9.5 if (tree.elemtype != null) { 9.6 print("new "); 9.7 - printTypeAnnotations(tree.annotations); 9.8 JCTree elem = tree.elemtype; 9.9 printBaseElementType(elem); 9.10 - boolean isElemAnnoType = elem instanceof JCAnnotatedType; 9.11 + 9.12 + if (!tree.annotations.isEmpty()) { 9.13 + print(' '); 9.14 + printTypeAnnotations(tree.annotations); 9.15 + } 9.16 + if (tree.elems != null) { 9.17 + print("[]"); 9.18 + } 9.19 + 9.20 int i = 0; 9.21 List<List<JCAnnotation>> da = tree.dimAnnotations; 9.22 for (List<JCExpression> l = tree.dims; l.nonEmpty(); l = l.tail) { 9.23 @@ -960,17 +967,7 @@ 9.24 printExpr(l.head); 9.25 print("]"); 9.26 } 9.27 - if (tree.elems != null) { 9.28 - if (isElemAnnoType) { 9.29 - print(' '); 9.30 - printTypeAnnotations(((JCAnnotatedType)tree.elemtype).annotations); 9.31 - } 9.32 - print("[]"); 9.33 - } 9.34 - if (isElemAnnoType) 9.35 - elem = ((JCAnnotatedType)elem).underlyingType; 9.36 - if (elem instanceof JCArrayTypeTree) 9.37 - printBrackets((JCArrayTypeTree) elem); 9.38 + printBrackets(elem); 9.39 } 9.40 if (tree.elems != null) { 9.41 print("{"); 9.42 @@ -1260,20 +1257,24 @@ 9.43 } 9.44 9.45 // prints the brackets of a nested array in reverse order 9.46 - private void printBrackets(JCArrayTypeTree tree) throws IOException { 9.47 - JCTree elem; 9.48 + // tree is either JCArrayTypeTree or JCAnnotatedTypeTree 9.49 + private void printBrackets(JCTree tree) throws IOException { 9.50 + JCTree elem = tree; 9.51 while (true) { 9.52 - elem = tree.elemtype; 9.53 if (elem.hasTag(ANNOTATED_TYPE)) { 9.54 JCAnnotatedType atype = (JCAnnotatedType) elem; 9.55 elem = atype.underlyingType; 9.56 - if (!elem.hasTag(TYPEARRAY)) break; 9.57 - print(' '); 9.58 - printTypeAnnotations(atype.annotations); 9.59 + if (elem.hasTag(TYPEARRAY)) { 9.60 + print(' '); 9.61 + printTypeAnnotations(atype.annotations); 9.62 + } 9.63 } 9.64 - print("[]"); 9.65 - if (!elem.hasTag(TYPEARRAY)) break; 9.66 - tree = (JCArrayTypeTree) elem; 9.67 + if (elem.hasTag(TYPEARRAY)) { 9.68 + print("[]"); 9.69 + elem = ((JCArrayTypeTree)elem).elemtype; 9.70 + } else { 9.71 + break; 9.72 + } 9.73 } 9.74 } 9.75 9.76 @@ -1378,22 +1379,15 @@ 9.77 9.78 public void visitAnnotatedType(JCAnnotatedType tree) { 9.79 try { 9.80 - if (tree.underlyingType.getKind() == JCTree.Kind.MEMBER_SELECT) { 9.81 + if (tree.underlyingType.hasTag(SELECT)) { 9.82 JCFieldAccess access = (JCFieldAccess) tree.underlyingType; 9.83 printExpr(access.selected, TreeInfo.postfixPrec); 9.84 print("."); 9.85 printTypeAnnotations(tree.annotations); 9.86 print(access.name); 9.87 - } else if (tree.underlyingType.getKind() == JCTree.Kind.ARRAY_TYPE) { 9.88 - JCArrayTypeTree array = (JCArrayTypeTree) tree.underlyingType; 9.89 + } else if (tree.underlyingType.hasTag(TYPEARRAY)) { 9.90 printBaseElementType(tree); 9.91 - print(' '); 9.92 - printTypeAnnotations(tree.annotations); 9.93 - print("[]"); 9.94 - JCExpression elem = array.elemtype; 9.95 - if (elem.hasTag(TYPEARRAY)) { 9.96 - printBrackets((JCArrayTypeTree) elem); 9.97 - } 9.98 + printBrackets(tree); 9.99 } else { 9.100 printTypeAnnotations(tree.annotations); 9.101 printExpr(tree.underlyingType);
10.1 --- a/test/tools/javac/annotations/typeAnnotations/classfile/CombinationsTargetTest2.java Tue Aug 20 15:12:16 2013 -0700 10.2 +++ b/test/tools/javac/annotations/typeAnnotations/classfile/CombinationsTargetTest2.java Wed Aug 21 16:13:50 2013 -0700 10.3 @@ -35,13 +35,16 @@ 10.4 // Test count helps identify test case in event of failure. 10.5 int testcount = 0; 10.6 10.7 - // Base test case template descriptions 10.8 + // Base test case template descriptions;true==annotations in code attribute. 10.9 enum srce { 10.10 src1("(repeating) type annotations on on field in method body",true), 10.11 src2("(repeating) type annotations on type parameters, bounds and type arguments", true), 10.12 src3("(repeating) type annotations on type parameters of class, method return value in method", true), 10.13 src4("(repeating) type annotations on field in anonymous class", false), 10.14 - src5("(repeating) type annotations on field in anonymous class", false); 10.15 + src5("(repeating) type annotations on field in anonymous class", false), 10.16 + src6("(repeating) type annotations on void method declaration", false), 10.17 + src7("(repeating) type annotations in use of instanceof", true), 10.18 + src8("(repeating) type annotations in use of instanceof in method", true); 10.19 10.20 String description; 10.21 Boolean local; 10.22 @@ -84,6 +87,12 @@ 10.23 test( 0, 8, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src1); 10.24 test( 2, 0, 2, 0, As, BDs, ABMix, "CLASS", et, ++testrun, srce.src5); 10.25 test( 0, 2, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src5); 10.26 + test( 0, 0, 2, 0, As, BDs, ABMix, "CLASS", et, ++testrun, srce.src6); 10.27 + test( 0, 0, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src6); 10.28 + test( 2, 0, 0, 0, As, BDs, ABMix, "CLASS", et, ++testrun, srce.src7); 10.29 + test( 0, 2, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src7); 10.30 + test( 4, 0, 0, 0, As, BDs, ABMix, "CLASS", et, ++testrun, srce.src8); 10.31 + test( 0, 4, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src8); 10.32 break; 10.33 case "FIELD": 10.34 test( 8, 0, 0, 0, As, BDs, ABMix, "CLASS", et, ++testrun, srce.src1); 10.35 @@ -121,18 +130,6 @@ 10.36 ", ABmix=" + ABmix + ", retention: " + rtn + ", anno2: " + 10.37 et2 + ", src=" + source + "\n " + source.description; 10.38 10.39 - if( 10.40 -// 8005681 - src1,2,3 - skip cases with repeated annotations on new, array, cast. 10.41 - (( source.equals(srce.src1) || source.equals(srce.src2) || 10.42 - source.equals(srce.src3)) && (ABmix || (Arepeats && BDrepeats))) 10.43 - // 8008928 - src4,5 - this change cause crash with t-a on anon class) 10.44 - || (source.equals(srce.src4) || source.equals(srce.src5)) 10.45 - ) { 10.46 - System.out.println(testDef + 10.47 - "\n 8005681-skip repeated annotations on new,array,cast"); 10.48 - return; 10.49 - } 10.50 - 10.51 println(testDef); 10.52 // Create test source and File. 10.53 String sourceString = sourceString(tname, rtn, et2, Arepeats, 10.54 @@ -178,9 +175,7 @@ 10.55 println("Pass"); 10.56 } 10.57 10.58 - // 10.59 // Source for test cases 10.60 - // 10.61 String sourceString(String testname, String retentn, String annot2, 10.62 Boolean Arepeats, Boolean BDrepeats, Boolean ABmix, 10.63 srce src) { 10.64 @@ -359,6 +354,63 @@ 10.65 hasInnerClass=true; 10.66 innerClassname="$1"; 10.67 break; 10.68 + case src6: // (repeating)annotations on void method declaration 10.69 + /* 10.70 + * class Test95{ 10.71 + * @A @A @B @B public void test() { }; 10.72 + * } 10.73 + */ 10.74 + source = new String( source + 10.75 + "// " + src.description + "\n" + 10.76 + "class "+ testname + "{\n" + 10.77 + " _As_ _Bs_ public void test() { }\n" + 10.78 + "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) + 10.79 + "\n\n"; 10.80 + hasInnerClass=false; 10.81 + break; 10.82 + case src7: // (repeating) type annotations in use of instanceof 10.83 + /* 10.84 + * class Test10{ 10.85 + * String data = "test"; 10.86 + * boolean dataIsString = ( data instanceof @A @B @A @B String); 10.87 + * } 10.88 + */ 10.89 + source = new String( source + 10.90 + "// " + src.description + "\n" + 10.91 + "class "+ testname + "{\n" + 10.92 + " String data = \"test\";\n" + 10.93 + " boolean dataIsString = ( data instanceof _As_ _Bs_ String);\n" + 10.94 + "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) + 10.95 + "\n\n"; 10.96 + hasInnerClass=false; 10.97 + break; 10.98 + case src8: // (repeating) type annotations in use of instanceof 10.99 + /* 10.100 + * class Test20{ 10.101 + * String data = "test"; 10.102 + * Boolean isString() { 10.103 + * if( data instanceof @A @B @A @B String ) 10.104 + * return true; 10.105 + * else 10.106 + * return( data instanceof @A @B @A @B String ); 10.107 + * } 10.108 + * } 10.109 + */ 10.110 + source = new String( source + 10.111 + "// " + src.description + "\n" + 10.112 + "class "+ testname + "{\n" + 10.113 + " String data = \"test\";\n" + 10.114 + " Boolean isString() { \n" + 10.115 + " if( data instanceof _As_ _Bs_ String )\n" + 10.116 + " return true;\n" + 10.117 + " else\n" + 10.118 + " return( data instanceof _As_ _Bs_ String );\n" + 10.119 + " }\n" + 10.120 + "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) + 10.121 + "\n\n"; 10.122 + hasInnerClass=false; 10.123 + break; 10.124 + 10.125 } 10.126 return imports + source; 10.127 }
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 11.2 +++ b/test/tools/javac/annotations/typeAnnotations/failures/DummyProcessor.java Wed Aug 21 16:13:50 2013 -0700 11.3 @@ -0,0 +1,43 @@ 11.4 +/* 11.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 11.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 11.7 + * 11.8 + * This code is free software; you can redistribute it and/or modify it 11.9 + * under the terms of the GNU General Public License version 2 only, as 11.10 + * published by the Free Software Foundation. 11.11 + * 11.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 11.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11.15 + * version 2 for more details (a copy is included in the LICENSE file that 11.16 + * accompanied this code). 11.17 + * 11.18 + * You should have received a copy of the GNU General Public License version 11.19 + * 2 along with this work; if not, write to the Free Software Foundation, 11.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 11.21 + * 11.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 11.23 + * or visit www.oracle.com if you need additional information or have any 11.24 + * questions. 11.25 + */ 11.26 + 11.27 +import javax.annotation.processing.*; 11.28 +import javax.lang.model.SourceVersion; 11.29 +import javax.lang.model.element.TypeElement; 11.30 + 11.31 +import java.util.Set; 11.32 + 11.33 +/* A simple annotation processor. */ 11.34 +@SupportedAnnotationTypes("*") 11.35 +public class DummyProcessor extends AbstractProcessor { 11.36 + @Override 11.37 + public SourceVersion getSupportedSourceVersion() { 11.38 + return SourceVersion.latest(); 11.39 + } 11.40 + 11.41 + @Override 11.42 + public final boolean process(Set<? extends TypeElement> annotations, 11.43 + RoundEnvironment roundEnv) { 11.44 + return false; 11.45 + } 11.46 +}
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 12.2 +++ b/test/tools/javac/annotations/typeAnnotations/failures/T8020715.java Wed Aug 21 16:13:50 2013 -0700 12.3 @@ -0,0 +1,49 @@ 12.4 +/* 12.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 12.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 12.7 + * 12.8 + * This code is free software; you can redistribute it and/or modify it 12.9 + * under the terms of the GNU General Public License version 2 only, as 12.10 + * published by the Free Software Foundation. 12.11 + * 12.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 12.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12.15 + * version 2 for more details (a copy is included in the LICENSE file that 12.16 + * accompanied this code). 12.17 + * 12.18 + * You should have received a copy of the GNU General Public License version 12.19 + * 2 along with this work; if not, write to the Free Software Foundation, 12.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 12.21 + * 12.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 12.23 + * or visit www.oracle.com if you need additional information or have any 12.24 + * questions. 12.25 + */ 12.26 + 12.27 +/* 12.28 + * @test 12.29 + * @summary Regression: compiling program with lambda crashed compiler 12.30 + * @bug 8020715 12.31 + * @compile T8020715.java 12.32 + */ 12.33 +class T8020715 { 12.34 + // This crashed. 12.35 + private static void makeTask1() { 12.36 + class LocalClass { 12.37 + private Runnable r = () -> {}; 12.38 + } 12.39 + } 12.40 + 12.41 + // This crashed, too. 12.42 + private void makeTask2() { 12.43 + class LocalClass { 12.44 + private Runnable r = () -> {}; 12.45 + } 12.46 + } 12.47 + 12.48 + // This is fine. 12.49 + private class InnerClass { 12.50 + private Runnable r = () -> {}; 12.51 + } 12.52 +}
13.1 --- a/test/tools/javac/annotations/typeAnnotations/referenceinfos/Constructors.java Tue Aug 20 15:12:16 2013 -0700 13.2 +++ b/test/tools/javac/annotations/typeAnnotations/referenceinfos/Constructors.java Wed Aug 21 16:13:50 2013 -0700 13.3 @@ -85,4 +85,24 @@ 13.4 " } } }"; 13.5 } 13.6 13.7 + @TADescriptions({ 13.8 + @TADescription(annotation = "TA", type = CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT, 13.9 + typeIndex = 0, offset = 4), 13.10 + @TADescription(annotation = "TB", type = CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT, 13.11 + typeIndex = 0, offset = 0) 13.12 + }) 13.13 + public String generic1() { 13.14 + return "class Test { <T> Test(int i) { new <@TA T>Test(); }" + 13.15 + " <T> Test() { <@TB String>this(0); } }"; 13.16 + } 13.17 + 13.18 + @TADescriptions({ 13.19 + @TADescription(annotation = "TA", type = CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT, 13.20 + typeIndex = 0, offset = 0) 13.21 + }) 13.22 + public String generic2() { 13.23 + return "class Super { <T> Super(int i) { } } " + 13.24 + "class Test extends Super { <T> Test() { <@TA String>super(0); } }"; 13.25 + } 13.26 + 13.27 }
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 14.2 +++ b/test/tools/javac/tree/TypeAnnotationsPretty.java Wed Aug 21 16:13:50 2013 -0700 14.3 @@ -0,0 +1,170 @@ 14.4 +/* 14.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 14.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 14.7 + * 14.8 + * This code is free software; you can redistribute it and/or modify it 14.9 + * under the terms of the GNU General Public License version 2 only, as 14.10 + * published by the Free Software Foundation. 14.11 + * 14.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 14.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14.15 + * version 2 for more details (a copy is included in the LICENSE file that 14.16 + * accompanied this code). 14.17 + * 14.18 + * You should have received a copy of the GNU General Public License version 14.19 + * 2 along with this work; if not, write to the Free Software Foundation, 14.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 14.21 + * 14.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 14.23 + * or visit www.oracle.com if you need additional information or have any 14.24 + * questions. 14.25 + */ 14.26 + 14.27 +/* 14.28 + * @test 14.29 + * @bug 1234567 14.30 + * @summary test Pretty print of type annotations 14.31 + * @author wmdietl 14.32 + */ 14.33 + 14.34 +import com.sun.source.tree.ClassTree; 14.35 +import com.sun.source.tree.CompilationUnitTree; 14.36 +import com.sun.tools.javac.api.JavacTaskImpl; 14.37 +import com.sun.tools.javac.tree.JCTree; 14.38 + 14.39 +import java.io.IOException; 14.40 +import java.net.URI; 14.41 +import java.util.Arrays; 14.42 +import java.util.List; 14.43 +import java.util.LinkedList; 14.44 + 14.45 +import javax.tools.JavaCompiler; 14.46 +import javax.tools.JavaFileObject; 14.47 +import javax.tools.SimpleJavaFileObject; 14.48 +import javax.tools.ToolProvider; 14.49 + 14.50 +public class TypeAnnotationsPretty { 14.51 + private final JavaCompiler tool; 14.52 + 14.53 + TypeAnnotationsPretty() { 14.54 + tool = ToolProvider.getSystemJavaCompiler(); 14.55 + } 14.56 + 14.57 + private List<String> matches = new LinkedList<String>(); 14.58 + private List<String> mismatches = new LinkedList<String>(); 14.59 + 14.60 + public static void main(String... args) throws Exception { 14.61 + TypeAnnotationsPretty tap = new TypeAnnotationsPretty(); 14.62 + 14.63 + tap.runField("@TA()\nObject cls = null"); 14.64 + tap.runField("@TA()\nObject cls = new @TA() Object()"); 14.65 + 14.66 + tap.runField("@TA()\nList<@TB() Object> cls = null"); 14.67 + tap.runField("@TA()\nList<@TB() Object> cls = new @TA() LinkedList<@TB() Object>()"); 14.68 + 14.69 + tap.runField("Class[] cls = null"); 14.70 + tap.runField("@TA()\nClass[] cls = null"); 14.71 + tap.runField("Class @TA() [] cls = null"); 14.72 + tap.runField("@TA()\nClass @TB() [] cls = null"); 14.73 + 14.74 + tap.runField("Class[] cls = new Class[]{Object.class}"); 14.75 + tap.runField("@TA()\nClass[] cls = new @TA() Class[]{Object.class}"); 14.76 + tap.runField("Class @TB() [] cls = new Class @TB() []{Object.class}"); 14.77 + tap.runField("@TA()\nClass @TB() [] cls = new @TA() Class @TB() []{Object.class}"); 14.78 + tap.runField("@TA()\nClass @TB() [] @TC() [] cls = new @TA() Class @TB() [10] @TC() []"); 14.79 + tap.runField("Class @TB() [] @TC() [] cls = new Class @TB() [10] @TC() []"); 14.80 + tap.runField("@TA()\nClass @TB() [] @TC() [] @TD() [] cls = new @TA() Class @TB() [10] @TC() [] @TD() []"); 14.81 + 14.82 + tap.runMethod("\n@TA()\nObject test(@TB()\nList<@TC() String> p) {\n" + 14.83 + " return null;\n" + 14.84 + "}"); 14.85 + 14.86 + 14.87 + if (!tap.matches.isEmpty()) { 14.88 + for (String m : tap.matches) 14.89 + System.out.println(m); 14.90 + } 14.91 + if (!tap.mismatches.isEmpty()) { 14.92 + for (String mm : tap.mismatches) 14.93 + System.err.println(mm + "\n"); 14.94 + throw new RuntimeException("Tests failed!"); 14.95 + } 14.96 + } 14.97 + 14.98 + private static final String prefix = 14.99 + "import java.lang.annotation.*;" + 14.100 + "import java.util.*;" + 14.101 + "public class Test {"; 14.102 + 14.103 + private static final String postfix = 14.104 + "@Target(ElementType.TYPE_USE)" + 14.105 + "@interface TA {}" + 14.106 + "@Target(ElementType.TYPE_USE)" + 14.107 + "@interface TB {}" + 14.108 + "@Target(ElementType.TYPE_USE)" + 14.109 + "@interface TC {}" + 14.110 + "@Target(ElementType.TYPE_USE)" + 14.111 + "@interface TD {}"; 14.112 + 14.113 + 14.114 + private void runField(String code) throws IOException { 14.115 + String src = prefix + 14.116 + code + "; }" + 14.117 + postfix; 14.118 + 14.119 + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, 14.120 + null, Arrays.asList(new MyFileObject(src))); 14.121 + 14.122 + 14.123 + for (CompilationUnitTree cut : ct.parse()) { 14.124 + JCTree.JCVariableDecl var = 14.125 + (JCTree.JCVariableDecl) ((ClassTree) cut.getTypeDecls().get(0)).getMembers().get(0); 14.126 + 14.127 + if (!code.equals(var.toString())) { 14.128 + mismatches.add("Expected: " + code + 14.129 + "\nObtained: " + var.toString()); 14.130 + } else { 14.131 + matches.add("Passed: " + code); 14.132 + } 14.133 + } 14.134 + } 14.135 + 14.136 + private void runMethod(String code) throws IOException { 14.137 + String src = prefix + 14.138 + code + "}" + 14.139 + postfix; 14.140 + 14.141 + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, 14.142 + null, Arrays.asList(new MyFileObject(src))); 14.143 + 14.144 + 14.145 + for (CompilationUnitTree cut : ct.parse()) { 14.146 + JCTree.JCMethodDecl var = 14.147 + (JCTree.JCMethodDecl) ((ClassTree) cut.getTypeDecls().get(0)).getMembers().get(0); 14.148 + 14.149 + if (!code.equals(var.toString())) { 14.150 + mismatches.add("Expected: " + code + 14.151 + "\nObtained: " + var.toString()); 14.152 + } else { 14.153 + matches.add("Passed: " + code); 14.154 + } 14.155 + } 14.156 + } 14.157 +} 14.158 + 14.159 + 14.160 +class MyFileObject extends SimpleJavaFileObject { 14.161 + 14.162 + private String text; 14.163 + 14.164 + public MyFileObject(String text) { 14.165 + super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); 14.166 + this.text = text; 14.167 + } 14.168 + 14.169 + @Override 14.170 + public CharSequence getCharContent(boolean ignoreEncodingErrors) { 14.171 + return text; 14.172 + } 14.173 +}