private static boolean isExpectedValue(Object annotationValue, String expectedValue) { if (annotationValue instanceof Tree) { // from sources return containsValue((Tree) annotationValue, expectedValue); } // from binaries if (annotationValue instanceof Object[]) { return containsValue((Object[]) annotationValue, expectedValue); } return expectedValue.equals(((Symbol) annotationValue).name()); }
private static boolean isExpectedValue(Object annotationValue, String expectedValue) { if (annotationValue instanceof Tree) { // from sources return containsValue((Tree) annotationValue, expectedValue); } // from binaries if (annotationValue instanceof Object[]) { return containsValue((Object[]) annotationValue, expectedValue); } return expectedValue.equals(((Symbol) annotationValue).name()); }
private static boolean containsValue(Tree annotationValue, String expectedValue) { Symbol symbol; switch (annotationValue.kind()) { case IDENTIFIER: symbol = ((IdentifierTree) annotationValue).symbol(); break; case MEMBER_SELECT: symbol = ((MemberSelectExpressionTree) annotationValue).identifier().symbol(); break; case NEW_ARRAY: return ((NewArrayTree) annotationValue).initializers().stream().anyMatch(expr -> containsValue(expr, expectedValue)); default: throw new IllegalArgumentException("Unexpected tree used to parameterize annotation"); } return expectedValue.equals(symbol.name()); }
private static boolean containsValue(Tree annotationValue, String expectedValue) { Symbol symbol; switch (annotationValue.kind()) { case IDENTIFIER: symbol = ((IdentifierTree) annotationValue).symbol(); break; case MEMBER_SELECT: symbol = ((MemberSelectExpressionTree) annotationValue).identifier().symbol(); break; case NEW_ARRAY: return ((NewArrayTree) annotationValue).initializers().stream().anyMatch(expr -> containsValue(expr, expectedValue)); default: throw new IllegalArgumentException("Unexpected tree used to parameterize annotation"); } return expectedValue.equals(symbol.name()); }