10.8.1.  Only Visit What is Needed

The Script API uses the "Visitor" pattern to traverse the information of a software system. The pattern is very popular and explanations are easy to find.

Use the Right "visit" Method

Choosing the "visit" method that matches the script's purpose leads to fewer methods being called by the visitor and faster execution:

  1. CoreAccess.visitLogicalModuleNamespaces() : Visits logical module namespaces an contained elements. See Section 4.4, “Logical Models” for details.

  2. CoreAccess.visitLogicalSystemNamespaces() : Visits logical system namespaces and contained elements. See Section 4.4, “Logical Models” for details.

  3. CoreAccess.visitParserModel() : Visits all elements of the parser model, i.e. no logical system or module namespaces.

  4. CoreAccess.visitModel() : Visits all elements of the model. Most powerful, but obviously the most detailed and slow execution.

Only Visit Interesting Parts of the Model

If you are not interested in visiting externals or certain root directories, stop the visitor traversing that part of the model. The easiest way to exclude external elements from the analysis:

visitor.onExternal
{      
    //We are not interested in external
    return;     
}

Similarly, if you only want to investigate dependencies to external elements, you can stop the visitor from traversing the internal model:

visitor.onModule
{      
    //We are not interested in internal
    return;     
}

If you want to check only a specific module named "Test", you can do the following:

v.onExternal
{
    return;
}

visitor.onModule
{
    ModuleAccess module -> 
    if (module.getName().equals("Test"))
    {
        //only visit children of this module
        visitor.visitChildren(module);
    }
}

visitor.onType
{
    TypeAccess type -> 
    
    //Prints out only types of module "Test"
    println "Type $type"; 
}

The same approach should be used to limit the visiting of other model elements (e.g. namespace, component, type, method, field).