|
|
|
|
|
Re: Problem with Generic [message #686860 is a reply to message #686690] |
Tue, 10 May 2011 15:26 |
Ed Merks 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> public <T extends Derived<T>> T1
caseDerived(Derived<T> object)<br>
{<br>
return null;<br>
}</small><br>
<br>
along with<br>
<br>
<small> protected T1 doSwitch(int classifierID, EObject theEObject)<br>
{<br>
switch (classifierID)<br>
{<br>
case AlainPackage.BASE:<br>
{<br>
Base base = (Base)theEObject;<br>
T1 result = caseBase(base);<br>
if (result == null) result = defaultCase(theEObject);<br>
return result;<br>
}<br>
case AlainPackage.DERIVED:<br>
{<br>
Derived<?> derived = (Derived<?>)theEObject;<br>
T1 result = caseDerived(derived);<br>
if (result == null) result = caseBase(derived);<br>
if (result == null) result = defaultCase(theEObject);<br>
return result;<br>
}<br>
default: return defaultCase(theEObject);<br>
}</small><br>
<br>
I don't see any errors. I even tried created a concrete derived class
to produce this, but still it works fine...<br>
<br>
case AlainPackage.CONCRETE:<br>
{<br>
Concrete concrete = (Concrete)theEObject;<br>
T1 result = caseConcrete(concrete);<br>
if (result == null) result = caseDerived(concrete);<br>
if (result == null) result = caseBase(concrete);<br>
if (result == null) result = defaultCase(theEObject);<br>
return result;<br>
}<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<T extends BaseNode<T>> 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 <T extends BaseNode<T>> T1
caseBaseNode(BaseNode<T> 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 #686862 is a reply to message #686704] |
Tue, 10 May 2011 17:12 |
Ed Merks 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/
|
|
|
|
Powered by
FUDForum. Page generated in 0.04126 seconds