LocalClassesModel.java revision 3792:d516975e8110
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 * @build LocalTest$1Local LocalTest$2Local LocalTest$3Local LocalTest$4Local LocalTest$5Local LocalTest
30 * @compile LocalClassesModel.java
31 * @compile/process/ref=LocalClassesModel.out -processor LocalClassesModel LocalTest$1Local LocalTest$2Local LocalTest$3Local LocalTest$4Local LocalTest$5Local LocalTest
32 */
33
34import java.util.Set;
35
36import javax.annotation.processing.AbstractProcessor;
37import javax.annotation.processing.RoundEnvironment;
38import javax.annotation.processing.SupportedAnnotationTypes;
39import javax.lang.model.SourceVersion;
40import javax.lang.model.element.ExecutableElement;
41import javax.lang.model.element.TypeElement;
42import javax.lang.model.element.VariableElement;
43import javax.lang.model.util.ElementFilter;
44
45@SupportedAnnotationTypes("*")
46public class LocalClassesModel extends AbstractProcessor {
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
69    @Override
70    public SourceVersion getSupportedSourceVersion() {
71        return SourceVersion.latestSupported();
72    }
73}
74