T8136453.java revision 3516:d5420d4ccbaa
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 8136453
27 * @summary Checking that javac's ClassReader expands its parameterNameIndices array properly.
28 * @modules jdk.compiler
29 * @build T T8136453
30 * @run main T8136453
31 */
32
33import java.util.Arrays;
34import java.util.List;
35
36import javax.lang.model.element.ExecutableElement;
37import javax.lang.model.element.Name;
38import javax.lang.model.element.TypeElement;
39import javax.lang.model.element.VariableElement;
40import javax.lang.model.util.ElementFilter;
41import javax.tools.JavaCompiler;
42import javax.tools.ToolProvider;
43
44import com.sun.source.util.JavacTask;
45
46public class T8136453 {
47    public static void main(String... args) {
48        new T8136453().run();
49    }
50
51    void run() {
52        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
53        List<String> opts = Arrays.asList("-parameters");
54        JavacTask task = (JavacTask) compiler.getTask(null, null, null, opts, null, null);
55        TypeElement t = task.getElements().getTypeElement("T");
56        ExecutableElement testMethod = ElementFilter.methodsIn(t.getEnclosedElements()).get(0);
57        VariableElement param = testMethod.getParameters().get(0);
58        Name paramName = param.getSimpleName();
59
60        if (!paramName.contentEquals("p")) {
61            throw new AssertionError("Wrong parameter name: " + paramName);
62        }
63    }
64}
65