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