Search in sources :

Example 71 with Annotation

use of java.lang.annotation.Annotation in project presto by prestodb.

the class BindableAggregationFunction method getParameterMetadata.

private static List<ParameterMetadata> getParameterMetadata(@Nullable Method method, List<Type> inputTypes) {
    if (method == null) {
        return null;
    }
    ImmutableList.Builder<ParameterMetadata> builder = ImmutableList.builder();
    Annotation[][] annotations = method.getParameterAnnotations();
    String methodName = method.getDeclaringClass() + "." + method.getName();
    checkArgument(annotations.length > 0, "At least @AggregationState argument is required for each of aggregation functions.");
    int inputId = 0;
    int i = 0;
    if (annotations[0].length == 0) {
        // Backward compatibility - first argument without annotations is interpreted as State argument
        builder.add(new ParameterMetadata(STATE));
        i++;
    }
    for (; i < annotations.length; i++) {
        Annotation baseTypeAnnotation = baseTypeAnnotation(annotations[i], methodName);
        if (baseTypeAnnotation instanceof SqlType) {
            builder.add(fromSqlType(inputTypes.get(i - 1), isParameterBlock(annotations[i]), isParameterNullable(annotations[i]), methodName));
        } else if (baseTypeAnnotation instanceof BlockIndex) {
            builder.add(new ParameterMetadata(BLOCK_INDEX));
        } else if (baseTypeAnnotation instanceof AggregationState) {
            builder.add(new ParameterMetadata(STATE));
        } else {
            throw new IllegalArgumentException("Unsupported annotation: " + annotations[i]);
        }
    }
    return builder.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ImmutableCollectors.toImmutableList(com.facebook.presto.util.ImmutableCollectors.toImmutableList) ParameterMetadata.fromSqlType(com.facebook.presto.operator.aggregation.AggregationMetadata.ParameterMetadata.fromSqlType) SqlType(com.facebook.presto.spi.function.SqlType) ParameterMetadata(com.facebook.presto.operator.aggregation.AggregationMetadata.ParameterMetadata) AggregationState(com.facebook.presto.spi.function.AggregationState) Annotation(java.lang.annotation.Annotation)

Example 72 with Annotation

use of java.lang.annotation.Annotation in project presto by prestodb.

the class AggregationCompiler method findPublicStaticMethodsWithAnnotation.

private static List<Method> findPublicStaticMethodsWithAnnotation(Class<?> clazz, Class<?> annotationClass) {
    ImmutableList.Builder<Method> methods = ImmutableList.builder();
    for (Method method : clazz.getMethods()) {
        for (Annotation annotation : method.getAnnotations()) {
            if (annotationClass.isInstance(annotation)) {
                checkArgument(Modifier.isStatic(method.getModifiers()) && Modifier.isPublic(method.getModifiers()), "%s annotated with %s must be static and public", method.getName(), annotationClass.getSimpleName());
                methods.add(method);
            }
        }
    }
    return methods.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ImmutableCollectors.toImmutableList(com.facebook.presto.util.ImmutableCollectors.toImmutableList) Method(java.lang.reflect.Method) Annotation(java.lang.annotation.Annotation)

Example 73 with Annotation

use of java.lang.annotation.Annotation in project presto by prestodb.

the class AggregationCompiler method getInputTypesSignatures.

private static List<TypeSignature> getInputTypesSignatures(Method inputFunction) {
    // FIXME Literal parameters should be part of class annotations.
    ImmutableList.Builder<TypeSignature> builder = ImmutableList.builder();
    Set<String> literalParameters = getLiteralParameter(inputFunction);
    Annotation[][] parameterAnnotations = inputFunction.getParameterAnnotations();
    for (Annotation[] annotations : parameterAnnotations) {
        for (Annotation annotation : annotations) {
            if (annotation instanceof SqlType) {
                String typeName = ((SqlType) annotation).value();
                builder.add(parseTypeSignature(typeName, literalParameters));
            }
        }
    }
    return builder.build();
}
Also used : TypeSignature(com.facebook.presto.spi.type.TypeSignature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) ImmutableList(com.google.common.collect.ImmutableList) ImmutableCollectors.toImmutableList(com.facebook.presto.util.ImmutableCollectors.toImmutableList) SqlType(com.facebook.presto.spi.function.SqlType) Annotation(java.lang.annotation.Annotation)

Example 74 with Annotation

use of java.lang.annotation.Annotation in project presto by prestodb.

the class AggregationCompiler method getLiteralParameter.

private static Set<String> getLiteralParameter(Method inputFunction) {
    ImmutableSet.Builder<String> literalParametersBuilder = ImmutableSet.builder();
    Annotation[] literalParameters = inputFunction.getAnnotations();
    for (Annotation annotation : literalParameters) {
        if (annotation instanceof LiteralParameters) {
            for (String literal : ((LiteralParameters) annotation).value()) {
                literalParametersBuilder.add(literal);
            }
        }
    }
    return literalParametersBuilder.build();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) LiteralParameters(com.facebook.presto.spi.function.LiteralParameters) Annotation(java.lang.annotation.Annotation)

Example 75 with Annotation

use of java.lang.annotation.Annotation in project platformlayer by platformlayer.

the class AnnotationDictionary method add.

public void add(Class<?> clazz) {
    Annotation annotation = clazz.getAnnotation(annotationClass);
    if (annotation == null) {
        throw new IllegalArgumentException();
    }
    classes.add(new AnnotatedClass(clazz, annotation));
}
Also used : Annotation(java.lang.annotation.Annotation)

Aggregations

Annotation (java.lang.annotation.Annotation)707 Method (java.lang.reflect.Method)171 ArrayList (java.util.ArrayList)99 Field (java.lang.reflect.Field)76 Test (org.junit.Test)66 Type (java.lang.reflect.Type)64 HashMap (java.util.HashMap)54 HashSet (java.util.HashSet)52 Map (java.util.Map)35 ParameterizedType (java.lang.reflect.ParameterizedType)34 List (java.util.List)30 Set (java.util.Set)27 InvocationTargetException (java.lang.reflect.InvocationTargetException)22 IOException (java.io.IOException)20 BindingAnnotation (com.google.inject.BindingAnnotation)17 AbstractModule (com.google.inject.AbstractModule)16 TypeElement (javax.lang.model.element.TypeElement)15 Injector (com.google.inject.Injector)14 MediaType (okhttp3.MediaType)14 AnnotatedElement (java.lang.reflect.AnnotatedElement)13