langtools/test/tools/javac/tree/TreeKindTest.java
author akulyakh
Thu, 21 May 2015 11:41:04 -0700
changeset 30730 d3ce7619db2c
parent 15385 ee1eebe7e210
child 42407 f3702cff2933
permissions -rw-r--r--
8076543: Add @modules as needed to the langtools tests Reviewed-by: jjg, shurailine
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 15385
diff changeset
     2
 * Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
06bc494ca11e Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    21
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
/*
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
 * @test
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
 * @bug 6341023
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
 * @summary Tree API: Tree.Kind should have mapping to interface
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 15385
diff changeset
    28
 * @modules jdk.compiler
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import com.sun.source.tree.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 7681
diff changeset
    33
public class TreeKindTest {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
    public static void main(String... args) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
        boolean ok = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
        for (Tree.Kind k: Tree.Kind.values()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
            //System.err.println(k + " " + k.asInterface());
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
            Class<? extends Tree> i = k.asInterface();
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
            switch (k) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
            case POSTFIX_INCREMENT:
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
            case POSTFIX_DECREMENT:
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
            case PREFIX_INCREMENT:
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
            case PREFIX_DECREMENT:
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
            case UNARY_PLUS:
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
            case UNARY_MINUS:
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
            case BITWISE_COMPLEMENT:
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
            case LOGICAL_COMPLEMENT:
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
                ok = ok & verify(k, i, i == UnaryTree.class);
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
            case MULTIPLY:
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
            case DIVIDE:
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
            case REMAINDER:
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
            case PLUS:
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
            case MINUS:
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
            case LEFT_SHIFT:
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
            case RIGHT_SHIFT:
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
            case UNSIGNED_RIGHT_SHIFT:
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
            case LESS_THAN:
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
            case GREATER_THAN:
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
            case LESS_THAN_EQUAL:
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
            case GREATER_THAN_EQUAL:
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
            case EQUAL_TO:
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
            case NOT_EQUAL_TO:
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
            case AND:
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
            case XOR:
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
            case OR:
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
            case CONDITIONAL_AND:
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
            case CONDITIONAL_OR:
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
                ok = ok & verify(k, i, i == BinaryTree.class);
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
            case MULTIPLY_ASSIGNMENT:
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
            case DIVIDE_ASSIGNMENT:
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
            case REMAINDER_ASSIGNMENT:
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
            case PLUS_ASSIGNMENT:
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
            case MINUS_ASSIGNMENT:
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
            case LEFT_SHIFT_ASSIGNMENT:
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
            case RIGHT_SHIFT_ASSIGNMENT:
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
            case UNSIGNED_RIGHT_SHIFT_ASSIGNMENT:
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
            case AND_ASSIGNMENT:
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
            case XOR_ASSIGNMENT:
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
            case OR_ASSIGNMENT:
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
                ok = ok & verify(k, i, i == CompoundAssignmentTree.class);
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
            case INT_LITERAL:
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
            case LONG_LITERAL:
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
            case FLOAT_LITERAL:
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
            case DOUBLE_LITERAL:
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
            case BOOLEAN_LITERAL:
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
            case CHAR_LITERAL:
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
            case STRING_LITERAL:
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
            case NULL_LITERAL:
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
                ok = ok & verify(k, i, i == LiteralTree.class);
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
            case UNBOUNDED_WILDCARD:
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
            case EXTENDS_WILDCARD:
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
            case SUPER_WILDCARD:
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
                ok = ok & verify(k, i, i == WildcardTree.class);
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
6580
d3d578d22cc7 6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents: 5520
diff changeset
   105
            case INTERFACE:
d3d578d22cc7 6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents: 5520
diff changeset
   106
            case ANNOTATION_TYPE:
d3d578d22cc7 6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents: 5520
diff changeset
   107
            case ENUM:
d3d578d22cc7 6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents: 5520
diff changeset
   108
            case CLASS:
d3d578d22cc7 6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents: 5520
diff changeset
   109
                ok = ok & verify(k, i, i == ClassTree.class);
d3d578d22cc7 6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents: 5520
diff changeset
   110
                break;
d3d578d22cc7 6570730: com.sun.source.tree.ModifiersTree.getFlags() should return class type
jjg
parents: 5520
diff changeset
   111
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 7681
diff changeset
   112
            case ANNOTATION:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 7681
diff changeset
   113
            case TYPE_ANNOTATION:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 7681
diff changeset
   114
                ok = ok & verify(k, i, i == AnnotationTree.class);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 7681
diff changeset
   115
                break;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 7681
diff changeset
   116
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
            case OTHER:
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
                ok = ok & verify(k, i, i == null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
            default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
                String ks = k.toString().replace("_", "") + "tree";
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
                String iName = i.getName();
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
                String is = iName.substring(iName.lastIndexOf(".") + 1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
                ok = ok & verify(k, i, ks.equalsIgnoreCase(is));
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
        if (!ok)
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
            throw new AssertionError("test failed");
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
    static boolean verify(Tree.Kind k, Class<?> c, boolean b) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
        if (!b)
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
            System.err.println("error: " + k + " " + c);
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
        return b;
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
}