Book a Demo

Author Topic: java annotations  (Read 5100 times)

korsbecker

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
java annotations
« on: February 21, 2008, 07:32:33 pm »
Hi

I'm a newbie to EA so please forgive my simple question. I'm trying to generate java code from my model and I want to annotate my classes. As far as I understand I should use code templates for this but I can't seem to find any examples on how to manipulate templates, what templates to manipulate!

I found to places in EA where I seem to be able to work with templates: [CTRL]+[SHIFT]+[P] (Code Generation Templates)and [CTRL]+[ALT]+[H] (Transformation Templates) . But no matter what I do I can’t seem to save any changes?? An asterics is always present on the tab no matter how many times I press the save button.
Any suggestions would be much appreciated.

Henrik  :)

Luis J. Lobo

  • EA User
  • **
  • Posts: 252
  • Karma: +0/-0
  • IT Consultant
    • View Profile
Re: java annotations
« Reply #1 on: February 21, 2008, 08:19:32 pm »
Find "Java Conventions" on the EA help.

korsbecker

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Re: java annotations
« Reply #2 on: February 21, 2008, 09:10:34 pm »
Hi Luis

thnx for the answer

I looked at the "Java convention" page in the help section, but i can't see how this helps me ???

henrik :-)

Luis J. Lobo

  • EA User
  • **
  • Posts: 252
  • Karma: +0/-0
  • IT Consultant
    • View Profile
Re: java annotations
« Reply #3 on: February 21, 2008, 09:28:33 pm »
When you create a Class in EA, you can add a Tagged Value to it, with the name "annotations" and the value of the annotation.

When you generate code of the Class, the annotations are generated too:

package aaa.aaa;
/**
 * @author luis.lobo
 * @version 1.0
 * @created 21-feb-2008 11:26:18
 */
Annotation text
public class Class1 {
      private int att1;
      public Class1(){
      }
      public void finalize() throws Throwable {
      }
      public void op1(){
      }
}

korsbecker

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Re: java annotations
« Reply #4 on: February 21, 2008, 10:01:25 pm »
Thnx that was very helpfull  :)

henrik :-)

korsbecker

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Re: java annotations
« Reply #5 on: February 22, 2008, 12:38:14 am »
Hi... again

Ok I got the annotation on the classes and if I generate code directly from my model the annotation is added to the code so this is fine. But in order to get some real java code (including getters and setters) I need to transform my model to java. I've done this and it seems to work except that my annotations disappear????

Also is there a simple way of adding an attribute to more classes in one operation. i.e. adding an "int id" to several classes?

henrik :-)

Luis J. Lobo

  • EA User
  • **
  • Posts: 252
  • Karma: +0/-0
  • IT Consultant
    • View Profile
Re: java annotations
« Reply #6 on: February 22, 2008, 01:59:51 am »
The annotations are Java implementations, then they should be included in the design classes (the transformated ones) not in the pre-transformed or analysis classes.

...and it's not possible to add an attribute to several classes in one action.

korsbecker

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Re: java annotations
« Reply #7 on: February 22, 2008, 05:30:22 pm »
Of course silly me....

hmm that is to bad....

Thnx Luis you have been most helpfull...

henrik :-)

Vincenzo

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: java annotations
« Reply #8 on: February 23, 2008, 08:39:57 pm »
Hi there,

I have a question about java annotations. I want to transform a plattform independent model in a Java model using annotations.

My problem is that I can't create annotations containing elements whose values have to be specified between quotations. For example

Code: [Select]
@OneToMany(mappedBy="department") cannot be generated.

This is so, because EA, while doing the transformation, creates a representation of the model in the intermediary language. So when I start the transformation an I try to produce the above java annotation, EA produces the intermediary code language snippet  displayed below and stops the transformation, because of the nested quotations characters.

Code: [Select]
Tag
{
  name="annotation"
  value="@OneToMany(mappedBy="department")"
}

Is there any workaround for this? I've already tried to use unicode for the quotation characters, but it doesn't work.

Thx in advance.
Vincenzo

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: java annotations
« Reply #9 on: February 25, 2008, 08:58:39 am »
Try this.

Code: [Select]
Tag
{
 name="annotation"
 value="@OneToMany(mappedBy=\"department\")"
}

Vincenzo

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: java annotations
« Reply #10 on: February 25, 2008, 09:58:28 pm »
I tried it out and it works.

Thx