Reverse transformations

When you create a UML-to-C# transformation configuration, you can enable a C#-to-UML, or reverse transformation. For example, if you are creating a UML-to-C# transformation configuration to transform a UML model into C# source code, you can enable the C#-to-UML, or reverse transformation, which transforms C# source code into a UML model.

You can use reverse transformations to recover changes to the model or recover changes to source code. This process is useful when the model and code are developed concurrently. For example, an architect can create a UML model and transform the model into source code. Developers can make changes to the generated code, and the architect can run the reverse transformation to recover the changes to the code. The transformation determines the differences between the source code and the UML model, and the architect can select which source code changes to apply to the model.

To recover changes to a model or recover changes to code, you should create a single transformation configuration and enable the Reconciled Modeling DCMP, instead of creating configurations for each transformation. If you follow this process, all the information about the applicable UML model and code is contained in one configuration; validation rules for both transformations are applied to the configuration to ensure that the generated model or code is as accurate as possible. Running transformations that have separate configurations can generate unexpected results.

To simplify working with the transformation configuration file, save the configuration file in the project that you specify as the source of the UML-to-C# transformation. For example, if you specify a UML model as the source of the transformation, save the configuration file in the same project as the UML model.

To avoid possible problems, do not change the source or target in the transformation configuration file. To specify different sources or targets for the transformation, create a new transformation configuration.

Cross-project references between projects and models in reverse transformations

If you work with domain-specific projects, such as C#, C++, Java, SOA, and so on, and transform the projects into UML models, you can create an association file that defines cross-project references between the source and model elements when the elements might be outside of the scope of a transformation configuration.

An association file for the cross-project reference has .xmi as a file name extension, and this file can be shared by multiple transformation configurations.

You can specify the following UML elements in an association:
  • Model
  • Package
  • Projects
  • Modules

By default, if the C#-to-UML transformation cannot create a reference to a concrete UML target element, it creates a visual reference to the corresponding C# element. If you define an association between the elements, the transformation creates a reference to a concrete UML target element and does not create a visual reference.

Consider a workspace that contains the following items:
  • C# projects named Project A and Project B
    • Project A has a class named ClassA and Project B has a class named ClassB
    • Project A depends on Project B, because ClassA references an attribute of type ClassB
  • UML models named Model A and Model B
  • A transformation configuration that specifies Project A as the transformation source and Model A as the transformation target
  • A transformation configuration that specifies Project B as the transformation source and Model B as the transformation target

When Project A is transformed into Model A, ClassA still references Project B through a cross-reference.

However, a more appropriate solution would be for the cross-reference to refer to the UML type ClassB under Model B. You can define this cross-reference by using an association, which you set up in the transformation configuration.


Feedback