@Override default <T extends Annotation> Set<T> getAnnotations(Class<T> annotationType) { T[] annotationsByType = getJavaMember().getAnnotationsByType(annotationType); return new LinkedHashSet<>(asList(annotationsByType)); } }
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))); }
final RequestConverter[] converters = constructor.getAnnotationsByType(RequestConverter.class); final List<AnnotatedValueResolver> resolvers = AnnotatedValueResolver.ofBeanConstructorOrMethod(
private static Map<Set<TypeParameter>, Constructor<?>> findConstructors(Class<?> clazz) { ImmutableMap.Builder<Set<TypeParameter>, Constructor<?>> builder = ImmutableMap.builder(); for (Constructor<?> constructor : clazz.getConstructors()) { Set<TypeParameter> typeParameters = new HashSet<>(); Stream.of(constructor.getAnnotationsByType(TypeParameter.class)) .forEach(typeParameters::add); builder.put(typeParameters, constructor); } return builder.build(); }
@Override default <T extends Annotation> Set<T> getAnnotations(Class<T> annotationType) { T[] annotationsByType = getJavaMember().getAnnotationsByType(annotationType); return new LinkedHashSet<>(asList(annotationsByType)); } }
@Override default <T extends Annotation> Set<T> getAnnotations(Class<T> annotationType) { T[] annotationsByType = getJavaMember().getAnnotationsByType(annotationType); return new LinkedHashSet<>(asList(annotationsByType)); } }
@Override default <T extends Annotation> Set<T> getAnnotations(Class<T> annotationType) { T[] annotationsByType = getJavaMember().getAnnotationsByType(annotationType); return new LinkedHashSet<>(asList(annotationsByType)); } }
@Override default <T extends Annotation> Set<T> getAnnotations(Class<T> annotationType) { T[] annotationsByType = getJavaMember().getAnnotationsByType(annotationType); return new LinkedHashSet<>(asList(annotationsByType)); } }
@Override default <T extends Annotation> Set<T> getAnnotations(Class<T> annotationType) { T[] annotationsByType = getJavaMember().getAnnotationsByType(annotationType); return new LinkedHashSet<>(asList(annotationsByType)); } }
@Override default <T extends Annotation> Set<T> getAnnotations(Class<T> annotationType) { return new LinkedHashSet<>(Arrays.asList(getJavaMember().getAnnotationsByType(annotationType))); } }
@Override default <T extends Annotation> Set<T> getAnnotations(Class<T> annotationType) { return new LinkedHashSet<>(Arrays.asList(getJavaMember().getAnnotationsByType(annotationType))); } }
@Override default <T extends Annotation> Set<T> getAnnotations(Class<T> annotationType) { T[] annotationsByType = getJavaMember().getAnnotationsByType(annotationType); return new LinkedHashSet<>(asList(annotationsByType)); } }
@Override default <T extends Annotation> Set<T> getAnnotations(Class<T> annotationType) { return new LinkedHashSet<>(Arrays.asList(getJavaMember().getAnnotationsByType(annotationType))); } }
protected <C> Constructor<?> findCreator(Class<C> clazz) throws MappingException { Constructor<?> binaryCreator = null; Constructor<?> defaultConstructor = null; for (Constructor<?> constructor : clazz.getConstructors()) { if (constructor.getParameterTypes().length == 0) { defaultConstructor = constructor; } T[] binaryCreators = constructor.getAnnotationsByType(creatorAnnotation); if (binaryCreators.length == 0) { continue; } else if (binaryCreators.length > 1) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("@"); stringBuilder.append(creatorAnnotation.getSimpleName()); stringBuilder.append(" annotation is only allowed once."); throw new MappingException(stringBuilder.toString()); } if (binaryCreator != null) { throw new MappingException("Only one constructor can be binary creator."); } binaryCreator = constructor; } if (binaryCreator.equals(defaultConstructor)) { throw new MappingException("Defining default constructor as creator is meaningless."); } return binaryCreator; }
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 AgentFactory buildFactory(Class<? extends Agent> agentClazz) { Constructor<?> bestMatch = null; Constructor<?>[] constructors = agentClazz.getConstructors(); for (Constructor<?> constructor : constructors) { if (constructor.getParameterCount() == 0 && Modifier.isPublic(constructor.getModifiers())) { bestMatch = constructor; } else { AgentConstructor builder = constructor.getAnnotation(AgentConstructor.class); if (builder == null) { continue; } String name = builder.value().equals("") ? agentClazz.getSimpleName() : builder.value(); bestMatch = constructor; HashMap<Integer, Parameter> parameters = new HashMap<>(); for (Parameter p : constructor.getAnnotationsByType(Parameter.class)) { if (!parameters.containsKey(p.id())) { parameters.put(p.id(), p); } } Function<String, ?>[] convertersInst = getConverters(agentClazz, constructor.getParameterTypes(), parameters); return new ConstructorFactory(agentClazz, constructor, convertersInst, name); } } if (bestMatch == null) { throw new IllegalArgumentException("You must either annotate a constructor or provide a public no-args constructor"); } return new ConstructorFactory(agentClazz, bestMatch, null); }
if(con.isAnnotationPresent(RegisterExempt.class)) continue; final AutoRegister[] methodAnns = con.getAnnotationsByType(AutoRegister.class); if(classAnns.length == 0 && methodAnns.length == 0) continue; final Class<?>[] cTypes = con.getParameterTypes(); final ParameterWrapper<?>[] pTypes = new ParameterWrapper[cTypes.length]; for(final ParameterOverride override:con.getAnnotationsByType(ParameterOverride.class)) pTypes[override.parameterIndex()] = ParameterTypes.getExceptionWrapper(override.exceptionKey()); for(int i = 0; i < cTypes.length; i++){