# HG changeset patch # User aeremeev # Date 1427268554 -10800 # Node ID c03745b71c70b8a608946990c4ccf46c65ee1db3 # Parent 47544495db2d3d2edf0f85862d8715592fdb919f 8049238: Implement classfile tests for Signature attribute Reviewed-by: jjg, shurailine, anazarov diff -r 47544495db2d -r c03745b71c70 langtools/test/tools/javac/classfiles/attributes/Signature/ConstructorTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/classfiles/attributes/Signature/ConstructorTest.java Wed Mar 25 10:29:14 2015 +0300 @@ -0,0 +1,170 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8049238 + * @summary Checks Signature attribute for constructors. + * @library /tools/lib /tools/javac/lib ../lib + * @build TestBase TestResult InMemoryFileManager ToolBox + * @build ConstructorTest Driver ExpectedSignature ExpectedSignatureContainer + * @run main Driver ConstructorTest + */ + +import java.lang.ref.ReferenceQueue; +import java.util.*; + +@ExpectedSignature(descriptor = "ConstructorTest", signature = "Ljava/lang/Object;") +public class ConstructorTest { + + @ExpectedSignature(descriptor = "(java.lang.Object, boolean)", signature = "(TT;Z)V") + ConstructorTest(T a, boolean b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, byte)", signature = "(TT;B)V") + ConstructorTest(T a, byte b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, char)", signature = "(TT;C)V") + ConstructorTest(T a, char b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, short)", signature = "(TT;S)V") + ConstructorTest(T a, short b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, int)", signature = "(TT;I)V") + ConstructorTest(T a, int b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, long)", signature = "(TT;J)V") + ConstructorTest(T a, long b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, float)", signature = "(TT;F)V") + ConstructorTest(T a, float b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, double)", signature = "(TT;D)V") + ConstructorTest(T a, double b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, java.lang.Runnable)", signature = "(TT;Ljava/lang/Runnable;)V") + ConstructorTest(T a, Runnable r) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, boolean[])", signature = "(TT;[Z)V") + ConstructorTest(T a, boolean[] b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, byte[])", signature = "(TT;[B)V") + ConstructorTest(T a, byte[] b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, char[])", signature = "(TT;[C)V") + ConstructorTest(T a, char[] b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, short[])", signature = "(TT;[S)V") + ConstructorTest(T a, short[] b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, int[])", signature = "(TT;[I)V") + ConstructorTest(T a, int[] b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, long[])", signature = "(TT;[J)V") + ConstructorTest(T a, long[] b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, float[])", signature = "(TT;[F)V") + ConstructorTest(T a, float[] b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, double[])", signature = "(TT;[D)V") + ConstructorTest(T a, double[] b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, java.lang.Runnable[])", signature = "(TT;[Ljava/lang/Runnable;)V") + ConstructorTest(T a, Runnable[] r) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object[])", signature = "([TT;)V") + ConstructorTest(T[] a) { + } + + @ExpectedSignature(descriptor = "(java.lang.Runnable[])", + signature = "([TT;)V") + ConstructorTest(T...a) { + } + + @ExpectedSignature(descriptor = "(java.util.Map)", signature = "(Ljava/util/Map<**>;)V") + ConstructorTest(Map a) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object)", signature = "(TT;)V") + ConstructorTest(T a) { + } + + @ExpectedSignature(descriptor = "(java.util.Set, java.util.Set)", + signature = ";>(TE;TE;)V") + > ConstructorTest(E a, E b) { + } + + @ExpectedSignature(descriptor = "(java.lang.ref.ReferenceQueue, java.lang.ref.ReferenceQueue)", + signature = ";:Ljava/util/Map<-TT;+TT;>;>(TE;TE;)V") + & Map> ConstructorTest(E a, E b) { + } + + @ExpectedSignature(descriptor = "(java.util.List)", signature = "(Ljava/util/List<+TT;>;)V") + ConstructorTest(List b) { + } + + @ExpectedSignature(descriptor = "(java.util.Set)", signature = "(Ljava/util/Set<-TT;>;)V") + ConstructorTest(Set b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Runnable)", signature = "(TE;)V") + ConstructorTest(E a) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, java.lang.Object)", signature = "(TT;TE;)V") + ConstructorTest(T a, E b) { + } + + // no Signature attribute + ConstructorTest(boolean b) { + } + + // no Signature attribute + ConstructorTest(HashMap a) { + } + + // no Signature attribute + ConstructorTest(boolean[] b) { + } + + // no Signature attribute + ConstructorTest(HashMap[] a) { + } +} diff -r 47544495db2d -r c03745b71c70 langtools/test/tools/javac/classfiles/attributes/Signature/Driver.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/classfiles/attributes/Signature/Driver.java Wed Mar 25 10:29:14 2015 +0300 @@ -0,0 +1,239 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import com.sun.tools.classfile.*; +import com.sun.tools.classfile.Field; +import com.sun.tools.classfile.Method; + +import java.io.File; +import java.io.FilenameFilter; +import java.lang.reflect.*; +import java.util.*; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.function.Supplier; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * The main class of Signature tests. + * Driver reads golden data of each class member that must have a Signature attribute, + * after that the class compares expected data with actual one. + * + * Example of usage Driver: + * java Driver Test + * + * Each member of the class Test should have @ExpectedSignature annotations + * if it must have the Signature attribute. Anonymous class cannot be annotated. + * So its enclosing class should be annotated and method isAnonymous + * of ExpectedSignature must return true. + */ +public class Driver extends TestResult { + + private final static String ACC_BRIDGE = "ACC_BRIDGE"; + + private final String topLevelClassName; + private final File[] files; + + public Driver(String topLevelClassName) { + this.topLevelClassName = topLevelClassName; + // Get top level class and all inner classes. + FilenameFilter filter = (dir, file) -> + file.equals(topLevelClassName + ".class") + || file.matches(topLevelClassName + "\\$.*\\.class"); + files = getClassDir().listFiles(filter); + } + + private boolean isAnonymous(String className) { + return className.matches(".*\\$\\d+$"); + } + + private Class getEnclosingClass(String className) throws ClassNotFoundException { + return Class.forName(className.replaceFirst("\\$\\d+$", "")); + } + + private ExpectedSignature getExpectedClassSignature(String className, Class clazz) + throws ClassNotFoundException { + // anonymous class cannot be annotated, so information about anonymous class + // is located in its enclosing class. + boolean isAnonymous = isAnonymous(className); + clazz = isAnonymous ? getEnclosingClass(className) : clazz; + return Stream.of(clazz.getAnnotationsByType(ExpectedSignature.class)) + .filter(s -> s.isAnonymous() == isAnonymous) + .collect(Collectors.toMap(ExpectedSignature::descriptor, Function.identity())) + .get(className); + } + + // Class.getName() cannot be used here, because the method can rely on signature attribute. + private Map getClassExpectedSignature(String className, Class clazz) + throws ClassNotFoundException { + Map classSignatures = new HashMap<>(); + ExpectedSignature classSignature = getExpectedClassSignature(className, clazz); + if (classSignature != null) { + classSignatures.put(className, classSignature); + } + return classSignatures; + } + + private Map getExpectedExecutableSignatures(Executable[] executables, + Predicate filterBridge) { + return Stream.of(executables) + .filter(filterBridge) + .map(e -> e.getAnnotation(ExpectedSignature.class)) + .filter(Objects::nonNull) + .collect(Collectors.toMap(ExpectedSignature::descriptor, Function.identity())); + } + + private Map getExpectedMethodSignatures(Class clazz) { + Map methodSignatures = + getExpectedExecutableSignatures(clazz.getDeclaredMethods(), + m -> !((java.lang.reflect.Method) m).isBridge()); + methodSignatures.putAll( + getExpectedExecutableSignatures(clazz.getDeclaredConstructors(), + m -> true)); + return methodSignatures; + } + + private Map getExpectedFieldSignatures(Class clazz) { + return Stream.of(clazz.getDeclaredFields()) + .map(f -> f.getAnnotation(ExpectedSignature.class)) + .filter(Objects::nonNull) + .collect(Collectors.toMap(ExpectedSignature::descriptor, Function.identity())); + } + + public void test() throws TestFailedException { + try { + addTestCase("Source is " + topLevelClassName + ".java"); + assertTrue(files.length > 0, "No class files found"); + for (File file : files) { + try { + String className = file.getName().replace(".class", ""); + Class clazz = Class.forName(className); + printf("Testing class %s\n", className); + ClassFile classFile = readClassFile(file); + + // test class signature + testAttribute( + className, + classFile, + () -> (Signature_attribute) classFile.getAttribute(Attribute.Signature), + getClassExpectedSignature(className, clazz).get(className)); + + testFields(getExpectedFieldSignatures(clazz), classFile); + + testMethods(getExpectedMethodSignatures(clazz), classFile); + } catch (Exception e) { + addFailure(e); + } + } + } catch (Exception e) { + addFailure(e); + } finally { + checkStatus(); + } + } + + private void checkAllMembersFound(Set found, Map signatures, String message) { + if (signatures != null) { + checkContains(found, + signatures.values().stream() + .map(ExpectedSignature::descriptor) + .collect(Collectors.toSet()), + message); + } + } + + private void testMethods(Map expectedSignatures, ClassFile classFile) + throws ConstantPoolException, Descriptor.InvalidDescriptor { + String className = classFile.getName(); + Set foundMethods = new HashSet<>(); + for (Method method : classFile.methods) { + String methodName = getMethodName(classFile, method); + printf("Testing method %s\n", methodName); + if (method.access_flags.getMethodFlags().contains(ACC_BRIDGE)) { + printf("Bridge method is skipped : %s\n", methodName); + continue; + } + testAttribute( + methodName, + classFile, + () -> (Signature_attribute) method.attributes.get(Attribute.Signature), + expectedSignatures.get(methodName)); + foundMethods.add(methodName); + } + checkAllMembersFound(foundMethods, expectedSignatures, + "Checking that all methods of class " + className + " with Signature attribute found"); + } + + private String getMethodName(ClassFile classFile, Method method) + throws ConstantPoolException, Descriptor.InvalidDescriptor { + return String.format("%s%s", + method.getName(classFile.constant_pool), + method.descriptor.getParameterTypes(classFile.constant_pool)); + } + + private void testFields(Map expectedSignatures, ClassFile classFile) + throws ConstantPoolException { + String className = classFile.getName(); + Set foundFields = new HashSet<>(); + for (Field field : classFile.fields) { + String fieldName = field.getName(classFile.constant_pool); + printf("Testing field %s\n", fieldName); + testAttribute( + fieldName, + classFile, + () -> (Signature_attribute) field.attributes.get(Attribute.Signature), + expectedSignatures.get(fieldName)); + foundFields.add(fieldName); + } + checkAllMembersFound(foundFields, expectedSignatures, + "Checking that all fields of class " + className + " with Signature attribute found"); + } + + private void testAttribute( + String memberName, + ClassFile classFile, + Supplier sup, + ExpectedSignature expectedSignature) + throws ConstantPoolException { + + Signature_attribute attribute = sup.get(); + if (expectedSignature != null && checkNotNull(attribute, memberName + " must have attribute")) { + checkEquals(classFile.constant_pool.getUTF8Value(attribute.attribute_name_index), + "Signature", "Attribute's name : " + memberName); + checkEquals(attribute.attribute_length, 2, "Attribute's length : " + memberName); + checkEquals(attribute.getSignature(classFile.constant_pool), + expectedSignature.signature(), + "Testing signature of : " + memberName); + } else { + checkNull(attribute, memberName + " must not have attribute"); + } + } + + public static void main(String[] args) throws TestFailedException { + if (args.length != 1) { + throw new IllegalArgumentException("Usage: Driver "); + } + new Driver(args[0]).test(); + } +} \ No newline at end of file diff -r 47544495db2d -r c03745b71c70 langtools/test/tools/javac/classfiles/attributes/Signature/EnumTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/classfiles/attributes/Signature/EnumTest.java Wed Mar 25 10:29:14 2015 +0300 @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8049238 + * @summary Checks Signature attribute for enum. + * @library /tools/lib /tools/javac/lib ../lib + * @build TestBase TestResult InMemoryFileManager ToolBox + * @build EnumTest Driver ExpectedSignature ExpectedSignatureContainer + * @run main Driver EnumTest + */ + +@ExpectedSignature(descriptor = "EnumTest", signature = "Ljava/lang/Enum;") +public enum EnumTest {; + // see 8026480 + @ExpectedSignature(descriptor = "(java.lang.String, int)", signature = "()V") + private EnumTest() {} +} \ No newline at end of file diff -r 47544495db2d -r c03745b71c70 langtools/test/tools/javac/classfiles/attributes/Signature/ExceptionTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/classfiles/attributes/Signature/ExceptionTest.java Wed Mar 25 10:29:14 2015 +0300 @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8049238 + * @summary Checks Signature attribute for methods which throw exceptions. + * @library /tools/lib /tools/javac/lib ../lib + * @build TestBase TestResult InMemoryFileManager ToolBox + * @build ExceptionTest Driver ExpectedSignature ExpectedSignatureContainer + * @run main Driver ExceptionTest + */ + +import java.io.IOError; +import java.io.IOException; + +@ExpectedSignature(descriptor = "ExceptionTest", + signature = "Ljava/lang/Object;") +public class ExceptionTest { + + @ExpectedSignature(descriptor = "()", signature = "()V^TE;") + ExceptionTest() throws E { + } + + @ExpectedSignature(descriptor = "(int)", + signature = "(I)V^Ljava/io/IOException;^TE;^Ljava/io/IOError;") + ExceptionTest(int a) throws IOException, E, IOError { + } + + @ExpectedSignature(descriptor = "(long)", signature = "(J)V^TExc;") + ExceptionTest(long a) throws Exc { + } + + @ExpectedSignature(descriptor = "(byte)", signature = "(B)V^Ljava/io/IOError;^TExc;^Ljava/io/IOException;") + ExceptionTest(byte a) throws IOError, Exc, IOException { + } + + @ExpectedSignature(descriptor = "(java.lang.RuntimeException)", signature = "(TExc;)V") + ExceptionTest(Exc a) throws IOException { + } + + // no Signature attribute + ExceptionTest(String a) throws IOError { + } + + void noSignatureAttributeMethod() throws IOException { + } + + @ExpectedSignature(descriptor = "genericMethod(int)", signature = "(I)V^TExc;") + void genericMethod(int a) throws Exc { + } + + @ExpectedSignature(descriptor = "genericMethod(long)", signature = "(J)V^TExc;^Ljava/io/IOException;") + void genericMethod(long a) throws Exc, IOException { + } + + @ExpectedSignature(descriptor = "genericMethod(java.lang.RuntimeException)", signature = "(TExc;)V") + void genericMethod(Exc a) throws IOError { + } + + static void staticNoSignatureAttributeMethod() throws IOException { + } + + @ExpectedSignature(descriptor = "staticGenericMethod(int)", + signature = "(I)V^TE;") + static void staticGenericMethod(int a) throws E { + } + + @ExpectedSignature(descriptor = "staticGenericMethod(long)", + signature = "(J)V^Ljava/io/IOError;^TE;^Ljava/io/IOException;") + static void staticGenericMethod(long a) throws IOError, E, IOException { + } + + @ExpectedSignature(descriptor = "staticGenericMethod(java.lang.Exception)", + signature = "(TE;)V") + static void staticGenericMethod(E a) throws IOError { + } +} diff -r 47544495db2d -r c03745b71c70 langtools/test/tools/javac/classfiles/attributes/Signature/ExpectedSignature.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/classfiles/attributes/Signature/ExpectedSignature.java Wed Mar 25 10:29:14 2015 +0300 @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.lang.annotation.Repeatable; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Repeatable(ExpectedSignatureContainer.class) +@Retention(RetentionPolicy.RUNTIME) +public @interface ExpectedSignature { + boolean isAnonymous() default false; + String descriptor(); + String signature(); +} \ No newline at end of file diff -r 47544495db2d -r c03745b71c70 langtools/test/tools/javac/classfiles/attributes/Signature/ExpectedSignatureContainer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/classfiles/attributes/Signature/ExpectedSignatureContainer.java Wed Mar 25 10:29:14 2015 +0300 @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface ExpectedSignatureContainer { + ExpectedSignature[] value(); +} \ No newline at end of file diff -r 47544495db2d -r c03745b71c70 langtools/test/tools/javac/classfiles/attributes/Signature/FieldTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/classfiles/attributes/Signature/FieldTest.java Wed Mar 25 10:29:14 2015 +0300 @@ -0,0 +1,206 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8049238 + * @summary Checks Signature attribute for fields. + * @library /tools/lib /tools/javac/lib ../lib + * @build TestBase TestResult InMemoryFileManager ToolBox + * @build FieldTest Driver ExpectedSignature ExpectedSignatureContainer + * @run main Driver FieldTest + */ + +import java.util.Comparator; +import java.util.List; +import java.util.Map; + +@ExpectedSignature(descriptor = "FieldTest", signature = "Ljava/lang/Object;") +public class FieldTest { + + @ExpectedSignature(descriptor = "typeInList", signature = "Ljava/util/List;") + List typeInList; + + @ExpectedSignature(descriptor = "boundsType", signature = "Ljava/util/List;>;") + List> boundsType; + + @ExpectedSignature(descriptor = "type", signature = "TT;") + T type; + + @ExpectedSignature(descriptor = "typeInArray", signature = "[TT;") + T[] typeInArray; + + @ExpectedSignature(descriptor = "byteArrayInList", signature = "Ljava/util/List<[B>;") + List byteArrayInList; + + @ExpectedSignature(descriptor = "shortArrayInList", signature = "Ljava/util/List<[S>;") + List shortArrayInList; + + @ExpectedSignature(descriptor = "intArrayInList", signature = "Ljava/util/List<[I>;") + List intArrayInList; + + @ExpectedSignature(descriptor = "longArrayInList", signature = "Ljava/util/List<[J>;") + List longArrayInList; + + @ExpectedSignature(descriptor = "charArrayInList", signature = "Ljava/util/List<[C>;") + List charArrayInList; + + @ExpectedSignature(descriptor = "booleanArrayInList", signature = "Ljava/util/List<[Z>;") + List booleanArrayInList; + + @ExpectedSignature(descriptor = "floatArrayInList", signature = "Ljava/util/List<[F>;") + List floatArrayInList; + + @ExpectedSignature(descriptor = "doubleArrayInList", signature = "Ljava/util/List<[D>;") + List doubleArrayInList; + + @ExpectedSignature(descriptor = "integerInList", signature = "Ljava/util/List;") + List integerInList; + + @ExpectedSignature(descriptor = "typeInMultiArray", signature = "[[TT;") + T[][] typeInMultiArray; + + @ExpectedSignature(descriptor = "arrayOfClasses", signature = "[Ljava/util/List;") + List[] arrayOfClasses; + + @ExpectedSignature(descriptor = "extendsWildCard", signature = "Ljava/util/List<+TT;>;") + List extendsWildCard; + + @ExpectedSignature(descriptor = "superWildCard", signature = "Ljava/util/Comparator<-TT;>;") + Comparator superWildCard; + + @ExpectedSignature(descriptor = "extendsSuperWildCard", + signature = "Ljava/util/List<+Ljava/util/Comparator<-TT;>;>;") + List> extendsSuperWildCard; + + @ExpectedSignature(descriptor = "wildCard", signature = "Ljava/util/Comparator<*>;") + Comparator wildCard; + + @ExpectedSignature(descriptor = "boundsBooleanArray", signature = "Ljava/util/Map<+[Z-[Z>;") + Map boundsBooleanArray; + + @ExpectedSignature(descriptor = "boundsByteArray", signature = "Ljava/util/Map<+[B-[B>;") + Map boundsByteArray; + + @ExpectedSignature(descriptor = "boundsShortArray", signature = "Ljava/util/Map<+[S-[S>;") + Map boundsShortArray; + + @ExpectedSignature(descriptor = "boundsIntArray", signature = "Ljava/util/Map<+[I-[I>;") + Map boundsIntArray; + + @ExpectedSignature(descriptor = "boundsLongArray", signature = "Ljava/util/Map<+[J-[J>;") + Map boundsLongArray; + + @ExpectedSignature(descriptor = "boundsCharArray", signature = "Ljava/util/Map<+[C-[C>;") + Map boundsCharArray; + + @ExpectedSignature(descriptor = "boundsFloatArray", signature = "Ljava/util/Map<+[F-[F>;") + Map boundsFloatArray; + + @ExpectedSignature(descriptor = "boundsDoubleArray", signature = "Ljava/util/Map<+[D-[D>;") + Map boundsDoubleArray; + + @ExpectedSignature(descriptor = "boundsObjectArray", + signature = "Ljava/util/Map<+[Ljava/lang/Object;-[Ljava/lang/Object;>;") + Map boundsObjectArray; + + boolean booleanNoSignatureAttribute; + byte byteNoSignatureAttribute; + char charNoSignatureAttribute; + short shortNoSignatureAttribute; + int intNoSignatureAttribute; + long longNoSignatureAttribute; + float floatNoSignatureAttribute; + double doubleNoSignatureAttribute; + + List listNoSignatureAttribute; + + @ExpectedSignature(descriptor = "staticByteArrayInList", signature = "Ljava/util/List<[B>;") + static List staticByteArrayInList; + + @ExpectedSignature(descriptor = "staticShortArrayInList", signature = "Ljava/util/List<[S>;") + static List staticShortArrayInList; + + @ExpectedSignature(descriptor = "staticIntArrayInList", signature = "Ljava/util/List<[I>;") + static List staticIntArrayInList; + + @ExpectedSignature(descriptor = "staticLongArrayInList", signature = "Ljava/util/List<[J>;") + static List staticLongArrayInList; + + @ExpectedSignature(descriptor = "staticCharArrayInList", signature = "Ljava/util/List<[C>;") + static List staticCharArrayInList; + + @ExpectedSignature(descriptor = "staticBooleanArrayInList", signature = "Ljava/util/List<[Z>;") + static List staticBooleanArrayInList; + + @ExpectedSignature(descriptor = "staticFloatArrayInList", signature = "Ljava/util/List<[F>;") + static List staticFloatArrayInList; + + @ExpectedSignature(descriptor = "staticDoubleArrayInList", signature = "Ljava/util/List<[D>;") + static List staticDoubleArrayInList; + + @ExpectedSignature(descriptor = "staticIntegerInList", signature = "Ljava/util/List;") + static List staticIntegerInList; + + @ExpectedSignature(descriptor = "staticWildCard", signature = "Ljava/util/Comparator<*>;") + static Comparator staticWildCard; + + @ExpectedSignature(descriptor = "staticBoundsBooleanArray", signature = "Ljava/util/Map<+[Z-[Z>;") + static Map staticBoundsBooleanArray; + + @ExpectedSignature(descriptor = "staticBoundsByteArray", signature = "Ljava/util/Map<+[B-[B>;") + static Map staticBoundsByteArray; + + @ExpectedSignature(descriptor = "staticBoundsShortArray", signature = "Ljava/util/Map<+[S-[S>;") + static Map staticBoundsShortArray; + + @ExpectedSignature(descriptor = "staticBoundsIntArray", signature = "Ljava/util/Map<+[I-[I>;") + static Map staticBoundsIntArray; + + @ExpectedSignature(descriptor = "staticBoundsLongArray", signature = "Ljava/util/Map<+[J-[J>;") + static Map staticBoundsLongArray; + + @ExpectedSignature(descriptor = "staticBoundsCharArray", signature = "Ljava/util/Map<+[C-[C>;") + static Map staticBoundsCharArray; + + @ExpectedSignature(descriptor = "staticBoundsFloatArray", signature = "Ljava/util/Map<+[F-[F>;") + static Map staticBoundsFloatArray; + + @ExpectedSignature(descriptor = "staticBoundsDoubleArray", signature = "Ljava/util/Map<+[D-[D>;") + static Map staticBoundsDoubleArray; + + @ExpectedSignature(descriptor = "staticBoundsObjectArray", + signature = "Ljava/util/Map<+[Ljava/lang/Object;-[Ljava/lang/Object;>;") + static Map staticBoundsObjectArray; + + static boolean staticBooleanNoSignatureAttribute; + static byte staticByteNoSignatureAttribute; + static char staticCharNoSignatureAttribute; + static short staticShortNoSignatureAttribute; + static int staticIntNoSignatureAttribute; + static long staticLongNoSignatureAttribute; + static float staticFloatNoSignatureAttribute; + static double staticDoubleNoSignatureAttribute; + + static List staticListNoSignatureAttribute; +} diff -r 47544495db2d -r c03745b71c70 langtools/test/tools/javac/classfiles/attributes/Signature/InnerClassTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/classfiles/attributes/Signature/InnerClassTest.java Wed Mar 25 10:29:14 2015 +0300 @@ -0,0 +1,362 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8049238 + * @summary Checks Signature attribute for inner classes. + * @library /tools/lib /tools/javac/lib ../lib + * @build TestBase TestResult InMemoryFileManager ToolBox + * @build InnerClassTest Driver ExpectedSignature ExpectedSignatureContainer + * @run main Driver InnerClassTest + */ + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.Callable; + +@ExpectedSignature(descriptor = "InnerClassTest", + signature = ";:Ljava/lang/Runnable;>Ljava/lang/Object;") +@ExpectedSignature(descriptor = "InnerClassTest$1", + signature = "LInnerClassTest$1Local1;", isAnonymous = true) +@ExpectedSignature(descriptor = "InnerClassTest$2", + signature = "LInnerClassTest$1Local2;" + + "Ljava/util/Map;Ljava/util/ArrayList;>;>;", isAnonymous = true) +public class InnerClassTest & Runnable> { + + { + class Local1 { + // no Signature attribute + Local1() { + } + + @ExpectedSignature(descriptor = "genericType", signature = "TT;") + T genericType; + + @ExpectedSignature(descriptor = "genericTypeArray", signature = "[TT;") + T[] genericTypeArray; + } + + @ExpectedSignature(descriptor = "InnerClassTest$1Local2", + signature = ";>Ljava/lang/Object;") + class Local2> { + // no Signature attribute + Local2() { + } + + @ExpectedSignature(descriptor = "(InnerClassTest, java.lang.Object, java.util.Map)", + signature = "(TT;TU;)V") + Local2(T a, U b) { + } + + @ExpectedSignature(descriptor = "genericMethod(java.lang.Object[])", + signature = "([TT;)[TU;") + U[] genericMethod(T...a) { + return null; + } + } + + @ExpectedSignature(descriptor = "InnerClassTest$1Local3", + signature = "LInnerClassTest$1Local2;" + + "Ljava/util/Map;Ljava/util/ArrayList;>;>;") + class Local3 extends Local2, Map, ArrayList>> { + } + + new Local1() { + @ExpectedSignature(descriptor = "genericType", signature = "TT;") + T genericType; + + @ExpectedSignature(descriptor = "genericTypeArray", signature = "[TT;") + T[] genericTypeArray; + }; + + new Local2, Map, ArrayList>>() { + }; + } + + @ExpectedSignature(descriptor = "InnerClassTest$InnerClass1", + signature = ";>Ljava/lang/Object;") + class InnerClass1> { + @ExpectedSignature(descriptor = "genericTypeArray", signature = "[TT;") + T[] genericTypeArray; + + @ExpectedSignature(descriptor = "genericListExtendsBound", signature = "Ljava/util/List<+TT;>;") + List genericListExtendsBound; + + @ExpectedSignature(descriptor = "genericListSuperBound", signature = "Ljava/util/List<-TU;>;") + List genericListSuperBound; + + @ExpectedSignature(descriptor = "genericListWildCard", signature = "Ljava/util/List<*>;") + List genericListWildCard; + + @ExpectedSignature(descriptor = "genericListExactType", signature = "Ljava/util/List;") + List genericListExactType; + + @ExpectedSignature(descriptor = "listWithGenericType", signature = "Ljava/util/List;") + List listWithGenericType; + + List listNoSignatureAttribute; + + // no Signature attribute + InnerClass1(List a) { + } + + @ExpectedSignature(descriptor = "(InnerClassTest, java.util.ArrayList)", + signature = "(TT;)V") + InnerClass1(T a) { + } + + @ExpectedSignature(descriptor = "(InnerClassTest, java.util.ArrayList, java.util.ArrayList)", + signature = "(TT;TE;)V") + InnerClass1(T a, E b) { + } + + @ExpectedSignature(descriptor = "genericMethod(java.util.ArrayList)", + signature = "(TT;)TE;") + E genericMethod(T a) { + return null; + } + } + + @ExpectedSignature(descriptor = "InnerClassTest$InnerInterface", + signature = "Ljava/lang/Object;") + interface InnerInterface { + @ExpectedSignature(descriptor = "genericMethod(java.lang.Object)", signature = "(TT;)TT;") + T genericMethod(T a); + + @ExpectedSignature(descriptor = "genericListExtendsBound", signature = "Ljava/util/List<+Ljava/lang/Number;>;") + List genericListExtendsBound = null; + + @ExpectedSignature(descriptor = "genericListSuperBound", signature = "Ljava/util/List<-Ljava/lang/Number;>;") + List genericListSuperBound = null; + + @ExpectedSignature(descriptor = "genericListWildCard", signature = "Ljava/util/List<*>;") + List genericListWildCard = null; + + @ExpectedSignature(descriptor = "genericListExactType", signature = "Ljava/util/List;") + List genericListExactType = null; + + List listNoSignatureAttribute = null; + + @ExpectedSignature(descriptor = "genericBoundsMethod1(java.util.List)", + signature = "(Ljava/util/List<-TT;>;)Ljava/util/List<+TT;>;") + List genericBoundsMethod1(List a); + + @ExpectedSignature(descriptor = "genericBoundsMethod2(java.util.List)", + signature = "(Ljava/util/List<+TT;>;)Ljava/util/List<-TT;>;") + List genericBoundsMethod2(List a); + + @ExpectedSignature(descriptor = "genericWildCardMethod(java.util.Map)", + signature = "(Ljava/util/Map<**>;)Ljava/util/Map<**>;") + Map genericWildCardMethod(Map a); + + @ExpectedSignature(descriptor = "defaultGenericMethod(java.util.List, java.util.List, java.util.Map)", + signature = "(Ljava/util/List<+TT;>;Ljava/util/List<-TT;>;Ljava/util/Map<**>;)Ljava/util/List<*>;") + default List defaultGenericMethod(List list1, List list2, Map map) { return null; } + + + default List defaultNoSignatureAttributeMethod(List list1, List list2, Map list3) { return null; } + + @ExpectedSignature(descriptor = "staticGenericMethod(java.util.List, java.util.List, java.util.Map)", + signature = "(Ljava/util/List<+TT;>;Ljava/util/List<-TT;>;Ljava/util/Map<**>;)Ljava/util/List<*>;") + static List staticGenericMethod(List list1, List list2, Map map) { return null; } + + + static List staticNoSignatureAttributeMethod(List list1, List list2, Map list3) { return null; } + } + + @ExpectedSignature(descriptor = "InnerClassTest$InnerClass2", + signature = "LInnerClassTest.InnerClass1;>;LInnerClassTest$InnerInterface;") + class InnerClass2 extends InnerClass1> implements InnerInterface { + + // no Signature attribute + InnerClass2() { + super(null); + } + + @ExpectedSignature(descriptor = "(InnerClassTest, java.util.ArrayList)", + signature = "(TT;)V") + InnerClass2(T a) { + super(a); + } + + @ExpectedSignature(descriptor = "(InnerClassTest, java.util.ArrayList, java.util.ArrayList)", + signature = "(TT;TT;)V") + InnerClass2(T a, T b) { + super(a, b); + } + + @ExpectedSignature(descriptor = "genericMethod(java.util.ArrayList)", signature = "(TT;)TT;") + @Override + public T genericMethod(T a) { + return null; + } + + @ExpectedSignature(descriptor = "genericBoundsMethod1(java.util.List)", + signature = "(Ljava/util/List<-TT;>;)Ljava/util/List<+TT;>;") + @Override + public List genericBoundsMethod1(List a) { + return null; + } + + @ExpectedSignature(descriptor = "genericBoundsMethod2(java.util.List)", + signature = "(Ljava/util/List<+TT;>;)Ljava/util/List<-TT;>;") + @Override + public List genericBoundsMethod2(List a) { + return null; + } + + @ExpectedSignature(descriptor = "genericWildCardMethod(java.util.Map)", + signature = "(Ljava/util/Map<**>;)Ljava/util/Map<**>;") + @Override + public Map genericWildCardMethod(Map a) { + return null; + } + } + + @ExpectedSignature(descriptor = "InnerClassTest$StaticInnerClass", + signature = ";>" + + "Ljava/lang/Object;LInnerClassTest$InnerInterface;") + static class StaticInnerClass> implements InnerInterface { + // no Signature attribute + StaticInnerClass(List a) { + } + + @ExpectedSignature(descriptor = "(java.lang.Runnable)", + signature = "(TE;)V") + StaticInnerClass(E a) { + } + + @ExpectedSignature(descriptor = "(java.lang.String)", + signature = "(TT;)V") + StaticInnerClass(T a) { + } + + @ExpectedSignature(descriptor = "(java.lang.String, java.util.Set)", + signature = "(TT;TE;)V") + StaticInnerClass(T a, E b) { + } + + @ExpectedSignature(descriptor = "genericListExtendsBound", signature = "Ljava/util/List<+Ljava/lang/Number;>;") + static List genericListExtendsBound; + + @ExpectedSignature(descriptor = "genericListSuperBound", signature = "Ljava/util/List<-Ljava/lang/Number;>;") + static List genericListSuperBound; + + @ExpectedSignature(descriptor = "genericListWildCard", signature = "Ljava/util/List<*>;") + static List genericListWildCard; + + @ExpectedSignature(descriptor = "genericListExactType", signature = "Ljava/util/List;") + static List genericListExactType; + + static List listNoSignatureAttribute; + + @ExpectedSignature(descriptor = "genericMethod(java.util.Set)", + signature = "(TE;)TE;") + @Override + public E genericMethod(E a) { + return null; + } + + @ExpectedSignature(descriptor = "genericBoundsMethod1(java.util.List)", + signature = "(Ljava/util/List<-TE;>;)Ljava/util/List<+TE;>;") + @Override + public List genericBoundsMethod1(List a) { + return null; + } + + @ExpectedSignature(descriptor = "genericBoundsMethod2(java.util.List)", + signature = "(Ljava/util/List<+TE;>;)Ljava/util/List<-TE;>;") + @Override + public List genericBoundsMethod2(List a) { + return null; + } + + @ExpectedSignature(descriptor = "genericWildCardMethod(java.util.Map)", + signature = "(Ljava/util/Map<**>;)Ljava/util/Map<**>;") + @Override + public Map genericWildCardMethod(Map a) { + return null; + } + + @ExpectedSignature(descriptor = "staticGenericMethod(java.lang.Object)", + signature = "(TE;)TE;") + public static E staticGenericMethod(E a) { + return null; + } + + @ExpectedSignature(descriptor = "staticGenericBoundsMethod1(java.util.List)", + signature = "(Ljava/util/List<-TE;>;)Ljava/util/List<+TE;>;") + public static List staticGenericBoundsMethod1(List a) { + return null; + } + + @ExpectedSignature(descriptor = "staticGenericBoundsMethod2(java.util.List)", + signature = "(Ljava/util/List<+TE;>;)Ljava/util/List<-TE;>;") + public static List staticGenericBoundsMethod2(List a) { + return null; + } + + @ExpectedSignature(descriptor = "staticGenericWildCardMethod(java.util.Map)", + signature = "(Ljava/util/Map<**>;)Ljava/util/Map<**>;") + public static Map staticGenericWildCardMethod(Map a) { + return null; + } + } + + @ExpectedSignature(descriptor = "InnerClassTest$InnerClass3", + signature = "Ljava/lang/Object;LInnerClassTest$ExceptionHolder" + + ";Ljava/util/concurrent/Callable;>;") + public static class InnerClass3 implements ExceptionHolder, Callable> { + @ExpectedSignature(descriptor = "call()", signature = "()Ljava/util/Map<**>;") + @Override + public Map call() throws Exception { + return null; + } + + @Override + public void Throw() throws RuntimeException { + } + + @Override + public RuntimeException Return() { + return null; + } + } + + /** + * Class is for checking that the Signature attribute is not generated + * for overridden methods despite of the appropriate methods in the parent class + * have the Signature attribute. + */ + @ExpectedSignature(descriptor = "InnerClassTest$ExceptionHolder", + signature = "Ljava/lang/Object;") + interface ExceptionHolder { + @ExpectedSignature(descriptor = "Throw()", signature = "()V^TE;") + void Throw() throws E; + @ExpectedSignature(descriptor = "Return()", signature = "()TE;") + E Return(); + } +} diff -r 47544495db2d -r c03745b71c70 langtools/test/tools/javac/classfiles/attributes/Signature/MethodParameterTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/classfiles/attributes/Signature/MethodParameterTest.java Wed Mar 25 10:29:14 2015 +0300 @@ -0,0 +1,203 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8049238 + * @summary Checks Signature attribute for method parameters. + * @library /tools/lib /tools/javac/lib ../lib + * @build TestBase TestResult InMemoryFileManager ToolBox + * @build MethodParameterTest Driver ExpectedSignature ExpectedSignatureContainer + * @run main Driver MethodParameterTest + */ + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +@ExpectedSignature(descriptor = "MethodParameterTest", signature = "Ljava/lang/Object;") +public class MethodParameterTest { + + @ExpectedSignature(descriptor = "(java.lang.Object, java.util.Set, java.util.ArrayList)", + signature = ";:Ljava/lang/Runnable;>" + + "(TT;Ljava/util/Set<-TE;>;Ljava/util/ArrayList<+Ljava/util/Set;>;)V") + & Runnable> + MethodParameterTest(T a, Set b, ArrayList> c) { + } + + @ExpectedSignature(descriptor = "method(java.lang.Object, java.util.List, java.util.ArrayList)", + signature = ";:Ljava/lang/Runnable;>" + + "(TT;TU;Ljava/util/ArrayList<+Ljava/util/Set;>;)V") + & Runnable> + void method(T a, U b, ArrayList> c) { + } + + @ExpectedSignature(descriptor = "staticMethod(java.util.Set, java.util.List[], java.util.Map)", + signature = ";E::Ljava/util/Set<-TT;>;>(TE;[TT;Ljava/util/Map<*+TE;>;)TE;") + static , E extends Set> E staticMethod(E a, T[] b, Map c) { + return null; + } + + @ExpectedSignature(descriptor = "(java.lang.Object, boolean[])", signature = "(TT;[Z)V") + MethodParameterTest(T a, boolean...b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, char[])", signature = "(TT;[C)V") + MethodParameterTest(T a, char...b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, byte[])", signature = "(TT;[B)V") + MethodParameterTest(T a, byte...b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, short[])", signature = "(TT;[S)V") + MethodParameterTest(T a, short...b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, int[])", signature = "(TT;[I)V") + MethodParameterTest(T a, int...b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, long[])", signature = "(TT;[J)V") + MethodParameterTest(T a, long...b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, float[])", signature = "(TT;[F)V") + MethodParameterTest(T a, float...b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, double[])", signature = "(TT;[D)V") + MethodParameterTest(T a, double...b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object, java.lang.Object[])", + signature = "(TT;[Ljava/lang/Object;)V") + MethodParameterTest(T a, Object...b) { + } + + @ExpectedSignature(descriptor = "(java.lang.Object[])", signature = "([TT;)V") + MethodParameterTest(T...a) { + } + + // no Signature attribute + MethodParameterTest(int...a) { + } + + @ExpectedSignature(descriptor = "genericBooleanMethod(java.lang.Object, boolean[])", signature = "(TT;[Z)V") + void genericBooleanMethod(T a, boolean...b) { + } + + @ExpectedSignature(descriptor = "genericCharMethod(java.lang.Object, char[])", signature = "(TT;[C)V") + void genericCharMethod(T a, char...b) { + } + + @ExpectedSignature(descriptor = "genericByteMethod(java.lang.Object, byte[])", signature = "(TT;[B)V") + void genericByteMethod(T a, byte...b) { + } + + @ExpectedSignature(descriptor = "genericShortMethod(java.lang.Object, short[])", signature = "(TT;[S)V") + void genericShortMethod(T a, short...b) { + } + + @ExpectedSignature(descriptor = "genericIntMethod(java.lang.Object, int[])", signature = "(TT;[I)V") + void genericIntMethod(T a, int...b) { + } + + @ExpectedSignature(descriptor = "genericLongMethod(java.lang.Object, long[])", signature = "(TT;[J)V") + void genericLongMethod(T a, long...b) { + } + + @ExpectedSignature(descriptor = "genericFloatMethod(java.lang.Object, float[])", signature = "(TT;[F)V") + void genericFloatMethod(T a, float...b) { + } + + @ExpectedSignature(descriptor = "genericDoubleMethod(java.lang.Object, double[])", signature = "(TT;[D)V") + void genericDoubleMethod(T a, double...b) { + } + + @ExpectedSignature(descriptor = "genericObjectMethod(java.lang.Object, java.lang.Object[])", + signature = "(TT;[Ljava/lang/Object;)V") + void genericObjectMethod(T a, Object...b) { + } + + @ExpectedSignature(descriptor = "genericMethod(java.lang.Object[])", signature = "([TT;)V") + void genericMethod(T...a) { + } + + void noSignature(int...a) { + } + + @ExpectedSignature(descriptor = "staticGenericBooleanMethod(java.lang.Object, boolean[])", + signature = "(TT;[Z)V") + static void staticGenericBooleanMethod(T a, boolean...b) { + } + + @ExpectedSignature(descriptor = "staticGenericCharMethod(java.lang.Object, char[])", + signature = "(TT;[C)V") + static void staticGenericCharMethod(T a, char...b) { + } + + @ExpectedSignature(descriptor = "staticGenericByteMethod(java.lang.Object, byte[])", + signature = "(TT;[B)V") + static void staticGenericByteMethod(T a, byte...b) { + } + + @ExpectedSignature(descriptor = "staticGenericShortMethod(java.lang.Object, short[])", + signature = "(TT;[S)V") + static void staticGenericShortMethod(T a, short...b) { + } + + @ExpectedSignature(descriptor = "staticGenericIntMethod(java.lang.Object, int[])", + signature = "(TT;[I)V") + static void staticGenericIntMethod(T a, int...b) { + } + + @ExpectedSignature(descriptor = "staticGenericLongMethod(java.lang.Object, long[])", + signature = "(TT;[J)V") + static void staticGenericLongMethod(T a, long...b) { + } + + @ExpectedSignature(descriptor = "staticGenericFloatMethod(java.lang.Object, float[])", + signature = "(TT;[F)V") + static void staticGenericFloatMethod(T a, float...b) { + } + + @ExpectedSignature(descriptor = "staticGenericDoubleMethod(java.lang.Object, double[])", + signature = "(TT;[D)V") + static void staticGenericDoubleMethod(T a, double...b) { + } + + @ExpectedSignature(descriptor = "staticGenericObjectMethod(java.lang.Object, java.lang.Object[])", + signature = "(TT;[Ljava/lang/Object;)V") + static void staticGenericObjectMethod(T a, Object...b) { + } + + @ExpectedSignature(descriptor = "staticGenericMethod(java.lang.Object[])", + signature = "([TT;)V") + static void staticGenericMethod(T...a) { + } + + static void staticNoSignatureAttribute(int...a) { + } +} diff -r 47544495db2d -r c03745b71c70 langtools/test/tools/javac/classfiles/attributes/Signature/MethodTypeBoundTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/classfiles/attributes/Signature/MethodTypeBoundTest.java Wed Mar 25 10:29:14 2015 +0300 @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8049238 + * @summary Checks Signature attribute for type bounds. + * @library /tools/lib /tools/javac/lib ../lib + * @build TestBase TestResult InMemoryFileManager ToolBox + * @build MethodTypeBoundTest Driver ExpectedSignature ExpectedSignatureContainer + * @run main Driver MethodTypeBoundTest + */ + +import java.util.*; + +@ExpectedSignature(descriptor = "MethodTypeBoundTest", signature = "Ljava/lang/Object;") +public class MethodTypeBoundTest { + + @ExpectedSignature(descriptor = "method1(java.lang.String)", + signature = ";>(TE;)TE;") + > E method1(E a) { + return a; + } + + @ExpectedSignature(descriptor = "method2(java.lang.Runnable)", + signature = ";>(TE;)TE;") + > E method2(E a) { + return a; + } + + @ExpectedSignature(descriptor = "method3(java.util.ArrayList)", + signature = ";>(TE;)TE;") + > E method3(E a) { + return a; + } + + @ExpectedSignature(descriptor = "method4(java.util.LinkedList)", + signature = ";:Ljava/util/List;>(TE;)TE;") + & List> E method4(E a) { + return a; + } + + @ExpectedSignature(descriptor = "method5(java.util.Iterator)", + signature = ";:Ljava/util/List;" + + "U::Ljava/util/Iterator<-LMethodTypeBoundTest.InnerClass;>;>(TU;)TE;") + & List, U extends Iterator>> E method5(U a) { + return null; + } + + @ExpectedSignature(descriptor = "method6()", + signature = ";U:TE;>()V") + , U extends E> void method6() { + } + + @ExpectedSignature(descriptor = "MethodTypeBoundTest$InnerClass", + signature = "Ljava/lang/Object;") + class InnerClass { + } +} diff -r 47544495db2d -r c03745b71c70 langtools/test/tools/javac/classfiles/attributes/Signature/ReturnTypeTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/classfiles/attributes/Signature/ReturnTypeTest.java Wed Mar 25 10:29:14 2015 +0300 @@ -0,0 +1,549 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8049238 + * @summary Checks Signature attribute for array return type of method. + * @library /tools/lib /tools/javac/lib ../lib + * @build TestBase TestResult InMemoryFileManager ToolBox + * @build ReturnTypeTest Driver ExpectedSignature ExpectedSignatureContainer + * @run main Driver ReturnTypeTest + */ + +import java.awt.Frame; +import java.util.List; +import java.util.Map; +import java.util.concurrent.Callable; + +@ExpectedSignature(descriptor = "ReturnTypeTest", + signature = ";>Ljava/lang/Object;") +public class ReturnTypeTest> { + + @ExpectedSignature(descriptor = "byteArrayReturnType(java.awt.Frame)", + signature = "(TT;)[B") + byte[] byteArrayReturnType(T a) { + return null; + } + + @ExpectedSignature(descriptor = "shortArrayReturnType(java.awt.Frame)", + signature = "(TT;)[S") + short[] shortArrayReturnType(T a) { + return null; + } + + @ExpectedSignature(descriptor = "charArrayReturnType(java.awt.Frame)", + signature = "(TT;)[C") + char[] charArrayReturnType(T a) { + return null; + } + + @ExpectedSignature(descriptor = "intArrayReturnType(java.awt.Frame)", + signature = "(TT;)[I") + int[] intArrayReturnType(T a) { + return null; + } + + @ExpectedSignature(descriptor = "longArrayReturnType(java.awt.Frame)", + signature = "(TT;)[J") + long[] longArrayReturnType(T a) { + return null; + } + + @ExpectedSignature(descriptor = "booleanArrayReturnType(java.awt.Frame)", + signature = "(TT;)[Z") + boolean[] booleanArrayReturnType(T a) { + return null; + } + + @ExpectedSignature(descriptor = "floatArrayReturnType(java.awt.Frame)", + signature = "(TT;)[F") + float[] floatArrayReturnType(T a) { + return null; + } + + @ExpectedSignature(descriptor = "doubleArrayReturnType(java.awt.Frame)", + signature = "(TT;)[D") + double[] doubleArrayReturnType(T a) { + return null; + } + + @ExpectedSignature(descriptor = "objectArrayReturnType(java.awt.Frame)", + signature = "(TT;)[Ljava/lang/Object;") + Object[] objectArrayReturnType(T a) { + return null; + } + + @ExpectedSignature(descriptor = "staticByteArrayReturnType(java.lang.Object)", + signature = "(TT;)[B") + static byte[] staticByteArrayReturnType(T a) { + return null; + } + + @ExpectedSignature(descriptor = "staticShortArrayReturnType(java.lang.Object)", + signature = "(TT;)[S") + static short[] staticShortArrayReturnType(T a) { + return null; + } + + @ExpectedSignature(descriptor = "staticCharArrayReturnType(java.lang.Object)", + signature = "(TT;)[C") + static char[] staticCharArrayReturnType(T a) { + return null; + } + + @ExpectedSignature(descriptor = "staticIntArrayReturnType(java.lang.Object)", + signature = "(TT;)[I") + static int[] staticIntArrayReturnType(T a) { + return null; + } + + @ExpectedSignature(descriptor = "staticLongArrayReturnType(java.lang.Object)", + signature = "(TT;)[J") + static long[] staticLongArrayReturnType(T a) { + return null; + } + + @ExpectedSignature(descriptor = "staticBooleanArrayReturnType(java.lang.Object)", + signature = "(TT;)[Z") + static boolean[] staticBooleanArrayReturnType(T a) { + return null; + } + + @ExpectedSignature(descriptor = "staticFloatArrayReturnType(java.lang.Object)", + signature = "(TT;)[F") + static float[] staticFloatArrayReturnType(T a) { + return null; + } + + @ExpectedSignature(descriptor = "staticDoubleArrayReturnType(java.lang.Object)", + signature = "(TT;)[D") + static double[] staticDoubleArrayReturnType(T a) { + return null; + } + + @ExpectedSignature(descriptor = "staticObjectArrayReturnType(java.lang.Object)", + signature = "(TT;)[Ljava/lang/Object;") + static Object[] staticObjectArrayReturnType(T a) { + return null; + } + + byte[] byteArrayReturnTypeNoSignatureAttribute() { + return null; + } + + short[] shortArrayReturnTypeNoSignatureAttribute() { + return null; + } + + char[] charArrayReturnTypeNoSignatureAttribute() { + return null; + } + + int[] intArrayReturnTypeNoSignatureAttribute() { + return null; + } + + long[] longArrayReturnTypeNoSignatureAttribute() { + return null; + } + + boolean[] booleanArrayReturnTypeNoSignatureAttribute() { + return null; + } + + float[] floatArrayReturnTypeNoSignatureAttribute() { + return null; + } + + double[] doubleArrayReturnTypeNoSignatureAttribute() { + return null; + } + + Object[] objectArrayReturnTypeNoSignatureAttribute() { + return null; + } + + static byte[] staticByteArrayReturnTypeNoSignatureAttribute() { + return null; + } + + static short[] staticShortArrayReturnTypeNoSignatureAttribute() { + return null; + } + + static char[] staticCharArrayReturnTypeNoSignatureAttribute() { + return null; + } + + static int[] staticIntArrayReturnTypeNoSignatureAttribute() { + return null; + } + + static long[] staticLongArrayReturnTypeNoSignatureAttribute() { + return null; + } + + static boolean[] staticBooleanArrayReturnTypeNoSignatureAttribute() { + return null; + } + + static float[] staticFloatArrayReturnTypeNoSignatureAttribute() { + return null; + } + + static double[] staticDoubleArrayReturnTypeNoSignatureAttribute() { + return null; + } + + static Object[] staticObjectArrayReturnTypeNoSignatureAttribute() { + return null; + } + + @ExpectedSignature(descriptor = "typeReturnType()", + signature = "()TT;") + T typeReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "typeArrayReturnType()", + signature = "()[TT;") + T[] typeArrayReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "extendsReturnType()", + signature = "()TE;") + E extendsReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "extendsArrayReturnType()", + signature = "()[TE;") + E[] extendsArrayReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "genericListReturnType()", + signature = "()Ljava/util/List;") + List genericListReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "genericListArrayReturnType()", + signature = "()[Ljava/util/List;") + List[] genericListArrayReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "extendsBoundReturnType()", + signature = "()Ljava/util/List<+TT;>;") + List extendsBoundReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "extendsBoundArrayReturnType()", + signature = "()[Ljava/util/List<+TT;>;") + List[] extendsBoundArrayReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "superBoundReturnType()", + signature = "()Ljava/util/List<-TT;>;") + List superBoundReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "superBoundArrayReturnType()", + signature = "()[Ljava/util/List<-TT;>;") + List[] superBoundArrayReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "wildcardReturnType()", + signature = "()Ljava/util/Map<**>;") + Map wildcardReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "wildcardArrayReturnType()", + signature = "()[Ljava/util/Map<**>;") + Map[] wildcardArrayReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "staticTypeReturnType()", + signature = "()TT;") + static T staticTypeReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "staticTypeArrayReturnType()", + signature = "()[TT;") + static T[] staticTypeArrayReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "staticExtendsReturnType()", + signature = "()TE;") + static E staticExtendsReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "staticExtendsArrayReturnType()", + signature = "()[TE;") + static E[] staticExtendsArrayReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "staticGenericListReturnType()", + signature = "()Ljava/util/List;") + static List staticGenericListReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "staticGenericListArrayReturnType()", + signature = "()[Ljava/util/List;") + static List[] staticGenericListArrayReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "staticExtendsBoundReturnType()", + signature = "()Ljava/util/List<+TT;>;") + static List staticExtendsBoundReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "staticExtendsBoundArrayReturnType()", + signature = "()[Ljava/util/List<+TT;>;") + static List[] staticExtendsBoundArrayReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "staticSuperBoundReturnType()", + signature = "()Ljava/util/List<-TT;>;") + static List staticSuperBoundReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "staticSuperBoundArrayReturnType()", + signature = "()[Ljava/util/List<-TT;>;") + static List[] staticSuperBoundArrayReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "staticWildcardReturnType()", + signature = "()Ljava/util/Map<**>;") + static Map staticWildcardReturnType() { + return null; + } + + @ExpectedSignature(descriptor = "staticWildcardArrayReturnType()", + signature = "()[Ljava/util/Map<**>;") + static Map[] staticWildcardArrayReturnType() { + return null; + } + + List noSignature() { + return null; + } + + static List staticNoSignatureAttribute() { + return null; + } + + @ExpectedSignature(descriptor = "boundsBooleanArray()", + signature = "()Ljava/util/Map<+[Z-[Z>;") + Map boundsBooleanArray() { + return null; + } + + @ExpectedSignature(descriptor = "boundsByteArray()", + signature = "()Ljava/util/Map<+[B-[B>;") + Map boundsByteArray() { + return null; + } + + @ExpectedSignature(descriptor = "boundsShortArray()", + signature = "()Ljava/util/Map<+[S-[S>;") + Map boundsShortArray() { + return null; + } + + @ExpectedSignature(descriptor = "boundsIntArray()", + signature = "()Ljava/util/Map<+[I-[I>;") + Map boundsIntArray() { + return null; + } + + @ExpectedSignature(descriptor = "boundsLongArray()", + signature = "()Ljava/util/Map<+[J-[J>;") + Map boundsLongArray() { + return null; + } + + @ExpectedSignature(descriptor = "boundsCharArray()", + signature = "()Ljava/util/Map<+[C-[C>;") + Map boundsCharArray() { + return null; + } + + @ExpectedSignature(descriptor = "boundsFloatArray()", + signature = "()Ljava/util/Map<+[F-[F>;") + Map boundsFloatArray() { + return null; + } + + @ExpectedSignature(descriptor = "boundsDoubleArray()", + signature = "()Ljava/util/Map<+[D-[D>;") + Map boundsDoubleArray() { + return null; + } + + @ExpectedSignature(descriptor = "boundsObjectArray()", + signature = "()Ljava/util/Map<+[Ljava/lang/Object;-[Ljava/lang/Object;>;") + Map boundsObjectArray() { + return null; + } + + @ExpectedSignature(descriptor = "voidMethod(java.awt.Frame)", signature = "(TT;)V") + void voidMethod(T a) { + } + + @ExpectedSignature(descriptor = "byteMethod(java.awt.Frame)", signature = "(TT;)B") + byte byteMethod(T a) { + return 0; + } + + @ExpectedSignature(descriptor = "shortMethod(java.awt.Frame)", signature = "(TT;)S") + short shortMethod(T a) { + return 0; + } + + @ExpectedSignature(descriptor = "charMethod(java.awt.Frame)", signature = "(TT;)C") + char charMethod(T a) { + return 0; + } + + @ExpectedSignature(descriptor = "intMethod(java.awt.Frame)", signature = "(TT;)I") + int intMethod(T a) { + return 0; + } + + @ExpectedSignature(descriptor = "longMethod(java.awt.Frame)", signature = "(TT;)J") + long longMethod(T a) { + return 0; + } + + @ExpectedSignature(descriptor = "booleanMethod(java.awt.Frame)", signature = "(TT;)Z") + boolean booleanMethod(T a) { + return false; + } + + @ExpectedSignature(descriptor = "floatMethod(java.awt.Frame)", signature = "(TT;)F") + float floatMethod(T a) { + return 0; + } + + @ExpectedSignature(descriptor = "doubleMethod(java.awt.Frame)", signature = "(TT;)D") + double doubleMethod(T a) { + return 0; + } + + @ExpectedSignature(descriptor = "objectMethod(java.awt.Frame)", signature = "(TT;)Ljava/lang/Object;") + Object objectMethod(T a) { + return null; + } + + @ExpectedSignature(descriptor = "staticVoidMethod(java.lang.Object)", signature = "(TT;)V") + static void staticVoidMethod(T a) { + } + + @ExpectedSignature(descriptor = "staticByteMethod(java.lang.Object)", signature = "(TT;)B") + static byte staticByteMethod(T a) { + return 0; + } + + @ExpectedSignature(descriptor = "staticShortMethod(java.lang.Object)", signature = "(TT;)S") + static short staticShortMethod(T a) { + return 0; + } + + @ExpectedSignature(descriptor = "staticCharMethod(java.lang.Object)", signature = "(TT;)C") + static char staticCharMethod(T a) { + return 0; + } + + @ExpectedSignature(descriptor = "staticIntMethod(java.lang.Object)", signature = "(TT;)I") + static int staticIntMethod(T a) { + return 0; + } + + @ExpectedSignature(descriptor = "staticLongMethod(java.lang.Object)", signature = "(TT;)J") + static long staticLongMethod(T a) { + return 0; + } + + @ExpectedSignature(descriptor = "staticBooleanMethod(java.lang.Object)", signature = "(TT;)Z") + static boolean staticBooleanMethod(T a) { + return false; + } + + @ExpectedSignature(descriptor = "staticFloatMethod(java.lang.Object)", signature = "(TT;)F") + static float staticFloatMethod(T a) { + return 0; + } + + @ExpectedSignature(descriptor = "staticDoubleMethod(java.lang.Object)", signature = "(TT;)D") + static double staticDoubleMethod(T a) { + return 0; + } + + @ExpectedSignature(descriptor = "staticObjectMethod(java.lang.Object)", + signature = "(TT;)Ljava/lang/Object;") + static Object staticObjectMethod(T a) { + return null; + } + + void voidReturnTypeNoSignatureAttribute() { + } + + byte byteReturnTypeNoSignatureAttribute() { + return 0; + } + + Object objectReturnNoSignatureAttribute() { + return null; + } + + static void staticVoidReturnTypeNoSignatureAttribute() { + } + + static byte staticByteReturnTypeNoSignatureAttribute() { + return 0; + } + + static Object staticObjectReturnTypeNoSignatureAttribute() { + return null; + } +} diff -r 47544495db2d -r c03745b71c70 langtools/test/tools/javac/classfiles/attributes/lib/TestResult.java --- a/langtools/test/tools/javac/classfiles/attributes/lib/TestResult.java Wed Jul 05 20:25:16 2017 +0200 +++ b/langtools/test/tools/javac/classfiles/attributes/lib/TestResult.java Wed Mar 25 10:29:14 2015 +0300 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -56,8 +56,9 @@ public boolean checkEquals(Object actual, Object expected, String message) { echo("Testing : " + message); if (!Objects.equals(actual, expected)) { - getLastTestCase().addAssert(new AssertionFailedException( - String.format("%s%nGot: %s, Expected: %s", message, actual, expected))); + getLastTestCase().addAssert(String.format("%s\n" + + "Expected: %s,\n" + + " Got: %s", message, expected, actual)); return false; } return true; @@ -70,8 +71,7 @@ public boolean checkNotNull(Object actual, String message) { echo("Testing : " + message); if (Objects.isNull(actual)) { - getLastTestCase().addAssert(new AssertionFailedException( - message + " : Expected not null value")); + getLastTestCase().addAssert(message + " : Expected not null value"); return false; } return true; @@ -88,7 +88,11 @@ public boolean checkContains(Set found, Set expected, String message) { Set copy = new HashSet<>(expected); copy.removeAll(found); - return checkTrue(found.containsAll(expected), message + " : " + copy); + if (!found.containsAll(expected)) { + return checkTrue(false, message + " FAIL : not found elements : " + copy); + } else { + return checkTrue(true, message + " PASS : all elements found"); + } } public void addFailure(Throwable th) { @@ -119,7 +123,7 @@ private class Info { private final String info; - private final List asserts; + private final List asserts; private final List errors; private Info(String info) { @@ -141,19 +145,25 @@ printf("[ERROR] : %s\n", getStackTrace(th)); } - public void addAssert(AssertionFailedException e) { + public void addAssert(String e) { asserts.add(e); - printf("[ASSERT] : %s\n", getStackTrace(e)); + printf("[ASSERT] : %s\n", e); } public String getMessage() { - return (asserts.size() > 0 ? getErrorMessage("[ASSERT]", asserts) + "\n" : "") - + getErrorMessage("[ERROR]", errors); + return (asserts.size() > 0 ? getAssertMessages(asserts) + "\n" : "") + + getErrorMessages(errors); } - public String getErrorMessage(String header, List list) { + public String getAssertMessages(List list) { return list.stream() - .map(throwable -> String.format("%s : %s", header, getStackTrace(throwable))) + .map(message -> String.format("[ASSERT] : %s", message)) + .collect(Collectors.joining("\n")); + } + + public String getErrorMessages(List list) { + return list.stream() + .map(throwable -> String.format("[ERROR] : %s", getStackTrace(throwable))) .collect(Collectors.joining("\n")); }