if (!RetentionPolicy.RUNTIME.equals(retentionPolicy)) { return Collections.emptyMap();
@Builder.Factory public static String factory5(@Builder.Switch(defaultName = "SOURCE") RetentionPolicy policy) { return policy.toString(); } }
public void configureAnnotationNodeFromDefinition(AnnotationNode definition, AnnotationNode root) { ClassNode type = definition.getClassNode(); if ("java.lang.annotation.Retention".equals(type.getName())) { Expression exp = definition.getMember("value"); if (!(exp instanceof PropertyExpression)) return; PropertyExpression pe = (PropertyExpression) exp; String name = pe.getPropertyAsString(); RetentionPolicy policy = RetentionPolicy.valueOf(name); setRetentionPolicy(policy, root); } else if ("java.lang.annotation.Target".equals(type.getName())) { Expression exp = definition.getMember("value"); if (!(exp instanceof ListExpression)) return; ListExpression le = (ListExpression) exp; int bitmap = 0; for (Expression e : le.getExpressions()) { if (!(e instanceof PropertyExpression)) return; PropertyExpression element = (PropertyExpression) e; String name = element.getPropertyAsString(); ElementType value = ElementType.valueOf(name); bitmap |= getElementCode(value); } root.setAllowedTargets(bitmap); } }
@Override protected String[] defaultSelectedEnums() { return new String[] { RetentionPolicy.CLASS.name() }; } }
@Override protected String[] defaultSelectedEnums() { return new String[] { RetentionPolicy.CLASS.name() }; } }
if (!RetentionPolicy.RUNTIME.equals(retentionPolicy)) { return Collections.emptyMap();
node.setMember("value", new PropertyExpression( new ClassExpression(ClassHelper.makeWithoutCaching(RetentionPolicy.class, false)), value.toString())); } else if (type == Target.class) { Target t = (Target) annotation;
private boolean hasRetentionPolicy(RetentionPolicy policy) { List<IAnnotationInfo> annotation = _type.getTypeInfo().getAnnotationsOfType( TypeSystem.get(Retention.class) ); if( annotation != null ) { for( IAnnotationInfo annotationInfo : annotation ) { String value = (String) annotationInfo.getFieldValue("value"); if( value.equals(policy.name()) ) { return true; } } } return false; }
private void configureAnnotationFromDefinition(AnnotationNode definition, AnnotationNode root) { ClassNode type = definition.getClassNode(); if (!type.isResolved()) return; Class clazz = type.getTypeClass(); if (clazz==Retention.class) { Expression exp = definition.getMember("value"); if (!(exp instanceof PropertyExpression)) return; PropertyExpression pe = (PropertyExpression) exp; String name = pe.getPropertyAsString(); RetentionPolicy policy = RetentionPolicy.valueOf(name); setRetentionPolicy(policy,root); } else if (clazz==Target.class) { Expression exp = definition.getMember("value"); if (!(exp instanceof ListExpression)) return; ListExpression le = (ListExpression) exp; int bitmap = 0; for (Iterator it=le.getExpressions().iterator(); it.hasNext();) { PropertyExpression element = (PropertyExpression) it.next(); String name = element.getPropertyAsString(); ElementType value = ElementType.valueOf(name); bitmap |= getElementCode(value); } root.setAllowedTargets(bitmap); } }
public void visitAnnotations(AnnotatedNode node) { List<AnnotationNode> annotations = node.getAnnotations(); if (annotations.isEmpty()) return; Map<String, AnnotationNode> tmpAnnotations = new HashMap<String, AnnotationNode>(); ClassNode annType; for (AnnotationNode an : annotations) { // skip built-in properties if (an.isBuiltIn()) continue; annType = an.getClassNode(); resolveOrFail(annType, ", unable to find class for annotation", an); for (Map.Entry<String, Expression> member : an.getMembers().entrySet()) { Expression newValue = transform(member.getValue()); Expression adjusted = transformInlineConstants(newValue); member.setValue(adjusted); checkAnnotationMemberValue(adjusted); } if (annType.isResolved()) { Class annTypeClass = annType.getTypeClass(); Retention retAnn = (Retention) annTypeClass.getAnnotation(Retention.class); if (retAnn != null && retAnn.value().equals(RetentionPolicy.RUNTIME) && !isRepeatable(annTypeClass)) { // remember runtime/non-repeatable annos (auto collecting of Repeatable annotations is handled elsewhere) AnnotationNode anyPrevAnnNode = tmpAnnotations.put(annTypeClass.getName(), an); if (anyPrevAnnNode != null) { addError("Cannot specify duplicate annotation on the same member : " + annType.getName(), an); } } } } }
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); }
private boolean isSourceAnnotation() { List<IAnnotationInfo> annotations = _type.getTypeInfo().getAnnotationsOfType( JavaTypes.getJreType(Retention.class) ); if( annotations != null ) { for( IAnnotationInfo annotationInfo : annotations ) { String fieldValue = (String) annotationInfo.getFieldValue( "value" ); if( fieldValue.equals( RetentionPolicy.SOURCE.name() ) ) { return true; } } } return false; }
@Override protected void visitType(TypeDefinition td) { if (!td.isAnnotation()) return; DeclaredAnnotation da = getOrCreate(td); for (CustomAnnotation ca : td.getAnnotations()) { if (Types.is(ca.getAnnotationType(), Retention.class)) { for (AnnotationParameter ap : ca.getParameters()) { if (ap.getMember().equals("value")) { AnnotationElement value = ap.getValue(); if (value instanceof EnumAnnotationElement) { EnumAnnotationElement enumValue = (EnumAnnotationElement) value; if (Types.is(enumValue.getEnumType(), RetentionPolicy.class)) { da.policy = RetentionPolicy.valueOf(enumValue.getEnumConstantName()); } } } } } } }
@Override public Set<ConstraintCheckIssue> checkAnnotationType(TypeElement element, AnnotationMirror annotation) { Retention retention = element.getAnnotation( Retention.class ); if ( retention == null ) { return CollectionHelper.asSet( ConstraintCheckIssue.error( element, null, "CONSTRAINT_TYPE_WITH_MISSING_OR_WRONG_RETENTION" ) ); } if ( !retention.value().equals( RetentionPolicy.RUNTIME ) ) { return CollectionHelper.asSet( ConstraintCheckIssue.error( element, annotationApiHelper.getMirror( element.getAnnotationMirrors(), Retention.class ), "CONSTRAINT_TYPE_WITH_MISSING_OR_WRONG_RETENTION" ) ); } return Collections.emptySet(); }
private AnnotationNode getRetentionAnnotation() { final ClassExpression classExpr = A.EXPR.classX(RetentionPolicy.class); final ConstantExpression constantExpr = A.EXPR.constX(RetentionPolicy.SOURCE.toString()); final PropertyExpression propertyExpr = A.EXPR.propX(classExpr, constantExpr); return A.NODES.annotation(Retention.class) .member(A.UTIL.NODE.ANNOTATION_VALUE, propertyExpr) .build(); }
public boolean retainInBytecode() { List<IAnnotationInfo> annotations = _container.getTypeInfo().getAnnotationsOfType( JavaTypes.getJreType( Retention.class ) ); if( annotations != null ) { for( IAnnotationInfo annotationInfo : annotations ) { String fieldValue = (String) annotationInfo.getFieldValue( "value" ); if( !fieldValue.equals( RetentionPolicy.SOURCE.name() ) ) { return true; } } } return false; }
private void configureAnnotationFromDefinition(AnnotationNode definition, AnnotationNode root) { ClassNode type = definition.getClassNode(); if (!type.isResolved()) return; Class clazz = type.getTypeClass(); if (clazz == Retention.class) { Expression exp = definition.getMember("value"); if (!(exp instanceof PropertyExpression)) return; PropertyExpression pe = (PropertyExpression) exp; String name = pe.getPropertyAsString(); RetentionPolicy policy = RetentionPolicy.valueOf(name); setRetentionPolicy(policy, root); } else if (clazz == Target.class) { Expression exp = definition.getMember("value"); if (!(exp instanceof ListExpression)) return; ListExpression le = (ListExpression) exp; int bitmap = 0; for (Expression e : le.getExpressions()) { PropertyExpression element = (PropertyExpression) e; String name = element.getPropertyAsString(); ElementType value = ElementType.valueOf(name); bitmap |= getElementCode(value); } root.setAllowedTargets(bitmap); } }
/** * Checks the bindingType to make sure the annotation was declared properly * as a binding type (annotated with @BindingType) and that it has a runtime * retention policy. * * @param binding The binding type to check * @return true only if the annotation is really a binding type */ @Deprecated // TODO Replace usage of this with metadatacache public static boolean isBindings(Annotation binding) { boolean isBindingAnnotation = false; if (binding.annotationType().isAnnotationPresent(Qualifier.class) && binding.annotationType().isAnnotationPresent(Retention.class) && binding.annotationType().getAnnotation(Retention.class).value().equals(RetentionPolicy.RUNTIME)) { isBindingAnnotation = true; } return isBindingAnnotation; }
public boolean check() { List<? extends AnnotationMirror> annotations = getElement() .getAnnotationMirrors(); boolean hasAnnotation = getHelper().hasAnnotation(annotations, getAnnotation()); if (!hasAnnotation) { // this is not subject annotation , just return false return false; } if ( !hasRuntimeRetention() ){ getLogger().log(Level.WARNING, "Annotation " + getElement().getQualifiedName() + " declared as " +getAnnotation()+" but has wrong retention policy." + " Correct retention policy is " + RetentionPolicy.RUNTIME.toString());// NOI18N return false; } return hasTarget(); }
private boolean hasRetentionPolicy(RetentionPolicy policy) { List<IAnnotationInfo> annotation = _type.getTypeInfo().getAnnotationsOfType( TypeSystem.get(Retention.class) ); if( annotation != null ) { for( IAnnotationInfo annotationInfo : annotation ) { String value = (String) annotationInfo.getFieldValue("value"); if( value.equals(policy.name()) ) { return true; } } } return false; }