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

Bug 317549

Summary: FactoryClass.javajet generates invalid FactoryImpl
Product: [Modeling] EMF Reporter: Henning Heitkoetter <hheitkoetter>
Component: ToolsAssignee: Dave Steinberg <davidms>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: Ed.Merks, mirko
Version: 2.6.0   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:
Bug Depends on:    
Bug Blocks: 320433    
Attachments:
Description Flags
Patches to address the issue.
none
The changes need for the 2.6 maintenance stream. none

Description Henning Heitkoetter CLA 2010-06-22 04:27:54 EDT
Line 365 of FactoryClass.javajet (1.36) reads as follows (as part of the body of create...FromString):
  for (String item : split(literal))

Two problems here:
1. There is no variable nor parameter named "literal" at this place (just initialValue).
2. The method split(String) is not defined.

The same expression is also found in line 264: here, a parameter named literal exists, but split is not defined either.

FYI, this was introduced by the patch for bug 310835.
Comment 1 Mirko Raner CLA 2010-06-30 21:05:40 EDT
I actually just ran into exactly this problem. The FactoryImpl for the generated model contained three broken methods:

...
    public List<String> createReferenceListTypeFromString(EDataType eDataType, String initialValue)
    {
        if (initialValue == null) return null;
        List<String> result = new ArrayList<String>();
        for (String item : split(literal))
        {
            result.add((String)XMLTypeFactory.eINSTANCE.createFromString(XMLTypePackage.Literals.ANY_URI, item));
        }
        return result;
    }

    public List<String> createRelatedFieldsTypeFromString(EDataType eDataType, String initialValue)
    {
        if (initialValue == null) return null;
        List<String> result = new ArrayList<String>();
        for (String item : split(literal))
        {
            result.add((String)XMLTypeFactory.eINSTANCE.createFromString(XMLTypePackage.Literals.STRING, item));
        }
        return result;
    }

    public List<String> createValueListTypeFromString(EDataType eDataType, String initialValue)
    {
        if (initialValue == null) return null;
        List<String> result = new ArrayList<String>();
        for (String item : split(literal))
        {
            result.add(createValueListTypeItemFromString(FilingPackage.Literals.VALUE_LIST_TYPE_ITEM, item));
        }
        return result;
    }
...

Unfortunately, the ECore file and the original XSD from which the model was generated are proprietary information, and I can't post them here. Let me know if there is anything else I can provide to help debugging this issue.

Also, I'm interested in a work-around, because now I always have to manually fix up the generated model classes.
Comment 2 Henning Heitkoetter CLA 2010-07-01 04:51:49 EDT
(In reply to comment #1)
> Also, I'm interested in a work-around, because now I always have to manually
> fix up the generated model classes.

You can take the old template from http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.codegen.ecore/templates/model/FactoryClass.javajet?revision=1.34&root=Modeling_Project&view=markup and store it (for example) in a folder "templates/model".

In your genmodel, look at the properties of the Templates&Merge category. Set "Dynamic Templates" to true and set "Template Directory" to point to the path where the model folder is stored (e.g. your_project_name/templates).
Comment 3 Ed Merks CLA 2010-07-20 13:14:52 EDT
Created attachment 174769 [details]
Patches to address the issue.

The split method should have been added to EFactoryImpl just as it was for GWT's version of EFactoryImpl and of course we should be referring to initialValue not literal in the case pointed out.
Comment 4 Ed Merks CLA 2010-07-20 14:41:19 EDT
Created attachment 174777 [details]
The changes need for the 2.6 maintenance stream.
Comment 5 Ed Merks CLA 2010-07-20 14:46:48 EDT
The changes are committed to CVS for 2.6.1.
Comment 6 Ed Merks CLA 2010-11-05 05:41:40 EDT
The fix is available in the latest build for the stream.