UML class diagrams
Right-click a class file or a package and select Diagrams | Show Diagram or Diagrams | Show Diagram Popup.
This functionality relies on the Diagrams plugin, which is bundled and enabled in IntelliJ IDEA by default. If the relevant features are not available, make sure that you did not disable the plugin.
Press CtrlAlt0S to open settings and then select Plugins.
Open the Installed tab, find the Diagrams plugin, and select the checkbox next to the plugin name.
IntelliJ IDEA lets you generate a diagram on a package in your project. Such diagrams always reflect the structure of actual classes and methods in your application.
note
IntelliJ IDEA supports creating and managing UML class diagrams for Kotlin the same way it does for Java.
In the Project tool window, right-click a package for which you want to create a diagram and select Diagrams | Show Diagram CtrlAltShift0U).
In the list that opens, select Java Class Diagram. IntelliJ IDEA generates a UML diagram for classes and their dependencies.
tip
You can view your VCS local changes as a diagram. Select VCS | Uncommitted Changes| Show Local Changes as UML CtrlAltShift0D.
tip
You can press CtrlF12 on the element to view a list of diagram elements and navigate between them.
To see the list of methods, fields, and other code elements, select the appropriate icon on the diagram toolbar located on top of the diagram editor.
The lists are displayed based on the selected visibility level, which you can change. For example, to view protected methods, click on the diagram toolbar and select protected from the list. IntelliJ IDEA displays members with visibility not less than protected, such as public, package local, and protected ones. The protected methods are displayed with modifier icons next to them.
You can click the icon to see class dependencies. IntelliJ IDEA follows the UML conventions in showing relationships between the classes.
When you click through classes in the graph, IntelliJ IDEA greys out classes that do not reside in the same package. This might be helpful, when you generate a diagram on a package that contains inner packages.
To save the diagram as a file, right-click the diagram editor and from the context menu, select Export Diagram | Export to File and then the file extension in which you want to save the diagram.
When working with diagrams, use the context menu in the diagram editor to perform different tasks. You can view members of the class, add new, delete the existing ones, see implementations, check parent classes, perform basic refactoring, add notes, and so on.
tip
You can select the icon on the diagram toolbar to draw relationship links between elements in your graph. To delete the existing links, select the ones you don't need and press Delete. IntelliJ IDEA will update the source code accordingly.
Generate a diagram.
Click Structure in the left toolbar. IntelliJ IDEA opens the Structure tool window that displays a map of your diagram with a small preview of the selected block and its neighbors.
Use the context menu to zoom in and out, move canvas, change layout, and export part of the diagram into an image.
Press Space.
In the search field that opens, start typing a name of the class you want to add. Then, select the desired class from the suggestion list.
If you want to add a class that is out of the project scope, select the Include non-project items checkbox.
Alternatively, select one or more elements in the Project tool window and drag them to the diagram.
In the diagram editor, select a node element you want to delete.
Right-click the element and from the context menu, select Delete Delete.
Alternatively, select Refactor | Safe Delete AltDelete. In this case, IntelliJ IDEA checks for usages before applying the changes.
tip
You can quickly search for usages by pressing AltF7 on a code element.
You can perform some forward engineering while in the diagram editor.
In the diagram editor, right-click anywhere and from the context menu, select Content | New. Then select a code element you want to create.
Depending on your selection, IntelliJ IDEA opens the appropriate dialog where you specify the necessary information for creating the new element.
IntelliJ IDEA adds the item to your diagram as well as to your project tree .
You can view implementations and parent classes in your diagram. If IntelliJ IDEA finds more than one parent class or implementation, it displays a list of appropriate items. Select the one you need to see the connections between the parent and its children.
In the diagram editor, select an item for which you want to see implementations or parent classes.
Right-click the items and from the context menu, select the Show Implementations CtrlAlt0B or Show Parents CtrlAlt0P respectively.
In the popup that opens, select items you need and press Enter. To extend your selection up or down while in the popup, press Shift0↑ or Shift0↓ respectively.
You can configure the diagram settings so that you have certain options available by default when you create a diagram.
Press CtrlAlt0S to open settings and then select Tools | Diagrams.
In the right-hand pane, select the options that you want to see by default and click OK to apply your changes.
The Analyze Graph action group lets you analyze the graph in various ways such as perform auto clusterization, measure the node centrality, search cycles, filter path between two nodes, and so on.
Most of the time, generated diagrams are big and complicated. Typically, you want to concentrate only on the specific part of the diagram. IntelliJ IDEA lets you filter paths between two diagram elements.
In the diagram editor, select two nodes on which you want to focus and right-click one of them to open the context menu.
From the context menu, select Analyze Graph | Focus On Paths Between Two Nodes.
note
If you want to focus not only on just two nodes, but on how the selected node is connected with its neighbors, select the Focus on Node Neighborhood option from the context menu.
In the dialog that opens, select additional options if needed and click Find.
IntelliJ IDEA displays connections associated only with the selected nodes.
You can use this action to identify the important nodes in the graph.
In the diagram editor, right-click anywhere in the editor to open the context menu.
From the context menu, select Analyze Graph | Measure Centrality.
In the dialog that opens, select additional options if needed and click Measure.
The node "importance" is expressed via fractional value from 0.0 to 1.0 measurement, and the brightest node selection should be explored first.
tip
Press Ctrl0Z to cancel the actions.
Thanks for your feedback!