[JSR308] Constructor Annotation Inference
Niko Matsakis
niko at alum.mit.edu
Thu Jan 15 11:51:34 EST 2009
Hello,
Unfortunately, I haven't been able to work on my JSR308 project for a
while. However, I am back at work and therefore have a few more
questions about the framework. :)
I am attempting add some code that infers the correct annotations on
constructors based on the types of their arguments. In my
AnnotatedTypeFactory, I overloaded constructorFromUse() to do the
correct inference and that seems to work correctly. However, I run
into some problems because the result of that method does not seem to
be connected to the type of a NewClassTree as computed by
AnnotatedTypeFactory.fromExpression().
I had expected that fromExpression() would eventually invoke
constructorFromUse() to get the correct constructor signature, and use
that to compute the resulting type of the NewClassTree, but I see that
is not the case. Moreover, thinking about it more, I'm not sure if
that makes sense anyhow-- as it happens, in my case the receiver in
the constructor's executable type is the same as the result from the
NewClassTree, but I suppose that is not necessarily the case.
In any case, where is the right place to overload so as to affect the
type which fromExpression() returns for a NewClassTree? Looking at
the code, I see no obvious hook apart from overloading
fromExpression() altogether.
As a side comment: I think that the use of static visitors in the
AnnotatedTypeFactory inhibits reuse, because there is no easy way for
a subtype to customize the content of those visitors. It would be
better to have a factory method like:
class AnnotatedTypeFactory {
class SomeVisitorClass extends TypeVisitor {
}
public TypeVisitor someVisitorClassInstance() {
return new SomeVisitorClass();
}
}
then a subclass could overload someVisitorClassInstance(). If
efficiency is a concern, then the result of that method could be cached.
Niko
More information about the JSR308
mailing list