Utilities for Jvm type analysis [message #727036] |
Tue, 20 September 2011 08:38 |
Hallvard Traetteberg Messages: 673 Registered: July 2009 Location: Trondheim, Norway |
Senior Member |
|
|
Hi,
I'm working on a DSL that refers to existing Java classes by means of
the JvmTypes. There are references to parameterized classes and their
methods, and I need to be able to find the resulting method types
(return value and parameters). E.g. suppose the following interface
definition exists:
interface I<T> {
public T m1();
public int m2(T t);
}
In my DSL there will be references to I with type arguments, e.g.
I<String> and references to m1 and m2. In a code generator I need to
infer that m1 now returns String and m2 takes a String argument. I see
two possible strategies:
1) Create a copy of the interface where type parameters are replaced by
the type arguments and use a scope provider that returns this structure,
so the method references are resolved to this structure.
2) Create a copy (as above) afterwards and use the mapping to link m1
and m2 to their copies with return and argument types now bound to
String instead of T.
Before trying this I would like to know which approach will work, and
whether the Jvm type system already has code that does similar things
(which I bet it has, it has to be doing similir analysis all the time).
Hallvard
|
|
|
Powered by
FUDForum. Page generated in 0.03551 seconds