Hi,
I was wondering if it is possible to get (values of) annotations using reflection.
E.g.
CLASS MyClass: @Mandatory DEFINE PROPERTY MyProperty AS CHARACTER NO-UNDO GET. SET. END CLASS.
That is correct. You cannot access them via reflection (as they are not in the r-code).
We have general annotations support in our roadmap already. But go ahead and create an idea and other people can vote on it.
Annotations are not compiled and as such, you cannot access them at runtime.
So probably xref could be the way to go here.
Compile with XREF can also be used for this purpose.
COMPILE value("MyClass.cls") xref-xml VALUE("MyClass.xref").
Sample annotation details.
<Reference Reference-type="ANNOTATION" Object-identifier="Mandatory"> <Source-guid>nWhIbUtEsZ4JFIm5lOOE3w</Source-guid> <File-num>1</File-num> <Ref-seq>7</Ref-seq> <Line-num>17</Line-num> <Object-context/> <Access-mode/> <Data-member-ref/> <Temp-ref/> <Detail/> <Is-static>false</Is-static> <Is-abstract>false</Is-abstract> </Reference>
The generate xref (XML) can be parsed to get the annotation details.
Annotations are not compiled and as such, you cannot access them at runtime.
So probably xref could be the way to go here.
I know I can get them through compilation with xref, but that's not an option.
I assume it's not possible as the documentation states that the compiler ignores annotations and treats them like comments.
Both Java and c# have this ability, so it's a pity this isn't possible in ABL.
I'll create an idea...
That is correct. You cannot access them via reflection (as they are not in the r-code).
We have general annotations support in our roadmap already. But go ahead and create an idea and other people can vote on it.
think of annotations as suggestions to the compiler. they are a bit like comments.
Does the compiler actually do something with them? Or is it some pre-compilation routine that processes them out?
Not knowing the internals I would think that the compiler just ignores them, while in other languages like c# and Java they're much more than suggestions or comments...
Simply put, there is no room for them in the r-code. The next major change in r-code format is possible with OpenEdge 12.
:-(
We have built a routine that extracts them from source code (either using proparse or xref) and makes them available at runtime in .annotation files.I believe that's as good as you can get with OE11.
Nice one Mike.
You could perhaps generate new metadata classes as well instead of .annotation files...
We considered that as well. In any case we need to deploy an extra file. (json or r-code). We flipped a coin and json won.
Kind of :-)
Currently, aside from some very basic formatting validation for some of the ones used by PDSOE, the compiler does not do anything with them.
This would be a cool addition to PCT :)