1 /*
   2  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 8055063
  27  * @summary javac should generate method parameters correctly.
  28  * @clean InnerClassToString
  29  * @compile -parameters InnerClassToString.java
  30  * @run main InnerClassToString
  31  * @clean InnerClassToString
  32  * @compile InnerClassToString.java
  33  * @run main InnerClassToString
  34  */
  35 
  36 import java.lang.reflect.Constructor;
  37 import java.lang.reflect.Parameter;
  38 import java.util.Set;
  39 
  40 // Test copied and expanded from webbug group report.
  41 public class InnerClassToString {
  42     private static final Class<?>[] genericParamClasses = new Class<?>[] {
  43         InnerClassToString.class, Set.class
  44     };
  45 
  46     private static final Class<?>[] nongenericParamClasses = new Class<?>[] {
  47         InnerClassToString.class, String.class
  48     };
  49 
  50     private int errors = 0;
  51 
  52     private void test(Constructor<MyEntity> constructor,
  53                      Class<?>[] paramClasses) {
  54         final Parameter[] params = constructor.getParameters();
  55 
  56         for (int i = 0; i < params.length; i++) {
  57             final Parameter parameter = params[i];
  58             System.out.println(parameter.toString());
  59 
  60             if (!parameter.getType().equals(paramClasses[i])) {
  61                 errors++;
  62                 System.err.println("Expected type " + paramClasses[i] +
  63                                    " but got " + parameter.getType());
  64             }
  65 
  66             System.out.println(parameter.getParameterizedType()); 
  67             System.out.println(parameter.getAnnotatedType()); 
  68         }
  69 
  70     }
  71 
  72     private void run() throws Exception {
  73         final Constructor<MyEntity> genericConstructor =
  74             MyEntity.class.getConstructor(InnerClassToString.class, Set.class);
  75 
  76         test(genericConstructor, genericParamClasses);
  77 
  78         final Constructor<MyEntity> nongenericConstructor =
  79             MyEntity.class.getConstructor(InnerClassToString.class, String.class);
  80 
  81         test(nongenericConstructor, nongenericParamClasses);
  82 
  83         if (errors != 0)
  84             throw new RuntimeException(errors + " errors in test");
  85     }
  86 
  87     public static void main(String[] args) throws Exception {
  88         new InnerClassToString().run();
  89     }
  90 
  91     public class MyEntity {
  92         public MyEntity(Set<?> names) {}
  93         public MyEntity(String names) {}
  94     }
  95 }