Mon, 24 Oct 2011 13:00:30 +0100
7098660: Write better overload resolution/inference tests
Summary: Add overload/inference debug diagnostics - added test harness using annotations to check outcome of overload resolution/inference
Reviewed-by: jjg
mcimadamore@1077 | 1 | /* |
mcimadamore@1077 | 2 | * Copyright (c) 20011, Oracle and/or its affiliates. All rights reserved. |
mcimadamore@1077 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
mcimadamore@1077 | 4 | * |
mcimadamore@1077 | 5 | * This code is free software; you can redistribute it and/or modify it |
mcimadamore@1077 | 6 | * under the terms of the GNU General Public License version 2 only, as |
mcimadamore@1077 | 7 | * published by the Free Software Foundation. |
mcimadamore@1077 | 8 | * |
mcimadamore@1077 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
mcimadamore@1077 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
mcimadamore@1077 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
mcimadamore@1077 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
mcimadamore@1077 | 13 | * accompanied this code). |
mcimadamore@1077 | 14 | * |
mcimadamore@1077 | 15 | * You should have received a copy of the GNU General Public License version |
mcimadamore@1077 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
mcimadamore@1077 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
mcimadamore@1077 | 18 | * |
mcimadamore@1077 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
mcimadamore@1077 | 20 | * or visit www.oracle.com if you need additional information or have any |
mcimadamore@1077 | 21 | * questions. |
mcimadamore@1077 | 22 | */ |
mcimadamore@1077 | 23 | |
mcimadamore@1077 | 24 | /* |
mcimadamore@1077 | 25 | * @test |
mcimadamore@1077 | 26 | * @bug 7086261 |
mcimadamore@1077 | 27 | * @summary javac doesn't report error as expected, it only reports ClientCodeWrapper$DiagnosticSourceUnwrapper |
mcimadamore@1077 | 28 | */ |
mcimadamore@1077 | 29 | |
mcimadamore@1077 | 30 | import javax.tools.*; |
mcimadamore@1077 | 31 | |
mcimadamore@1077 | 32 | import com.sun.tools.javac.api.ClientCodeWrapper.DiagnosticSourceUnwrapper; |
mcimadamore@1077 | 33 | import com.sun.tools.javac.util.JCDiagnostic; |
mcimadamore@1077 | 34 | |
mcimadamore@1077 | 35 | import java.net.URI; |
mcimadamore@1077 | 36 | import java.util.Arrays; |
mcimadamore@1077 | 37 | |
mcimadamore@1077 | 38 | import static javax.tools.StandardLocation.*; |
mcimadamore@1077 | 39 | import static javax.tools.JavaFileObject.Kind.*; |
mcimadamore@1077 | 40 | |
mcimadamore@1077 | 41 | |
mcimadamore@1077 | 42 | public class T7086261 { |
mcimadamore@1077 | 43 | |
mcimadamore@1077 | 44 | static class ErroneousSource extends SimpleJavaFileObject { |
mcimadamore@1077 | 45 | public ErroneousSource() { |
mcimadamore@1077 | 46 | super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); |
mcimadamore@1077 | 47 | } |
mcimadamore@1077 | 48 | public CharSequence getCharContent(boolean ignoreEncodingErrors) { |
mcimadamore@1077 | 49 | return "class Test { NonexistentClass c = null; }"; |
mcimadamore@1077 | 50 | } |
mcimadamore@1077 | 51 | } |
mcimadamore@1077 | 52 | |
mcimadamore@1077 | 53 | static class DiagnosticChecker implements DiagnosticListener<javax.tools.JavaFileObject> { |
mcimadamore@1077 | 54 | public void report(Diagnostic message) { |
mcimadamore@1077 | 55 | if (!(message instanceof DiagnosticSourceUnwrapper)) { |
mcimadamore@1077 | 56 | throw new AssertionError("Wrapped diagnostic expected!"); |
mcimadamore@1077 | 57 | } |
mcimadamore@1077 | 58 | String actual = message.toString(); |
mcimadamore@1077 | 59 | JCDiagnostic jd = (JCDiagnostic)((DiagnosticSourceUnwrapper)message).d; |
mcimadamore@1077 | 60 | String expected = jd.toString(); |
mcimadamore@1077 | 61 | if (!actual.equals(expected)) { |
mcimadamore@1077 | 62 | throw new AssertionError("expected = " + expected + "\nfound = " + actual); |
mcimadamore@1077 | 63 | } |
mcimadamore@1077 | 64 | } |
mcimadamore@1077 | 65 | }; |
mcimadamore@1077 | 66 | |
mcimadamore@1077 | 67 | void test() throws Throwable { |
mcimadamore@1077 | 68 | JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); |
mcimadamore@1077 | 69 | JavaFileManager jfm = javac.getStandardFileManager(null, null, null); |
mcimadamore@1077 | 70 | JavaCompiler.CompilationTask task = |
mcimadamore@1077 | 71 | javac.getTask(null, jfm, new DiagnosticChecker(), null, null, Arrays.asList(new ErroneousSource())); |
mcimadamore@1077 | 72 | task.call(); |
mcimadamore@1077 | 73 | } |
mcimadamore@1077 | 74 | |
mcimadamore@1077 | 75 | public static void main(String[] args) throws Throwable { |
mcimadamore@1077 | 76 | new T7086261().test(); |
mcimadamore@1077 | 77 | } |
mcimadamore@1077 | 78 | } |