Transformations give you almost unlimited control over the structure of your model. You can specify a number of expressions that modify the fully-qualified names of the classes in your project - in effect moving them to locations other than their actual locations in the code-base.
When would you want to do this? Basically any time that you think you'd like to see code with a different hierarchy. For example:
- If you have lots of test classes co-located with your application code and would like to move them out to a parallel "test" packagehierarchy.
- If you have physically split your packagesinto an "API" and "Implementation" hierarchy for easy shipment to customers, and you would prefer to see the "real" logical model where the classes are merged into single corresponding packages.
- If your understanding of the "architecture" is different to the actual packagestructure - you may want to merge some packages, or split other packages, so as to reflect what you consider to be the architectural components.
You define a Transformation using menu Project/Transformations and then specifying a number of "Match" and "Output" pairs. The syntax uses "*" to match one or more tokens or characters, and "?" to match exactly one token or character (a token being an element of a path, e.g. A and B and C in A.B.C). If you want to change the sequence of wildcards in the Match expression, you can use "{1}", "{2}" etc. in the Output expression. "{jar}" can be used in Output expressions and has the value of {jar} file from which an input item is derived.
Examples:
Match pattern | Output pattern | Result |
*.Test* | test.*.Test* | Moves all classes whose local name starts with "Test" to a parallel hierarchy called "test" |
com.foo.public.* com.foo.private.* |
com.foo.components.* com.foo.components.* |
Merges com.foo.public.X and com.foo.private.X into com.foo.components.X and com.foo.public.Y and com.foo.private.Y into com.foo.components.Y |
com.foo.* | * | Removes com.foo from all names |
*.? | {2}.{1} | Changes a.b.C to C.a.b |
?.?.* | {2}.{1}.{3} | Changes a.b.C to b.a.C |
Tip:
- You can import a transformation from a comma-separated text file. This can be useful if you need a lot of expressions and would prefer to use an editor rather than the simple GUI provided by Structure101 Studio. Also, you may find it convenient to automate the creation of the transformation using scripts and/or data from other tools.
- Don't be afraid to experiment with transformations - they are transient and you cannot break anything.