1 /*
   2  * Copyright (c) 2016, 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 8166700
  27  * @summary Check that local classes originating in static initializer can be loaded properly.
  28  * @modules jdk.compiler
  29  * @library /tools/javac/lib
  30  * @build LocalTest$1Local LocalTest$2Local LocalTest$3Local LocalTest$4Local LocalTest$5Local LocalTest JavacTestingAbstractProcessor
  31  * @compile LocalClassesModel.java
  32  * @compile/process/ref=LocalClassesModel.out -processor LocalClassesModel LocalTest$1Local LocalTest$2Local LocalTest$3Local LocalTest$4Local LocalTest$5Local LocalTest
  33  */
  34 
  35 import java.util.Set;
  36 
  37 import javax.annotation.processing.AbstractProcessor;
  38 import javax.annotation.processing.RoundEnvironment;
  39 import javax.annotation.processing.SupportedAnnotationTypes;
  40 import javax.lang.model.SourceVersion;
  41 import javax.lang.model.element.ExecutableElement;
  42 import javax.lang.model.element.TypeElement;
  43 import javax.lang.model.element.VariableElement;
  44 import javax.lang.model.util.ElementFilter;
  45 
  46 public class LocalClassesModel extends JavacTestingAbstractProcessor {
  47 
  48     @Override
  49     public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
  50         for (TypeElement root : ElementFilter.typesIn(roundEnv.getRootElements())) {
  51             System.out.println(processingEnv.getElementUtils().getBinaryName(root));
  52             for (ExecutableElement constr : ElementFilter.constructorsIn(root.getEnclosedElements())) {
  53                 System.out.print("  (");
  54                 boolean first = true;
  55                 for (VariableElement param : constr.getParameters()) {
  56                     if (!first) {
  57                         System.out.print(", ");
  58                     }
  59                     first = false;
  60                     System.out.print(param.asType().toString());
  61                 }
  62                 System.out.println(")");
  63             }
  64         }
  65 
  66         return false;
  67     }
  68 }