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

changeset 1
9a66ca7c79fa
child 495
fe17a9dbef03
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javac/api/6468404/T6468404.java	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,148 @@
     1.4 +/*
     1.5 + * Copyright 2006-2007 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + */
    1.26 +
    1.27 +/*
    1.28 + * @test
    1.29 + * @bug     6468404
    1.30 + * @summary ExecutableElement.getParameters() uses raw type for class loaded from -g bytecode
    1.31 + * @author  jesse.glick@...
    1.32 + * @author  Peter von der Ah\u00e9
    1.33 + * @library ../lib
    1.34 + * @compile T6468404.java
    1.35 + * @run main T6468404
    1.36 + */
    1.37 +
    1.38 +import java.io.IOException;
    1.39 +import java.net.URI;
    1.40 +import java.util.Arrays;
    1.41 +import java.util.Collections;
    1.42 +import java.util.Set;
    1.43 +import javax.annotation.processing.AbstractProcessor;
    1.44 +import javax.annotation.processing.RoundEnvironment;
    1.45 +import javax.annotation.processing.SupportedAnnotationTypes;
    1.46 +import javax.annotation.processing.SupportedSourceVersion;
    1.47 +import javax.annotation.processing.ProcessingEnvironment;
    1.48 +import javax.lang.model.SourceVersion;
    1.49 +import javax.lang.model.element.ExecutableElement;
    1.50 +import javax.lang.model.element.TypeElement;
    1.51 +import javax.lang.model.type.ExecutableType;
    1.52 +import javax.lang.model.type.DeclaredType;
    1.53 +import javax.lang.model.type.TypeMirror;
    1.54 +import javax.lang.model.util.Elements;
    1.55 +import javax.tools.JavaCompiler;
    1.56 +import javax.tools.JavaFileObject;
    1.57 +import javax.tools.SimpleJavaFileObject;
    1.58 +import javax.tools.ToolProvider;
    1.59 +
    1.60 +public class T6468404 extends ToolTester {
    1.61 +    void test(String... args) {
    1.62 +        System.err.println("Compiling with sources:");
    1.63 +        task = tool.getTask(
    1.64 +                null, fm, null, null,
    1.65 +                null, Collections.singleton(new DummyFO("C")));
    1.66 +        task.setProcessors(Collections.singleton(new P()));
    1.67 +        if (!task.call())
    1.68 +            throw new AssertionError();
    1.69 +
    1.70 +        System.err.println("Compiling with binaries w/o -g:");
    1.71 +        task = tool.getTask(
    1.72 +                null, fm, null, null,
    1.73 +                null, Collections.singleton(new DummyFO("Dummy")));
    1.74 +        task.setProcessors(Collections.singleton(new P()));
    1.75 +        if (!task.call())
    1.76 +            throw new AssertionError();
    1.77 +
    1.78 +        task = tool.getTask(
    1.79 +                null, fm, null,
    1.80 +                Arrays.asList("-g"),
    1.81 +                null, Collections.singleton(new DummyFO("C")));
    1.82 +        if (!task.call())
    1.83 +            throw new AssertionError();
    1.84 +
    1.85 +        System.err.println("Compiling with binaries w/ -g:");
    1.86 +        task = tool.getTask(
    1.87 +                null, fm, null, null,
    1.88 +                null, Collections.singleton(new DummyFO("Dummy")));
    1.89 +        task.setProcessors(Collections.singleton(new P()));
    1.90 +        if (!task.call())
    1.91 +            throw new AssertionError();
    1.92 +    }
    1.93 +    public static void main(String... args) {
    1.94 +        new T6468404().test(args);
    1.95 +    }
    1.96 +
    1.97 +}
    1.98 +
    1.99 +class DummyFO extends SimpleJavaFileObject {
   1.100 +    String n;
   1.101 +    public DummyFO(String n) {
   1.102 +        super(URI.create("nowhere:/" + n + ".java"), JavaFileObject.Kind.SOURCE);
   1.103 +        this.n = n;
   1.104 +    }
   1.105 +    public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
   1.106 +        return "public class " + n + " {" + n + "(java.util.List<String> l) {}}";
   1.107 +    }
   1.108 +}
   1.109 +
   1.110 +@SupportedAnnotationTypes("*")
   1.111 +@SupportedSourceVersion(SourceVersion.RELEASE_6)
   1.112 +class P extends AbstractProcessor {
   1.113 +    boolean ran = false;
   1.114 +
   1.115 +    Elements elements;
   1.116 +
   1.117 +    @Override
   1.118 +    public synchronized void init(ProcessingEnvironment processingEnv) {
   1.119 +        super.init(processingEnv);
   1.120 +        elements = processingEnv.getElementUtils();
   1.121 +    }
   1.122 +
   1.123 +    ExecutableElement getFirstMethodIn(String name) {
   1.124 +        return (ExecutableElement)elements.getTypeElement(name).getEnclosedElements().get(0);
   1.125 +    }
   1.126 +
   1.127 +    boolean isParameterized(TypeMirror type) {
   1.128 +        return !((DeclaredType)type).getTypeArguments().isEmpty();
   1.129 +    }
   1.130 +
   1.131 +    @Override
   1.132 +    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
   1.133 +        if (!ran) {
   1.134 +            ran = true;
   1.135 +            ExecutableElement m = getFirstMethodIn("C");
   1.136 +            System.err.println("method: " + m);
   1.137 +
   1.138 +            TypeMirror type = (DeclaredType)m.getParameters().get(0).asType();
   1.139 +            System.err.println("parameters[0]: " + type);
   1.140 +            if (!isParameterized(type))
   1.141 +                throw new AssertionError(type);
   1.142 +
   1.143 +            type = ((ExecutableType)m.asType()).getParameterTypes().get(0);
   1.144 +            System.err.println("parameterTypes[0]: " + type);
   1.145 +            if (!isParameterized(type))
   1.146 +                throw new AssertionError(type);
   1.147 +            System.err.println();
   1.148 +        }
   1.149 +        return true;
   1.150 +    }
   1.151 +}

mercurial