@Override public boolean equals(final Object obj) { return obj instanceof Named && CDIAnnotationUtils.equals(this, (Annotation) obj); } };
@Override public int hashCode() { return CDIAnnotationUtils.hashCode(this); }
@Override public String toString() { return CDIAnnotationUtils.toString(this); }
/** * Helper method for generating a hash code for a member of an annotation. * * @param name the name of the member * @param value the value of the member * @return a hash code for this member */ private static int hashMember(String name, Object value) { final int part1 = name.hashCode() * 127; if (value.getClass().isArray()) { return part1 ^ arrayMemberHash(value.getClass().getComponentType(), value); } if (value instanceof Annotation) { return part1 ^ hashCode((Annotation) value); } return part1 ^ value.hashCode(); }
/** * Helper method for checking whether two objects of the given type are * equal. This method is used to compare the parameters of two annotation * instances. * * @param type the type of the objects to be compared * @param o1 the first object * @param o2 the second object * @return a flag whether these objects are equal */ private static boolean memberEquals(Class<?> type, Object o1, Object o2) { if (o1 == o2) { return true; } if (o1 == null || o2 == null) { return false; } if (type.isArray()) { return arrayMemberEquals(type.getComponentType(), o1, o2); } if (type.isAnnotation()) { return equals((Annotation) o1, (Annotation) o2); } return o1.equals(o2); }
public static AnnotationPropertyAccessor createDynamicSerializer(final Class<? extends Annotation> annotationType) { final AnnotationPropertyAccessorBuilder builder = AnnotationPropertyAccessorBuilder.create(); final Collection<Method> annoAttrs = CDIAnnotationUtils.getAnnotationAttributes(annotationType); for (final Method attr : annoAttrs) { builder.with(attr.getName(), anno -> { try { final String retVal; final Function<Object, String> toString = componentToString( attr.getReturnType().isArray() ? attr.getReturnType().getComponentType() : attr.getReturnType()); if (attr.getReturnType().isArray()) { final StringBuilder sb = new StringBuilder(); final Object[] array = (Object[]) attr.invoke(anno); sb.append("["); for (final Object obj : array) { sb.append(toString.apply(obj)).append(","); } sb.replace(sb.length()-1, sb.length(), "]"); retVal = sb.toString(); } else { retVal = toString.apply(attr.invoke(anno)); } return retVal; } catch (final Exception e) { throw new RuntimeException(String.format("Could not access '%s' property while serializing %s.", attr.getName(), anno.annotationType()), e); } }); } return builder.build(); }
static String generateSource(final Iterable<MetaClass> qualifiers) { final ClassStructureBuilder<?> body = ClassBuilder .define(SERIALIZER_PACKAGE_NAME + "." + SERIALIZER_CLASS_NAME, EventQualifierSerializer.class) .publicScope().body(); final ConstructorBlockBuilder<?> ctor = body.publicConstructor(); for (final MetaClass qual : qualifiers) { final Collection<MetaMethod> bindingAttributes = CDIAnnotationUtils.getAnnotationAttributes(qual); if (!bindingAttributes.isEmpty()) { ctor.append(loadVariable("serializers").invoke("put", qual.getFullyQualifiedName(), generateEntryStatement(qual, bindingAttributes))); } } ctor.finish(); return body.toJavaString(); }
public static Iterable<MetaClass> getTranslatableQualifiers(final TypeOracle oracle) { final Set<Class<?>> typesAnnotatedWith = CDIAnnotationUtils.getQualifiersAsClasses();
return annotationArrayMemberEquals((Annotation[]) o1, (Annotation[]) o2);
/** * Helper method for generating a hash code for a member of an annotation. * * @param name the name of the member * @param value the value of the member * @return a hash code for this member */ private static int hashMember(String name, Object value) { final int part1 = name.hashCode() * 127; if (value.getClass().isArray()) { return part1 ^ arrayMemberHash(value.getClass().getComponentType(), value); } if (value instanceof Annotation) { return part1 ^ hashCode((Annotation) value); } return part1 ^ value.hashCode(); }
/** * Helper method for checking whether two objects of the given type are * equal. This method is used to compare the parameters of two annotation * instances. * * @param type the type of the objects to be compared * @param o1 the first object * @param o2 the second object * @return a flag whether these objects are equal */ private static boolean memberEquals(Class<?> type, Object o1, Object o2) { if (o1 == o2) { return true; } if (o1 == null || o2 == null) { return false; } if (type.isArray()) { return arrayMemberEquals(type.getComponentType(), o1, o2); } if (type.isAnnotation()) { return equals((Annotation) o1, (Annotation) o2); } return o1.equals(o2); }
public static AnnotationPropertyAccessor createDynamicSerializer(final Class<? extends Annotation> annotationType) { final AnnotationPropertyAccessorBuilder builder = AnnotationPropertyAccessorBuilder.create(); final Collection<Method> annoAttrs = CDIAnnotationUtils.getAnnotationAttributes(annotationType); for (final Method attr : annoAttrs) { builder.with(attr.getName(), anno -> { try { final String retVal; final Function<Object, String> toString = componentToString( attr.getReturnType().isArray() ? attr.getReturnType().getComponentType() : attr.getReturnType()); if (attr.getReturnType().isArray()) { final StringBuilder sb = new StringBuilder(); final Object[] array = (Object[]) attr.invoke(anno); sb.append("["); for (final Object obj : array) { sb.append(toString.apply(obj)).append(","); } sb.replace(sb.length()-1, sb.length(), "]"); retVal = sb.toString(); } else { retVal = toString.apply(attr.invoke(anno)); } return retVal; } catch (final Exception e) { throw new RuntimeException(String.format("Could not access '%s' property while serializing %s.", attr.getName(), anno.annotationType()), e); } }); } return builder.build(); }
final Collection<MetaMethod> methods = CDIAnnotationUtils.getAnnotationAttributes(MC_annotationClass);
public static Set<MetaClass> getQualifiers() { final Set<Class<?>> qualifiersAsClasses = getQualifiersAsClasses(); final Set<MetaClass> qualifiersAsMetaClasses = qualifiersAsClasses.stream().map(c -> MetaClassFactory.get(c)).collect(Collectors.toSet()); if (qualifiersAsClasses.size() > qualifiersAsMetaClasses.size()) { throw new RuntimeException("Lost some qualifiers when converting from Class to MetaClass"); } return qualifiersAsMetaClasses; }
return annotationArrayMemberEquals((Annotation[]) o1, (Annotation[]) o2);
@Override public boolean equals(final Object obj) { if (!(obj instanceof AnnotationWrapper)) { return false; } final AnnotationWrapper other = (AnnotationWrapper) obj; return CDIAnnotationUtils.equals(anno, other.anno); }
@Override public int hashCode() { return CDIAnnotationUtils.hashCode(this); }
@Override public String toString() { return CDIAnnotationUtils.toString(this); }
public static Set<MetaClass> getQualifiers() { final Set<Class<?>> qualifiersAsClasses = getQualifiersAsClasses(); final Set<MetaClass> qualifiersAsMetaClasses = qualifiersAsClasses.stream().map(c -> MetaClassFactory.get(c)).collect(Collectors.toSet()); if (qualifiersAsClasses.size() > qualifiersAsMetaClasses.size()) { throw new RuntimeException("Lost some qualifiers when converting from Class to MetaClass"); } return qualifiersAsMetaClasses; }
@Override public boolean equals(final Object obj) { return obj instanceof Named && CDIAnnotationUtils.equals(this, (Annotation) obj); } };