New protocol extensions

 

+

Search Tips   |   Advanced Search

 

This section describes the implementation of the code generation subsystem extension for the socket protocol as an example of using code generation extensibility features.

A dedicated code generation plug-in, called...

...was created with subpackages of config, lang, and model. The socket code generation subsystem extends the capabilities of the codegen.core plug-in.

The config package contains the SocketExtensionPreferences class which contains the supportsFeatures() method that expresses interest in tests with feature lists containing the socket feature. Also, its getSupportedModelElements() method declares which translator-associated model element types this codegen extension will support.

The lang package contains two main classes, a script definition (SocketScriptDefinition) class and a translator (SocketTranslator) class. The classes extend the appropriate super classes from the codegen.core plug-in, and defining methods for translating script and test elements. The script definition class overrides the doScriptLevelTranslation() method which, after calling its superclass, translates all socket script template parameters specific to the socket protocol. The translator class overrides the getTranslationFor() method, handling all non-socket functionality by calling its superclass, and all socket-specific test elements and parameters locally.

The model package contains the SocketElementAdapter class, which implements a getAdapterFor() method that states what Common Behavior element type this protocol extension handles, and returns the corresponding codegen model element.

The template directory was also added to the protocol extension plug-in, and socket-specific templates were created and placed there. All necessary extensions were defined in the protocol extension plugin.xml file.

For the code generation extension sample, see the plug-in...


Related

  • Code generation
  • Generate test code
  • Create the script class
  • Extension points for code generation
  • Code generation templates
  • Public APIs of codegen.core