static { map.put(Tree.Kind.BOOLEAN_LITERAL, Boolean.class); map.put(Tree.Kind.CHAR_LITERAL, Character.class); map.put(Tree.Kind.STRING_LITERAL, String.class); map.put(Tree.Kind.INT_LITERAL, Integer.class); map.put(Tree.Kind.LONG_LITERAL, Long.class); map.put(Tree.Kind.FLOAT_LITERAL, Float.class); map.put(Tree.Kind.DOUBLE_LITERAL, Double.class); }
public Void visitLiteral(LiteralTree tree, Void ignore) { System.err.println(tree); Class expect = map.get(tree.getKind()); if (!check(tree.getValue(), expect)) { System.err.println("tree: " + tree); System.err.println("expected class: " + expect); if (tree.getValue() != null) System.err.println("actual class: " + tree.getValue().getClass()); throw new AssertionError("unexpected value for literal"); } return null; }
private String getValue(AnnotationMirror am) { Map<? extends ExecutableElement, ? extends AnnotationValue> map = am.getElementValues(); if (map.size() != 1) throw new IllegalArgumentException(); AnnotationValue v = map.values().iterator().next(); return (String) v.getValue(); }