test/tools/javac/api/6468404/T6468404.java

Wed, 27 Apr 2016 01:34:52 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:34:52 +0800
changeset 0
959103a6100f
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/langtools/
changeset: 2573:53ca196be1ae
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 */
aoqi@0 23
aoqi@0 24 /*
aoqi@0 25 * @test
aoqi@0 26 * @bug 6468404
aoqi@0 27 * @summary ExecutableElement.getParameters() uses raw type for class loaded from -g bytecode
aoqi@0 28 * @author jesse.glick@...
aoqi@0 29 * @author Peter von der Ah\u00e9
aoqi@0 30 * @library ../lib
aoqi@0 31 * @build ToolTester
aoqi@0 32 * @compile T6468404.java
aoqi@0 33 * @run main T6468404
aoqi@0 34 */
aoqi@0 35
aoqi@0 36 import java.io.IOException;
aoqi@0 37 import java.net.URI;
aoqi@0 38 import java.util.Arrays;
aoqi@0 39 import java.util.Collections;
aoqi@0 40 import java.util.Set;
aoqi@0 41 import javax.annotation.processing.AbstractProcessor;
aoqi@0 42 import javax.annotation.processing.RoundEnvironment;
aoqi@0 43 import javax.annotation.processing.SupportedAnnotationTypes;
aoqi@0 44 import javax.annotation.processing.SupportedSourceVersion;
aoqi@0 45 import javax.annotation.processing.ProcessingEnvironment;
aoqi@0 46 import javax.lang.model.SourceVersion;
aoqi@0 47 import javax.lang.model.element.ExecutableElement;
aoqi@0 48 import javax.lang.model.element.TypeElement;
aoqi@0 49 import javax.lang.model.type.ExecutableType;
aoqi@0 50 import javax.lang.model.type.DeclaredType;
aoqi@0 51 import javax.lang.model.type.TypeMirror;
aoqi@0 52 import javax.lang.model.util.Elements;
aoqi@0 53 import javax.tools.JavaCompiler;
aoqi@0 54 import javax.tools.JavaFileObject;
aoqi@0 55 import javax.tools.SimpleJavaFileObject;
aoqi@0 56 import javax.tools.ToolProvider;
aoqi@0 57
aoqi@0 58 public class T6468404 extends ToolTester {
aoqi@0 59 void test(String... args) {
aoqi@0 60 System.err.println("Compiling with sources:");
aoqi@0 61 task = tool.getTask(
aoqi@0 62 null, fm, null, null,
aoqi@0 63 null, Collections.singleton(new DummyFO("C")));
aoqi@0 64 task.setProcessors(Collections.singleton(new P()));
aoqi@0 65 if (!task.call())
aoqi@0 66 throw new AssertionError();
aoqi@0 67
aoqi@0 68 System.err.println("Compiling with binaries w/o -g:");
aoqi@0 69 task = tool.getTask(
aoqi@0 70 null, fm, null, null,
aoqi@0 71 null, Collections.singleton(new DummyFO("Dummy")));
aoqi@0 72 task.setProcessors(Collections.singleton(new P()));
aoqi@0 73 if (!task.call())
aoqi@0 74 throw new AssertionError();
aoqi@0 75
aoqi@0 76 task = tool.getTask(
aoqi@0 77 null, fm, null,
aoqi@0 78 Arrays.asList("-g"),
aoqi@0 79 null, Collections.singleton(new DummyFO("C")));
aoqi@0 80 if (!task.call())
aoqi@0 81 throw new AssertionError();
aoqi@0 82
aoqi@0 83 System.err.println("Compiling with binaries w/ -g:");
aoqi@0 84 task = tool.getTask(
aoqi@0 85 null, fm, null, null,
aoqi@0 86 null, Collections.singleton(new DummyFO("Dummy")));
aoqi@0 87 task.setProcessors(Collections.singleton(new P()));
aoqi@0 88 if (!task.call())
aoqi@0 89 throw new AssertionError();
aoqi@0 90 }
aoqi@0 91 public static void main(String... args) {
aoqi@0 92 new T6468404().test(args);
aoqi@0 93 }
aoqi@0 94
aoqi@0 95 }
aoqi@0 96
aoqi@0 97 class DummyFO extends SimpleJavaFileObject {
aoqi@0 98 String n;
aoqi@0 99 public DummyFO(String n) {
aoqi@0 100 super(URI.create("nowhere:/" + n + ".java"), JavaFileObject.Kind.SOURCE);
aoqi@0 101 this.n = n;
aoqi@0 102 }
aoqi@0 103 public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
aoqi@0 104 return "public class " + n + " {" + n + "(java.util.List<String> l) {}}";
aoqi@0 105 }
aoqi@0 106 }
aoqi@0 107
aoqi@0 108 @SupportedAnnotationTypes("*")
aoqi@0 109 class P extends AbstractProcessor {
aoqi@0 110 boolean ran = false;
aoqi@0 111
aoqi@0 112 Elements elements;
aoqi@0 113
aoqi@0 114 @Override
aoqi@0 115 public synchronized void init(ProcessingEnvironment processingEnv) {
aoqi@0 116 super.init(processingEnv);
aoqi@0 117 elements = processingEnv.getElementUtils();
aoqi@0 118 }
aoqi@0 119
aoqi@0 120 ExecutableElement getFirstMethodIn(String name) {
aoqi@0 121 return (ExecutableElement)elements.getTypeElement(name).getEnclosedElements().get(0);
aoqi@0 122 }
aoqi@0 123
aoqi@0 124 boolean isParameterized(TypeMirror type) {
aoqi@0 125 return !((DeclaredType)type).getTypeArguments().isEmpty();
aoqi@0 126 }
aoqi@0 127
aoqi@0 128 @Override
aoqi@0 129 public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
aoqi@0 130 if (!ran) {
aoqi@0 131 ran = true;
aoqi@0 132 ExecutableElement m = getFirstMethodIn("C");
aoqi@0 133 System.err.println("method: " + m);
aoqi@0 134
aoqi@0 135 TypeMirror type = (DeclaredType)m.getParameters().get(0).asType();
aoqi@0 136 System.err.println("parameters[0]: " + type);
aoqi@0 137 if (!isParameterized(type))
aoqi@0 138 throw new AssertionError(type);
aoqi@0 139
aoqi@0 140 type = ((ExecutableType)m.asType()).getParameterTypes().get(0);
aoqi@0 141 System.err.println("parameterTypes[0]: " + type);
aoqi@0 142 if (!isParameterized(type))
aoqi@0 143 throw new AssertionError(type);
aoqi@0 144 System.err.println();
aoqi@0 145 }
aoqi@0 146 return true;
aoqi@0 147 }
aoqi@0 148
aoqi@0 149 @Override
aoqi@0 150 public SourceVersion getSupportedSourceVersion() {
aoqi@0 151 return SourceVersion.latest();
aoqi@0 152 }
aoqi@0 153 }

mercurial