|
Re: EMF 2.7 Unable to support enumerations called Enum [message #1042597 is a reply to message #1042519] |
Tue, 16 April 2013 16:18 |
Ed Merks Messages: 33218 Registered: July 2009 |
Senior Member |
|
|
Rob,
Open a bugzilla and I can look at addressing it in 2.9. It looks like
adding and explicit import to the file avoids the problem.
import com.example.enumtest.Enum;
On 16/04/2013 4:26 PM, Rob Mising name wrote:
> Hi Ed,
>
> I have been updating our system from EMF 2.4 to EMF 2.7 and unfortunately we have stumbled accross a problem that I'm really hoping that you can assist with please.
>
> If we have an XSD:
>
> <xsd:schema xmlns="http://www.example.com/enumtest/" xmlns:tns1="http://www.example.com/enumtest/" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.com/enumtest/" elementFormDefault="qualified" attributeFormDefault="qualified">
> <xsd:simpleType name="Enum" ecore:name="Enum">
> <xsd:restriction base="xsd:string">
> <xsd:enumeration value="One" ecore:name="ONE"/>
> <xsd:enumeration value="Two" ecore:name="TWO"/>
> <xsd:enumeration value="Three" ecore:name="THREE"/>
> </xsd:restriction>
> </xsd:simpleType>
> </xsd:schema>
>
> And then use that to create an ecore/genmodel and then generate java code (Using the default templates), then it generates invalid code that will not compile - in the Factory java files.
>
> In EMF 2.4 it worked OK, because it would generate code that used the fully qualified name for things like Enum:
>
> public com.example.enumtest.Enum createEnumObjectFromString(EDataType eDataType, String initialValue) {
> return createEnumFromString(EnumtestPackage.Literals.ENUM, initialValue);
> }
>
> However in EMF 2.7 is will generate:
>
> public Enum createEnumObjectFromString(EDataType eDataType, String initialValue) {
> return createEnumFromString(EnumtestPackage.Literals.ENUM, initialValue);
> }
>
>
> Any assistance you can give would be greatly appreciated.
>
> Thanks
>
> Rob
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
|
|
|
|
|
|
Re: EMF 2.7 Unable to support enumerations called Enum [message #1058660 is a reply to message #1058654] |
Tue, 14 May 2013 15:49 |
Ed Merks Messages: 33218 Registered: July 2009 |
Senior Member |
|
|
Rob,
Yes, that looks reasonable. It does appear that the factory
implementation is the only generated artifact that runs into problems...
On 14/05/2013 5:35 PM, Rob Mising name wrote:
> Hi Ed,
>
> Thank you for fixing that. For my patch I have tried to copy what you
> have done but using templates. This is because it is quite hard for
> us to override just a single EMF file to apply a patch on top of the
> original EMF features/plugins.
>
> So I have added the following to the FactoryClass.javajet:
>
> <%// PATCH for https://bugs.eclipse.org/bugs/show_bug.cgi?id=405854 %>
> <%List<String> result = new ArrayList<String>();%>
> <%for (GenEnum genEnum : genPackage.getGenEnums()) { String name =
> genEnum.getName(); if
> (org.eclipse.emf.codegen.util.CodeGenUtil.isJavaDefaultType(name)) {
> result.add(name); } }%>
> <%genModel.getImportManager().addJavaLangImports(result);%>
> <%// END PATCH %>
>
>
> I hope this is OK.
>
> Thanks
>
> Rob
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.06391 seconds