@Nullable public static String[] evaluate(Constructor<?> candidate, int paramCount) { ConstructorProperties cp = candidate.getAnnotation(ConstructorProperties.class); if (cp != null) { String[] names = cp.value(); if (names.length != paramCount) { throw new IllegalStateException("Constructor annotated with @ConstructorProperties but not " + "corresponding to actual number of parameters (" + paramCount + "): " + candidate); } return names; } else { return null; } } }
@Nullable public static String[] evaluate(Constructor<?> candidate, int paramCount) { ConstructorProperties cp = candidate.getAnnotation(ConstructorProperties.class); if (cp != null) { String[] names = cp.value(); if (names.length != paramCount) { throw new IllegalStateException("Constructor annotated with @ConstructorProperties but not " + "corresponding to actual number of parameters (" + paramCount + "): " + candidate); } return names; } else { return null; } } }
private static String paramName(Parameter[] parameters, int position, ConstructorProperties parameterNames) { final Parameter parameter = parameters[position]; ColumnName dbName = parameter.getAnnotation(ColumnName.class); if (dbName != null) { return dbName.value(); } if (parameterNames != null) { return parameterNames.value()[position]; } return parameter.getName(); }
String[] paramNames = (cp != null ? cp.value() : parameterNameDiscoverer.getParameterNames(ctor)); Assert.state(paramNames != null, () -> "Cannot resolve parameter names for constructor " + ctor); Class<?>[] paramTypes = ctor.getParameterTypes();
@Override public PropertyName findConstructorName(AnnotatedParameter p) { AnnotatedWithParams ctor = p.getOwner(); if (ctor != null) { ConstructorProperties props = ctor.getAnnotation(ConstructorProperties.class); if (props != null) { String[] names = props.value(); int ix = p.getIndex(); if (ix < names.length) { return PropertyName.construct(names[ix]); } } } return null; } }
@Override public PropertyName findConstructorName(AnnotatedParameter p) { AnnotatedWithParams ctor = p.getOwner(); if (ctor != null) { ConstructorProperties props = ctor.getAnnotation(ConstructorProperties.class); if (props != null) { String[] names = props.value(); int ix = p.getIndex(); if (ix < names.length) { return PropertyName.construct(names[ix]); } } } return null; } }
for (Constructor constr : annotatedConstrList) { String[] propertyNames = ((ConstructorProperties) constr.getAnnotation(propertyNamesClass)).value();
String[] paramNames = (cp != null ? cp.value() : parameterNameDiscoverer.getParameterNames(ctor)); Assert.state(paramNames != null, () -> "Cannot resolve parameter names for constructor " + ctor); Class<?>[] paramTypes = ctor.getParameterTypes();
@Override public PropertyName findConstructorName(AnnotatedParameter p) { AnnotatedWithParams ctor = p.getOwner(); if (ctor != null) { ConstructorProperties props = ctor.getAnnotation(ConstructorProperties.class); if (props != null) { String[] names = props.value(); int ix = p.getIndex(); if (ix < names.length) { return PropertyName.construct(names[ix]); } } } return null; } }
String[] paramNames = (cp != null ? cp.value() : parameterNameDiscoverer.getParameterNames(ctor)); Assert.state(paramNames != null, () -> "Cannot resolve parameter names for constructor " + ctor); Class<?>[] paramTypes = ctor.getParameterTypes();
public static String[] evaluateAnnotation(Constructor<?> candidate, int paramCount) { ConstructorProperties cp = candidate.getAnnotation(ConstructorProperties.class); if (cp != null) { String[] names = cp.value(); if (names.length != paramCount) { throw new IllegalStateException("Constructor annotated with @ConstructorProperties but not " + "corresponding to actual number of parameters (" + paramCount + "): " + candidate); } return names; } else { return null; } } }
private Optional<Object> lookupClass(final Class<?> cls, final boolean secondary) { return Arrays .stream(cls.getConstructors()) .filter(c -> c.isAnnotationPresent(ConstructorProperties.class)) .findAny() .map(c -> { final String[] names = c.getAnnotation(ConstructorProperties.class).value(); final Type[] types = c.getGenericParameterTypes(); if (names.length != types.length) { throw new IllegalArgumentException( "@ConstructorProperties number of arguments do not match number of " + "parameters: " + c); } final Object[] arguments = new Object[types.length]; for (int i = 0; i < types.length; i++) { arguments[i] = lookup(types[i], secondary, names[i]); } try { return c.newInstance(arguments); } catch (final ReflectiveOperationException e) { throw Throwables.propagate(e); } }); }
Arrays.stream(parameters).map(Parameter::getParameterizedType).toArray(Type[]::new); final String[] names = constructor.getAnnotation(ConstructorProperties.class).value();
private static Map<String, SqlParameterDefinition> getSqlBeanParametersFromConstructorProperties(Constructor<?> c, SqlObjectConfig config) { Map<String, SqlParameterDefinition> parameters = new LinkedHashMap<String, SqlParameterDefinition>(); String[] constructorProperties = c.getAnnotation(ConstructorProperties.class).value(); Class<?>[] pts = c.getParameterTypes(); for (int i = 0; i < pts.length; i++) { parameters.put(constructorProperties[i], parameterDef(config, c.getDeclaringClass(), constructorProperties[i], pts[i], i)); } return parameters; } }
private String[] findArgsName(final Class clazz) { return Stream .of(clazz.getConstructors()) .filter(c -> c.isAnnotationPresent(ConstructorProperties.class)) .findFirst() .map(c -> ConstructorProperties.class.cast(c.getAnnotation(ConstructorProperties.class)).value()) .orElse(null); }
private static String paramName(Parameter[] parameters, int position, ConstructorProperties parameterNames) { final Parameter parameter = parameters[position]; ColumnName dbName = parameter.getAnnotation(ColumnName.class); if (dbName != null) { return dbName.value(); } if (parameterNames != null) { return parameterNames.value()[position]; } return parameter.getName(); } }
@VisibleForTesting <T> String translateName(Invokable<T, T> c, int index) { String name = null; if (markers.contains(ConstructorProperties.class) && c.getAnnotation(ConstructorProperties.class) != null) { String[] names = c.getAnnotation(ConstructorProperties.class).value(); if (names != null && names.length > index) { name = names[index]; } } for (Annotation annotation : c.getParameters().get(index).getAnnotations()) { if (annotationToNameExtractor.containsKey(annotation.annotationType())) { name = annotationToNameExtractor.get(annotation.annotationType()).apply(annotation); break; } } return name; } }
private void addJacksonAnnotationsToContructorParameters(AnnotatedConstructor annotatedConstructor) { ConstructorProperties properties = getConstructorPropertiesAnnotation(annotatedConstructor); for (int i = 0; i < annotatedConstructor.getParameterCount(); i++) { String name = properties.value()[i]; AnnotatedParameter parameter = annotatedConstructor.getParameter(i); Field field = null; try { field = annotatedConstructor.getDeclaringClass().getDeclaredField(name); } catch (NoSuchFieldException ignored) { } addJacksonAnnotationsToConstructorParameter(field, parameter, name); } }
private void addJacksonAnnotationsToContructorParameters(AnnotatedConstructor annotatedConstructor) { ConstructorProperties properties = getConstructorPropertiesAnnotation(annotatedConstructor); for (int i = 0; i < annotatedConstructor.getParameterCount(); i++) { String name = properties.value()[i]; AnnotatedParameter parameter = annotatedConstructor.getParameter(i); Field field = null; try { field = annotatedConstructor.getDeclaringClass().getDeclaredField(name); } catch (NoSuchFieldException ignored) { } addJacksonAnnotationsToConstructorParameter(field, parameter, name); } }
@Override public PropertyName findConstructorName(AnnotatedParameter p) { AnnotatedWithParams ctor = p.getOwner(); if (ctor != null) { ConstructorProperties props = ctor.getAnnotation(ConstructorProperties.class); if (props != null) { String[] names = props.value(); int ix = p.getIndex(); if (ix < names.length) { return PropertyName.construct(names[ix]); } } } return null; } }