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();
}
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();
}
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();
}
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();
}
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));
}
Aggregations