Exercise 3. Code Generator Memory Options
What This Exercise Is About
Using the PurchaseOrder model, you will experiment with how to tune the impact that generated code has on memory footprint. In particular, you will enable memory-related generator options.
For your reference, here again is the UML class diagram describing the purchase order model:

What You Should Be Able To Do
At the end of the lab, you should be able to:
- Make use of code generator options to affect the memory footprint of your model.
Required Materials
- Eclipse 3.2
- Eclipse Modeling Framework (EMF) 2.2
General Advice / Warnings
- Eclipse conventions suggest naming plug-in projects with a fully qualified plug-in ID, such as com.example.po. Do not use dashes in project names - this will create invalid entries in your MANIFEST.MF file.
- Make sure you're using the IBM JDK or else have implemented the Sun JDK Crimson DOM bug workaround (http://eclipse.org/emf/downloads-xerces.php).
Exercise Instructions
This exercise is carried out entirely using the Eclipse Software Development Kit (SDK) version 3.2 with the Eclipse Modeling Framework (EMF) 2.2 installed into it. The exercise instructions refer to this product as either Eclipse or as "the workbench".
These instructions are located in the exercises/Exercise3_CodeGen_Memory_Options folder. If you browse into this location by expanding the folders, you should find one additional folder: org.eclipse.emf.tutorial.advanced.po. This is an Eclipse project that you will import into your workspace to complete this exercise.
The folder exercises/Solution3 contains examples of the files you will create during this exercise.
Directions
- See Exercise 1, Step A.
- See Exercise 1, Step B.
- Set the Feature Delegation generator model property in the PurchaseOrder generator model.
- Open the PurchaseOrder.genmodel file available in the model folder of the project imported in step B (if not already open).
- Select the topmost node PurchaseOrder, right-click, and select Show Properties View (if this view is not already shown).
- Scroll the Properties view to find the Model twisty. Underneath is the Feature Delegation property. Set that property to Virtual.

- Set the Boolean Flags Field generator model property in the PurchaseOrder generator model.
- Open the PurchaseOrder.genmodel file available in the model folder of the project imported in step B (if not already open).
- Select the topmost node PurchaseOrder, right-click, and select Show Properties View (if this view is not already shown).
- Scroll the Properties view to find the Model Feature Defaults twisty. Underneath is the Boolean Flags Field property. Set that property to flags.

- Generate the model code from the genmodel file.
- Open the PurchaseOrder.genmodel file available in the model folder of the project imported in step B (if not already open).
- Select the topmost node PurchaseOrder, right-click, and select Generate Model Code.
- The code should be compiled automatically as it is generated, and should recompile whenever it is changed. If you have disabled automatic building in the workbench preferences, you can initiate compilation manually by selecting Build All from the Project menu.

- Analyze the PersonImpl.java source file.
- Open the PersonImpl.java file available in the org.emf.tutorial.advanced.po package.
- Notice that an array field (eVirtualValues) and associated index field (eVirtualIndexBits0) were generated to store the values of non-primitive features.
- Notice a bit field (flags) was generated to represent the values of boolean attributes.

- Analyze the CustomerImpl.java source file.
- Open the CustomerImpl.java file available in the org.emf.tutorial.advanced.po package.
- Notice that no field was generated for the purchaseOrders reference. The accessor for the purchaseOrders reference gets/sets the value at a specific index (maintained in the index field in PersonImpl) in the array field inherited from PersonImpl.

- Notice that no field was generated for the vip attribute, but instead there is a static constant bit index (VIP_EFLAG). The accessors for the vip attribute get and set the corresponding bit in the bit field inherited from PersonImpl.

Summary
You experimented with memory-related EMF code generator options and witnessed the effect of such options on the generated code.