AnyLogic
Expand
Font size

Java editor

Using the Java editor, you can:

  • view and edit Java class code,
  • view and edit Java interface code,
  • view the code generated by AnyLogic for your agent types (in read-only mode).

Java editor

To open code the Java class or interface code in the Java editor

  1. Double-click the Java class or interface in the Projects view.

To open the code of agent type in the Java editor in read-only mode

  1. You can examine the code of the agent type only after the model has been built at least once. To build the model, select any model element and click the Build model toolbar button, or
    Press F7.
  2. Now AnyLogic has compiled code for all classes defined in the model. In the Projects view, right-click (macOS: Ctrl + click) the agent type whose code you want to view and select Open with > Java Editor from the context menu.
  3. The Java editor opens.

Note the syntax highlighting. Different types of elements in the Java source are rendered in unique colors. Examples of Java source elements that are rendered differently are:

  • regular comments,
  • Javadoc comments,
  • keywords,
  • strings.

Opening property source code

When working with the properties in the user interface, you can use a hotkey to quickly build the agent and jump to the location of where that property is defined in its code. This feature also works in read-only mode.

To open the source code for a property

  1. In the Properties view, click in the property with a code field whose source code you want to examine.
  2. Press Ctrl + J (macOS: Cmd + J), or
    Right-click (macOS: Ctrl + click) and select Show in Java editor from the context menu.
  3. If the model has not yet been compiled, AnyLogic will compile it first. Once ready, it will open the agent’s code and scroll to the section where the value of the selected property is defined, highlighting the relevant snippet.

The code editor provides the following navigation features:

  • Go to line — Right-click (macOS: Ctrl + click) anywhere in the Java editor and select Go to line from the context menu. In the dialog that appears, specify the line number and press Enter.
  • Open Call Hierarchy — Allows you to see all the places where a function or class is used in the code in a separate view. Right-click (macOS: Ctrl + click) a function or class and select Open Call Hierarchy from the context menu.
  • References — Finds all references to the selected code element in the workspace and shows them in a separate view. Unlike Call hierarchy, this works for all kinds of entities, including variables. Right-click (macOS: Ctrl + click) a function or class and select References from the context menu.
  • Navigate to the element — Quickly opens the graphical representation of the element in the graphical diagram of the agent, or, if it does not exist there, its declaration in the source code. Allows you to navigate to the element even if it is located in another agent. To do this, Ctrl + click (macOS: Cmd + Click) the element in the Java editor.
How can we improve this article?