RuleWizard Commands
When you right-click the workspace area around the rule, a shortcut menu containing all available commands will open.
- Undo: Undoes the previous command.
- Paste New Head Node: Pastes the node from the clipboard as the new head node.
When you right-click a rule node or element, a shortcut menu containing all available commands for that node or element will open. Most commands are programming elements or concepts. The following commands are unique to RuleWizard:
- Edit: Lets you use the editing commands; you can cut, copy, delete, or paste the selected node or element.
- Cut: Cuts the selected node from the workspace area and places it on the clipboard.
- Copy: Copies the selected node or element onto the clipboard
- Delete: Deletes the selected node or element from the workspace.
- Paste: Pastes the contents of the clipboard onto the workspace.
- Paste As: This command allows you to paste the contents of the clipboard as a different form. For a copied or cut node this can be as a condition (Body, Context, etc.). For a copied or cut element, they can be pasted as another element (IsDecl, IsFinal, etc.).
- Create Assertion: Adds an assertion. An assertion specifies the numerical relationship between node collectors. Assertions use the set references MIN, MAX, AVERAGE, and MEDIAN. They are used on set components whose elements are number nodes to compare the values of the counts.
For information on assertions, see Working With Node Sets.
- Add Logic Component: (Only available if logic components are enabled. To enable logic components, change the showLogicComponent variable in <jtest install dir>/bin/lib/Java.cwd from "false" to "true" If logic components are not enabled, AND will always be used).
Adds a logic component. Logic components let you place AND, OR, NAND, and NOR conditions on rule branches. Available options are:
- AND: Every branch must be true for the expression to return true.
- OR: At least one branch must be true for the expression to return true.
- NAND: At least one branch must be false for the expression to return true. (This is the negation of AND).
- NOR: Every branch must be false for the expression to return true.
- Change Type: (Only available if logic components are enabled. To enable logic components, change the showLogicComponent variable in <jtest install dir>/bin/lib/Java.cwd from "false" to "true" If logic components are not enabled, AND will always be used).
Changes the type of logic component.
- Create Collector: Adds a collector, displayed as a pentagon, to the selected rule node. The collector allows you to place numerical stipulations on the outcome of a rule. Works with the Count command (available by right-clicking the collector). The collector keeps track of the number of times a pattern is found; Count places a condition on what number of instances constitutes a rule violation.
- Create Output: Adds an output arrow to the selected rule node. The output arrow is the essential closing to any rule. An output arrow tells RuleWizard to report an error if the specified pattern is found; if no output arrow is included, no violations of this rule can be reported. The placement of the arrow determines what line number is reported in the error message. For example, if you have a rule with nodes A, B, and C and you attach the output arrow to node C, the line number will reference the line where C occurs; if you attach the output to node A, the line number will reference the line where A occurs.
- If you are adding an output arrow to a set component (a collector or set operator), you must choose between the following two types of output arrows:
- Hits Output: Choose this output to indicate that:
- One output message should be reported each time that the attached node is matched
- The output message should reference the line number of the node to which the collector is attached. For example, if you have a collector that contains variables in Java or C++ and you select a Hits Output, you can use an output message such as "Initialize all variables in constructor. Variable $name is not initialized." (When this rule is actually violated, the $name variable will be replaced with the name of the uninitialized variable).
This type of output can contain variables (such as "$tag", or "$value") for nodes contained in the set collector or operator. For example, if you have a collector that contains variables in Java or C++ and you select a Hits Output, you can use an output message such as "Initialize all variables in constructor. Variable $name is not initialized." (When this rule is actually violated, the $name variable will be replaced with the name of the uninitialized variable).
- Trigger Output: Choose this output to indicate that:
- One output message should be reported each time that the trigger point is matched (for example, if the trigger point references a file, one message will be reported for each file).
- The output message's line number should reference the line number of the trigger point node. This type of output arrow is placed below the center of the set operator that it is attached to.
When you choose this type of output, the violation output can contain properties of the collector, but not properties of nodes contained in the set operator. Currently, the only variable you can use here is "$count".
- Indirect/Direct Check: When an indirect check is performed, Jtest searches for the specified condition in all nodes that have the specified relationship to the given node.
When a direct check is performed, Jtest searches for the specified condition only in the first node that has the specified relationship to the given node.
- Create Set Operator: Creates a set operator. Set operators are used to specify relationships between set components.
- Available options include:
- Union: The set of nodes that are in either the attached set component or the operand, including the nodes that are in both.
- Intersection: The set of nodes that are in both the attached set component and the operand.
- Difference: The set of nodes that are in the attached set component but not in the operand, or the set of nodes that are in the operand but not in the attached set component.
- Left minus Right: The set of nodes that are in the attached set component (to the left of the set operator), but which are not in the operand (as indicated in the circle attached to the right of the set operator).
- Right minus Left: The set of nodes that are in the operand (as indicated in the circle attached to the right of the set operator), but which are not in the attached set component (to the left of the set operator).
- XOR: The set of nodes that are either in the attached set component, the operand, but not in both.
- For information on set components and set operators, see Working With Node Sets.
- Label: Labels a set component so that it can be used as the operand of a set operator.
RuleWizard commands will be displayed at the top of the shortcut menu; options that pertain to programming elements and concepts are displayed below the menu's line.
Each non-RuleWizard command in the shortcut menu is followed by a symbol that describes the function of the item:
[...] indicates an item which can have either a direct or indirect check.
(S) indicates an item that takes a string input.
[T/F] indicates an item that lets you toggle between true and false inputs.
[M] indicates an item that lets you choose between predetermined input options. For example, Permission [M].
(#) indicates an item that takes a numerical input.
* indicates a property/node that is available from more than one command. For example, if you can choose the Body property from more than one of the available commands, the Body command will contain an asterisk.
The commands available depend on which node or rule element was selected. Some of these commands that you may not be familiar with include:
- Count: Lets you create a rule condition that restricts a node's quantity. Must be used in conjunction with the Create Collector command (First, create a collector, then right-click the collector and choose Count). The collector keeps track of the number of times a pattern is found; Count places a condition on what number of instances constitutes a rule violation. For information on determining exactly how counts are calculated, see Working With Node Sets.
- Body: Lets you create a rule condition about the code element that is a subnode of the parent node. (The body of Node A returns a "body" that is A's subnode; the exact definition of the "body" depends on the node itself).
- Context: Lets you create a rule condition about the code element that contains the parent node. (The context of Node A returns the node that contains Node A). For example, if you wanted to create a rule that said "always put X inside of Y," you would create a parent node for X, use Context to attach Y, create a collector, then use Count to specify that a count of $$==0 constitutes a violation.
-
- Note: Some rules can use only Body, some can use only Context, some can use neither, and some can use both. If you have a choice, choose Body because Body will result in better performance than Context. In many-- but not all-- cases, Body and Context are inverse operations. For example, an expression can be in the context of a statement, but be contained in the condition (rather than the body) of the statement.
-
- Condition: Lets you create a rule condition about the parent node's statement (if, increment, for, while, switch, and do while).
|