Source:
public ScalarImplementationChoice( boolean nullable, List<ArgumentProperty> argumentProperties, ReturnPlaceConvention returnPlaceConvention, MethodHandle methodHandle, Optional<MethodHandle> instanceFactory) { this.nullable = nullable; this.argumentProperties = ImmutableList.copyOf(requireNonNull(argumentProperties, "argumentProperties is null")); this.returnPlaceConvention = requireNonNull(returnPlaceConvention, "returnPlaceConvention is null"); this.methodHandle = requireNonNull(methodHandle, "methodHandle is null"); this.instanceFactory = requireNonNull(instanceFactory, "instanceFactory is null"); if (instanceFactory.isPresent()) { Class<?> instanceType = instanceFactory.get().type().returnType(); checkArgument(instanceFactory.get().type().parameterList().size() == 0, "instanceFactory should have no parameter"); checkArgument(instanceType.equals(methodHandle.type().parameterType(0)), "methodHandle is not an instance method"); } List<Class<?>> parameterList = methodHandle.type().parameterList(); boolean hasSession = false; if (parameterList.contains(SqlFunctionProperties.class)) { checkArgument(parameterList.stream().filter(SqlFunctionProperties.class::equals).count() == 1, "function implementation should have exactly one SqlFunctionProperties parameter"); if (!instanceFactory.isPresent()) { checkArgument(parameterList.get(0) == SqlFunctionProperties.class, "SqlFunctionProperties must be the first argument when instanceFactory is not present"); } else { checkArgument(parameterList.get(1) == SqlFunctionProperties.class, "SqlFunctionProperties must be the second argument when instanceFactory is present"); } hasSession = true; } this.hasSession = hasSession; }

Target:
public ScalarImplementationChoice( boolean nullable, List<ArgumentProperty> argumentProperties, ReturnPlaceConvention returnPlaceConvention, MethodHandle methodHandle, Optional<MethodHandle> instanceFactory) { this.nullable = nullable; this.argumentProperties = ImmutableList.copyOf(requireNonNull(argumentProperties, "argumentProperties is null")); this.returnPlaceConvention = requireNonNull(returnPlaceConvention, "returnPlaceConvention is null"); this.methodHandle = requireNonNull(methodHandle, "methodHandle is null"); this.instanceFactory = requireNonNull(instanceFactory, "instanceFactory is null"); if (instanceFactory.isPresent()) { Class<?> instanceType = instanceFactory.get().type().returnType(); checkArgument(instanceFactory.get().type().parameterList().size() == 0, "instanceFactory should have no parameter"); checkArgument(instanceType.equals(methodHandle.type().parameterType(0)), "methodHandle is not an instance method"); } List<Class<?>> parameterList = methodHandle.type().parameterList(); boolean hasProperties = false; if (parameterList.contains(SqlFunctionProperties.class)) { checkArgument(parameterList.stream().filter(SqlFunctionProperties.class::equals).count() == 1, "function implementation should have exactly one SqlFunctionProperties parameter"); if (!instanceFactory.isPresent()) { checkArgument(parameterList.get(0) == SqlFunctionProperties.class, "SqlFunctionProperties must be the first argument when instanceFactory is not present"); } else { checkArgument(parameterList.get(1) == SqlFunctionProperties.class, "SqlFunctionProperties must be the second argument when instanceFactory is present"); } hasProperties = true; } this.hasProperties = hasProperties; }