Reflective Access to @NonNull [message #1060365] |
Fri, 24 May 2013 06:07  |
Eclipse User |
|
|
|
Hi
I'm trying to determine if a method has an @NonNull return
I would expect to just do
myMethod.getAnnotation(NonNull.class)
but the return is always null even though org.eclipse.jdt.annotation is
on the class path and the method has an @NonNull annotation.
Is there some magic command line option to activate annotations within a
JUnit launch?
Is there some magic command line option to avoid annotations being
stripped out somewhere?
[I've exported org.eclipse.jdt.annotation from the plugin containing the
annotated method.]
Regards
Ed Willink
|
|
|
|
|
|
|
Re: Reflective Access to @NonNull [message #1060446 is a reply to message #1060443] |
Fri, 24 May 2013 12:59  |
Eclipse User |
|
|
|
Hi
Thanks for the explanation.
At one level I agree, at another, I regard @NonNull as part of the type
system and so it should be available just like the rest of it.
I have no favourite bytecode library. Never used any of them. Can you
recommend one that is in Orbit or better?
org.objectweb.asm?
org.apache.xbean.asm?
org.apache.bcel?
Any short cuts to a cookbook example just like
myMethod.getAnnotation(NonNull.class)?
FYI. My OCL to Java codegen plugin generates Java code with annotations
that indicate the internal non-null and non-invalid analysis. However
the CG analysis knows more than Java and so spurious warnings need to be
suppressed by auto-generating @suppressWarnings("null").
Regards
Ed Willink
On 24/05/2013 17:26, Stephan Herrmann wrote:
> Right, @NonNull is not available at runtime.
> The reason being: people want to be able to run the code without
> linking the annotation library. Makes sense?
>
> If the JUnit has access to the class files it could, however, use your
> favorite bytecode library (BCEL, ASM, ...) to retrieve the annotation
> from there. Would that be feasible for your case?
>
|
|
|
Powered by
FUDForum. Page generated in 0.04204 seconds