/* * 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(); } }