Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 142870

Summary: Generate for parents of selected model element
Product: [Modeling] EMF Reporter: Dave Steinberg <davidms>
Component: ToolsAssignee: Dave Steinberg <davidms>
Status: VERIFIED FIXED QA Contact:
Severity: enhancement    
Priority: P1    
Version: 2.2   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:
Bug Depends on:    
Bug Blocks: 104727    

Description Dave Steinberg CLA 2006-05-19 18:13:41 EDT
In bug 104727, it's pointed out that it's easy to select a package, instead of the whole model, and generate code for that.  Code is generated, without warning, but because of the missing artifacts, it does not compile.

This issue has generated considerable newsgroup traffic and is probably the single most common mistake made by EMF users.

This could be solved using the new Generator design. GeneratorAdapters could be queried for a parent that should be generated along with the object.  The generator can walk up this chain to collect all the parents and invoke generation on all of them, along with the object and its children.

Thus, if a class is selected for code generation, its package and model would also be generated, but not the other classes in the package.
Comment 1 Dave Steinberg CLA 2006-05-19 18:32:17 EDT
This is fixed in CVS.

Two methods have been added to the GeneratorAdapter interface: getCanGenerateParent() and getGenerateParent(). Default implementations in AbstractGeneratorAdapter simply return null.  GenPackageGeneratorAdapter, GenClassGeneratorAdapter, and GenEnumGeneratorAdapter override the latter method to return the object's parent.

Generator uses these methods in building the collection of objects to query for canGenerate() and to invoke for generate().
Comment 2 Marcelo Paternostro CLA 2006-05-23 18:53:35 EDT
Fixed in 2.2.0RC5
Comment 3 Nick Boldt CLA 2008-01-28 16:47:19 EST
Move to verified as per bug 206558.