Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Problem with Generic
Problem with Generic [message #686690] Mon, 09 May 2011 21:36 Go to next message
Alain Picard is currently offline Alain PicardFriend
Messages: 266
Registered: July 2009
Senior Member
I have a Eclass defined as follow:
public interface BaseNode<T extends BaseNode<T>> extends
AbstractIstElement {

and I'm getting an error in the generated switch class here:
if (result == null) result = caseBaseNode(baseCodeNode);
error:Type mismatch: cannot convert from Object to T1

and the method is defined as:
public <T extends BaseNode<T>> T1 caseBaseNode(BaseNode<T> object) {

I am doing anything wrong? The rest of the code is generated correctly.

Thanks,
Alain
Re: Problem with Generic [message #686703 is a reply to message #686690] Tue, 10 May 2011 15:26 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Alain,<br>
<br>
I tried it and produced<br>
<br>
<small>&nbsp; public &lt;T extends Derived&lt;T&gt;&gt; T1
caseDerived(Derived&lt;T&gt; object)<br>
&nbsp; {<br>
&nbsp;&nbsp;&nbsp; return null;<br>
&nbsp; }</small><br>
<br>
along with<br>
<br>
<small>&nbsp; protected T1 doSwitch(int classifierID, EObject theEObject)<br>
&nbsp; {<br>
&nbsp;&nbsp;&nbsp; switch (classifierID)<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case AlainPackage.BASE:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Base base = (Base)theEObject;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; T1 result = caseBase(base);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (result == null) result = defaultCase(theEObject);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return result;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case AlainPackage.DERIVED:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Derived&lt;?&gt; derived = (Derived&lt;?&gt;)theEObject;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; T1 result = caseDerived(derived);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (result == null) result = caseBase(derived);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (result == null) result = defaultCase(theEObject);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return result;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; default: return defaultCase(theEObject);<br>
&nbsp;&nbsp;&nbsp; }</small><br>
&nbsp; <br>
I don't see any errors.&nbsp; I even tried created a concrete derived class
to produce this, but still it works fine...<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case AlainPackage.CONCRETE:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Concrete concrete = (Concrete)theEObject;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; T1 result = caseConcrete(concrete);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (result == null) result = caseDerived(concrete);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (result == null) result = caseBase(concrete);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (result == null) result = defaultCase(theEObject);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return result;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
<br>
Which version of EMF are you using?<br>
<br>
<br>
<br>
Alain Picard wrote:
<blockquote cite="mid:iq9m96$g2p$1@news.eclipse.org" type="cite">I have
a Eclass defined as follow:
<br>
public interface BaseNode&lt;T extends BaseNode&lt;T&gt;&gt; extends
AbstractIstElement {
<br>
<br>
and I'm getting an error in the generated switch class here:
<br>
if (result == null) result = caseBaseNode(baseCodeNode);
<br>
error:Type mismatch: cannot convert from Object to T1
<br>
<br>
and the method is defined as:
<br>
public &lt;T extends BaseNode&lt;T&gt;&gt; T1
caseBaseNode(BaseNode&lt;T&gt; object) {
<br>
<br>
I am doing anything wrong? The rest of the code is generated correctly.
<br>
<br>
Thanks,
<br>
Alain
<br>
</blockquote>
</body>
</html>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Problem with Generic [message #686704 is a reply to message #686703] Tue, 10 May 2011 16:54 Go to previous messageGo to next message
Alain Picard is currently offline Alain PicardFriend
Messages: 266
Registered: July 2009
Senior Member
Ed,
I am using 2.6.0. Tried with 20100914 and 20110128 and 20110502.

I am getting the error only in the concrete case, but everything looks
exactly like what you're showing:
case IstPackage.BASE_NODE: {
BaseNode<?> baseNode = (BaseNode<?>)theEObject;
T1 result = caseBaseNode(baseNode);
if (result == null) result = caseAbstractIstElement(baseNode);
if (result == null) result = caseEntity(baseNode);
if (result == null) result = caseModelElement(baseNode);
if (result == null) result = caseElement(baseNode);
if (result == null) result = caseEObject(baseNode);
if (result == null) result = defaultCase(theEObject);
return result;
}

case IstPackage.BASE_CODE_NODE: {
BaseCodeNode baseCodeNode = (BaseCodeNode)theEObject;
T1 result = caseBaseCodeNode(baseCodeNode);
if (result == null) result = caseBaseNode(baseCodeNode); <===error here
if (result == null) result = caseComparable(baseCodeNode);
if (result == null) result = caseAbstractIstElement(baseCodeNode);
if (result == null) result = caseEntity(baseCodeNode);
if (result == null) result = caseModelElement(baseCodeNode);
if (result == null) result = caseElement(baseCodeNode);
if (result == null) result = caseEObject(baseCodeNode);
if (result == null) result = defaultCase(theEObject);
return result;
}

public <T extends BaseNode<T>> T1 caseBaseNode(BaseNode<T> object) {
return null;
}


Even stranger I guess. What could it be?

Alain



On 5/10/2011 11:26 AM, Ed Merks wrote:
> Alain,
>
> I tried it and produced
>
> public <T extends Derived<T>> T1 caseDerived(Derived<T> object)
> {
> return null;
> }
>
> along with
>
> protected T1 doSwitch(int classifierID, EObject theEObject)
> {
> switch (classifierID)
> {
> case AlainPackage.BASE:
> {
> Base base = (Base)theEObject;
> T1 result = caseBase(base);
> if (result == null) result = defaultCase(theEObject);
> return result;
> }
> case AlainPackage.DERIVED:
> {
> Derived<?> derived = (Derived<?>)theEObject;
> T1 result = caseDerived(derived);
> if (result == null) result = caseBase(derived);
> if (result == null) result = defaultCase(theEObject);
> return result;
> }
> default: return defaultCase(theEObject);
> }
>
> I don't see any errors. I even tried created a concrete derived class to
> produce this, but still it works fine...
>
> case AlainPackage.CONCRETE:
> {
> Concrete concrete = (Concrete)theEObject;
> T1 result = caseConcrete(concrete);
> if (result == null) result = caseDerived(concrete);
> if (result == null) result = caseBase(concrete);
> if (result == null) result = defaultCase(theEObject);
> return result;
> }
>
> Which version of EMF are you using?
>
>
>
> Alain Picard wrote:
>> I have a Eclass defined as follow:
>> public interface BaseNode<T extends BaseNode<T>> extends
>> AbstractIstElement {
>>
>> and I'm getting an error in the generated switch class here:
>> if (result == null) result = caseBaseNode(baseCodeNode);
>> error:Type mismatch: cannot convert from Object to T1
>>
>> and the method is defined as:
>> public <T extends BaseNode<T>> T1 caseBaseNode(BaseNode<T> object) {
>>
>> I am doing anything wrong? The rest of the code is generated correctly.
>>
>> Thanks,
>> Alain
Re: Problem with Generic [message #686705 is a reply to message #686704] Tue, 10 May 2011 17:12 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Alain,

I can't explain it. To me it looks like a compiler error. It's clear
that caseBaseNode must return a T1 regardless of the type of the
argument (and it's not complaining about the type of the argument).
It's also possible something else subtle is going on that's missing from
my test case and that you've not elaborated. Could you reduce your test
case and provide the Ecore file for it?


Alain Picard wrote:
> Ed,
> I am using 2.6.0. Tried with 20100914 and 20110128 and 20110502.
>
> I am getting the error only in the concrete case, but everything looks
> exactly like what you're showing:
> case IstPackage.BASE_NODE: {
> BaseNode<?> baseNode = (BaseNode<?>)theEObject;
> T1 result = caseBaseNode(baseNode);
> if (result == null) result = caseAbstractIstElement(baseNode);
> if (result == null) result = caseEntity(baseNode);
> if (result == null) result = caseModelElement(baseNode);
> if (result == null) result = caseElement(baseNode);
> if (result == null) result = caseEObject(baseNode);
> if (result == null) result = defaultCase(theEObject);
> return result;
> }
>
> case IstPackage.BASE_CODE_NODE: {
> BaseCodeNode baseCodeNode = (BaseCodeNode)theEObject;
> T1 result = caseBaseCodeNode(baseCodeNode);
> if (result == null) result = caseBaseNode(baseCodeNode); <===error here
> if (result == null) result = caseComparable(baseCodeNode);
> if (result == null) result = caseAbstractIstElement(baseCodeNode);
> if (result == null) result = caseEntity(baseCodeNode);
> if (result == null) result = caseModelElement(baseCodeNode);
> if (result == null) result = caseElement(baseCodeNode);
> if (result == null) result = caseEObject(baseCodeNode);
> if (result == null) result = defaultCase(theEObject);
> return result;
> }
>
> public <T extends BaseNode<T>> T1 caseBaseNode(BaseNode<T> object) {
> return null;
> }
>
>
> Even stranger I guess. What could it be?
>
> Alain
>
>
>
> On 5/10/2011 11:26 AM, Ed Merks wrote:
>> Alain,
>>
>> I tried it and produced
>>
>> public <T extends Derived<T>> T1 caseDerived(Derived<T> object)
>> {
>> return null;
>> }
>>
>> along with
>>
>> protected T1 doSwitch(int classifierID, EObject theEObject)
>> {
>> switch (classifierID)
>> {
>> case AlainPackage.BASE:
>> {
>> Base base = (Base)theEObject;
>> T1 result = caseBase(base);
>> if (result == null) result = defaultCase(theEObject);
>> return result;
>> }
>> case AlainPackage.DERIVED:
>> {
>> Derived<?> derived = (Derived<?>)theEObject;
>> T1 result = caseDerived(derived);
>> if (result == null) result = caseBase(derived);
>> if (result == null) result = defaultCase(theEObject);
>> return result;
>> }
>> default: return defaultCase(theEObject);
>> }
>>
>> I don't see any errors. I even tried created a concrete derived class to
>> produce this, but still it works fine...
>>
>> case AlainPackage.CONCRETE:
>> {
>> Concrete concrete = (Concrete)theEObject;
>> T1 result = caseConcrete(concrete);
>> if (result == null) result = caseDerived(concrete);
>> if (result == null) result = caseBase(concrete);
>> if (result == null) result = defaultCase(theEObject);
>> return result;
>> }
>>
>> Which version of EMF are you using?
>>
>>
>>
>> Alain Picard wrote:
>>> I have a Eclass defined as follow:
>>> public interface BaseNode<T extends BaseNode<T>> extends
>>> AbstractIstElement {
>>>
>>> and I'm getting an error in the generated switch class here:
>>> if (result == null) result = caseBaseNode(baseCodeNode);
>>> error:Type mismatch: cannot convert from Object to T1
>>>
>>> and the method is defined as:
>>> public <T extends BaseNode<T>> T1 caseBaseNode(BaseNode<T> object) {
>>>
>>> I am doing anything wrong? The rest of the code is generated correctly.
>>>
>>> Thanks,
>>> Alain
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Problem with Generic [message #686706 is a reply to message #686704] Tue, 10 May 2011 17:14 Go to previous message
Alain Picard is currently offline Alain PicardFriend
Messages: 266
Registered: July 2009
Senior Member
Ed,

Well I got it.

The problem seems to be related to the editor and not the generator.

I first created my model without the generics, which I forgot. I then
added the generic type, but that didn't change concrete subclasses.

Even then, I couldn't add the type parameter. I had to delete the
supertype reference, save the ecore and then re-add the super-type. Then
I was able to specify the type parameter information.

So there is probably a bug in the editor, but not in the most important
code generator.

Thanks for your help and sorry to have raised the wrong issue.

Cheers,
Alain
Re: Problem with Generic [message #686860 is a reply to message #686690] Tue, 10 May 2011 15:26 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Alain,<br>
<br>
I tried it and produced<br>
<br>
<small>&nbsp; public &lt;T extends Derived&lt;T&gt;&gt; T1
caseDerived(Derived&lt;T&gt; object)<br>
&nbsp; {<br>
&nbsp;&nbsp;&nbsp; return null;<br>
&nbsp; }</small><br>
<br>
along with<br>
<br>
<small>&nbsp; protected T1 doSwitch(int classifierID, EObject theEObject)<br>
&nbsp; {<br>
&nbsp;&nbsp;&nbsp; switch (classifierID)<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case AlainPackage.BASE:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Base base = (Base)theEObject;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; T1 result = caseBase(base);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (result == null) result = defaultCase(theEObject);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return result;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case AlainPackage.DERIVED:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Derived&lt;?&gt; derived = (Derived&lt;?&gt;)theEObject;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; T1 result = caseDerived(derived);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (result == null) result = caseBase(derived);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (result == null) result = defaultCase(theEObject);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return result;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; default: return defaultCase(theEObject);<br>
&nbsp;&nbsp;&nbsp; }</small><br>
&nbsp; <br>
I don't see any errors.&nbsp; I even tried created a concrete derived class
to produce this, but still it works fine...<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case AlainPackage.CONCRETE:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Concrete concrete = (Concrete)theEObject;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; T1 result = caseConcrete(concrete);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (result == null) result = caseDerived(concrete);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (result == null) result = caseBase(concrete);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (result == null) result = defaultCase(theEObject);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return result;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
<br>
Which version of EMF are you using?<br>
<br>
<br>
<br>
Alain Picard wrote:
<blockquote cite="mid:iq9m96$g2p$1@news.eclipse.org" type="cite">I have
a Eclass defined as follow:
<br>
public interface BaseNode&lt;T extends BaseNode&lt;T&gt;&gt; extends
AbstractIstElement {
<br>
<br>
and I'm getting an error in the generated switch class here:
<br>
if (result == null) result = caseBaseNode(baseCodeNode);
<br>
error:Type mismatch: cannot convert from Object to T1
<br>
<br>
and the method is defined as:
<br>
public &lt;T extends BaseNode&lt;T&gt;&gt; T1
caseBaseNode(BaseNode&lt;T&gt; object) {
<br>
<br>
I am doing anything wrong? The rest of the code is generated correctly.
<br>
<br>
Thanks,
<br>
Alain
<br>
</blockquote>
</body>
</html>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Problem with Generic [message #686861 is a reply to message #686703] Tue, 10 May 2011 16:54 Go to previous message
Alain Picard is currently offline Alain PicardFriend
Messages: 266
Registered: July 2009
Senior Member
Ed,
I am using 2.6.0. Tried with 20100914 and 20110128 and 20110502.

I am getting the error only in the concrete case, but everything looks
exactly like what you're showing:
case IstPackage.BASE_NODE: {
BaseNode<?> baseNode = (BaseNode<?>)theEObject;
T1 result = caseBaseNode(baseNode);
if (result == null) result = caseAbstractIstElement(baseNode);
if (result == null) result = caseEntity(baseNode);
if (result == null) result = caseModelElement(baseNode);
if (result == null) result = caseElement(baseNode);
if (result == null) result = caseEObject(baseNode);
if (result == null) result = defaultCase(theEObject);
return result;
}

case IstPackage.BASE_CODE_NODE: {
BaseCodeNode baseCodeNode = (BaseCodeNode)theEObject;
T1 result = caseBaseCodeNode(baseCodeNode);
if (result == null) result = caseBaseNode(baseCodeNode); <===error here
if (result == null) result = caseComparable(baseCodeNode);
if (result == null) result = caseAbstractIstElement(baseCodeNode);
if (result == null) result = caseEntity(baseCodeNode);
if (result == null) result = caseModelElement(baseCodeNode);
if (result == null) result = caseElement(baseCodeNode);
if (result == null) result = caseEObject(baseCodeNode);
if (result == null) result = defaultCase(theEObject);
return result;
}

public <T extends BaseNode<T>> T1 caseBaseNode(BaseNode<T> object) {
return null;
}


Even stranger I guess. What could it be?

Alain



On 5/10/2011 11:26 AM, Ed Merks wrote:
> Alain,
>
> I tried it and produced
>
> public <T extends Derived<T>> T1 caseDerived(Derived<T> object)
> {
> return null;
> }
>
> along with
>
> protected T1 doSwitch(int classifierID, EObject theEObject)
> {
> switch (classifierID)
> {
> case AlainPackage.BASE:
> {
> Base base = (Base)theEObject;
> T1 result = caseBase(base);
> if (result == null) result = defaultCase(theEObject);
> return result;
> }
> case AlainPackage.DERIVED:
> {
> Derived<?> derived = (Derived<?>)theEObject;
> T1 result = caseDerived(derived);
> if (result == null) result = caseBase(derived);
> if (result == null) result = defaultCase(theEObject);
> return result;
> }
> default: return defaultCase(theEObject);
> }
>
> I don't see any errors. I even tried created a concrete derived class to
> produce this, but still it works fine...
>
> case AlainPackage.CONCRETE:
> {
> Concrete concrete = (Concrete)theEObject;
> T1 result = caseConcrete(concrete);
> if (result == null) result = caseDerived(concrete);
> if (result == null) result = caseBase(concrete);
> if (result == null) result = defaultCase(theEObject);
> return result;
> }
>
> Which version of EMF are you using?
>
>
>
> Alain Picard wrote:
>> I have a Eclass defined as follow:
>> public interface BaseNode<T extends BaseNode<T>> extends
>> AbstractIstElement {
>>
>> and I'm getting an error in the generated switch class here:
>> if (result == null) result = caseBaseNode(baseCodeNode);
>> error:Type mismatch: cannot convert from Object to T1
>>
>> and the method is defined as:
>> public <T extends BaseNode<T>> T1 caseBaseNode(BaseNode<T> object) {
>>
>> I am doing anything wrong? The rest of the code is generated correctly.
>>
>> Thanks,
>> Alain
Re: Problem with Generic [message #686862 is a reply to message #686704] Tue, 10 May 2011 17:12 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Alain,

I can't explain it. To me it looks like a compiler error. It's clear
that caseBaseNode must return a T1 regardless of the type of the
argument (and it's not complaining about the type of the argument).
It's also possible something else subtle is going on that's missing from
my test case and that you've not elaborated. Could you reduce your test
case and provide the Ecore file for it?


Alain Picard wrote:
> Ed,
> I am using 2.6.0. Tried with 20100914 and 20110128 and 20110502.
>
> I am getting the error only in the concrete case, but everything looks
> exactly like what you're showing:
> case IstPackage.BASE_NODE: {
> BaseNode<?> baseNode = (BaseNode<?>)theEObject;
> T1 result = caseBaseNode(baseNode);
> if (result == null) result = caseAbstractIstElement(baseNode);
> if (result == null) result = caseEntity(baseNode);
> if (result == null) result = caseModelElement(baseNode);
> if (result == null) result = caseElement(baseNode);
> if (result == null) result = caseEObject(baseNode);
> if (result == null) result = defaultCase(theEObject);
> return result;
> }
>
> case IstPackage.BASE_CODE_NODE: {
> BaseCodeNode baseCodeNode = (BaseCodeNode)theEObject;
> T1 result = caseBaseCodeNode(baseCodeNode);
> if (result == null) result = caseBaseNode(baseCodeNode); <===error here
> if (result == null) result = caseComparable(baseCodeNode);
> if (result == null) result = caseAbstractIstElement(baseCodeNode);
> if (result == null) result = caseEntity(baseCodeNode);
> if (result == null) result = caseModelElement(baseCodeNode);
> if (result == null) result = caseElement(baseCodeNode);
> if (result == null) result = caseEObject(baseCodeNode);
> if (result == null) result = defaultCase(theEObject);
> return result;
> }
>
> public <T extends BaseNode<T>> T1 caseBaseNode(BaseNode<T> object) {
> return null;
> }
>
>
> Even stranger I guess. What could it be?
>
> Alain
>
>
>
> On 5/10/2011 11:26 AM, Ed Merks wrote:
>> Alain,
>>
>> I tried it and produced
>>
>> public <T extends Derived<T>> T1 caseDerived(Derived<T> object)
>> {
>> return null;
>> }
>>
>> along with
>>
>> protected T1 doSwitch(int classifierID, EObject theEObject)
>> {
>> switch (classifierID)
>> {
>> case AlainPackage.BASE:
>> {
>> Base base = (Base)theEObject;
>> T1 result = caseBase(base);
>> if (result == null) result = defaultCase(theEObject);
>> return result;
>> }
>> case AlainPackage.DERIVED:
>> {
>> Derived<?> derived = (Derived<?>)theEObject;
>> T1 result = caseDerived(derived);
>> if (result == null) result = caseBase(derived);
>> if (result == null) result = defaultCase(theEObject);
>> return result;
>> }
>> default: return defaultCase(theEObject);
>> }
>>
>> I don't see any errors. I even tried created a concrete derived class to
>> produce this, but still it works fine...
>>
>> case AlainPackage.CONCRETE:
>> {
>> Concrete concrete = (Concrete)theEObject;
>> T1 result = caseConcrete(concrete);
>> if (result == null) result = caseDerived(concrete);
>> if (result == null) result = caseBase(concrete);
>> if (result == null) result = defaultCase(theEObject);
>> return result;
>> }
>>
>> Which version of EMF are you using?
>>
>>
>>
>> Alain Picard wrote:
>>> I have a Eclass defined as follow:
>>> public interface BaseNode<T extends BaseNode<T>> extends
>>> AbstractIstElement {
>>>
>>> and I'm getting an error in the generated switch class here:
>>> if (result == null) result = caseBaseNode(baseCodeNode);
>>> error:Type mismatch: cannot convert from Object to T1
>>>
>>> and the method is defined as:
>>> public <T extends BaseNode<T>> T1 caseBaseNode(BaseNode<T> object) {
>>>
>>> I am doing anything wrong? The rest of the code is generated correctly.
>>>
>>> Thanks,
>>> Alain
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Problem with Generic [message #686863 is a reply to message #686704] Tue, 10 May 2011 17:14 Go to previous message
Alain Picard is currently offline Alain PicardFriend
Messages: 266
Registered: July 2009
Senior Member
Ed,

Well I got it.

The problem seems to be related to the editor and not the generator.

I first created my model without the generics, which I forgot. I then
added the generic type, but that didn't change concrete subclasses.

Even then, I couldn't add the type parameter. I had to delete the
supertype reference, save the ecore and then re-add the super-type. Then
I was able to specify the type parameter information.

So there is probably a bug in the editor, but not in the most important
code generator.

Thanks for your help and sorry to have raised the wrong issue.

Cheers,
Alain
Previous Topic:Java native type array in EMF DataType
Next Topic:(no subject)
Goto Forum:
  


Current Time: Fri Apr 26 22:36:12 GMT 2024

Powered by FUDForum. Page generated in 0.04126 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top