Restrict the link search of a Universal Analyzer language

Write the optional xxxInformationTracking.xml file that limits where the Universal Analyzer searches for the callee of a link, to reduce incorrect links
Updated

Overview

The metamodel declares which object types can be the caller and the callee of each link type, but not where to search for the callee when a link is found. By default, the Universal Analyzer searches the whole analysis, which can create links to the wrong object when several objects have the same name. The optional xxxInformationTracking.xml file restricts the search, for each caller type and link type, to a scope such as the same file.

Name the file after the language, for example PHPInformationTracking.xml, and save it in the language package folder.

Scope and transitions

For each caller object type and link type, you can define:

  • A scope: the metamodel type that is the top of the area in which the callee is searched. For example, sourceFile restricts the search to the file that contains the caller, and a class type restricts it to the class. If no scope is defined, the whole analysis is searched.
  • Transitions: link types that the search follows to move outside the scope, for example includeLink to search the files that the current file includes. A transition is ignored if no scope is defined. If a scope is defined without transitions, only the scope is searched.

Each transition has two options:

Element Values Description
method direct, recursive (default) direct follows the transition one level only. recursive also follows the transitions of the objects it reaches.
priority first, all (default) first stops searching as soon as a callee is found in the scope. all creates the link and continues the search through the transitions.

Example

<?xml version="1.0" encoding="utf-8"?>
<InformationTracking id="PHP">
    <searchLinksInString>false</searchLinksInString>
    <phpClass>
        <callLink>
            <scope>sourceFile</scope>
            <transition>
                <linkType>includeLink</linkType>
                <method>recursive</method>
                <priority>first</priority>
            </transition>
        </callLink>
    </phpClass>
</InformationTracking>

With this file:

  • Links are not searched for in character strings. searchLinksInString applies to the whole language and is true by default.
  • When a callLink is found in a phpClass object, the callee is searched for first in the same file. If it is not found there, the search continues in the files that the file includes directly, then in the files they include, recursively.

The root element of the file has the language name in its id attribute. Each caller object type is an element named after the type, which contains one element per link type.

To enable the search for generic links, which are not defined in the language pattern, make the caller type inherit from CallerLinkable, and the callee type from CalleeLinkable, in the metamodel. Typed links, defined in the language pattern and the metamodel, are searched for even when these categories are not inherited.

By default, the sourceFile type is a caller and a callee of all link types, generic and typed, and is searched for embedded SQL. Because sourceFile is defined in the CAST core metamodel, you cannot change this in your metamodel. Instead, add a sourceFileLinkSearchDeactivation element to the information tracking file:

  • In caller:
    • <genericLinks/> stops the search for generic links in files, as if sourceFile did not inherit from CallerLinkable.
    • <link> elements list the link types that are not searched for in files, for example <link>inheritLink</link>.
  • In callee:
    • <genericLinks/> stops files from being the callee of generic links, as if sourceFile did not inherit from CalleeLinkable.
    • <link> elements list the link types of which files cannot be the callee.
<?xml version="1.0" encoding="utf-8"?>
<InformationTracking id="PHP">
    <sourceFileLinkSearchDeactivation>
        <caller>
            <genericLinks/>
            <link>inheritLink</link>
            <link>callLink</link>
        </caller>
        <callee>
            <link>inheritLink</link>
        </callee>
    </sourceFileLinkSearchDeactivation>
</InformationTracking>

With this file, files are not searched for generic links, inheritLink or callLink, and files cannot be the callee of an inheritLink.

Validation and limitations

See Validate the package.

Avoid circular dependencies between link types. If resolving link type A requires following the transitions of link type B, and resolving B requires following the transitions of A, the results can be inconsistent. The analysis log reports this situation and lists the links involved.