0N/A/*
797N/A * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
553N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
553N/A * or visit www.oracle.com if you need additional information or have any
553N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A * @test
0N/A * @bug 6338064 6346249 6340951 6392177
0N/A * @summary Tree API: can't determine kind of operator
0N/A * @author Peter von der Ah\u00e9
0N/A * @compile TestOperators.java
0N/A * @compile -processor TestOperators -proc:only TestOperators.java
0N/A */
0N/A
0N/Aimport java.util.Set;
0N/Aimport javax.annotation.processing.*;
0N/Aimport javax.lang.model.element.*;
0N/Aimport javax.lang.model.util.*;
0N/Aimport static javax.tools.Diagnostic.Kind.*;
0N/A
0N/Aimport com.sun.source.tree.*;
0N/Aimport com.sun.source.util.Trees;
0N/A
0N/Aimport static com.sun.source.tree.Tree.Kind.*;
0N/A
0N/A@interface TestMe {
0N/A Tree.Kind value();
0N/A}
0N/A
0N/A@SupportedAnnotationTypes("TestMe")
0N/Apublic class TestOperators extends AbstractProcessor {
0N/A
0N/A @TestMe(POSTFIX_INCREMENT)
0N/A public int test_POSTFIX_INCREMENT(int i) {
0N/A return i++;
0N/A }
0N/A
0N/A @TestMe(POSTFIX_DECREMENT)
0N/A public int test_POSTFIX_DECREMENT(int i) {
0N/A return i--;
0N/A }
0N/A
0N/A @TestMe(PREFIX_INCREMENT)
0N/A public int test_PREFIX_INCREMENT(int i) {
0N/A return ++i;
0N/A }
0N/A
0N/A @TestMe(PREFIX_DECREMENT)
0N/A public int test_PREFIX_DECREMENT(int i) {
0N/A return --i;
0N/A }
0N/A
0N/A @TestMe(UNARY_PLUS)
0N/A public int test_UNARY_PLUS(int i) {
0N/A return +i;
0N/A }
0N/A
0N/A @TestMe(UNARY_MINUS)
0N/A public int test_UNARY_MINUS(int i) {
0N/A return -i;
0N/A }
0N/A
0N/A @TestMe(BITWISE_COMPLEMENT)
0N/A public int test_BITWISE_COMPLEMENT(int i) {
0N/A return ~i;
0N/A }
0N/A
0N/A @TestMe(LOGICAL_COMPLEMENT)
0N/A public boolean test_LOGICAL_COMPLEMENT(boolean b) {
0N/A return !b;
0N/A }
0N/A
0N/A @TestMe(MULTIPLY)
0N/A public int test_MULTIPLY(int i, int j) {
0N/A return i * j;
0N/A }
0N/A
0N/A @TestMe(DIVIDE)
0N/A public int test_DIVIDE(int i, int j) {
0N/A return i / j;
0N/A }
0N/A
0N/A @TestMe(REMAINDER)
0N/A public int test_REMAINDER(int i, int j) {
0N/A return i % j;
0N/A }
0N/A
0N/A @TestMe(PLUS)
0N/A public int test_PLUS(int i, int j) {
0N/A return i + j;
0N/A }
0N/A
0N/A @TestMe(MINUS)
0N/A public int test_MINUS(int i, int j) {
0N/A return i - j;
0N/A }
0N/A
0N/A @TestMe(LEFT_SHIFT)
0N/A public int test_LEFT_SHIFT(int i, int j) {
0N/A return i << j;
0N/A }
0N/A
0N/A @TestMe(RIGHT_SHIFT)
0N/A public int test_RIGHT_SHIFT(int i, int j) {
0N/A return i >> j;
0N/A }
0N/A
0N/A @TestMe(UNSIGNED_RIGHT_SHIFT)
0N/A public int test_UNSIGNED_RIGHT_SHIFT(int i, int j) {
0N/A return i >>> j;
0N/A }
0N/A
0N/A @TestMe(LESS_THAN)
0N/A public boolean test_LESS_THAN(int i, int j) {
0N/A return i < j;
0N/A }
0N/A
0N/A @TestMe(GREATER_THAN)
0N/A public boolean test_GREATER_THAN(int i, int j) {
0N/A return i > j;
0N/A }
0N/A
0N/A @TestMe(LESS_THAN_EQUAL)
0N/A public boolean test_LESS_THAN_EQUAL(int i, int j) {
0N/A return i <= j;
0N/A }
0N/A
0N/A @TestMe(GREATER_THAN_EQUAL)
0N/A public boolean test_GREATER_THAN_EQUAL(int i, int j) {
0N/A return i >= j;
0N/A }
0N/A
0N/A @TestMe(EQUAL_TO)
0N/A public boolean test_EQUAL_TO(int i, int j) {
0N/A return i == j;
0N/A }
0N/A
0N/A @TestMe(NOT_EQUAL_TO)
0N/A public boolean test_NOT_EQUAL_TO(int i, int j) {
0N/A return i != j;
0N/A }
0N/A
0N/A @TestMe(AND)
0N/A public boolean test_AND(boolean a, boolean b) {
0N/A return a & b;
0N/A }
0N/A
0N/A @TestMe(XOR)
0N/A public boolean test_XOR(boolean a, boolean b) {
0N/A return a ^ b;
0N/A }
0N/A
0N/A @TestMe(OR)
0N/A public boolean test_OR(boolean a, boolean b) {
0N/A return a | b;
0N/A }
0N/A
0N/A @TestMe(CONDITIONAL_AND)
0N/A public boolean test_CONDITIONAL_AND(boolean a, boolean b) {
0N/A return a && b;
0N/A }
0N/A
0N/A @TestMe(CONDITIONAL_OR)
0N/A public boolean test_CONDITIONAL_OR(boolean a, boolean b) {
0N/A return a || b;
0N/A }
0N/A
0N/A @TestMe(MULTIPLY_ASSIGNMENT)
0N/A public int test_MULTIPLY_ASSIGNMENT(int i, int j) {
0N/A return i *= j;
0N/A }
0N/A
0N/A @TestMe(DIVIDE_ASSIGNMENT)
0N/A public int test_DIVIDE_ASSIGNMENT(int i, int j) {
0N/A return i /= j;
0N/A }
0N/A
0N/A @TestMe(REMAINDER_ASSIGNMENT)
0N/A public int test_REMAINDER_ASSIGNMENT(int i, int j) {
0N/A return i %= j;
0N/A }
0N/A
0N/A @TestMe(PLUS_ASSIGNMENT)
0N/A public int test_PLUS_ASSIGNMENT(int i, int j) {
0N/A return i += j;
0N/A }
0N/A
0N/A @TestMe(MINUS_ASSIGNMENT)
0N/A public int test_MINUS_ASSIGNMENT(int i, int j) {
0N/A return i -= j;
0N/A }
0N/A
0N/A @TestMe(LEFT_SHIFT_ASSIGNMENT)
0N/A public int test_LEFT_SHIFT_ASSIGNMENT(int i, int j) {
0N/A return i <<= j;
0N/A }
0N/A
0N/A @TestMe(RIGHT_SHIFT_ASSIGNMENT)
0N/A public int test_RIGHT_SHIFT_ASSIGNMENT(int i, int j) {
0N/A return i >>= j;
0N/A }
0N/A
0N/A @TestMe(UNSIGNED_RIGHT_SHIFT_ASSIGNMENT)
0N/A public int test_UNSIGNED_RIGHT_SHIFT_ASSIGNMENT(int i, int j) {
0N/A return i >>>= j;
0N/A }
0N/A
0N/A @TestMe(AND_ASSIGNMENT)
0N/A public boolean test_AND_ASSIGNMENT(boolean a, boolean b) {
0N/A return a &= b;
0N/A }
0N/A
0N/A @TestMe(XOR_ASSIGNMENT)
0N/A public boolean test_XOR_ASSIGNMENT(boolean a, boolean b) {
0N/A return a ^= b;
0N/A }
0N/A
0N/A @TestMe(OR_ASSIGNMENT)
0N/A public boolean test_OR_ASSIGNMENT(boolean a, boolean b) {
0N/A return a |= b;
0N/A }
0N/A
0N/A @TestMe(INT_LITERAL)
0N/A public Object test_INT_LITERAL() {
0N/A return 0;
0N/A }
0N/A
0N/A @TestMe(LONG_LITERAL)
0N/A public Object test_LONG_LITERAL() {
0N/A return 0L;
0N/A }
0N/A
0N/A @TestMe(FLOAT_LITERAL)
0N/A public Object test_FLOAT_LITERAL() {
0N/A return 0.0F;
0N/A }
0N/A
0N/A @TestMe(DOUBLE_LITERAL)
0N/A public Object test_DOUBLE_LITERAL() {
0N/A return 0.0;
0N/A }
0N/A
0N/A @TestMe(BOOLEAN_LITERAL)
0N/A public Object test_BOOLEAN_LITERAL() {
0N/A return true;
0N/A }
0N/A
0N/A @TestMe(CHAR_LITERAL)
0N/A public Object test_CHAR_LITERAL() {
0N/A return 'a';
0N/A }
0N/A
0N/A @TestMe(STRING_LITERAL)
0N/A public Object test_STRING_LITERAL() {
0N/A return "a";
0N/A }
0N/A
0N/A @TestMe(NULL_LITERAL)
0N/A public Object test_NULL_LITERAL() {
0N/A return null;
0N/A }
0N/A
0N/A @TestMe(UNBOUNDED_WILDCARD)
0N/A public Set<?> test_UNBOUNDED_WILDCARD() {
0N/A return null;
0N/A }
0N/A
0N/A @TestMe(EXTENDS_WILDCARD)
0N/A public Set<? extends Number> test_EXTENDS_WILDCARD() {
0N/A return null;
0N/A }
0N/A
0N/A @TestMe(SUPER_WILDCARD)
0N/A public Set<? super Number> test_SUPER_WILDCARD() {
0N/A return null;
0N/A }
0N/A
0N/A public boolean process(Set<? extends TypeElement> annotations,
0N/A RoundEnvironment roundEnvironment)
0N/A {
0N/A final Trees trees = Trees.instance(processingEnv);
0N/A final Messager log = processingEnv.getMessager();
0N/A final Elements elements = processingEnv.getElementUtils();
574N/A class Scan extends ElementScanner7<Void,Void> {
0N/A @Override
0N/A public Void visitExecutable(ExecutableElement e, Void p) {
0N/A Object debug = e; // info for exception handler
0N/A try {
0N/A TestMe info = e.getAnnotation(TestMe.class);
0N/A if (info == null)
0N/A return null;
0N/A
0N/A Tree.Kind kind = info.value();
0N/A MethodTree node = trees.getTree(e);
0N/A debug = node;
0N/A Tree testNode;
0N/A switch (kind) {
0N/A case UNBOUNDED_WILDCARD:
0N/A case EXTENDS_WILDCARD:
0N/A case SUPER_WILDCARD:
0N/A ParameterizedTypeTree typeTree;
0N/A typeTree = (ParameterizedTypeTree) node.getReturnType();
0N/A testNode = typeTree.getTypeArguments().get(0);
0N/A break;
0N/A default:
0N/A ReturnTree returnNode;
0N/A returnNode = (ReturnTree) node.getBody().getStatements().get(0);
0N/A testNode = returnNode.getExpression();
0N/A }
0N/A if (testNode.getKind() != kind) {
0N/A log.printMessage(ERROR, testNode.getKind() + " != " + kind, e);
0N/A throw new AssertionError(testNode);
0N/A }
0N/A System.err.format("OK: %32s %s%n", kind, testNode);
0N/A } catch (Error ex) {
0N/A System.err.println("Error while looking at " + debug);
0N/A throw ex;
0N/A }
0N/A return null;
0N/A }
0N/A }
0N/A Scan scan = new Scan();
0N/A for (Element e : roundEnvironment.getRootElements()) {
0N/A scan.scan(e);
0N/A }
0N/A return true;
0N/A }
0N/A
0N/A}