Spec update for Class#getDeclaredMethods()
Joseph D. Darcy
Joe.Darcy at Sun.COM
Thu Jul 16 09:38:44 PDT 2009
Florian Weimer wrote:
> * Rémi Forax:
>> The solution is to not rely on reflection and to parse the bytecode
>> using by example ASM :
>> see http://asm.ow2.org/
> I think you'd still need to sort based on line numbers, which requires
> debugging information which is not always available.
> The only reliable way I know is to use a JSR 269 compiler plugin.
> Members are guaranteed to be in source order over there. (But this
> still suffers from poor IDE support, AFAICS.)
The source ordering from JSR 269 is only guaranteed if the information
is coming from a source file; from javax.lang.model.element.TypeElement:
"Each method of this interface that returns a list of elements will
return them in the order that is natural for the underlying source of
program information. For example, if the underlying source of
information is Java source code, then the elements will be returned in
source code order."
If the information is coming from a class file, elements will be
returned in the same order as they were in the class file.
Note that in the case of core reflection, which actually mostly present
a JVM model of the world rather than a Java source model, there are more
cases where non-source artifacts can crop up, including but not limited
to implicit no-arg constructors and bridge methods.
More information about the core-libs-dev