Accessing Class annotation values from JvmDeclaredType? [message #1730848] |
Fri, 29 April 2016 05:09  |
Eclipse User |
|
|
|
Is it possible to access the declared value of a class's annotation via JvmDeclaredType?
e.g. Take this class:
@ExampleAnnotation(exampleVal = "hi")
Class Foo {}
I'm using XBase, and would like to be able to get this value, "hi" from a JvmDeclaredType that's referencing Foo.
I've been able to access the JvmAnnotationReference, which gives me information about the annotation type itself, but doesn't seem to grant access to the specific class's defined value.
Is this possible, or do I need to create an instance of the Class<Foo> object itself to do this?
Thanks!
|
|
|
|
Re: Accessing Class annotation values from JvmDeclaredType? [message #1730854 is a reply to message #1730851] |
Fri, 29 April 2016 05:47   |
Eclipse User |
|
|
|
Right, JvmAnnotationReference lets me access the list of JvmAnnotationValue for the annotation, but this just gives me the name of the value and the operation it supports. I don't see a way to get the actual defined value, as specified by the annotated class.
For my example, I can get information like:
name: exampleVal
operation: JvmOperation: packageName.exampleVal() (visibility: PUBLIC, simpleName: exampleVal, identifier: packageName.exampleVal(), deprecated: false) (varArgs: false) (static: false, final: false, abstract: true, synchronized: false, default: false, native: false, strictFloatingPoint: false)
What I'm looking for is the equivalent of what I can invoke on the Foo.class object itself:
val fooAnnotation = Foo.class.getAnnotation(ExampleAnnotation.class)
System.out.println(fooAnnotation.exampleVal) // prints "hi"
I can get this class instance by calling: Class.forName(jvmDeclaredType.qualifiedName), but not sure this is a fully safe operation during inferral.
[Updated on: Fri, 29 April 2016 05:48] by Moderator
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04712 seconds