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