/* * Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/* * @test * @bug 6338064 6346249 6340951 6392177 * @summary Tree API: can't determine kind of operator * @author Peter von der Ah\u00e9 * @library ../lib * @modules jdk.compiler * @build JavacTestingAbstractProcessor TestOperators * @compile -processor TestOperators -proc:only TestOperators.java
*/
@TestMe(LOGICAL_COMPLEMENT) publicboolean test_LOGICAL_COMPLEMENT(boolean b) { return !b;
}
@TestMe(MULTIPLY) publicint test_MULTIPLY(int i, int j) { return i * j;
}
@TestMe(DIVIDE) publicint test_DIVIDE(int i, int j) { return i / j;
}
@TestMe(REMAINDER) publicint test_REMAINDER(int i, int j) { return i % j;
}
@TestMe(PLUS) publicint test_PLUS(int i, int j) { return i + j;
}
@TestMe(MINUS) publicint test_MINUS(int i, int j) { return i - j;
}
@TestMe(LEFT_SHIFT) publicint test_LEFT_SHIFT(int i, int j) { return i << j;
}
@TestMe(RIGHT_SHIFT) publicint test_RIGHT_SHIFT(int i, int j) { return i >> j;
}
@TestMe(UNSIGNED_RIGHT_SHIFT) publicint test_UNSIGNED_RIGHT_SHIFT(int i, int j) { return i >>> j;
}
@TestMe(LESS_THAN) publicboolean test_LESS_THAN(int i, int j) { return i < j;
}
@TestMe(GREATER_THAN) publicboolean test_GREATER_THAN(int i, int j) { return i > j;
}
@TestMe(LESS_THAN_EQUAL) publicboolean test_LESS_THAN_EQUAL(int i, int j) { return i <= j;
}
@TestMe(GREATER_THAN_EQUAL) publicboolean test_GREATER_THAN_EQUAL(int i, int j) { return i >= j;
}
@TestMe(EQUAL_TO) publicboolean test_EQUAL_TO(int i, int j) { return i == j;
}
@TestMe(NOT_EQUAL_TO) publicboolean test_NOT_EQUAL_TO(int i, int j) { return i != j;
}
@TestMe(AND) publicboolean test_AND(boolean a, boolean b) { return a & b;
}
@TestMe(XOR) publicboolean test_XOR(boolean a, boolean b) { return a ^ b;
}
@TestMe(OR) publicboolean test_OR(boolean a, boolean b) { return a | b;
}
@TestMe(CONDITIONAL_AND) publicboolean test_CONDITIONAL_AND(boolean a, boolean b) { return a && b;
}
@TestMe(CONDITIONAL_OR) publicboolean test_CONDITIONAL_OR(boolean a, boolean b) { return a || b;
}
@TestMe(MULTIPLY_ASSIGNMENT) publicint test_MULTIPLY_ASSIGNMENT(int i, int j) { return i *= j;
}
@TestMe(DIVIDE_ASSIGNMENT) publicint test_DIVIDE_ASSIGNMENT(int i, int j) { return i /= j;
}
@TestMe(REMAINDER_ASSIGNMENT) publicint test_REMAINDER_ASSIGNMENT(int i, int j) { return i %= j;
}
@TestMe(PLUS_ASSIGNMENT) publicint test_PLUS_ASSIGNMENT(int i, int j) { return i += j;
}
@TestMe(MINUS_ASSIGNMENT) publicint test_MINUS_ASSIGNMENT(int i, int j) { return i -= j;
}
@TestMe(LEFT_SHIFT_ASSIGNMENT) publicint test_LEFT_SHIFT_ASSIGNMENT(int i, int j) { return i <<= j;
}
@TestMe(RIGHT_SHIFT_ASSIGNMENT) publicint test_RIGHT_SHIFT_ASSIGNMENT(int i, int j) { return i >>= j;
}
@TestMe(UNSIGNED_RIGHT_SHIFT_ASSIGNMENT) publicint test_UNSIGNED_RIGHT_SHIFT_ASSIGNMENT(int i, int j) { return i >>>= j;
}
@TestMe(AND_ASSIGNMENT) publicboolean test_AND_ASSIGNMENT(boolean a, boolean b) { return a &= b;
}
@TestMe(XOR_ASSIGNMENT) publicboolean test_XOR_ASSIGNMENT(boolean a, boolean b) { return a ^= b;
}
@TestMe(OR_ASSIGNMENT) publicboolean test_OR_ASSIGNMENT(boolean a, boolean b) { return a |= b;
}
@TestMe(INT_LITERAL) public Object test_INT_LITERAL() { return 0;
}
@TestMe(LONG_LITERAL) public Object test_LONG_LITERAL() { return 0L;
}
@TestMe(FLOAT_LITERAL) public Object test_FLOAT_LITERAL() { return 0.0F;
}
@TestMe(DOUBLE_LITERAL) public Object test_DOUBLE_LITERAL() { return 0.0;
}
@TestMe(BOOLEAN_LITERAL) public Object test_BOOLEAN_LITERAL() { returntrue;
}
@TestMe(CHAR_LITERAL) public Object test_CHAR_LITERAL() { return'a';
}
@TestMe(STRING_LITERAL) public Object test_STRING_LITERAL() { return"a";
}
@TestMe(NULL_LITERAL) public Object test_NULL_LITERAL() { returnnull;
}
@TestMe(UNBOUNDED_WILDCARD) public Set<?> test_UNBOUNDED_WILDCARD() { returnnull;
}
@TestMe(EXTENDS_WILDCARD) public Set<? extends Number> test_EXTENDS_WILDCARD() { returnnull;
}
@TestMe(SUPER_WILDCARD) public Set<? super Number> test_SUPER_WILDCARD() { returnnull;
}
publicboolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnvironment)
{ final Trees trees = Trees.instance(processingEnv); final Messager log = processingEnv.getMessager(); final Elements elements = processingEnv.getElementUtils(); class Scan extends ElementScanner<Void,Void> {
@Override publicVoid visitExecutable(ExecutableElement e, Void p) {
Object debug = e; // info for exception handler try {
TestMe info = e.getAnnotation(TestMe.class); if (info == null) returnnull;
Tree.Kind kind = info.value();
MethodTree node = trees.getTree(e);
debug = node;
Tree testNode; switch (kind) { case UNBOUNDED_WILDCARD: case EXTENDS_WILDCARD: case SUPER_WILDCARD:
ParameterizedTypeTree typeTree;
typeTree = (ParameterizedTypeTree) node.getReturnType();
testNode = typeTree.getTypeArguments().get(0); break; default:
ReturnTree returnNode;
returnNode = (ReturnTree) node.getBody().getStatements().get(0);
testNode = returnNode.getExpression();
} if (testNode.getKind() != kind) {
log.printError(testNode.getKind() + " != " + kind, e); thrownew AssertionError(testNode);
}
System.err.format("OK: %32s %s%n", kind, testNode);
} catch (Error ex) {
System.err.println("Error while looking at " + debug); throw ex;
} returnnull;
}
}
Scan scan = new Scan(); for (Element e : roundEnvironment.getRootElements()) {
scan.scan(e);
} returntrue;
}
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.31 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.