private static ImmutableList<String> containerOf(VisitorState state, Compound attr) { Attribute m = attr.member(state.getName("containerOf")); if (m == null) { return ImmutableList.of(); } ImmutableList.Builder<String> containerOf = ImmutableList.builder(); m.accept( new SimpleAnnotationValueVisitor8<Void, Void>() { @Override public Void visitString(String s, Void unused) { containerOf.add(s); return null; } @Override public Void visitArray(List<? extends AnnotationValue> list, Void unused) { for (AnnotationValue value : list) { value.accept(this, null); } return null; } }, null); return containerOf.build(); }
private static Set<Modifier> getIncompatibleModifiers(AnnotationTree tree, VisitorState state) { for (Attribute.Compound c : ASTHelpers.getSymbol(tree).getAnnotationMirrors()) { if (((TypeElement) c.getAnnotationType().asElement()) .getQualifiedName() .contentEquals(GUAVA_ANNOTATION)) { @SuppressWarnings("unchecked") List<Attribute.Enum> modifiers = (List<Attribute.Enum>) c.member(state.getName("value")).getValue(); return ImmutableSet.copyOf( Iterables.transform( modifiers, (Attribute.Enum input) -> Modifier.valueOf(input.getValue().name.toString()))); } } IncompatibleModifiers annotation = ASTHelpers.getAnnotation(tree, IncompatibleModifiers.class); if (annotation != null) { return ImmutableSet.copyOf(annotation.value()); } return ImmutableSet.of(); }
private static Set<Modifier> getIncompatibleModifiers(AnnotationTree tree, VisitorState state) { for (Attribute.Compound c : ASTHelpers.getSymbol(tree).getAnnotationMirrors()) { if (((TypeElement) c.getAnnotationType().asElement()) .getQualifiedName() .contentEquals(GUAVA_ANNOTATION)) { @SuppressWarnings("unchecked") List<Attribute.Enum> modifiers = (List<Attribute.Enum>) c.member(state.getName("value")).getValue(); return ImmutableSet.copyOf(Iterables.transform(modifiers, TO_MODIFIER)); } } IncompatibleModifiers annotation = ASTHelpers.getAnnotation(tree, IncompatibleModifiers.class); if (annotation != null) { return ImmutableSet.copyOf(annotation.value()); } return ImmutableSet.of(); }
return inferTargetMetaInfo(a, s); Attribute atValue = atTarget.member(names.value); if (!(atValue instanceof Attribute.Array)) { Assert.error("annotationType(): bad @Target argument " + atValue +
return inferTargetMetaInfo(a, s); Attribute atValue = atTarget.member(names.value); if (!(atValue instanceof Attribute.Array)) { Assert.error("annotationType(): bad @Target argument " + atValue +
a.annotationType.type.tsym.attribute(syms.annotationTargetType.tsym); if (atTarget == null) return true; Attribute atValue = atTarget.member(names.value); if (!(atValue instanceof Attribute.Array)) return true; // error recovery Attribute.Array arr = (Attribute.Array) atValue;
a.annotationType.type.tsym.attribute(syms.annotationTargetType.tsym); if (atTarget == null) return true; Attribute atValue = atTarget.member(names.value); if (!(atValue instanceof Attribute.Array)) return true; // error recovery Attribute.Array arr = (Attribute.Array) atValue;
/** Is the annotation applicable to types? */ protected boolean isTypeAnnotation(JCAnnotation a, boolean isTypeParameter) { Attribute.Compound atTarget = a.annotationType.type.tsym.attribute(syms.annotationTargetType.tsym); if (atTarget == null) { // An annotation without @Target is not a type annotation. return false; } Attribute atValue = atTarget.member(names.value); if (!(atValue instanceof Attribute.Array)) { return false; // error recovery } Attribute.Array arr = (Attribute.Array) atValue; for (Attribute app : arr.values) { if (!(app instanceof Attribute.Enum)) { return false; // recovery } Attribute.Enum e = (Attribute.Enum) app; if (e.value.name == names.TYPE_USE) return true; else if (isTypeParameter && e.value.name == names.TYPE_PARAMETER) return true; } return false; }
/** Is the annotation applicable to types? */ protected boolean isTypeAnnotation(JCAnnotation a, boolean isTypeParameter) { Attribute.Compound atTarget = a.annotationType.type.tsym.attribute(syms.annotationTargetType.tsym); if (atTarget == null) { // An annotation without @Target is not a type annotation. return false; } Attribute atValue = atTarget.member(names.value); if (!(atValue instanceof Attribute.Array)) { return false; // error recovery } Attribute.Array arr = (Attribute.Array) atValue; for (Attribute app : arr.values) { if (!(app instanceof Attribute.Enum)) { return false; // recovery } Attribute.Enum e = (Attribute.Enum) app; if (e.value.name == names.TYPE_USE) return true; else if (isTypeParameter && e.value.name == names.TYPE_PARAMETER) return true; } return false; }
private static ImmutableList<String> containerOf(VisitorState state, Compound attr) { Attribute m = attr.member(state.getName("containerOf")); if (m == null) { return ImmutableList.of(); } ImmutableList.Builder<String> containerOf = ImmutableList.builder(); m.accept( new SimpleAnnotationValueVisitor8<Void, Void>() { @Override public Void visitString(String s, Void unused) { containerOf.add(s); return null; } @Override public Void visitArray(List<? extends AnnotationValue> list, Void unused) { for (AnnotationValue value : list) { value.accept(this, null); } return null; } }, null); return containerOf.build(); }
public RetentionPolicy getRetention(Symbol sym) { RetentionPolicy vis = RetentionPolicy.CLASS; // the default Attribute.Compound c = sym.attribute(syms.retentionType.tsym); if (c != null) { Attribute value = c.member(names.value); if (value != null && value instanceof Attribute.Enum) { Name levelName = ((Attribute.Enum)value).value.name; if (levelName == names.SOURCE) vis = RetentionPolicy.SOURCE; else if (levelName == names.CLASS) vis = RetentionPolicy.CLASS; else if (levelName == names.RUNTIME) vis = RetentionPolicy.RUNTIME; else ;// /* fail soft */ throw new AssertionError(levelName); } } return vis; } // </editor-fold>
public RetentionPolicy getRetention(Symbol sym) { RetentionPolicy vis = RetentionPolicy.CLASS; // the default Attribute.Compound c = sym.attribute(syms.retentionType.tsym); if (c != null) { Attribute value = c.member(names.value); if (value != null && value instanceof Attribute.Enum) { Name levelName = ((Attribute.Enum)value).value.name; if (levelName == names.SOURCE) vis = RetentionPolicy.SOURCE; else if (levelName == names.CLASS) vis = RetentionPolicy.CLASS; else if (levelName == names.RUNTIME) vis = RetentionPolicy.RUNTIME; else ;// /* fail soft */ throw new AssertionError(levelName); } } return vis; } // </editor-fold>
RetentionPolicy getRetention(TypeSymbol annotationType) { RetentionPolicy vis = RetentionPolicy.CLASS; // the default Attribute.Compound c = annotationType.attribute(syms.retentionType.tsym); if (c != null) { Attribute value = c.member(names.value); if (value != null && value instanceof Attribute.Enum) { Name levelName = ((Attribute.Enum)value).value.name; if (levelName == names.SOURCE) vis = RetentionPolicy.SOURCE; else if (levelName == names.CLASS) vis = RetentionPolicy.CLASS; else if (levelName == names.RUNTIME) vis = RetentionPolicy.RUNTIME; else ;// /* fail soft */ throw new AssertionError(levelName); } } return vis; }
Attribute.Array getAttributeTargetAttribute(Symbol s) { Attribute.Compound atTarget = s.attribute(syms.annotationTargetType.tsym); if (atTarget == null) return null; // ok, is applicable Attribute atValue = atTarget.member(names.value); if (!(atValue instanceof Attribute.Array)) return null; // error recovery return (Attribute.Array) atValue; }
Attribute.Array getAttributeTargetAttribute(Symbol s) { Attribute.Compound atTarget = s.attribute(syms.annotationTargetType.tsym); if (atTarget == null) return null; // ok, is applicable Attribute atValue = atTarget.member(names.value); if (!(atValue instanceof Attribute.Array)) return null; // error recovery return (Attribute.Array) atValue; }
private static Attribute[] unpackAttributes(Attribute.Compound container) { // We now have an instance of the container, // unpack it returning an instance of the // contained type or null return ((Attribute.Array)container.member(container.type.tsym.name.table.names.value)).values; }
RetentionPolicy getRetention(TypeSymbol annotationType) { RetentionPolicy vis = RetentionPolicy.CLASS; // the default Attribute.Compound c = annotationType.attribute(syms.retentionType.tsym); if (c != null) { Attribute value = c.member(names.value); if (value != null && value instanceof Attribute.Enum) { Name levelName = ((Attribute.Enum)value).value.name; if (levelName == names.SOURCE) vis = RetentionPolicy.SOURCE; else if (levelName == names.CLASS) vis = RetentionPolicy.CLASS; else if (levelName == names.RUNTIME) vis = RetentionPolicy.RUNTIME; else ;// /* fail soft */ throw new AssertionError(levelName); } } return vis; }
private static Attribute[] unpackAttributes(Attribute.Compound container) { // We now have an instance of the container, // unpack it returning an instance of the // contained type or null return ((Attribute.Array)container.member(container.type.tsym.name.table.names.value)).values; }
/** Returns true if the given method symbol has a {@code @Test(expected=...)} annotation. */ private static boolean isExpectedExceptionTest(MethodSymbol sym, VisitorState state) { Compound attribute = sym.attribute(state.getSymbolFromString(JUnitMatchers.JUNIT4_TEST_ANNOTATION)); if (attribute == null) { return false; } return attribute.member(state.getName("expected")) != null; }
/** Returns true if the given method symbol has a {@code @Test(expected=...)} annotation. */ private static boolean isExpectedExceptionTest(MethodSymbol sym, VisitorState state) { Compound attribute = sym.attribute(state.getSymbolFromString(JUnitMatchers.JUNIT4_TEST_ANNOTATION)); if (attribute == null) { return false; } return attribute.member(state.getName("expected")) != null; }