test/tools/javac/quid/QuotedIdent.java

Thu, 15 Jul 2010 16:31:02 +0100

author
mcimadamore
date
Thu, 15 Jul 2010 16:31:02 +0100
changeset 607
b49b0d72c071
parent 554
9d9f26857129
child 674
584365f256a7
permissions
-rw-r--r--

6967002: JDK7 b99 javac compilation error (java.lang.AssertionError)
Summary: bug in JavacParser related to parsing of type annotations in varargs position
Reviewed-by: jjg
Contributed-by: mahmood@notnoop.com

     1 /*
     2  * Copyright (c) 2008, 2009, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  */
    24 /*
    25  * @test
    26  * @bug 6746458
    27  * @summary Verify correct lexing of quoted identifiers.
    28  * @author jrose
    29  * @ignore 6877225 test fails on Windows:
    30  *      QuotedIdent.java:81: error while writing QuotedIdent.*86: PATH\QuotedIdent$*86.class
    31  *      (The filename, directory name, or volume label syntax is incorrect)
    32  *
    33  * @library ..
    34  * @run main quid.QuotedIdent
    35  */
    37 /*
    38  * Standalone testing:
    39  * <code>
    40  * $ cd $MY_REPO_DIR/langtools
    41  * $ (cd make; make)
    42  * $ ./dist/bootstrap/bin/javac -d dist test/tools/javac/quid/QuotedIdent.java
    43  * $ java -version  # should print 1.6 or later
    44  * $ java -cp dist quid.QuotedIdent
    45  * </code>
    46  */
    48 package quid;
    50 public class QuotedIdent {
    51     static void check(int testid, String have, String expect)
    52                 throws RuntimeException {
    53         if ((have == null && have != expect) ||
    54                 (have != null && !have.equals(expect))) {
    55             String msg =
    56                 "TEST " + testid + ": HAVE \"" +
    57                 have + "\" EXPECT \"" + expect + "\"";
    58             System.out.println("StringConversion: " + msg);
    59             throw new RuntimeException(msg);
    60         }
    61     }
    63     // negative tests:
    64     //static class #"" { } //BAD empty ident name
    65     //static class #"<foo>" { } //BAD bad char in ident name
    66     /*static class /*(//BAD ident name interrupted by newline) #"jump:
    67     " { } /* uncomment previous line to attempt class w/ bad name */
    69     static class #"int" extends Number {
    70         final int #"int";
    71         #"int"(int #"int") {
    72             this.#"int" = #"int";
    73         }
    74         static #"int" valueOf(int #"int") {
    75             return new #"int"(#"int");
    76         }
    77         public int intValue() { return #"int"; }
    78         public long longValue() { return #"int"; }
    79         public float floatValue() { return #"int"; }
    80         public double doubleValue() { return #"int"; }
    81         public String toString() { return String.valueOf(#"int"); }
    82     }
    84     class #"*86" {
    85         String #"555-1212"() { return "[*86.555-1212]"; }
    86     }
    87     static#"*86"#"MAKE-*86"() {   // note close spacing
    88         return new QuotedIdent().new#"*86"();
    89     }
    91     static String bar() { return "[bar]"; }
    93     public static void main(String[] args) throws Exception {
    94         String s;
    96         String #"sticky \' wicket" = "wicked ' stick";
    97         s = #"sticky ' wicket";
    98         check(11, s, "wicked \' stick");
    99         check(12, #"s", s);
   100         check(13, #"\163", s);
   102         s = #"QuotedIdent".bar();
   103         check(21, s, "[bar]");
   105         s = #"int".valueOf(123).toString();
   106         check(22, s, "123");
   108         s = #"MAKE-*86"().#"555-1212"();
   109         check(23, s, "[*86.555-1212]");
   111         class#"{{{inmost}}}" { }
   112         s = new#"{{{inmost}}}"().getClass().getName();
   113         if (!s.endsWith("{{{inmost}}}"))
   114             check(24, s, "should end with \"{{{inmost}}}\"");
   116         s = #"Yog-Shoggoth".#"(nameless ululation)";
   117         check(25, s, "Tekeli-li!");
   119         s = #"int".class.getName();
   120         check(31, s, QuotedIdent.class.getName()+"$int");
   122         Class x86 = Class.forName(QuotedIdent.class.getName()+"$*86");
   123         if (x86 != #"*86".class)
   124             check(32, "reflected "+x86, "static "+#"*86".class);
   126         s = (String) x86.getDeclaredMethod("555-1212").invoke(#"MAKE-*86"());
   127         check(31, s, "[*86.555-1212]");
   129         System.out.println("OK");
   130     }
   131 }
   133 interface #"Yog-Shoggoth" {
   134     final String #"(nameless ululation)" = "Tekeli-li!";
   135 }

mercurial