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