static void validateImplementationDependencyAnnotation(AnnotatedElement element, Annotation annotation, Set<String> typeParametersNames, Collection<String> literalParameters) { if (annotation instanceof TypeParameter) { checkTypeParameters(parseTypeSignature(((TypeParameter) annotation).value()), typeParametersNames, element); } if (annotation instanceof LiteralParameter) { checkArgument(literalParameters.contains(((LiteralParameter) annotation).value()), "Parameter injected by @LiteralParameter must be declared with @LiteralParameters on the method [%s]", element); } }
static void validateImplementationDependencyAnnotation(AnnotatedElement element, Annotation annotation, Set<String> typeParametersNames, Collection<String> literalParameters) { if (annotation instanceof TypeParameter) { checkTypeParameters(parseTypeSignature(((TypeParameter) annotation).value()), typeParametersNames, element); } if (annotation instanceof LiteralParameter) { checkArgument(literalParameters.contains(((LiteralParameter) annotation).value()), "Parameter injected by @LiteralParameter must be declared with @LiteralParameters on the method [%s]", element); } }
String name = typeParameter.value(); if (orderableRequired.contains(name)) { typeVariableConstraints.add(orderableTypeParameter(name));
String name = typeParameter.value(); if (orderableRequired.contains(name)) { typeVariableConstraints.add(orderableTypeParameter(name));
private Optional<MethodHandle> getConstructor(Method method, Optional<Constructor<?>> optionalConstructor) { if (isStatic(method.getModifiers())) { return Optional.empty(); } checkArgument(optionalConstructor.isPresent(), "Method [%s] is an instance method. It must be in a class annotated with @ScalarFunction, and the class is required to have a public constructor.", method); Constructor<?> constructor = optionalConstructor.get(); Set<TypeParameter> constructorTypeParameters = Stream.of(constructor.getAnnotationsByType(TypeParameter.class)) .collect(ImmutableSet.toImmutableSet()); checkArgument(constructorTypeParameters.containsAll(typeParameters), "Method [%s] is an instance method and requires a public constructor containing all type parameters: %s", method, typeParameters); for (int i = 0; i < constructor.getParameterCount(); i++) { Annotation[] annotations = constructor.getParameterAnnotations()[i]; checkArgument(containsImplementationDependencyAnnotation(annotations), "Constructors may only have meta parameters [%s]", constructor); checkArgument(annotations.length == 1, "Meta parameters may only have a single annotation [%s]", constructor); Annotation annotation = annotations[0]; if (annotation instanceof TypeParameter) { checkTypeParameters(parseTypeSignature(((TypeParameter) annotation).value()), typeParameterNames, method); } constructorDependencies.add(createDependency(annotation, literalParameters)); } MethodHandle result = constructorMethodHandle(FUNCTION_IMPLEMENTATION_ERROR, constructor); // Change type of return value to Object to make sure callers won't have classloader issues return Optional.of(result.asType(result.type().changeReturnType(Object.class))); }
private Optional<MethodHandle> getConstructor(Method method, Optional<Constructor<?>> optionalConstructor) { if (isStatic(method.getModifiers())) { return Optional.empty(); } checkArgument(optionalConstructor.isPresent(), "Method [%s] is an instance method. It must be in a class annotated with @ScalarFunction, and the class is required to have a public constructor.", method); Constructor<?> constructor = optionalConstructor.get(); Set<TypeParameter> constructorTypeParameters = Stream.of(constructor.getAnnotationsByType(TypeParameter.class)) .collect(ImmutableSet.toImmutableSet()); checkArgument(constructorTypeParameters.containsAll(typeParameters), "Method [%s] is an instance method and requires a public constructor containing all type parameters: %s", method, typeParameters); for (int i = 0; i < constructor.getParameterCount(); i++) { Annotation[] annotations = constructor.getParameterAnnotations()[i]; checkArgument(containsImplementationDependencyAnnotation(annotations), "Constructors may only have meta parameters [%s]", constructor); checkArgument(annotations.length == 1, "Meta parameters may only have a single annotation [%s]", constructor); Annotation annotation = annotations[0]; if (annotation instanceof TypeParameter) { checkTypeParameters(parseTypeSignature(((TypeParameter) annotation).value()), typeParameterNames, method); } constructorDependencies.add(createDependency(annotation, literalParameters)); } MethodHandle result = constructorMethodHandle(FUNCTION_IMPLEMENTATION_ERROR, constructor); // Change type of return value to Object to make sure callers won't have classloader issues return Optional.of(result.asType(result.type().changeReturnType(Object.class))); }
public static ImplementationDependency createDependency(Annotation annotation, Set<String> literalParameters) { if (annotation instanceof TypeParameter) { return new TypeImplementationDependency(((TypeParameter) annotation).value()); } if (annotation instanceof LiteralParameter) { return new LiteralImplementationDependency(((LiteralParameter) annotation).value()); } if (annotation instanceof FunctionDependency) { FunctionDependency functionDependency = (FunctionDependency) annotation; return new FunctionImplementationDependency( functionDependency.name(), parseTypeSignature(functionDependency.returnType(), literalParameters), Arrays.stream(functionDependency.argumentTypes()) .map(signature -> parseTypeSignature(signature, literalParameters)) .collect(toImmutableList()), toInvocationConvention(functionDependency.convention())); } if (annotation instanceof OperatorDependency) { OperatorDependency operatorDependency = (OperatorDependency) annotation; return new OperatorImplementationDependency( operatorDependency.operator(), parseTypeSignature(operatorDependency.returnType(), literalParameters), Arrays.stream(operatorDependency.argumentTypes()) .map(signature -> parseTypeSignature(signature, literalParameters)) .collect(toImmutableList()), toInvocationConvention(operatorDependency.convention())); } throw new IllegalArgumentException("Unsupported annotation " + annotation.getClass().getSimpleName()); }
public static ImplementationDependency createDependency(Annotation annotation, Set<String> literalParameters) { if (annotation instanceof TypeParameter) { return new TypeImplementationDependency(((TypeParameter) annotation).value()); } if (annotation instanceof LiteralParameter) { return new LiteralImplementationDependency(((LiteralParameter) annotation).value()); } if (annotation instanceof FunctionDependency) { FunctionDependency functionDependency = (FunctionDependency) annotation; return new FunctionImplementationDependency( functionDependency.name(), parseTypeSignature(functionDependency.returnType(), literalParameters), Arrays.stream(functionDependency.argumentTypes()) .map(signature -> parseTypeSignature(signature, literalParameters)) .collect(toImmutableList()), toInvocationConvention(functionDependency.convention())); } if (annotation instanceof OperatorDependency) { OperatorDependency operatorDependency = (OperatorDependency) annotation; return new OperatorImplementationDependency( operatorDependency.operator(), parseTypeSignature(operatorDependency.returnType(), literalParameters), Arrays.stream(operatorDependency.argumentTypes()) .map(signature -> parseTypeSignature(signature, literalParameters)) .collect(toImmutableList()), toInvocationConvention(operatorDependency.convention())); } throw new IllegalArgumentException("Unsupported annotation " + annotation.getClass().getSimpleName()); }