Back to TTCN-3 Refactoring Catalog
Prefix Imported Declarations
References to imported declarations are prefixed to avoid possible name clashes.
Motivation
References to imported declarations can be prefixed with the module name where they originate from. Usage of this refactoring should only be considered when name clashes are inevitable (e.g. when an imported module cannot be changed) and should not be applied generally as prefixed references are typically harder to read. Also, in the case of name clashes, it should be verified if the Rename refactoring applied to the local clashing declaration would not yield a better result.
Mechanics
- In the source module, find the module from which the declaration to be prefixed is imported from and find the module's name.
- For each reference to this imported declaration, add a prefix containing the module name.
- Compile and validate.
Example
The next listing shows the unrefactored version. In the ExampleModule?, a type SipMethod? is declared which is then imported by the DependantModule?. There is a second type declaration with the name SipMethod? which causes a name clash. According to the scoping rules, v_method uses SipMethod? as a charstring, but the actual value hints that the imported SipMethod? is meant.
module ExampleModule {
group types {
type charstring SipMethod ("REGISTER", "INVITE", "ACK", "BYE",
"CANCEL", "OPTIONS");
}
}
module DependantModule {
import from ExampleModule all;
type charstring SipMethod;
testcase tc_exampleTestCase() runs on ExampleComponent {
// ...
var SipMethod v_method := "QUIT";
}
}
The following listing solves this problem by prefixing SipMethod? with ExampleModule? on declaration of v_method. It is clear now that v_method should use the imported type declaration.
module ExampleModule {
group types {
type charstring SipMethod ("REGISTER", "INVITE", "ACK", "BYE",
"CANCEL", "OPTIONS");
}
}
module DependantModule {
import from ExampleModule all;
type charstring SipMethod;
testcase tc_exampleTestCase() runs on ExampleComponent {
// ...
var ExampleModule.SipMethod v_method := "QUIT";
}
}
