Renaming a DSL model element

Tuesday, December 4, 2007 – 10:27 AM

One of the things that proved to be move complicated than it should have been when we were developing the DSLs for the Service Factory: Modeling Edition was renaming DSL model elements.

This sounds easy; open the DSL designer, rename the element and then transform all templates to regenerate the code. Unfortunately this doesn’t update any of the custom code you may have written because the DSL designer doesn’t inform Visual Studio of the change. Worse still Visual Studio’s code model is now unable to help you finish the renaming because the code is incorrect.

The trick is to use the Visual Studio refactoring tools to change the code before you change the DSL. This will change both the custom code and the generated code but not the DSL model. Once you’ve done this then go back and change the DSL model using the designer.

  1. Rename the model element class using the VS refactoring tools.
  2. Update any related property names on other model element classes that refer to renamed element (see below).
  3. Open the DSL designer and rename the model element.
  4. Transform all templates to regenerate the code.
  5. Rebuild the solution to check everything is consistent.

Note that the DSL designer may do additional renaming. For example if I have a model element Foo that has a relationship with another element Bar then Bar will have a property Bar.Foo. When I rename Foo to NewFoo the DSL designer will also rename the property to Bar.NewFoo. You need to anticipate this when you rename the code prior (step 2) to changing the DSL model.

Sorry, comments for this entry are closed at this time.