Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to access annotations in JvmAnnotaionReference?
How to access annotations in JvmAnnotaionReference? [message #972174] Mon, 05 November 2012 12:15 Go to next message
Tobias Huppertz is currently offline Tobias HuppertzFriend
Messages: 2
Registered: November 2012
Junior Member
Hi,

I'm trying to access the AttributeOverrides annotation with AttributeOverride annotation like:

@AttributeOverrides({
  @AttributeOverride(name="street",
        column=@Column(name="ADDR_street")),
  [...]
})
@Embedded Address address;


but it looks like

  @AttributeOverrides({ "street", "no", "zip" })
  @Embedded
  private Address address;


Maybe someone here can give me a hint on how to do this? I think the problem is my operator ("val op = a.annotation.members."...), because it changes nothing if I remove these lines.

A part from the ModelInferrer:
members += property.toField( property.name, property.type) [

        val a = property.toAnnotation("javax.persistence.AttributeOverrides")
        val v = TypesFactory::eINSTANCE.createJvmStringAnnotationValue
              
              
        for (EObject t : property.type.type.eContents) {
          if (t instanceof JvmFieldImpl) {
            val op = a.annotation.members.filter(typeof(JvmOperation)).filter(o|o.simpleName == "name").head
            v.operation = op
            v.values += (t as JvmFieldImpl).simpleName
            
            a.values += v
          }
        }

      annotations += a
      annotations += property.toAnnotation("javax.persistence.Embedded")
        ]


Thanks in advance for any help!

Tobias

[Updated on: Wed, 07 November 2012 13:15]

Report message to a moderator

Re: How to access annotations in JvmAnnotaionReference? [message #977789 is a reply to message #972174] Fri, 09 November 2012 15:26 Go to previous message
Tobias Huppertz is currently offline Tobias HuppertzFriend
Messages: 2
Registered: November 2012
Junior Member
I found the solution, if somebody else need the answer:

members += property.toField( property.name, property.type) [
    setVisibility(JvmVisibility::PROTECTED)
    annotations += property.toAnnotation("javax.persistence.AttributeOverrides") => [
      values += TypesFactory::eINSTANCE.createJvmAnnotationAnnotationValue  => [
        for (EObject t : property.type.type.eContents) {
          if (t instanceof JvmFieldImpl) {
            annotations += property.toAnnotation("javax.persistence.AttributeOverride") => [
              val opName   = annotation.members.filter(typeof(JvmOperation)).filter(o|o.simpleName == "name").head
              val opColumn = annotation.members.filter(typeof(JvmOperation)).filter(o|o.simpleName == "column").head

              values += TypesFactory::eINSTANCE.createJvmStringAnnotationValue => [
                operation = opName
                values += (t as JvmFieldImpl).simpleName
              ]
              values += TypesFactory::eINSTANCE.createJvmAnnotationAnnotationValue => [
                operation = opColumn
                annotations += property.toAnnotation("javax.persistence.Column") => [
                  values += TypesFactory::eINSTANCE.createJvmStringAnnotationValue => [
                    operation = opName
                    values += (property.eContainer as DslEntity).databaseColumnPrefix+"_"+(t as JvmFieldImpl).simpleName
                  ]
                ]
              ]
            ]
          }
        }
      ]
    ]

    annotations += property.toAnnotation("javax.persistence.Embedded")
]
Previous Topic:inject extension not injected in JUnit test
Next Topic:Best way to extend Xtend?
Goto Forum:
  


Current Time: Sat Nov 29 01:42:47 GMT 2014

Powered by FUDForum. Page generated in 0.09842 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software