EObject as reference type [message #655261] |
Fri, 18 February 2011 20:15 |
Eclipse User |
|
|
|
Originally posted by: c.krause.cwi.nl
Hi,
in Henshin, we would like to provide a generic trace model for model
transformations in EMF. We have defined a model with a class 'Trace'
with references of type EObject. The idea is that for these references,
eObjects of any type can be used.
We tried to use our new trace model and immediately ran into a problem,
i.e. the reference type 'EObject' is, apparently, not supertype of
eclasses (anymore?) ?
In our transformation model we have classes Node and Edge. Nodes have
a reference 'type':EClass, and edges a reference 'type':EReference. The
type of the reference should match the type of the target node.
In our editors we have a check for this:
boolean canCreateEdge(Node source, Node target, EReference edgeType) {
// Get the source and target type.
EClass targetType = target.getType();
EClass sourceType = source.getType();
// ...
// Target type must be ok:
if (!edgeType.getEReferenceType().isSuperTypeOf(targetType)) {
System.out.println("ref type: " + edgeType.getEReferenceType());
System.out.println("target type: " + targetType);
return false;
}
//...
}
For an example that uses the trace model we get the following output
(the check fails):
ref type: org.eclipse.emf.ecore.impl.EClassImpl@5ddffa (name: EObject)
(instanceClassName: null) (abstract: false, interface: false)
target type: org.eclipse.emf.ecore.impl.EClassImpl@1675ff4 (name: Book)
(instanceClassName: null) (abstract: false, interface: false)
So it seems that EObject cannot be used as 'the most general' superclass
of *all* EClasses.
Does this have to do with the fact that EModelElement does not inherit
from EObject anymore? Or is it a different problem?
Cheers,
Christian
|
|
|
Re: EObject as reference type [message #655603 is a reply to message #655261] |
Mon, 21 February 2011 21:41 |
Eclipse User |
|
|
|
Originally posted by: c.krause.cwi.nl
Well, I guess it is as I expected. EObject is not supertype of EClasses
anymore. If anyone is interested, we now do this in our editors to
support EObject as reference types:
// Target type must be ok. Extra check for EObjects!!!
if (!edgeType.getEReferenceType().isSuperTypeOf(targetType) &&
edgeType.getEReferenceType()!=EcorePackage.eINSTANCE.getEObj ect()) {
return false;
}
...ugly, but that is the only solution.
On 02/18/11 21:15, Christian Krause wrote:
> Hi,
>
> in Henshin, we would like to provide a generic trace model for model
> transformations in EMF. We have defined a model with a class 'Trace'
> with references of type EObject. The idea is that for these references,
> eObjects of any type can be used.
>
> We tried to use our new trace model and immediately ran into a problem,
> i.e. the reference type 'EObject' is, apparently, not supertype of
> eclasses (anymore?) ?
>
> In our transformation model we have classes Node and Edge. Nodes have
> a reference 'type':EClass, and edges a reference 'type':EReference. The
> type of the reference should match the type of the target node.
> In our editors we have a check for this:
>
> boolean canCreateEdge(Node source, Node target, EReference edgeType) {
>
> // Get the source and target type.
> EClass targetType = target.getType();
> EClass sourceType = source.getType();
>
> // ...
>
> // Target type must be ok:
> if (!edgeType.getEReferenceType().isSuperTypeOf(targetType)) {
> System.out.println("ref type: " + edgeType.getEReferenceType());
> System.out.println("target type: " + targetType);
> return false;
> }
>
> //...
>
> }
>
> For an example that uses the trace model we get the following output
> (the check fails):
>
> ref type: org.eclipse.emf.ecore.impl.EClassImpl@5ddffa (name: EObject)
> (instanceClassName: null) (abstract: false, interface: false)
>
> target type: org.eclipse.emf.ecore.impl.EClassImpl@1675ff4 (name: Book)
> (instanceClassName: null) (abstract: false, interface: false)
>
> So it seems that EObject cannot be used as 'the most general' superclass
> of *all* EClasses.
>
> Does this have to do with the fact that EModelElement does not inherit
> from EObject anymore? Or is it a different problem?
>
> Cheers,
> Christian
|
|
|
Powered by
FUDForum. Page generated in 0.03587 seconds