Reflection - any way to get annotations?

Posted by Lieven De Foor on 10-Feb-2016 02:16

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.


Posted by Fernando Souza on 10-Feb-2016 07:00

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.

Posted by Ruben Dröge on 10-Feb-2016 04:06

Annotations are not compiled and as such, you cannot access them at runtime.

So probably xref could be the way to go here.

All Replies

Posted by Phani Sajja on 10-Feb-2016 03:51

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.

Posted by Ruben Dröge on 10-Feb-2016 04:06

Annotations are not compiled and as such, you cannot access them at runtime.

So probably xref could be the way to go here.

Posted by Lieven De Foor on 10-Feb-2016 04:09

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...

Posted by Fernando Souza on 10-Feb-2016 07:00

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.

Posted by Lieven De Foor on 10-Feb-2016 10:15
Posted by gus on 10-Feb-2016 13:22

think of annotations as suggestions to the compiler. they are a bit like comments.

Posted by Lieven De Foor on 11-Feb-2016 02:07

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...

Posted by Mike Fechner on 11-Feb-2016 02:14

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.

Posted by Lieven De Foor on 11-Feb-2016 02:55

Nice one Mike.

You could perhaps generate new metadata classes as well instead of .annotation files...

Posted by Mike Fechner on 11-Feb-2016 03:27

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 :-)

Posted by Fernando Souza on 11-Feb-2016 08:18

Currently, aside from some very basic formatting validation for some of the ones used by PDSOE, the compiler does not do anything with them.

Posted by Peter Judge on 11-Feb-2016 08:21

This would be a cool addition to PCT :)

This thread is closed