Impact of model and source code changes on UML-to-C++ transformation output

The changes that you make to the source model or generated source code might affect the transformation output when you rerun the UML-to-C++ transformation. The transformation output varies whether you configure the transformation to create derived relationships between the model elements and generated source code, or whether you remove the @generated tag for elements in the generated source code.

When you configure the transformation to create derived relationships between source model elements, the transformation adds a unique identifier to each transformed element in the generated source code.

The following table lists how changes to the source model impact previously generated code when you rerun a transformation, and assumes that the transformation is configured to create derived relationships between model elements and the generated source code.
Note: To preserve the code changes, you can delete the @generated tag for an element in either the header file or body file.
Model element Change Impact on previously generated code when you rerun the transformation
Attribute Rename or move If you delete the @generated tag of the attribute, no changes are made to the attribute. No changes are made to its getter and setter methods, if generated.
If you do not delete the @generated tag of the attribute, the following actions occur:
  • The attribute is renamed or moved to the new location. Default getter and setter methods, if generated, are renamed or moved.
  • Getter and setter methods that you create are preserved.
  • Code changes that refer to the attribute or its getter and setter methods are not refactored.
Class or interface Rename If you delete the @generated tag of the class or interface, the file for the class is not renamed.
If you do not delete the @generated tag, the following actions occur:
  • Constructors and deconstructors, if generated, and instances of the class name in the code, are renamed.
  • For top-level classes that are not mapped to a different file name in a mapping model, the header and body files are renamed.
  • Code that you added to this class, such as attributes, methods, base classes, comments, and class hierarchies, is preserved.
  • Code that you added that references the renamed class is not refactored.
  • Generated code, such as attributes, parameters, or return values of the same type as the renamed class, that references the renamed class, is refactored.
  • For top-level classes, the previously generated file is deleted if you select the obsolete file deletion option in the transformation configuration, and if you do not map the original UML class to a file that contains other top-level classes. Otherwise, the previously generated file does not change.
Top-level class or interface Move If you delete the @generated tag of the top-level class or interface, the file for the class does not change.
If you do not delete the @generated tag, the following actions occur:
  • A new source code file is generated in the location that corresponds to the new location of the UML class. If a mapping model does not exist, the following actions occur:
    • If a nested UML class becomes non-nested, a new source code file is generated.
    • If a non-nested UML class becomes nested, a new source code file is not generated.
  • If a mapping model exists, the transformation generates the source code files according to the mapping in the mapping model.
  • Changes that you make to the source code, such as adding attributes, methods, base classes, comments, class hierarchies, are preserved in the new source code file. This applies to non-nested classes that become nested, and the opposite.
  • Code changes that refer to the original class are not refactored.
  • Obsolete files are deleted if the obsolete file deletion option is selected in the transformation configuration
Operation Rename, move, or modify a return type or signature If you delete the @generated tag of the operation, no changes are made to the operation.
If you do not delete the @generated tag, the following actions occur:
  • The same changes are made to the operation source code.
  • Changes to the body of the operation are preserved.
  • Changes to code that reference the operation are not refactored.
Package Rename or move The files in the original generated folder are moved to the new folder.

Obsolete folders and files are deleted if the obsolete file deletion option is selected in the transformation configuration.

Package with «cpp_namespace» applied Rename the NamespaceName property The namespace is renamed in all generated source files. Code changes that refer to the original namespace are not refactored.
Rename the package The code is refactored and moved to the renamed package because the package does not have a unique identifier.

Example of generated code when you rerun the transformation

The following example shows the changes to the code when you rerun the transformation, depending on the existence of unique identifiers and the @generated tag.

Assume that the UML source model in this example contains the following class:

This image shows a UML class named Class1 that has an integer attribute named attribute1, and an operation named Operation1.
In this example, assume that Operation1 has a signature of Operation1 ([in] Parameter1 : Integer), and returns an integer that has a value of zero.

The following table shows the code that the transformation generates:
Class1.h Class1.cpp
//@uml.annotationsderived_abstraction="platform:/resource/Bug-Fixes/GUIDs.emx#_0NWVMJy6EdueYKrofslx4A"
//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
class Class1
{

    //Begin section for Class1
    //TODO: Add attributes that you want preserved
    //End section for Class1

    private:

 	//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
//@uml.annotationsderived_abstraction="platform:/resource/Bug-Fixes/GUIDs.emx#_0NWVMJy6EdueYKrofslw3S"

        int attribute1;
    public:

        //@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
//@uml.annotationsderived_abstraction="platform:/resource/Bug-Fixes/GUIDs.emx#_0NWVMJy6EdueYKrofsly5D"

        int Operation1(int Parameter1);

};  //end class Class1
#include "Class1.h"
//Begin section for file Class1.cpp
//TODO: Add definitions that you want preserved
//End section for file Class1.cpp


//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
int Class1::Operation1(int Parameter1) 
{
    //TODO Auto-generated method stub
    return 0;
}
Assume that the user makes the following changes:
  • In the generated code, the user implements Operation1:
    int Class1::Operation1(int Parameter1) 
    {
        return Parameter1;
    }
  • In the source model, the user renames Operation1 to Operation2
The code that the transformation generates depends on the following events:
  • Whether you configure the transformation to generate trace relationships, which generates a unique identifier for each element that supports the @generated tag. See the Code with unique identifiers table to view the code that the transformation generates when you configure the transformation to create trace relationships. See the Code without unique identifiers table to view the code that the transformation generates when you do not configure the transformation to generate trace relationships.
  • Whether you delete the @generated tag in the generated source code
The following table shows the code that the transformation generates when you rerun a transformation that is configured to generate derived relationships, which appends a unique identifier to the source code comments of each element that supports the @generated tag.
Code with unique identifiers
@generated tag not deleted
The code illustrates the following changes:
  • The transformation renames Operation1 to Operation2.
  • The implementation that you specified in Operation1 appears in Operation2.

Class1.h:

//@uml.annotationsderived_abstraction="platform:/resource/Bug-Fixes/GUIDs.emx#_0NWVMJy6EdueYKrofslx4A"
//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
class Class1
{

    //Begin section for Class1
    //TODO: Add attributes that you want preserved
    //End section for Class1

    private:

 	//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
//@uml.annotationsderived_abstraction="platform:/resource/Bug-Fixes/GUIDs.emx#_0NWVMJy6EdueYKrofslw3S"

        int attribute1;
    public:

        //@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
//@uml.annotationsderived_abstraction="platform:/resource/Bug-Fixes/GUIDs.emx#_0NWVMJy6EdueYKrofsly5D"

        int Operation2(int Parameter1);

};  //end class Class1
Class1.cpp:
#include "Class1.h"
//Begin section for file Class1.cpp
//TODO: Add definitions that you want preserved
//End section for file Class1.cpp


//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
int Class1::Operation2(int Parameter1) 
{
    return Parameter1;
}
@generated tag deleted from Class1.h or Class1.cpp
The transformation uses unique identifiers to determine that Operation1 was renamed to Operation2 in the model, but because you deleted the @generated tag of the method, the transformation preserves the changes to Operation1. Therefore, Operation1 does not change in Class1.h or Class1.cpp, and the transformation does not generate a method called Operation2.
Class1.h:
//@uml.annotationsderived_abstraction="platform:/resource/Bug-Fixes/GUIDs.emx#_0NWVMJy6EdueYKrofslx4A"
//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
class Class1
{

    //Begin section for Class1
    //TODO: Add attributes that you want preserved
    //End section for Class1

    private:

 	//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
//@uml.annotationsderived_abstraction="platform:/resource/Bug-Fixes/GUIDs.emx#_0NWVMJy6EdueYKrofslw3S"

        int attribute1;
    public:

//@uml.annotationsderived_abstraction="platform:/resource/Bug-Fixes/GUIDs.emx#_0NWVMJy6EdueYKrofsly5D"

        int Operation1(int Parameter1);

};  //end class Class1
Class1.cpp:
#include "Class1.h"
//Begin section for file Class1.cpp
//TODO: Add definitions that you want preserved
//End section for file Class1.cpp


int Class1::Operation1(int Parameter1) 
{
    return Parameter1;
}

The following table shows the code that the transformation generates when you rerun a transformation that is not configured to generate derived relationships. Without unique identifiers, the transformation uses fully qualified names and method signatures to link model elements to source code elements; also, refactoring is not supported.

Code without unique identifiers
@generated tag not deleted
The code illustrates the following changes:
  • The transformation renames Operation1 to Operation2.
  • The transformation overwrites the user implementation of Operation1 with the default implementation because, without a unique identifier, it cannot link the new method name to the original method. The overwrite occurs because the @generated tag was not deleted.
Typically, the transformation preserves changes to function bodies, but in this example, the change is not preserved because the transformation could not find the renamed method.
Class1.h:
#ifndef CLASS1_H
#define CLASS1_H
//Begin section for file Class1.h
//TODO: Add definitions that you want preserved
//End section for file Class1.h

//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
class Class1
{

    //Begin section for Class1
    //TODO: Add attributes that you want preserved
    //End section for Class1

    private:

        //@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
        int attribute1;
    public:

        //@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
        int Operation2(int Parameter1);

};  //end class Class1
Class1.cpp:
//Begin section for file Class1.cpp
//TODO: Add definitions that you want preserved
//End section for file Class1.cpp


//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
int Class1::Operation2(int Parameter1) 
{
    //TODO Auto-generated method stub
    return 0;
}
@generated tag deleted from Class1.h or Class1.cpp
Without unique identifiers, the transformation determines that Operation2 is a new method.
The code illustrates the following changes:
  • The transformation generates a default method body in Operation2.
  • The transformation preserves the changes to Operation1. Because the @generated tag was deleted, the transformation preserves the changes even if there is no matching method in the UML model.
Class1.h:
#ifndef CLASS1_H
#define CLASS1_H
//Begin section for file Class1.h
//TODO: Add definitions that you want preserved
//End section for file Class1.h

//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
class Class1
{

    //Begin section for Class1
    //TODO: Add attributes that you want preserved
    //End section for Class1

    private:

        //@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
        int attribute1;
    public:

        int Operation1(int Parameter1);

        //@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
        int Operation2(int Parameter1);

};  //end class Class1

#endif
Class1.cpp:
#include "Class1.h"
//Begin section for file Class1.cpp
//TODO: Add definitions that you want preserved
//End section for file Class1.cpp


int Class1::Operation1(int Parameter1) 
{
	return Parameter1;
}

//@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"
int Class1::Operation2(int Parameter1) 
{
    //TODO Auto-generated method stub
    return 0;
}

Feedback