javax.enterprise.util.Nonbinding Java Examples

The following examples show how to use javax.enterprise.util.Nonbinding. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Qualifiers.java    From quarkus with Apache License 2.0 5 votes vote down vote up
static boolean hasQualifier(Iterable<Annotation> qualifiers, Annotation requiredQualifier) {

        Class<? extends Annotation> requiredQualifierClass = requiredQualifier.annotationType();
        Method[] members = requiredQualifierClass.getDeclaredMethods();

        for (Annotation qualifier : qualifiers) {
            Class<? extends Annotation> qualifierClass = qualifier.annotationType();
            if (!qualifierClass.equals(requiredQualifierClass)) {
                continue;
            }
            boolean matches = true;
            for (Method value : members) {
                if (value.isAnnotationPresent(Nonbinding.class)) {
                    continue;
                }
                Object val1 = invoke(value, requiredQualifier);
                Object val2 = invoke(value, qualifier);
                if (val1.getClass().isArray()) {
                    if (!val2.getClass().isArray() || !Arrays.equals((Object[]) val1, (Object[]) val2)) {
                        matches = false;
                        break;
                    }
                } else if (!val1.equals(val2)) {
                    matches = false;
                    break;
                }
            }
            if (matches) {
                return true;
            }
        }
        return false;
    }
 
Example #2
Source File: ExcludeExtension.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
private boolean doesQualifierMatch(Annotation currentQualifier, Annotation qualifierConfiguredBean)
{
    if (!currentQualifier.annotationType().equals(qualifierConfiguredBean.annotationType()))
    {
        return false;
    }

    Object currentValue;
    Object valueOfQualifierConfiguredBean;
    for (Method currentMethod : currentQualifier.annotationType().getDeclaredMethods())
    {
        if (currentMethod.isAnnotationPresent(Nonbinding.class))
        {
            continue;
        }

        try
        {
            currentMethod.setAccessible(true);
            currentValue = currentMethod.invoke(currentQualifier);
            valueOfQualifierConfiguredBean = currentMethod.invoke(qualifierConfiguredBean);

            if (!currentValue.equals(valueOfQualifierConfiguredBean))
            {
                return false;
            }
        }
        catch (Exception e)
        {
            throw new IllegalStateException("Can't compare " + currentQualifier.annotationType().getName() +
                " with " + qualifierConfiguredBean.annotationType().getName(), e);
        }
    }
    return true;
}
 
Example #3
Source File: AnnotationUtils.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example #4
Source File: ReflectionUtils.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
public static int calculateHashCodeOfAnnotation(Annotation annotation, boolean skipNonbindingMembers)
{
    Class annotationClass = annotation.annotationType();

    // the hashCode of an Annotation is calculated solely via the hashCodes
    // of it's members. If there are no members, it is 0.
    // thus we first need to get the annotation-class hashCode
    int hashCode = calculateHashCodeOfType(annotationClass);

    // and now add the hashCode of all it's Nonbinding members
    // the following algorithm is defined by the Annotation class definition
    // see the JavaDoc for Annotation!
    // we only change it so far that we skip evaluating @Nonbinding members
    final Method[] members = annotationClass.getDeclaredMethods();

    for (Method member : members)
    {
        if (skipNonbindingMembers && member.isAnnotationPresent(Nonbinding.class))
        {
            // ignore the non binding
            continue;
        }

        // Member value
        final Object object = invokeMethod(annotation, member, Object.class, true, EMPTY_OBJECT_ARRAY);
        final int value;
        if (object.getClass().isArray())
        {
            Class<?> type = object.getClass().getComponentType();
            if (type.isPrimitive())
            {
                if (Long.TYPE == type)
                {
                    value = Arrays.hashCode((long[]) object);
                }
                else if (Integer.TYPE == type)
                {
                    value = Arrays.hashCode((int[])object);
                }
                else if (Short.TYPE == type)
                {
                    value = Arrays.hashCode((short[])object);
                }
                else if (Double.TYPE == type)
                {
                    value = Arrays.hashCode((double[])object);
                }
                else if (Float.TYPE == type)
                {
                    value = Arrays.hashCode((float[])object);
                }
                else if (Boolean.TYPE == type)
                {
                    value = Arrays.hashCode((boolean[])object);
                }
                else if (Byte.TYPE == type)
                {
                    value = Arrays.hashCode((byte[])object);
                }
                else if (Character.TYPE == type)
                {
                    value = Arrays.hashCode((char[])object);
                }
                else
                {
                    value = 0;
                }
            }
            else
            {
                value = Arrays.hashCode((Object[])object);
            }
        }
        else
        {
            value = object.hashCode();
        }

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

    return hashCode;
}