/** * Returns true if the specified binding is of an annotation that has a runtime retention policy. */ public static boolean isRuntimeAnnotation(ITypeBinding binding) { if (binding != null && binding.isAnnotation()) { for (IAnnotationBinding ann : binding.getAnnotations()) { if (ann.getName().equals("Retention")) { IVariableBinding retentionBinding = (IVariableBinding) ann.getDeclaredMemberValuePairs()[0].getValue(); return retentionBinding.getName().equals(RetentionPolicy.RUNTIME.name()); } } if (binding.isNested()) { return BindingUtil.isRuntimeAnnotation(binding.getDeclaringClass()); } } return false; }
public boolean hasRuntimeRetention() { Map<String, ? extends AnnotationMirror> types = getHelper().getAnnotationsByType(getElement().getAnnotationMirrors()); AnnotationMirror retention = types.get(Retention.class.getCanonicalName()); if (retention == null) { handleNoRetention(); return false; } AnnotationParser parser = AnnotationParser.create(getHelper()); parser.expectEnumConstant( AnnotationUtil.VALUE, getHelper().resolveType(RetentionPolicy.class.getCanonicalName()), null); String retentionPolicy = parser.parse(retention).get(AnnotationUtil.VALUE, String.class); return RetentionPolicy.RUNTIME.toString().equals(retentionPolicy); }