deltaspike/core/api/obsolete/src/main/java/org/apache/deltaspike/core/util/AnnotationUtils.java [30:170]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@Typed()
public abstract class AnnotationUtils
{
    private AnnotationUtils()
    {
        // prevent instantiation
    }

    public static <T extends Annotation> T extractAnnotationFromMethodOrClass(
        BeanManager beanManager, Method targetMethod, Class targetClass, Class<T> targetAnnotationType)
    {
        T result = extractAnnotationFromMethod(beanManager, targetMethod, targetAnnotationType);

        if (result == null)
        {
            //see DELTASPIKE-517
            Class unproxiedTargetClass = ProxyUtils.getUnproxiedClass(targetClass);

            // and if not found search on the class
            result = findAnnotation(beanManager, unproxiedTargetClass.getAnnotations(), targetAnnotationType);
        }
        return result;
    }

    public static <T extends Annotation> T extractAnnotationFromMethod(
        BeanManager beanManager, Method targetMethod, Class<T> targetAnnotationType)
    {
        return findAnnotation(beanManager, targetMethod.getAnnotations(), targetAnnotationType);
    }

    public static  <T extends Annotation> T findAnnotation(
            BeanManager beanManager, Annotation[] annotations, Class<T> targetAnnotationType)
    {
        for (Annotation annotation : annotations)
        {
            if (targetAnnotationType.equals(annotation.annotationType()))
            {
                return (T) annotation;
            }
            if (beanManager.isStereotype(annotation.annotationType()))
            {
                T result = findAnnotation(
                        beanManager, annotation.annotationType().getAnnotations(), targetAnnotationType);
                if (result != null)
                {
                    return result;
                }
            }
        }
        return null;
    }

    //based on org.apache.webbeans.container.BeanCacheKey#getQualifierHashCode
    public static int getQualifierHashCode(Annotation annotation)
    {
        Class annotationClass = annotation.annotationType();

        int hashCode = getTypeHashCode(annotationClass);

        for (Method member : annotationClass.getDeclaredMethods())
        {
            if (member.isAnnotationPresent(Nonbinding.class))
            {
                continue;
            }

            final Object annotationMemberValue = ReflectionUtils.invokeMethod(annotation, member, Object.class, true);

            final int arrayValue;
            if (annotationMemberValue == null /*possible with literals*/)
            {
                arrayValue = 0;
            }
            else if (annotationMemberValue.getClass().isArray())
            {
                Class<?> annotationMemberType = annotationMemberValue.getClass().getComponentType();
                if (annotationMemberType.isPrimitive())
                {
                    if (Long.TYPE == annotationMemberType)
                    {
                        arrayValue = Arrays.hashCode((long[]) annotationMemberValue);
                    }
                    else if (Integer.TYPE == annotationMemberType)
                    {
                        arrayValue = Arrays.hashCode((int[]) annotationMemberValue);
                    }
                    else if (Short.TYPE == annotationMemberType)
                    {
                        arrayValue = Arrays.hashCode((short[]) annotationMemberValue);
                    }
                    else if (Double.TYPE == annotationMemberType)
                    {
                        arrayValue = Arrays.hashCode((double[]) annotationMemberValue);
                    }
                    else if (Float.TYPE == annotationMemberType)
                    {
                        arrayValue = Arrays.hashCode((float[]) annotationMemberValue);
                    }
                    else if (Boolean.TYPE == annotationMemberType)
                    {
                        arrayValue = Arrays.hashCode((boolean[]) annotationMemberValue);
                    }
                    else if (Byte.TYPE == annotationMemberType)
                    {
                        arrayValue = Arrays.hashCode((byte[]) annotationMemberValue);
                    }
                    else if (Character.TYPE == annotationMemberType)
                    {
                        arrayValue = Arrays.hashCode((char[]) annotationMemberValue);
                    }
                    else
                    {
                        arrayValue = 0;
                    }
                }
                else
                {
                    arrayValue = Arrays.hashCode((Object[]) annotationMemberValue);
                }
            }
            else
            {
                arrayValue = annotationMemberValue.hashCode();
            }

            hashCode = 29 * hashCode + arrayValue;
            hashCode = 29 * hashCode + member.getName().hashCode();
        }

        return hashCode;
    }

    private static int getTypeHashCode(Type type)
    {
        int typeHash = type.hashCode();
        if (typeHash == 0 && type instanceof Class)
        {
            return ((Class)type).getName().hashCode();
        }

        return typeHash;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/AnnotationUtils.java [30:170]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@Typed()
public abstract class AnnotationUtils
{
    private AnnotationUtils()
    {
        // prevent instantiation
    }

    public static <T extends Annotation> T extractAnnotationFromMethodOrClass(
        BeanManager beanManager, Method targetMethod, Class targetClass, Class<T> targetAnnotationType)
    {
        T result = extractAnnotationFromMethod(beanManager, targetMethod, targetAnnotationType);

        if (result == null)
        {
            //see DELTASPIKE-517
            Class unproxiedTargetClass = ProxyUtils.getUnproxiedClass(targetClass);

            // and if not found search on the class
            result = findAnnotation(beanManager, unproxiedTargetClass.getAnnotations(), targetAnnotationType);
        }
        return result;
    }

    public static <T extends Annotation> T extractAnnotationFromMethod(
        BeanManager beanManager, Method targetMethod, Class<T> targetAnnotationType)
    {
        return findAnnotation(beanManager, targetMethod.getAnnotations(), targetAnnotationType);
    }

    public static  <T extends Annotation> T findAnnotation(
            BeanManager beanManager, Annotation[] annotations, Class<T> targetAnnotationType)
    {
        for (Annotation annotation : annotations)
        {
            if (targetAnnotationType.equals(annotation.annotationType()))
            {
                return (T) annotation;
            }
            if (beanManager.isStereotype(annotation.annotationType()))
            {
                T result = findAnnotation(
                        beanManager, annotation.annotationType().getAnnotations(), targetAnnotationType);
                if (result != null)
                {
                    return result;
                }
            }
        }
        return null;
    }

    //based on org.apache.webbeans.container.BeanCacheKey#getQualifierHashCode
    public static int getQualifierHashCode(Annotation annotation)
    {
        Class annotationClass = annotation.annotationType();

        int hashCode = getTypeHashCode(annotationClass);

        for (Method member : annotationClass.getDeclaredMethods())
        {
            if (member.isAnnotationPresent(Nonbinding.class))
            {
                continue;
            }

            final Object annotationMemberValue = ReflectionUtils.invokeMethod(annotation, member, Object.class, true);

            final int arrayValue;
            if (annotationMemberValue == null /*possible with literals*/)
            {
                arrayValue = 0;
            }
            else if (annotationMemberValue.getClass().isArray())
            {
                Class<?> annotationMemberType = annotationMemberValue.getClass().getComponentType();
                if (annotationMemberType.isPrimitive())
                {
                    if (Long.TYPE == annotationMemberType)
                    {
                        arrayValue = Arrays.hashCode((long[]) annotationMemberValue);
                    }
                    else if (Integer.TYPE == annotationMemberType)
                    {
                        arrayValue = Arrays.hashCode((int[]) annotationMemberValue);
                    }
                    else if (Short.TYPE == annotationMemberType)
                    {
                        arrayValue = Arrays.hashCode((short[]) annotationMemberValue);
                    }
                    else if (Double.TYPE == annotationMemberType)
                    {
                        arrayValue = Arrays.hashCode((double[]) annotationMemberValue);
                    }
                    else if (Float.TYPE == annotationMemberType)
                    {
                        arrayValue = Arrays.hashCode((float[]) annotationMemberValue);
                    }
                    else if (Boolean.TYPE == annotationMemberType)
                    {
                        arrayValue = Arrays.hashCode((boolean[]) annotationMemberValue);
                    }
                    else if (Byte.TYPE == annotationMemberType)
                    {
                        arrayValue = Arrays.hashCode((byte[]) annotationMemberValue);
                    }
                    else if (Character.TYPE == annotationMemberType)
                    {
                        arrayValue = Arrays.hashCode((char[]) annotationMemberValue);
                    }
                    else
                    {
                        arrayValue = 0;
                    }
                }
                else
                {
                    arrayValue = Arrays.hashCode((Object[]) annotationMemberValue);
                }
            }
            else
            {
                arrayValue = annotationMemberValue.hashCode();
            }

            hashCode = 29 * hashCode + arrayValue;
            hashCode = 29 * hashCode + member.getName().hashCode();
        }

        return hashCode;
    }

    private static int getTypeHashCode(Type type)
    {
        int typeHash = type.hashCode();
        if (typeHash == 0 && type instanceof Class)
        {
            return ((Class)type).getName().hashCode();
        }

        return typeHash;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



