jjg@309: /* jjg@309: * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. jjg@309: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jjg@309: * jjg@309: * This code is free software; you can redistribute it and/or modify it jjg@309: * under the terms of the GNU General Public License version 2 only, as jjg@309: * published by the Free Software Foundation. jjg@309: * jjg@309: * This code is distributed in the hope that it will be useful, but WITHOUT jjg@309: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jjg@309: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jjg@309: * version 2 for more details (a copy is included in the LICENSE file that jjg@309: * accompanied this code). jjg@309: * jjg@309: * You should have received a copy of the GNU General Public License version jjg@309: * 2 along with this work; if not, write to the Free Software Foundation, jjg@309: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jjg@309: * jjg@309: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, jjg@309: * CA 95054 USA or visit www.sun.com if you need additional information or jjg@309: * have any questions. jjg@309: */ jjg@309: jjg@309: /* jjg@309: * ##test jjg@309: * ##bug 6746458 jjg@309: * ##summary Verify correct lexing of quoted identifiers. jjg@309: * ##author jrose jjg@309: * jjg@309: * ##library .. jjg@309: * ##run main quid.QuotedIdent_BAD61 jjg@309: */ jjg@309: jjg@309: /* jjg@309: * Standalone testing: jjg@309: * jjg@309: * $ cd $MY_REPO_DIR/langtools jjg@309: * $ (cd make; make) jjg@309: * $ ./dist/bootstrap/bin/javac -d dist test/tools/javac/quid/QuotedIdent_BAD61.java jjg@309: * $ java -version # should print 1.6 or later jjg@309: * $ java -cp dist quid.QuotedIdent_BAD61 jjg@309: * jjg@309: */ jjg@309: jjg@309: package quid; jjg@309: jjg@309: public class QuotedIdent_BAD61 { jjg@309: static void check(int testid, String have, String expect) jjg@309: throws RuntimeException { jjg@309: if ((have == null && have != expect) || jjg@309: (have != null && !have.equals(expect))) { jjg@309: String msg = jjg@309: "TEST " + testid + ": HAVE \"" + jjg@309: have + "\" EXPECT \"" + expect + "\""; jjg@309: System.out.println("StringConversion: " + msg); jjg@309: throw new RuntimeException(msg); jjg@309: } jjg@309: } jjg@309: jjg@309: // negative tests: jjg@309: static class #"" { } //BAD empty ident name jjg@309: //static class #"" { } //BAD bad char in ident name jjg@309: /*static class /*(//BAD ident name interrupted by newline) #"jump: jjg@309: " { } /* uncomment previous line to attempt class w/ bad name */ jjg@309: jjg@309: static class #"int" extends Number { jjg@309: final int #"int"; jjg@309: #"int"(int #"int") { jjg@309: this.#"int" = #"int"; jjg@309: } jjg@309: static #"int" valueOf(int #"int") { jjg@309: return new #"int"(#"int"); jjg@309: } jjg@309: public int intValue() { return #"int"; } jjg@309: public long longValue() { return #"int"; } jjg@309: public float floatValue() { return #"int"; } jjg@309: public double doubleValue() { return #"int"; } jjg@309: public String toString() { return String.valueOf(#"int"); } jjg@309: } jjg@309: jjg@309: class #"*86" { jjg@309: String #"555-1212"() { return "[*86.555-1212]"; } jjg@309: } jjg@309: static#"*86"#"MAKE-*86"() { // note close spacing jjg@309: return new QuotedIdent_BAD61().new#"*86"(); jjg@309: } jjg@309: jjg@309: static String bar() { return "[bar]"; } jjg@309: jjg@309: public static void main(String[] args) throws Exception { jjg@309: String s; jjg@309: jjg@309: String #"sticky \' wicket" = "wicked ' stick"; jjg@309: s = #"sticky ' wicket"; jjg@309: check(11, s, "wicked \' stick"); jjg@309: check(12, #"s", s); jjg@309: check(13, #"\163", s); jjg@309: jjg@309: s = #"QuotedIdent_BAD61".bar(); jjg@309: check(21, s, "[bar]"); jjg@309: jjg@309: s = #"int".valueOf(123).toString(); jjg@309: check(22, s, "123"); jjg@309: jjg@309: s = #"MAKE-*86"().#"555-1212"(); jjg@309: check(23, s, "[*86.555-1212]"); jjg@309: jjg@309: class#"{{{inmost}}}" { } jjg@309: s = new#"{{{inmost}}}"().getClass().getName(); jjg@309: if (!s.endsWith("{{{inmost}}}")) jjg@309: check(24, s, "should end with \"{{{inmost}}}\""); jjg@309: jjg@309: s = #"Yog-Shoggoth".#"(nameless ululation)"; jjg@309: check(25, s, "Tekeli-li!"); jjg@309: jjg@309: s = #"int".class.getName(); jjg@309: check(31, s, QuotedIdent_BAD61.class.getName()+"$int"); jjg@309: jjg@309: Class x86 = Class.forName(QuotedIdent_BAD61.class.getName()+"$*86"); jjg@309: if (x86 != #"*86".class) jjg@309: check(32, "reflected "+x86, "static "+#"*86".class); jjg@309: jjg@309: s = (String) x86.getDeclaredMethod("555-1212").invoke(#"MAKE-*86"()); jjg@309: check(31, s, "[*86.555-1212]"); jjg@309: jjg@309: System.out.println("OK"); jjg@309: } jjg@309: } jjg@309: jjg@309: interface #"Yog-Shoggoth" { jjg@309: final String #"(nameless ululation)" = "Tekeli-li!"; jjg@309: }