test/tools/javac/quid/QuotedIdent.java

Fri, 12 Nov 2010 12:33:52 +0000

author
mcimadamore
date
Fri, 12 Nov 2010 12:33:52 +0000
changeset 742
fdc67f5170e9
parent 674
584365f256a7
permissions
-rw-r--r--

6999067: cast for invokeExact call gets redundant cast to <type> warnings
Summary: Xlint:cast should not report cast used in order to specify target type in polymorphic signature calls
Reviewed-by: jjg

jrose@267 1 /*
mcimadamore@674 2 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
jrose@267 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jrose@267 4 *
jrose@267 5 * This code is free software; you can redistribute it and/or modify it
jrose@267 6 * under the terms of the GNU General Public License version 2 only, as
jrose@267 7 * published by the Free Software Foundation.
jrose@267 8 *
jrose@267 9 * This code is distributed in the hope that it will be useful, but WITHOUT
jrose@267 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jrose@267 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jrose@267 12 * version 2 for more details (a copy is included in the LICENSE file that
jrose@267 13 * accompanied this code).
jrose@267 14 *
jrose@267 15 * You should have received a copy of the GNU General Public License version
jrose@267 16 * 2 along with this work; if not, write to the Free Software Foundation,
jrose@267 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jrose@267 18 *
ohair@554 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 20 * or visit www.oracle.com if you need additional information or have any
ohair@554 21 * questions.
jrose@267 22 */
jrose@267 23
jrose@267 24 /*
jrose@267 25 * @test
jrose@267 26 * @bug 6746458
jrose@267 27 * @summary Verify correct lexing of quoted identifiers.
jrose@267 28 * @author jrose
jjg@392 29 * @ignore 6877225 test fails on Windows:
jjg@392 30 * QuotedIdent.java:81: error while writing QuotedIdent.*86: PATH\QuotedIdent$*86.class
jjg@392 31 * (The filename, directory name, or volume label syntax is incorrect)
jrose@267 32 *
jrose@267 33 * @library ..
mcimadamore@674 34 * @compile -source 7 -target 7 -XDinvokedynamic QuotedIdent.java
jrose@267 35 * @run main quid.QuotedIdent
jrose@267 36 */
jrose@267 37
jrose@267 38 /*
jrose@267 39 * Standalone testing:
jrose@267 40 * <code>
jrose@267 41 * $ cd $MY_REPO_DIR/langtools
jrose@267 42 * $ (cd make; make)
jrose@267 43 * $ ./dist/bootstrap/bin/javac -d dist test/tools/javac/quid/QuotedIdent.java
jrose@267 44 * $ java -version # should print 1.6 or later
jrose@267 45 * $ java -cp dist quid.QuotedIdent
jrose@267 46 * </code>
jrose@267 47 */
jrose@267 48
jrose@267 49 package quid;
jrose@267 50
jrose@267 51 public class QuotedIdent {
jrose@267 52 static void check(int testid, String have, String expect)
jrose@267 53 throws RuntimeException {
jrose@267 54 if ((have == null && have != expect) ||
jrose@267 55 (have != null && !have.equals(expect))) {
jrose@267 56 String msg =
jrose@267 57 "TEST " + testid + ": HAVE \"" +
jrose@267 58 have + "\" EXPECT \"" + expect + "\"";
jrose@267 59 System.out.println("StringConversion: " + msg);
jrose@267 60 throw new RuntimeException(msg);
jrose@267 61 }
jrose@267 62 }
jrose@267 63
jrose@267 64 // negative tests:
jrose@267 65 //static class #"" { } //BAD empty ident name
jrose@267 66 //static class #"<foo>" { } //BAD bad char in ident name
jrose@267 67 /*static class /*(//BAD ident name interrupted by newline) #"jump:
jrose@267 68 " { } /* uncomment previous line to attempt class w/ bad name */
jrose@267 69
jrose@267 70 static class #"int" extends Number {
jrose@267 71 final int #"int";
jrose@267 72 #"int"(int #"int") {
jrose@267 73 this.#"int" = #"int";
jrose@267 74 }
jrose@267 75 static #"int" valueOf(int #"int") {
jrose@267 76 return new #"int"(#"int");
jrose@267 77 }
jrose@267 78 public int intValue() { return #"int"; }
jrose@267 79 public long longValue() { return #"int"; }
jrose@267 80 public float floatValue() { return #"int"; }
jrose@267 81 public double doubleValue() { return #"int"; }
jrose@267 82 public String toString() { return String.valueOf(#"int"); }
jrose@267 83 }
jrose@267 84
jrose@267 85 class #"*86" {
jrose@267 86 String #"555-1212"() { return "[*86.555-1212]"; }
jrose@267 87 }
jrose@267 88 static#"*86"#"MAKE-*86"() { // note close spacing
jrose@267 89 return new QuotedIdent().new#"*86"();
jrose@267 90 }
jrose@267 91
jrose@267 92 static String bar() { return "[bar]"; }
jrose@267 93
jrose@267 94 public static void main(String[] args) throws Exception {
jrose@267 95 String s;
jrose@267 96
jrose@267 97 String #"sticky \' wicket" = "wicked ' stick";
jrose@267 98 s = #"sticky ' wicket";
jrose@267 99 check(11, s, "wicked \' stick");
jrose@267 100 check(12, #"s", s);
jrose@267 101 check(13, #"\163", s);
jrose@267 102
jrose@267 103 s = #"QuotedIdent".bar();
jrose@267 104 check(21, s, "[bar]");
jrose@267 105
jrose@267 106 s = #"int".valueOf(123).toString();
jrose@267 107 check(22, s, "123");
jrose@267 108
jrose@267 109 s = #"MAKE-*86"().#"555-1212"();
jrose@267 110 check(23, s, "[*86.555-1212]");
jrose@267 111
jrose@267 112 class#"{{{inmost}}}" { }
jrose@267 113 s = new#"{{{inmost}}}"().getClass().getName();
jrose@267 114 if (!s.endsWith("{{{inmost}}}"))
jrose@267 115 check(24, s, "should end with \"{{{inmost}}}\"");
jrose@267 116
jrose@267 117 s = #"Yog-Shoggoth".#"(nameless ululation)";
jrose@267 118 check(25, s, "Tekeli-li!");
jrose@267 119
jrose@267 120 s = #"int".class.getName();
jrose@267 121 check(31, s, QuotedIdent.class.getName()+"$int");
jrose@267 122
mcimadamore@674 123 Class<?> x86 = Class.forName(QuotedIdent.class.getName()+"$*86");
jrose@267 124 if (x86 != #"*86".class)
jrose@267 125 check(32, "reflected "+x86, "static "+#"*86".class);
jrose@267 126
jrose@267 127 s = (String) x86.getDeclaredMethod("555-1212").invoke(#"MAKE-*86"());
jrose@267 128 check(31, s, "[*86.555-1212]");
jrose@267 129
jrose@267 130 System.out.println("OK");
jrose@267 131 }
jrose@267 132 }
jrose@267 133
jrose@267 134 interface #"Yog-Shoggoth" {
jrose@267 135 final String #"(nameless ululation)" = "Tekeli-li!";
jrose@267 136 }

mercurial