test/tools/javac/tree/TreeKindTest.java

Tue, 28 Dec 2010 15:54:52 -0800

author
ohair
date
Tue, 28 Dec 2010 15:54:52 -0800
changeset 798
4868a36f6fd8
parent 662
b4e7a57af8df
child 1521
71f35e4b93a5
permissions
-rw-r--r--

6962318: Update copyright year
Reviewed-by: xdono

     1 /*
     2  * Copyright (c) 2006, 2010, 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 6341023
    27  * @summary Tree API: Tree.Kind should have mapping to interface
    28  */
    30 import com.sun.source.tree.*;
    32 public class TreeKindTest{
    33     public static void main(String... args) {
    34         boolean ok = true;
    36         for (Tree.Kind k: Tree.Kind.values()) {
    37             //System.err.println(k + " " + k.asInterface());
    38             Class<? extends Tree> i = k.asInterface();
    39             switch (k) {
    40             case POSTFIX_INCREMENT:
    41             case POSTFIX_DECREMENT:
    42             case PREFIX_INCREMENT:
    43             case PREFIX_DECREMENT:
    44             case UNARY_PLUS:
    45             case UNARY_MINUS:
    46             case BITWISE_COMPLEMENT:
    47             case LOGICAL_COMPLEMENT:
    48                 ok = ok & verify(k, i, i == UnaryTree.class);
    49                 break;
    51             case MULTIPLY:
    52             case DIVIDE:
    53             case REMAINDER:
    54             case PLUS:
    55             case MINUS:
    56             case LEFT_SHIFT:
    57             case RIGHT_SHIFT:
    58             case UNSIGNED_RIGHT_SHIFT:
    59             case LESS_THAN:
    60             case GREATER_THAN:
    61             case LESS_THAN_EQUAL:
    62             case GREATER_THAN_EQUAL:
    63             case EQUAL_TO:
    64             case NOT_EQUAL_TO:
    65             case AND:
    66             case XOR:
    67             case OR:
    68             case CONDITIONAL_AND:
    69             case CONDITIONAL_OR:
    70                 ok = ok & verify(k, i, i == BinaryTree.class);
    71                 break;
    73             case MULTIPLY_ASSIGNMENT:
    74             case DIVIDE_ASSIGNMENT:
    75             case REMAINDER_ASSIGNMENT:
    76             case PLUS_ASSIGNMENT:
    77             case MINUS_ASSIGNMENT:
    78             case LEFT_SHIFT_ASSIGNMENT:
    79             case RIGHT_SHIFT_ASSIGNMENT:
    80             case UNSIGNED_RIGHT_SHIFT_ASSIGNMENT:
    81             case AND_ASSIGNMENT:
    82             case XOR_ASSIGNMENT:
    83             case OR_ASSIGNMENT:
    84                 ok = ok & verify(k, i, i == CompoundAssignmentTree.class);
    85                 break;
    87             case INT_LITERAL:
    88             case LONG_LITERAL:
    89             case FLOAT_LITERAL:
    90             case DOUBLE_LITERAL:
    91             case BOOLEAN_LITERAL:
    92             case CHAR_LITERAL:
    93             case STRING_LITERAL:
    94             case NULL_LITERAL:
    95                 ok = ok & verify(k, i, i == LiteralTree.class);
    96                 break;
    98             case UNBOUNDED_WILDCARD:
    99             case EXTENDS_WILDCARD:
   100             case SUPER_WILDCARD:
   101                 ok = ok & verify(k, i, i == WildcardTree.class);
   102                 break;
   104             case INTERFACE:
   105             case ANNOTATION_TYPE:
   106             case ENUM:
   107             case CLASS:
   108                 ok = ok & verify(k, i, i == ClassTree.class);
   109                 break;
   111             case OTHER:
   112                 ok = ok & verify(k, i, i == null);
   113                 break;
   115             default:
   116                 String ks = k.toString().replace("_", "") + "tree";
   117                 String iName = i.getName();
   118                 String is = iName.substring(iName.lastIndexOf(".") + 1);
   119                 ok = ok & verify(k, i, ks.equalsIgnoreCase(is));
   120             }
   121         }
   123         if (!ok)
   124             throw new AssertionError("test failed");
   125     }
   127     static boolean verify(Tree.Kind k, Class<?> c, boolean b) {
   128         if (!b)
   129             System.err.println("error: " + k + " " + c);
   130         return b;
   131     }
   132 }

mercurial