Restrict the link search of a Universal Analyzer language
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,
sourceFilerestricts 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
includeLinkto 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.
searchLinksInStringapplies to the whole language and istrueby default. - When a
callLinkis found in aphpClassobject, 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.
Generic links
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.
Disable the link search for source files
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 ifsourceFiledid not inherit fromCallerLinkable.<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 ifsourceFiledid not inherit fromCalleeLinkable.<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.