Tue, 07 Sep 2010 17:32:27 +0100
6979327: method handle invocation should use casts instead of type parameters to specify return type
Summary: infer return type for polymorphic signature calls according to updated JSR 292 draft
Reviewed-by: jjg
Contributed-by: john.r.rose@oracle.com
1 /*
2 * Copyright (c) 2008, 2010, 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 */
24 /*
25 * @test
26 * @bug 6746458
27 * @summary Verify correct lexing of quoted identifiers.
28 * @author jrose
29 * @ignore 6877225 test fails on Windows:
30 * QuotedIdent.java:81: error while writing QuotedIdent.*86: PATH\QuotedIdent$*86.class
31 * (The filename, directory name, or volume label syntax is incorrect)
32 *
33 * @library ..
34 * @compile -source 7 -target 7 -XDinvokedynamic QuotedIdent.java
35 * @run main quid.QuotedIdent
36 */
38 /*
39 * Standalone testing:
40 * <code>
41 * $ cd $MY_REPO_DIR/langtools
42 * $ (cd make; make)
43 * $ ./dist/bootstrap/bin/javac -d dist test/tools/javac/quid/QuotedIdent.java
44 * $ java -version # should print 1.6 or later
45 * $ java -cp dist quid.QuotedIdent
46 * </code>
47 */
49 package quid;
51 public class QuotedIdent {
52 static void check(int testid, String have, String expect)
53 throws RuntimeException {
54 if ((have == null && have != expect) ||
55 (have != null && !have.equals(expect))) {
56 String msg =
57 "TEST " + testid + ": HAVE \"" +
58 have + "\" EXPECT \"" + expect + "\"";
59 System.out.println("StringConversion: " + msg);
60 throw new RuntimeException(msg);
61 }
62 }
64 // negative tests:
65 //static class #"" { } //BAD empty ident name
66 //static class #"<foo>" { } //BAD bad char in ident name
67 /*static class /*(//BAD ident name interrupted by newline) #"jump:
68 " { } /* uncomment previous line to attempt class w/ bad name */
70 static class #"int" extends Number {
71 final int #"int";
72 #"int"(int #"int") {
73 this.#"int" = #"int";
74 }
75 static #"int" valueOf(int #"int") {
76 return new #"int"(#"int");
77 }
78 public int intValue() { return #"int"; }
79 public long longValue() { return #"int"; }
80 public float floatValue() { return #"int"; }
81 public double doubleValue() { return #"int"; }
82 public String toString() { return String.valueOf(#"int"); }
83 }
85 class #"*86" {
86 String #"555-1212"() { return "[*86.555-1212]"; }
87 }
88 static#"*86"#"MAKE-*86"() { // note close spacing
89 return new QuotedIdent().new#"*86"();
90 }
92 static String bar() { return "[bar]"; }
94 public static void main(String[] args) throws Exception {
95 String s;
97 String #"sticky \' wicket" = "wicked ' stick";
98 s = #"sticky ' wicket";
99 check(11, s, "wicked \' stick");
100 check(12, #"s", s);
101 check(13, #"\163", s);
103 s = #"QuotedIdent".bar();
104 check(21, s, "[bar]");
106 s = #"int".valueOf(123).toString();
107 check(22, s, "123");
109 s = #"MAKE-*86"().#"555-1212"();
110 check(23, s, "[*86.555-1212]");
112 class#"{{{inmost}}}" { }
113 s = new#"{{{inmost}}}"().getClass().getName();
114 if (!s.endsWith("{{{inmost}}}"))
115 check(24, s, "should end with \"{{{inmost}}}\"");
117 s = #"Yog-Shoggoth".#"(nameless ululation)";
118 check(25, s, "Tekeli-li!");
120 s = #"int".class.getName();
121 check(31, s, QuotedIdent.class.getName()+"$int");
123 Class<?> x86 = Class.forName(QuotedIdent.class.getName()+"$*86");
124 if (x86 != #"*86".class)
125 check(32, "reflected "+x86, "static "+#"*86".class);
127 s = (String) x86.getDeclaredMethod("555-1212").invoke(#"MAKE-*86"());
128 check(31, s, "[*86.555-1212]");
130 System.out.println("OK");
131 }
132 }
134 interface #"Yog-Shoggoth" {
135 final String #"(nameless ululation)" = "Tekeli-li!";
136 }