test/tools/javac/quid/QuotedIdent_BAD61.java

Fri, 26 Jun 2009 19:12:41 -0700

author
jjg
date
Fri, 26 Jun 2009 19:12:41 -0700
changeset 309
664edca41e34
permissions
-rw-r--r--

6855544: add missing files
Reviewed-by: jjg, mcimadamore, darcy
Contributed-by: mernst@cs.washington.edu, mali@csail.mit.edu, mpapi@csail.mit.edu

     1 /*
     2  * Copyright 2008 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
    21  * have any questions.
    22  */
    24 /*
    25  * ##test
    26  * ##bug 6746458
    27  * ##summary Verify correct lexing of quoted identifiers.
    28  * ##author jrose
    29  *
    30  * ##library ..
    31  * ##run main quid.QuotedIdent_BAD61
    32  */
    34 /*
    35  * Standalone testing:
    36  * <code>
    37  * $ cd $MY_REPO_DIR/langtools
    38  * $ (cd make; make)
    39  * $ ./dist/bootstrap/bin/javac -d dist test/tools/javac/quid/QuotedIdent_BAD61.java
    40  * $ java -version  # should print 1.6 or later
    41  * $ java -cp dist quid.QuotedIdent_BAD61
    42  * </code>
    43  */
    45 package quid;
    47 public class QuotedIdent_BAD61 {
    48     static void check(int testid, String have, String expect)
    49                 throws RuntimeException {
    50         if ((have == null && have != expect) ||
    51                 (have != null && !have.equals(expect))) {
    52             String msg =
    53                 "TEST " + testid + ": HAVE \"" +
    54                 have + "\" EXPECT \"" + expect + "\"";
    55             System.out.println("StringConversion: " + msg);
    56             throw new RuntimeException(msg);
    57         }
    58     }
    60     // negative tests:
    61     static class #"" { } //BAD empty ident name
    62     //static class #"<foo>" { } //BAD bad char in ident name
    63     /*static class /*(//BAD ident name interrupted by newline) #"jump:
    64     " { } /* uncomment previous line to attempt class w/ bad name */
    66     static class #"int" extends Number {
    67         final int #"int";
    68         #"int"(int #"int") {
    69             this.#"int" = #"int";
    70         }
    71         static #"int" valueOf(int #"int") {
    72             return new #"int"(#"int");
    73         }
    74         public int intValue() { return #"int"; }
    75         public long longValue() { return #"int"; }
    76         public float floatValue() { return #"int"; }
    77         public double doubleValue() { return #"int"; }
    78         public String toString() { return String.valueOf(#"int"); }
    79     }
    81     class #"*86" {
    82         String #"555-1212"() { return "[*86.555-1212]"; }
    83     }
    84     static#"*86"#"MAKE-*86"() {   // note close spacing
    85         return new QuotedIdent_BAD61().new#"*86"();
    86     }
    88     static String bar() { return "[bar]"; }
    90     public static void main(String[] args) throws Exception {
    91         String s;
    93         String #"sticky \' wicket" = "wicked ' stick";
    94         s = #"sticky ' wicket";
    95         check(11, s, "wicked \' stick");
    96         check(12, #"s", s);
    97         check(13, #"\163", s);
    99         s = #"QuotedIdent_BAD61".bar();
   100         check(21, s, "[bar]");
   102         s = #"int".valueOf(123).toString();
   103         check(22, s, "123");
   105         s = #"MAKE-*86"().#"555-1212"();
   106         check(23, s, "[*86.555-1212]");
   108         class#"{{{inmost}}}" { }
   109         s = new#"{{{inmost}}}"().getClass().getName();
   110         if (!s.endsWith("{{{inmost}}}"))
   111             check(24, s, "should end with \"{{{inmost}}}\"");
   113         s = #"Yog-Shoggoth".#"(nameless ululation)";
   114         check(25, s, "Tekeli-li!");
   116         s = #"int".class.getName();
   117         check(31, s, QuotedIdent_BAD61.class.getName()+"$int");
   119         Class x86 = Class.forName(QuotedIdent_BAD61.class.getName()+"$*86");
   120         if (x86 != #"*86".class)
   121             check(32, "reflected "+x86, "static "+#"*86".class);
   123         s = (String) x86.getDeclaredMethod("555-1212").invoke(#"MAKE-*86"());
   124         check(31, s, "[*86.555-1212]");
   126         System.out.println("OK");
   127     }
   128 }
   130 interface #"Yog-Shoggoth" {
   131     final String #"(nameless ululation)" = "Tekeli-li!";
   132 }

mercurial