@Override @Nullable public String[] getParameterNames(Method method) { return getParameterNames(method.getParameters()); }
private String[] getParameterNames(Method m) { Parameter[] parameters = m.getParameters(); String[] paramNames = new String[parameters.length]; for (int i = 0; i < parameters.length; i++) { paramNames[i] = parameters[i].getName(); } return paramNames; }
@Override public List<String> getParameterNames(Method method) { Parameter[] parameters = method.getParameters(); Annotation[][] parameterAnnotations = method.getParameterAnnotations(); List<String> names = new ArrayList<>(parameterAnnotations.length); for (int i = 0; i < parameterAnnotations.length; i++) { Annotation[] annotations = parameterAnnotations[i]; String name = getParameterNameFromAnnotations(annotations).orElse(parameters[i].getName()); names.add(name); } return names; }
private static boolean hasSameSignature(Method left, Method right) { return (left.getName().equals(right.getName()) && left.getReturnType().equals(right.getReturnType()) && left.getParameterCount() == right.getParameterCount() && left.getParameters().equals(right.getParameters())); }
@Override @Nullable public String[] getParameterNames(Method method) { return getParameterNames(method.getParameters()); }
@Override public void invoke(T component, ClassMapper classMapper) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NotInjectableException { final Object[] args = Stream.of(method.getParameters()) .map(Parameter::getType) .map(classMapper::apply) .toArray(); method.setAccessible(true); method.invoke(component, args); }
static Method getParseMethod(Field f) { for (Method m : f.getType().getMethods()) { if (Modifier.isStatic(m.getModifiers()) && f.getType().equals(m.getReturnType()) && m.getParameters().length == 1 && CharSequence.class.isAssignableFrom(m.getParameters()[0].getType()) && (m.getName().startsWith("parse") || m.getName().startsWith("valueOf"))) { return m; } } return null; }
@Override public String[] getParameterNames(Method method) { Parameter[] parameters = method.getParameters(); String[] parameterNames = new String[parameters.length]; for (int i = 0; i < parameters.length; i++) { Parameter param = parameters[i]; if (!param.isNamePresent()) { return null; } parameterNames[i] = param.getName(); } return parameterNames; }
@Override public String toString() { return getType().getSimpleName() + "#" + method.getName() + "(" + Stream.of(method.getParameters()) .map(p -> p.getType().getSimpleName().substring(0, 1)) .collect(joining(", ")) + ")"; } }
private Stream<BoundCustomizer> parameterCustomizers(Class<?> type, Method method) { final Parameter[] parameters = method.getParameters(); return IntStream.range(0, parameters.length) .boxed() .flatMap(i -> eachParameterCustomizers(type, method, parameters[i], i)); }
private static Optional<MethodHandle> unreflect(Method method) { try { return Optional.of(MethodHandles.publicLookup().unreflect(method)); } catch (IllegalAccessException ex) { LOGGER.log(Level.FINER, ex, () -> "Access checking fails on " + method.getDeclaringClass() + " class, method '" + method.getName() + "' with parameters " + Arrays.asList(method.getParameters()) + "."); } return Optional.empty(); }
private String formatMethod() { return (method().getName() + Arrays.stream(this.method.getParameters()) .map(this::formatParameter) .collect(joining(",\n\t", "(\n\t", "\n)"))); }
private String formatMethod() { return (method().getName() + Arrays.stream(this.method.getParameters()) .map(this::formatParameter) .collect(joining(",\n\t", "(\n\t", "\n)"))); }
public List<ImplementationDependency> parseImplementationDependencies(Method inputFunction) { ImmutableList.Builder<ImplementationDependency> builder = ImmutableList.builder(); for (Parameter parameter : inputFunction.getParameters()) { Class<?> parameterType = parameter.getType(); // Skip injected parameters if (parameterType == ConnectorSession.class) { continue; } getImplementationDependencyAnnotation(parameter).ifPresent(annotation -> { // check if only declared typeParameters and literalParameters are used validateImplementationDependencyAnnotation( inputFunction, annotation, typeParameters.stream() .map(TypeParameter::value) .collect(toImmutableSet()), literalParameters); builder.add(createDependency(annotation, literalParameters)); }); } return builder.build(); }
ConsumerResultReturner(Method method, int consumerIndex) { this.consumerIndex = consumerIndex; Type parameterType = method.getGenericParameterTypes()[consumerIndex]; this.elementType = QualifiedType.of( GenericTypes.findGenericParameter(parameterType, Consumer.class) .orElseThrow(() -> new IllegalStateException( "Cannot reflect Consumer<T> element type T in method consumer parameter " + parameterType))) .with(getQualifiers(method.getParameters()[consumerIndex])); }
public ParaProcessor build(Class<? extends Controller> controllerClass, Method method) { final int paraCount = method.getParameterCount(); // 无参 action 共享同一个对象,该分支以外的所有 ParaProcessor 都是有参 action,不必进行 null 值判断 if (paraCount == 0) { return NullParaProcessor.me; } ParaProcessor ret = new ParaProcessor(paraCount); Parameter[] paras = method.getParameters(); for (int i=0; i<paraCount; i++) { IParaGetter<?> pg = createParaGetter(controllerClass, method, paras[i]); ret.addParaGetter(i, pg); } return ret; }
private static RouteMethod toRouteMethod(final Route.Definition route) { Method handler = ((Route.MethodHandler) route.filter()).method(); return new RouteMethod(route.method(), route.pattern(), new RouteResponse(handler.getGenericReturnType())) .name(route.name()) .parameters(Arrays.asList(handler.getParameters()).stream() .filter(SKIP) .map(it -> BytecodeRouteParser.toRouteParameter(route.pattern(), it)) .filter(Objects::nonNull) .collect(Collectors.toList())); }
@Test public void testFactoryMethods() { assertEquals(stringParameter, SynthesizingMethodParameter.forExecutable(method, 0)); assertEquals(longParameter, SynthesizingMethodParameter.forExecutable(method, 1)); assertEquals(stringParameter, SynthesizingMethodParameter.forParameter(method.getParameters()[0])); assertEquals(longParameter, SynthesizingMethodParameter.forParameter(method.getParameters()[1])); }
@Test @SuppressWarnings("deprecation") public void testFactoryMethods() { assertEquals(stringParameter, MethodParameter.forMethodOrConstructor(method, 0)); assertEquals(longParameter, MethodParameter.forMethodOrConstructor(method, 1)); assertEquals(stringParameter, MethodParameter.forExecutable(method, 0)); assertEquals(longParameter, MethodParameter.forExecutable(method, 1)); assertEquals(stringParameter, MethodParameter.forParameter(method.getParameters()[0])); assertEquals(longParameter, MethodParameter.forParameter(method.getParameters()[1])); }
@Before public void setUp() throws Exception { assumeFalse(BindDao.class.getMethod("getByIdImplicitBindPositional", int.class).getParameters()[0].isNamePresent()); h = dbRule.getSharedHandle(); h.registerRowMapper(BeanMapper.factory(Something.class)); h.execute("insert into something (id, name) values (1, 'Elsie Hughes')"); }