google-code-export / umple

Automatically exported from code.google.com/p/umple
1 stars 0 forks source link

Potential need for syntax to specify which of several constructors to inject code into #499

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
In the following code, two constructors are generated for Y. It might be 
necessary to inject different code using 'after constructor' or 'before 
constructor'. There us currently no way to specify this.

class X{
  1 -- * Y;
  * -- 1 Z;
  Integer i;
}
class Y{
  1 -- 1 Z;
  String name;
}
class Z{
} 

The generated code of Y class includes two constructors:

 public Y(String aName, Z aZ, X aX)
  {
    name = aName;
    if (aZ == null || aZ.getY() != null)
    {
      throw new RuntimeException("Unable to create Y due to aZ");
    }
    z = aZ;
    boolean didAddX = setX(aX);
    if (!didAddX)
    {
      throw new RuntimeException("Unable to create y due to x");
    }
  }

  public Y(String aName, X aX)
  {
    name = aName;
    z = new Z(this);
    boolean didAddX = setX(aX);
    if (!didAddX)
    {
      throw new RuntimeException("Unable to create y due to x");
    }
  }

If we want to inject specific code into one of these constructors, let's say in 
public Y(String aName, X aX), the same code will be injected into the other 
constructor. Sometimes, we do not want to do injection into all constructors 
because it may lead to duplication and other issues.

Please use tags such as 'stateMachines', 'Tracing', etc. to help us
categorize this request.

Original issue reported on code.google.com by TimothyCLethbridge on 6 Feb 2014 at 8:35

GoogleCodeExporter commented 9 years ago

Original comment by TimothyCLethbridge on 11 Feb 2014 at 4:46