Dependencies - using Reference Patterns
The CAST Management Studio includes a built in feature called Reference Patterns - their usage is explained in more detail in Reference Pattern tab (part of the Technology editors). This page explains how to create a new Reference Pattern and how to test and use it.
Add a new Reference Pattern
- You must be working in Expert mode
- Open the required Technology editor - choose the Technology type that will form the Source Technology (see Dependencies - Rules tab for more information)
- Select the Reference Pattern tab
- Click the button to add a new Reference Pattern - the Reference Pattern dialog box will then be displayed - in the example below, we have chosen Visual Basic as the Technology type:
- Now fill in the relevant field and options as required. Each is explained below:
Technology | Displays the Technology type that will be targeted by the Reference Pattern. This is not editable. | |
Name | Choose a name for the Reference Pattern. CAST recommends choosing a name that will help you recognise the Reference Pattern more easily. | |
Description | Add an optional description of the Reference Pattern to help distinguish it. | |
Search in | Code | This section enables you to choose where you want to search for the string entered in the Regular Expression text box (see below). By default, the Code option is selected. Select the options you require by clicking in the check box next to the item. |
Comments | ||
String Literals | ||
Select the language to which it applies | This section is only visible for Technologies that have multiple component languages, for example:
The purpose is to enable you to configure specific search parameters for a specific component language if required. When the Reference Pattern is run (see below), the search parameters will be applied to each selected component language independently of the other component languages. | |
Languages filter |
| |
Regular Expression | This section enables you to choose what to search for and whether to enable "replacement". | |
Regular Expression (boost) |
| |
Match case | If you select this option, the search will only return results that match the case sensitivity of the string you entered. In other words, if you enter Select, then SELECT or select will not be returned. By default this option is left blank, meaning case sensitivity will be ignored. | |
Match whole word only | If you select this option, the results that are returned will correspond exactly to the string you enter in the Expression text box. For the following text examples:
...the search string "TITLE[A-Z]+" will identify the following hypothetical results:
If you leave this option blank, then the default setting (sub-match) will be applied. In effect this means that the results that are returned will correspond in part to the string you enter in the Expression text box. The search string "TITLE[A-Z]+" will identify the following hypothetical results:
Notes
| |
Enable Replacement | Activating this option enables you to apply a replacement process to the results of the Regular Expression search prior the results being saved to the Analysis Service How does it work? Each time the Regular Expression is matched in the source, the chosen replacement string is produced and is used to match the name (with the same sub/over/whole match options). Replacement is based on Regular Expression grouping. For example:
Examples These examples illustrate how this feature could be used: 1)
2)
3)
4)
Order of events during execution A source code analysis has already been carried out and the Analysis Service contains the objects resulting from this analysis. A Reference Pattern is then created and the Enable Replacement option is activated and a replacement text entered in the field. When the Reference Pattern is then run, the following occurs:
Limitations
Notes
| |
Replacement Regular Expression | Enter the replacement Regular Expression text. | |
Check RegExp. on file | These options enable you to test the search string on a specific file or on a specific folder of files - a standard Windows dialog box will be displayed enabling you to choose the file or folder you want to run the search on. Results are displayed as follows:
The upper section lists the file or files that contain a matched string for the Regular Expression, together with the actual matched string. Clicking on a file will show the file's code and a bookmark (green icon) will be placed on the matched string. | |
Check RegExp. on directory | ||
Match Target options | Match | This section enables you to define what the results of the Source search will be matched to in the Target. Choose from:
|
Match case | Select this option if you want the results of the Source search to match the Target using case sensitivity. For example, a Source search for author[a-z] may return strings in the Source such as AUTHORS or authors. Links would only be created to objects called authors in the Target if this Match case option is selected. | |
Name Matching |
| |
Link Options | Link Type | Use this option to select the link that will be created between the Source and the Target. By default the link type is set to Match. |
Do not create links between different files | Use this option if you want to avoid links being created between different source code files or between files and database objects. In other words, this restricts the links to inter-file links. |
- Click OK to confirm the settings.
- The new Reference Pattern will now be displayed in the Reference Pattern tab:
- See below for more information about using the Reference Pattern.
Using a Reference Pattern you have added
To use a Reference Pattern that you have added, you need to associate it to an existing Dependency Rule. Dependency Rules are managed in the Dependencies tab in the Application editor:
- You must be working in Expert mode
- Open the Application editor
- Select the Dependencies - Rules tab
- Select the existing Default rule between the two Technologies - the Source technology must be the same as the Technology for which you created the Reference Pattern::
- You can then either:
- Copy the rule to leave the Default rule in place (we will do this)
- Edit the existing rule to transform it into a Custom rule
- Click the button to copy the existing rule
- Select the new custom rule:
- Expand the Reference Pattern section and select the Reference Pattern you created above - only Reference Patterns that match the Source Technology for the current Dependency Rule will be displayed:
- The Reference Pattern will now be associated with the custom Dependency Rule:
Testing a Reference Pattern
Before running a Reference Pattern and saving the results in the Analysis Service, you have several opportunities to test the outcome of the process:
- You can test the Regular Expression search string you have defined on an individual file or folder of files (see the Check RegExp. on file and Check RegExp. on directory options listed above for more information)
- You can test the Reference Pattern itself on a Dependency Rule using the Check Reference Pattern Dependency Results option in the Dependencies tab (an analysis of the Application must have already been complete). The upper section lists the file or files that contain a matched string for the Regular Expression, together with the actual matched string and the object in the Target which will be linked. Clicking on a line in the upper section will show the file's code and a bookmark (green icon) will be placed on the matched string which will create the link.
Running a Reference Pattern
There are several ways to run a Reference Pattern:
- Use the Run Reference Pattern on Dependency option in the Dependencies tab - this runs the Reference Pattern against a specific Dependency Rule and results will be saved to the Analysis Service
- Create a Reference Pattern tool - see the Content Enrichment tab in the Application editor.
- Run an analysis - during the analysis the Reference Pattern (if configured in a Dependency Rule) will be run
- Generate a Snapshot -during the analysis part of the snapshot generation process, the Reference Pattern (if configured in a Dependency Rule) will be run
Results
Results (i.e. links between source code objects) can be displayed in CAST Enlighten.
See Also
Dependencies tab | Application editor | Reference Pattern tab