4.2. Using Non-Default Ada Source File Names

By default, GNAT compilers require a specific Ada source file naming convention. In this default convention, “spec” files (those containing declarations) have an extension of ”.ads” and “body” files (those containing completions) have an extension of ”.adb” (i.e., ‘s’ for “spec” and ‘b’ for “body”).

GNATbench uses the convention for a given project when displaying and operating upon source files. For example, double-clicking on a file invokes the Ada language-sensitive editor only if the file has an extension indicating that it is indeed a source file. Similarly, only those files recognized as source files are displayed in source folders within the GNAT Project Explorer.

You can change the default Ada source file naming convention used by any given project.

To make the change requires two steps:

  • You must specify the new naming scheme in the GNAT project file (the “gpr file”), and
  • You must associate the file extension with the AdaCore language-sensitive editor within Eclipse itself.

4.2.1. Specifying the Naming Scheme In the Project File

For the first step, you can use the GUI dialog to specify the naming scheme in the project properties. To invoke the dialog, right-click on the project node in the GNAT Project Explorer, select “GNAT Project”, then select “Edit Properties” as shown below. Note that the first time you invoke the dialog it may take a little while to appear.


In the resulting dialog, select the Naming tab:


There are a few alternative naming schemes already defined. Active the pull-down menu to see these alternatives. If one of them matches your scheme you simply select that scheme and press OK to finish. Press OK when asked if you want to save the project file changes.


If none of the predefined schemes match your convention you may create a new convention by selecting “custom” in the pull-down list, giving the scheme a new name to replace “custom” and then specifying the details of the convention in the various “Details” entry panes.

In the following figure we have selected a common scheme in which spec file names end with an underscore, both kinds of file end with ”.ada”, and dots in Ada unit names are replaced by a a double underscore.

gnat properties naming underscore scheme

The GUI makes your changes effective by modifying the GNAT project file (the “gpr file”) if you choose to save the changes. In this case, it either adds or changes a package named “Naming” within the file. For the above selections these changes would look like the following:


As an alternative to the GUI, you may also simply edit the gpr file manually and insert the package Naming and its contents.

4.2.2. Associating the File Name Extension with the Ada Editor

For the second step, you set the file associations via Eclipse preferences. Specifically, invoke the Window menu and select Preferences to invoke the dialog. Then expand the General and Editors categories. You should now see a choice “File Associations” underneath the Editors category. Click it to open that page.


In that page you will see a list of file name extensions on the upper part of the page, and associated editors in the lower part. If your extension is not defined, click the Add button to open a new dialog and specify your extension (e.g., “*.ada”, but without the quotes). For example, the following figure illustrates the Add button dialog with “*.ada” specified:


Press OK to close the Add extension dialog.

Then, back in the File Associations page of the original dialog, select your new extension in the upper part of the page and press the other Add button, the one for the editors in the lower part of the page. Another popup will appear, in which you will select “AdaCore’s Ada Editor”:


Press OK to close the editor selection dialog. The completed association will appear in the File Associations page:


Press OK again to close the Preferences dialog and you’re done.