Book a Demo

Author Topic: Generate Source Code: Java  (Read 3339 times)

Rafael Santini

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Generate Source Code: Java
« on: July 13, 2012, 08:41:00 am »
What is the expected code to following class diagram?



I expected some like this:

public class Class1 {

  public Class2 m_a;

  public Class2 m_b;

}

public class Class2 {

}


But EA is coding:

public class Class1 {

  public Class2 m_Class2;

}

public class Class2 {

}


It is a bug or what I'm missing?

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +55/-3
    • View Profile
Re: Generate Source Code: Java
« Reply #1 on: July 13, 2012, 09:18:50 am »
It looks to me like you have named the associations. You need to name the association ends: open the association properties and go to the Target Role tab and put "a" or "b" into the "Class2 Role" field.
The Sparx Team
[email protected]

Rafael Santini

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Generate Source Code: Java
« Reply #2 on: July 13, 2012, 11:44:04 am »
I have named the associations instead of named the association ends. Sorry. Now I know how to do.

I would like that the member in the Class1 was coded as property.

Instead of:

public class Class1 {

  public Class2 a;

}


I wish:

public class Class1 {

  private Class2 a;

  public Class2 getA() {
    return a;
  }

  public void setA(Class2 a) {
    this.a = a;
  }

}


It is possible?

Thanks!