test/tools/javac/tree/TreeKindTest.java

changeset 662
b4e7a57af8df
parent 554
9d9f26857129
child 798
4868a36f6fd8
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javac/tree/TreeKindTest.java	Fri Aug 27 17:21:17 2010 -0700
     1.3 @@ -0,0 +1,132 @@
     1.4 +/*
     1.5 + * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + */
    1.26 +
    1.27 +/*
    1.28 + * @test
    1.29 + * @bug 6341023
    1.30 + * @summary Tree API: Tree.Kind should have mapping to interface
    1.31 + */
    1.32 +
    1.33 +import com.sun.source.tree.*;
    1.34 +
    1.35 +public class TreeKindTest{
    1.36 +    public static void main(String... args) {
    1.37 +        boolean ok = true;
    1.38 +
    1.39 +        for (Tree.Kind k: Tree.Kind.values()) {
    1.40 +            //System.err.println(k + " " + k.asInterface());
    1.41 +            Class<? extends Tree> i = k.asInterface();
    1.42 +            switch (k) {
    1.43 +            case POSTFIX_INCREMENT:
    1.44 +            case POSTFIX_DECREMENT:
    1.45 +            case PREFIX_INCREMENT:
    1.46 +            case PREFIX_DECREMENT:
    1.47 +            case UNARY_PLUS:
    1.48 +            case UNARY_MINUS:
    1.49 +            case BITWISE_COMPLEMENT:
    1.50 +            case LOGICAL_COMPLEMENT:
    1.51 +                ok = ok & verify(k, i, i == UnaryTree.class);
    1.52 +                break;
    1.53 +
    1.54 +            case MULTIPLY:
    1.55 +            case DIVIDE:
    1.56 +            case REMAINDER:
    1.57 +            case PLUS:
    1.58 +            case MINUS:
    1.59 +            case LEFT_SHIFT:
    1.60 +            case RIGHT_SHIFT:
    1.61 +            case UNSIGNED_RIGHT_SHIFT:
    1.62 +            case LESS_THAN:
    1.63 +            case GREATER_THAN:
    1.64 +            case LESS_THAN_EQUAL:
    1.65 +            case GREATER_THAN_EQUAL:
    1.66 +            case EQUAL_TO:
    1.67 +            case NOT_EQUAL_TO:
    1.68 +            case AND:
    1.69 +            case XOR:
    1.70 +            case OR:
    1.71 +            case CONDITIONAL_AND:
    1.72 +            case CONDITIONAL_OR:
    1.73 +                ok = ok & verify(k, i, i == BinaryTree.class);
    1.74 +                break;
    1.75 +
    1.76 +            case MULTIPLY_ASSIGNMENT:
    1.77 +            case DIVIDE_ASSIGNMENT:
    1.78 +            case REMAINDER_ASSIGNMENT:
    1.79 +            case PLUS_ASSIGNMENT:
    1.80 +            case MINUS_ASSIGNMENT:
    1.81 +            case LEFT_SHIFT_ASSIGNMENT:
    1.82 +            case RIGHT_SHIFT_ASSIGNMENT:
    1.83 +            case UNSIGNED_RIGHT_SHIFT_ASSIGNMENT:
    1.84 +            case AND_ASSIGNMENT:
    1.85 +            case XOR_ASSIGNMENT:
    1.86 +            case OR_ASSIGNMENT:
    1.87 +                ok = ok & verify(k, i, i == CompoundAssignmentTree.class);
    1.88 +                break;
    1.89 +
    1.90 +            case INT_LITERAL:
    1.91 +            case LONG_LITERAL:
    1.92 +            case FLOAT_LITERAL:
    1.93 +            case DOUBLE_LITERAL:
    1.94 +            case BOOLEAN_LITERAL:
    1.95 +            case CHAR_LITERAL:
    1.96 +            case STRING_LITERAL:
    1.97 +            case NULL_LITERAL:
    1.98 +                ok = ok & verify(k, i, i == LiteralTree.class);
    1.99 +                break;
   1.100 +
   1.101 +            case UNBOUNDED_WILDCARD:
   1.102 +            case EXTENDS_WILDCARD:
   1.103 +            case SUPER_WILDCARD:
   1.104 +                ok = ok & verify(k, i, i == WildcardTree.class);
   1.105 +                break;
   1.106 +
   1.107 +            case INTERFACE:
   1.108 +            case ANNOTATION_TYPE:
   1.109 +            case ENUM:
   1.110 +            case CLASS:
   1.111 +                ok = ok & verify(k, i, i == ClassTree.class);
   1.112 +                break;
   1.113 +
   1.114 +            case OTHER:
   1.115 +                ok = ok & verify(k, i, i == null);
   1.116 +                break;
   1.117 +
   1.118 +            default:
   1.119 +                String ks = k.toString().replace("_", "") + "tree";
   1.120 +                String iName = i.getName();
   1.121 +                String is = iName.substring(iName.lastIndexOf(".") + 1);
   1.122 +                ok = ok & verify(k, i, ks.equalsIgnoreCase(is));
   1.123 +            }
   1.124 +        }
   1.125 +
   1.126 +        if (!ok)
   1.127 +            throw new AssertionError("test failed");
   1.128 +    }
   1.129 +
   1.130 +    static boolean verify(Tree.Kind k, Class<?> c, boolean b) {
   1.131 +        if (!b)
   1.132 +            System.err.println("error: " + k + " " + c);
   1.133 +        return b;
   1.134 +    }
   1.135 +}

mercurial