As you work with capsule-based diagrams, you might choose
to add code to or edit the code for UML model elements by using the Code View editor. In some cases, the Code View allows you to select one element in order to provide support for
a collection of other associated elements. For example, selecting
a Class provides access to all class operations,
or selecting a Choice Point or Junction
Point provides access to the guards of any of the outgoing
transitions.
About this task
When you write code, you can use the content assist feature
to see valid code completions for your context. You can select a proposal
from the content assist feature to minimize typing, or you can review
the proposed items to see which classes you can access in that context.
To add code to model elements in capsule-based diagrams:
Procedure
- Click .
- Expand UML Development Tooling;
then click Code View.
- In the diagram editor, click a model element to edit.
- In the Code View editor, type the
code to add to the element. To open the content assist
feature in the Code View editor, press Ctrl+Space
or type a period (.).
Results
You can navigate the model elements references in the Code
View. Select Open Model Element menu item for the highlighted model
element to navigate to that model element in the Project Explorer
view.
Before the Open Model Element action can work, it is required
that generated sources exist. The Code View will provide you with
a message in the case that generated sources are not available. This
means that you must run the transformation configuration at least
once before you can navigate to the model element from the Code View.
You must generate the source before you can open the model element.
The code that you type in the Code View editor is saved automatically.
Tip: The code that
is visible in the Code View editor constantly
changes based on what you select in the diagram. To keep the code
that you are editing visible and to make it persist, despite what
is selected in the diagram, open it in a separate editor window: right-click
an editable area in the Code View editor; then
click Show source in editor. Although the code
that you type in the Code View editor is saved
automatically, the code in the separate editor window is saved to
the model only when you save it manually.