Define the metamodel of a Universal Analyzer language

Write the xxxMetaModel.xml file that defines the language, project type, object types, links and icons of a Universal Analyzer language package
Updated

Overview

The xxxMetaModel.xml file defines what the Universal Analyzer identifies in your language: the language itself, its project type, its object types, the links between objects and which of these are saved in the analysis schema. Define the language here first, then describe how to find its objects in the language pattern.

A metamodel is also required for a language that is imported with the Universal Importer.

File structure

The root element is metaModel, which declares the file number of the metamodel. Each category and type gets a relative ID, rid, that is unique within the file:

<?xml version="1.0" encoding="utf-8"?>
<metaModel file_level="client" file_no="2">
    <category name="TEST" rid="0">
        ...
    </category>
    <type name="testFunction" rid="1">
        ...
    </type>
</metaModel>

The ID of each item is 2,000,000 + (1,000 x file_no) + rid. Reserve the block for your file_no before you start: see Reserve ID ranges. Set file_level to client or omit it.

The following rules apply to names:

  • A type or category name must not start with CAST_.
  • A type or category name can contain only the letters A-Z, the digits 0-9 and the underscore _.

Main categories

Your language, project and object types inherit from predefined categories. The main ones are:

Category Description
CsvLanguage The base category for a language.
UniversalLanguage A language handled by the Universal Analyzer, which analyzes raw source code.
UniversalImporter A language handled by the Universal Importer, which loads .uax files. The language must also inherit from UniversalLanguage.
UAProject A project of a Universal Analyzer language. See UAObject and UAProject.
UAObject An object of a Universal Analyzer language. See UAObject and UAProject.
identification The name, description and full name of an object.
persistent The object is saved in the analysis schema.
bookmark The source of an object, for example the file that contains it.
POSITIONABLE The position of an object in its source file: start line, start column, end line and end column.
metric The metrics of an object: lines of code and lines of comment.
METRICABLE Metrics can be calculated on objects of this type.
APM All Artifacts Enables the copy-paste diagnostics for all METRICABLE objects.
object The parent and children of an object.
CastSystemViews The item is visible in the CAST system views. Always specify this category: omitting it can corrupt data. UAObject and UAProject include it.
Shell For files and folders, the full path and the path relative to a root path.

Metamodels also use the categories EnlightenBrowsable, EnlightenGraphable, WithEnlightenProperties, EnlightenStandard and EnlightenTree. Their names come from CAST Enlighten, which CAST Imaging no longer includes, but keep them in your metamodel: they are still used. The examples on this page include them.

UAObject and UAProject

Always use UAObject for object types and UAProject for project types. They replace a set of standard categories that must otherwise be declared one by one.

UAObject is equivalent to inheriting all of the following categories:

<inheritedCategory name="KB object" />
<inheritedCategory name="withCode" />
<inheritedCategory name="EnlightenStandard" />
<inheritedCategory name="ESCALATION_ALL" />
<inheritedCategory name="CastSystemViews" />

UAProject is equivalent to inheriting all of the following categories:

<inheritedCategory name="project" />
<inheritedCategory name="KB object" />
<inheritedCategory name="CastSystemViews" />

These replaced categories are predefined as follows. Do not redefine them in your metamodel:

Category ID Inherits from or contains
KB object 2500 object, identification, persistent, CAST_Guid_FatherReady, CAST_Guid_ProjectReady
withCode 1107 comment, bookmark, POSITIONABLE, metric, checksum
EnlightenStandard 5026 EnlightenBrowsable, EnlightenGraphable, WithEnlightenProperties
ESCALATION_ALL 6508 The four basic escalation categories
CastSystemViews 6060 -
project 1013 The properties merged (ID 102) and projectClass (ID 122)

Step 1 - Define the language category

Define one category for the language.

For a language analyzed by the Universal Analyzer, the category must:

  • have a name, a rid and a description
  • list the file extensions of the language in the extensions attribute, separated by semicolons
  • inherit from UniversalLanguage and CsvLanguage
<category name="PHP" rid="0">
    <description>PHP</description>
    <attribute name="extensions" stringValue="*.php;*.php3;*.php4;*.php5;*.php6;*.inc"/>
    <inheritedCategory name="UniversalLanguage"/>
    <inheritedCategory name="CsvLanguage"/>
</category>

For a language imported with the Universal Importer, do not list file extensions: the source is supplied as .uax files. The category must inherit from UniversalLanguage, from the importer category and from CsvLanguage:

<category name="Siebel" rid="2">
    <description>Siebel</description>
    <inheritedCategory name="UniversalLanguage"/>
    <inheritedCategory name="UniversalImporter"/>
    <inheritedCategory name="CsvLanguage"/>
</category>

Step 2 - Define the project type

Define a type for the projects of the language. It must inherit from UAProject and from the language category:

<type name="phpProject" rid="6">
    <description>PHP Project</description>
    <inheritedCategory name="UAProject"/>
    <inheritedCategory name="PHP"/>
</type>

Step 3 - Define the object types

Define a type for each kind of object in the language, such as programs, classes or functions. Each object type must inherit from UAObject and from the language category.

Use a tree element to declare each possible parent type. An object type can have several parent types: for example, a class can be the child of a file or of another class. A type for source files already exists, named sourceFile, so do not define one. An object type whose parent is the file declares:

<tree parent="sourceFile" category="amtParentship"/>

For example, PHP functions, which are children of PHP source files:

<type name="phpFunction" rid="5">
    <description>PHP Function</description>
    <inheritedCategory name="UAObject"/>
    <inheritedCategory name="CalleeLinkable"/>
    <inheritedCategory name="CallerLinkable"/>
    <inheritedCategory name="METRICABLE"/>
    <inheritedCategory name="PHP"/>
    <inheritedCategory name="caseInsensitive"/>
    <tree parent="sourceFile" category="amtParentship"/>
    <tree parent="EnlightenPHP" category="EnlightenTree"/>
</type>

Case sensitivity

Object types are case-sensitive by default, for both identification and search. To make a type case-insensitive, inherit from caseInsensitive:

<type name="phpInterface" rid="1">
    ...
    <inheritedCategory name="caseInsensitive"/>
    ...
</type>

If the whole language is case-insensitive, make the language category inherit from caseInsensitive instead of each type. Source files, sourceFile, are always case-sensitive, and this cannot be changed.

Escalation

Escalation lets a link to or from a child object be reported on its parent. An object type that inherits from none of the escalation categories does not take part in escalation, and its children do not escalate to it. The four basic categories are:

Category Effect
ESCALATION_AS_CALLER_CHILD When the object is the caller of a link, the link escalates to its parent, if the parent allows it.
ESCALATION_AS_CALLEE_CHILD When the object is the callee of a link, the link escalates to its parent, if the parent allows it.
ESCALATION_AS_CALLER_PARENT When a direct child is the caller of a link, the link can escalate to this object.
ESCALATION_AS_CALLEE_PARENT When a direct child is the callee of a link, the link can escalate to this object.

The following categories combine them:

Category Inherits from
ESCALATION_ALL All four basic categories. Included in UAObject.
ESCALATION_AS_CHILD ESCALATION_AS_CALLER_CHILD and ESCALATION_AS_CALLEE_CHILD
ESCALATION_AS_PARENT ESCALATION_AS_CALLER_PARENT and ESCALATION_AS_CALLEE_PARENT
ESCALATION_AS_CALLER ESCALATION_AS_CALLER_CHILD and ESCALATION_AS_CALLER_PARENT
ESCALATION_AS_CALLEE ESCALATION_AS_CALLEE_CHILD and ESCALATION_AS_CALLEE_PARENT

Links are directional. For each link type an object can have, declare whether the object can be the caller (the source of the link), the callee (the target), or both:

<tree parent="LinkType" category="CallerLinkable"/>
<tree parent="LinkType" category="CalleeLinkable"/>

For example, a PHP class can inherit from another class and be inherited from, so it is both caller and callee of inheritLink:

<type name="phpClass" rid="2">
    <description>PHP Class</description>
    <inheritedCategory name="UAObject"/>
    <inheritedCategory name="CalleeLinkable"/>
    <inheritedCategory name="CallerLinkable"/>
    <inheritedCategory name="PHP"/>
    <inheritedCategory name="APM Classes"/>
    <inheritedCategory name="caseInsensitive"/>
    <inheritedCategory name="AUTO_VIEW_HIGH_LEVEL_OBJECT"/>
    <tree parent="inheritLink" category="CallerLinkable"/>
    <tree parent="inheritLink" category="CalleeLinkable"/>
    <tree parent="sourceFile" category="amtParentship"/>
    <tree parent="EnlightenPHP" category="EnlightenTree"/>
</type>

Inheriting directly from CallerLinkable or CalleeLinkable is a shortcut:

  • An object type that inherits from CallerLinkable, or that is the caller of at least one link type, has the internal and external link search enabled.
  • An object type that inherits from CalleeLinkable is the callee of all link types. This is less precise than declaring each link type.

The metamodel defines the link types that an object can have. The language pattern defines how to recognize each link in the source code.

Group Link types
access accessLink, accessMemberLink, accessOpenLink, accessPageForwardLink, accessPageIncludeLink, accessReadLink, accessWriteLink
call callGotoLink, callLink, callPerformLink, callProgLink, callTransacLink
catch catchLink
contain containDeclareLink, containDefineLink, containLink
ddl ddlAlterLink, ddlCreateLink, ddlDropLink, ddlLink, ddlReplaceLink
fire fireAfterLink, fireInsertLink, fireInsteadOfLink, fireLink, fireSelectLink, fireUpdateLink
friend friendLink
gothrough gothroughLink
include includeLink
inherit inheritExtendLink, inheritHideLink, inheritImplementLink, inheritLink, inheritOverrideLink
internallyEscalated internallyEscalatedLink
join joinLink, joinNonSysCatalogLink, joinSpCommonKeyLink, joinSpForeignKeyLink
lock lockLink
match matchLink
mention mentionLink
monitor monitorForAllRowsLink, monitorForEachRowLink, monitorInsertLink, monitorInsteadOfLink, monitorLink, monitorSelectLink, monitorUpdateLink
prototype prototypeLink
raise raiseLink
refer referCascadeLink, referDeleteLink, referInsertLink, referLink, referSetnullLink, referUpdateLink
relyon relyonIsInstanceOfLink, relyonLink
throw throwLink
use useDeleteLink, useInsertLink, useLink, useSelectLink, useUpdateLink

There is no direct link declaration between two object types: each type is declared as caller or callee of a link type, and the link type is the pivot of the search. When the Universal Analyzer processes an object X:

  1. It blanks out the name of X and the source code of its children.
  2. For each link type of which X is a caller, it searches the source of X with the regular expression for that link, defined in the language pattern, and creates a reference that holds the caller (X), the link type and the code of the callee. For example, in class Bicycle extends Vehicle.TwoWheels, the caller is Bicycle, the link type is inheritLink and the code is Vehicle.TwoWheels.
  3. It blanks out the links it found, so that the external link search ignores them.

When all objects are processed, it resolves each reference:

  • It searches for objects that can be the callee of the link type and whose name appears in the code of the reference. If it finds one, it creates the link. Otherwise, it passes the reference to the external link search.
  • If the search for untyped links between Universal Analyzer objects is enabled, which is the default, it searches the blanked-out bodies of caller objects for the names of callee objects and creates a useLink for each match.

Finally, the external link search processes the typed links that were not resolved, without their type filter, and the blanked-out bodies of all caller objects.

To restrict where the analyzer searches for callees, see Restrict the link search.

Embedded SQL

If the language contains embedded SQL, make each object type that can contain SQL inherit from ESQLSearchable:

<inheritedCategory name="ESQLSearchable"/>

Then define where each embedded SQL statement begins and ends in the language pattern.

When the analyzer finds an embedded SQL statement in such an object:

  • it parses the statement and creates use select, use insert, use update and use delete links (Us, Ui, Uu, Ud) to the database objects
  • it does not save the statement as an object
  • it calculates the SQL metrics, such as the number of FROM and WHERE clauses, and the quality rules that apply to all technologies and to SQL metrics

Icons

Each object type can have its own icon. Name the icon after the object type and save it in the Res folder of the language package. For example, the icon of the phpFunction type is Res\phpFunction.ico.

An .ico file contains two images: one of 16 x 16 pixels and one of 32 x 32 pixels.