Generated switch class and external interfaces [message #988624] |
Fri, 30 November 2012 12:49  |
Eclipse User |
|
|
|
Hi all,
I have rather a usual scenario with some modeled classes having external interfaces specified in the InstanceTypeName property. The generated Switch class contains appropriate case* methods for all of them, but the doSwitch() method misses the corresponding case labels and because of it the generated Switch doesn't work for classes with external interfaces. This is due to the JET template implementation (SwitchClass.javajet), which generates case blocks only if a class doesn't have an external interface.
I am not really sure, if this is a bug or there was some reason behind doing it so. May be there is just another if block for external interfaces missing in the template? Can someone please clarify that for me?
Thanks in advance,
Vladimir
[Updated on: Fri, 30 November 2012 12:50] by Moderator
|
|
|
|
|
|
|
Re: Switch class and external interfaces [message #989832 is a reply to message #989759] |
Sat, 08 December 2012 00:58   |
Eclipse User |
|
|
|
Vladimir,
I see what you mean. This guard in the templates seems questionable:
<%if (!genClass.isExternalInterface() && !genClass.isEObject() ||
genClass.isMapEntry())
Even guarding against abstract classes seems questionable in the general
case because this logic in Switch might well delegate to an abstract
class' classifier ID.
protected T doSwitch(EClass eClass, EObject eObject)
{
if (isSwitchFor(eClass.getEPackage()))
{
return doSwitch(eClass.getClassifierID(), eObject);
}
else
{
List<EClass> eSuperTypes = eClass.getESuperTypes();
return eSuperTypes.isEmpty() ? defaultCase(eObject) :
doSwitch(eSuperTypes.get(0), eObject);
}
}
Please open a bugzilla.
On 07/12/2012 4:48 PM, Wladimir Safonov wrote:
> Hi Ed,
>
> your are speaking about abstract classes. Actually I was assuming I don't need any abstract classes as the class implementing external interface can be provided all required implementation details either in the generated class or in the ecore model.
>
> I attached a model project with an example containing single class which demonstrates what I mean. Note that the modeled class is not complete in the sence that it is missing some methods from the external interface. I add them in the generated code. Now with the generated factory I can create objects of the external interface type instead of some EMF generated interface. But if you look in the switch class, the delegation to the case* method in the switch block is missing.
>
> I thought such scenario would be valid from the EMF point of view and should be supported. If it is not, then at least there is some inconsistency here that makes me wonder why the generated factory can create instances of such classes, but the switch class considers them abstract.
>
> Regards,
> Vladimir
>
>
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.04970 seconds