-
Notifications
You must be signed in to change notification settings - Fork 38.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow MethodReference to support a more flexible signature #29005
Comments
private CodeBlock generateReturnStatement(GeneratedMethod getInstanceMethod) {
return CodeBlock.of("$T.$L()", this.className, getInstanceMethod.getName());
} |
|
Most of the |
I've had a brainstorming session with @wilkinsona and @bclozel today. We've discussed various options and the pros and cons and we conclude that it is overkill to try to avoid both side having some sort of shared context. Trying to do that means too much context needs to be provided by the caller and We came back with the original need of offering a more flexible signature and we'd like to explore how |
I've made some good progress in https://github.com/snicoll/spring-framework/tree/gh-29005 - One advantage of knowing the ultimate location of the code is that we don't expand the class name for static internal calls. For instance, the following code: beanDefinition.setInstanceSupplier(ApplicationAvailabilityAutoConfiguration__BeanDefinitions.getApplicationAvailabilityInstanceSupplier()); Is now: beanDefinition.setInstanceSupplier(getApplicationAvailabilityInstanceSupplier()); However, knowing the ultimate target class isn't always possible so we might need to adapt some API. Perhaps |
This commit updates GeneratedMethod and its underlying infrastructure to be able to produce a MethodReference. This simplifies the need when such a reference needs to be created manually and reuses more of what MethodReference has to offer. See spring-projectsgh-29005
This commit moves MethodReference to an interface with a default implementation that relies on a MethodSpec. Such an arrangement avoid the need of specifying attributes of the method such as whether it is static or not. The resolution of the invocation block now takes an ArgumentCodeGenerator rather than the raw arguments. Doing so gives the opportunity to create more flexible signatures. See spring-projectsgh-29005
This commit allows bean factory initialization to use a more flexible signature than just consuming the DefaultListableBeanFactory. The environment and the resource loader can now be specified if necessary. See spring-projectsgh-29005
This commit updates GeneratedMethod and its underlying infrastructure to be able to produce a MethodReference. This simplifies the need when such a reference needs to be created manually and reuses more of what MethodReference has to offer. See gh-29005
This commit moves MethodReference to an interface with a default implementation that relies on a MethodSpec. Such an arrangement avoid the need of specifying attributes of the method such as whether it is static or not. The resolution of the invocation block now takes an ArgumentCodeGenerator rather than the raw arguments. Doing so gives the opportunity to create more flexible signatures. See gh-29005
This commit allows bean factory initialization to use a more flexible signature than just consuming the DefaultListableBeanFactory. The environment and the resource loader can now be specified if necessary. See gh-29005
While working on #28976, it became apparent that a
BeanFactory
initializer registered inBeanFactoryInitializationCode
could use a more flexible signature. Rather than injecting theDefaultListableBeanFactory
the contribution needs aConfigurableEnvironment
and aResourceLoader
. The former can be retrieved by the bean factory (although a bit odd). The latter is harder.MethodReference
provides a very nice abstraction and we've almost what we need but I'd like to use the opportunity to see if we can avoid adding yet anothertoCodeBlock
method as the current ones are already a bit confusing IMO.GeneratedMethod
It's often needed to get a
MethodReference
from aGeneratedMethod
. It seems it would be relatively easy to pass aClassName
toGeneratedMethods
so that theGenerateMethod
it produces can return aMethodReference
(toMethodReference
or something like that).Also a method reference that's built from a
MethodSpec
this way knows about its name, kind, and declaring class.MethodReference
getDeclaringClass
andgetMethodName
Both of these seem to be unused so they should probably be removed.
CodeBlock patterns
MethodReference
provides several ways of invoking the method:toCodeBlock()
: is producing a method reference, expecting the current context to match the signature and the method to be defined in the current class (if not static).toCodeBlock(String instanceVariable)
: is producing a method reference, expecting the current context to match the signature and the method to be defined by the class referred to theinstanceVariable
argument. (It looks like it's only used in tests or bytoCodeBlock
that's calling with anull
instance variable).toInvokeCodeBlock(CodeBlock... args)
: is producing a method invocation expected to match the arguments and the method to be defined in the current class (if not static)toInvokeCodeBlock(String instanceVariable, CodeBlock... args)
: is producing a method invocation expected to match the arguments and the method to be defined by the class referred to theinstanceVariable
argument.I wonder if a unique
toCodeBlock
that provides a context could let theMethodReference
decide for itself how the method invocation should occur. The following information would be needed:CodeBlock
for a givenClass
instanceVariable
.The text was updated successfully, but these errors were encountered: