| Generic Collection [message #541554] |
Mon, 21 June 2010 10:27  |
jeremie Messages: 233 Registered: April 2010 |
Senior Member |
|
|
Hi,
In my ecore model, I create a Type Collection<T>
in My class VariableAccessImpl, I have these methods :
public EClassifier getType() {
return (isCollection()) ? AdapterDSLFactory.eINSTANCE.createCollection().eClass() : getVariable().getEType();
}
public boolean isCollection() {
return getVariable().isCollection();
}
The problem, is the generic type of Collection. At this moment I don"t know the generic type, it is dynamic.
The generic type of Collection is getVariable().getEType() :
So I write this :
public EClassifier getType() {
return (isCollection()) ? AdapterDSLFactory.eINSTANCE.<getVariable().getEType()>createCollection().eClass() : getVariable().getEType();
}
but java don't like ".<getVariable().getEType()>createCollection()"
How can I resolve this problem?
Thanks,
Jérémie
|
|
|
| Re: Generic Collection [message #541573 is a reply to message #541554] |
Mon, 21 June 2010 11:12   |
Ed Merks Messages: 24538 Registered: July 2009 |
Senior Member |
|
|
Jérémie,
No matter what type you specify, it doesn't affect the result value, so
why not use AdapterDSLFactory.eINSTANCE.<Object>createCollection().eClass()
jeremie wrote:
> Hi,
>
> In my ecore model, I create a Type Collection<T>
>
> in My class VariableAccessImpl, I have these methods :
>
> public EClassifier getType() {
> return (isCollection()) ?
> AdapterDSLFactory.eINSTANCE.createCollection().eClass() :
> getVariable().getEType();
> }
>
> public boolean isCollection() {
> return getVariable().isCollection();
> }
>
>
> The problem, is the generic type of Collection. At this moment I don"t
> know the generic type, it is dynamic.
> The generic type of Collection is getVariable().getEType() :
>
> So I write this :
>
> public EClassifier getType() {
> return (isCollection()) ?
> AdapterDSLFactory.eINSTANCE.<getVariable().getEType()>createCollection().eClass()
> : getVariable().getEType();
> }
>
>
> but java don't like ".<getVariable().getEType()>createCollection()"
>
> How can I resolve this problem?
>
> Thanks,
>
> Jérémie
>
|
|
|
|
|
|
| Re: Generic Collection [message #541602 is a reply to message #541596] |
Mon, 21 June 2010 14:07   |
Ed Merks Messages: 24538 Registered: July 2009 |
Senior Member |
|
|
This is a multi-part message in MIME format.
--------------070402060805060203090904
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Jeremie,
Comments below.
jeremie wrote:
> I try to do something like this,
>
> public EClassifier getType() {
> EClassifier eType = getVariable().getEType();
> EGenericType eGenericType =
> EcoreFactory.eINSTANCE.createEGenericType();
> eGenericType.setEClassifier(eType);
> ETypeParameter eTypeParameter =
> EcoreFactory.eINSTANCE.createETypeParameter();
> eTypeParameter.setName(eType.getName());
> Collection<eTypeParameter> collection =
> AdapterDSLFactory.eINSTANCE.<eTypeParameter>createCollection();
No matter how hard you try, you'll never be able to pass the value of a
variable as the static type. It *must *be the static name of a class.
> Collection<eGenericType> collection2 =
> AdapterDSLFactory.eINSTANCE.<eGenericType>createCollection();
> // ETypeParameter eTypeParameter =
> collection.eClass().getETypeParameters().get(0); //
> eTypeParameter = (ETypeParameter) getVariable().getEType();
> return (isCollection()) ? collection.eClass() :
> getVariable().getEType();
And as I also said, no matter how hard you try, the collection will
never reveal its type arguments.
> }
>
>
> But it still doesn't work.
It never will. You're going down dead end.
>
> I am not sure it is possible why this way.
>
Only if you change the return to be EGenericType will you get
somewhere. It's not entirely clear what you're trying to accomplish...
--------------070402060805060203090904
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Jeremie,<br>
<br>
Comments below.<br>
<br>
<br>
jeremie wrote:
<blockquote cite="mid:hvo7id$er4$1@build.eclipse.org" type="cite">I try
to do something like this,
<br>
<br>
public EClassifier getType() {
<br>
EClassifier eType = getVariable().getEType();
<br>
EGenericType eGenericType =
EcoreFactory.eINSTANCE.createEGenericType();
<br>
eGenericType.setEClassifier(eType);
<br>
ETypeParameter eTypeParameter =
EcoreFactory.eINSTANCE.createETypeParameter();
<br>
eTypeParameter.setName(eType.getName());
<br>
Collection<eTypeParameter> collection =
AdapterDSLFactory.eINSTANCE.<eTypeParameter>cr eateCollection();
<br>
</blockquote>
No matter how hard you try, you'll never be able to pass the value of a
variable as the static type. It <b>must </b>be the static name of a
class.<br>
<blockquote cite="mid:hvo7id$er4$1@build.eclipse.org" type="cite">
Collection<eGenericType> collection2 =
AdapterDSLFactory.eINSTANCE.<eGenericType>crea teCollection();
<br>
// ETypeParameter eTypeParameter =
collection.eClass().getETypeParameters().get(0); //
eTypeParameter = (ETypeParameter) getVariable().getEType();
<br>
return (isCollection()) ? collection.eClass() :
getVariable().getEType();
<br>
</blockquote>
And as I also said, no matter how hard you try, the collection will
never reveal its type arguments.<br>
<blockquote cite="mid:hvo7id$er4$1@build.eclipse.org" type="cite"> }
<br>
<br>
<br>
But it still doesn't work.
<br>
</blockquote>
It never will. You're going down dead end.<br>
<blockquote cite="mid:hvo7id$er4$1@build.eclipse.org" type="cite"><br>
I am not sure it is possible why this way.
<br>
<br>
</blockquote>
Only if you change the return to be EGenericType will you get
somewhere. It's not entirely clear what you're trying to accomplish...<br>
</body>
</html>
--------------070402060805060203090904--
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.01718 seconds