Home » Modeling » EMF » [Xcore]? Type of EAttributes always EJavaObject
[Xcore]? Type of EAttributes always EJavaObject [message #1737926] |
Thu, 14 July 2016 08:33 |
|
Hi,
I'm currently trying to read an ecore model from an Xcore file. This is
my Xcore file:
--
package Sample
class C {
String s
Boolean b
int i
org.eclipse.emf.ecore.xml.^type.Boolean eb
}
--
And this is how I load the model (the code is run in Eclipse, that is,
it is invoked from an action, so the resource factory registries are set
up -- at least I assume that and most things work):
--
URI uri = URI.createFileURI(fileEditorInput.getPath().toString());
ResourceSet rs = new ResourceSetImpl();
res = rs.createResource(uri);
List<EObject> content = res.getContents();
Optional<EObject> optPackage =
content.stream().filter(e -> e instanceof EPackage).findFirst();
EPackage ePackage = (EPackage) optPackage.get();
--
Actually, the resource contains several models, that is:
[0] XPackage
[1] GenModel
[2] EPackage -- the one I select
[3] JvmGenericTypeImplCustom
... -- the "generated" Java classes
[10]JvmGenericTypeImplCustom
The EPackage "Sample" contains an EClass "C" as expected.
And the EClass "C" contains four EAttributes: "s", "b", i", and "eb" --
as expected.
But: The type of all attributes (EAttribute.eType, equals
EAttribute.eAttributeType) refers to a single EDataTypeImpl instance
with name "EJavaObject".
This really surprises me: I would have expected unresolved proxies or
something. But why do all attribute types refer to the very same
instance? Even the last one (which I only added for demonstrating
purposes, the type was suggested by content assist).
Do I need to pre-load other models? Do I have to configure the resource
set somehow? Do I have to pass some options when loading the resource?
Regards,
Jens
|
|
|
Re: [Xcore]? Type of EAttributes always EJavaObject [message #1737941 is a reply to message #1737926] |
Thu, 14 July 2016 09:36 |
Ed Merks Messages: 33216 Registered: July 2009 |
Senior Member |
|
|
Jens,
So this is a project in the workspace? If you do Open With ->
Reflective Xcore Model Editor, does the Ecore model look okay there?
Perhaps it's just a problem that you should open it with a
platform:/resource URI because otherwise it won't know the IJavaProject
and won't be able to resolve references based on the scope.
On 14.07.2016 10:33, Jens v.P. wrote:
> Hi,
>
> I'm currently trying to read an ecore model from an Xcore file. This
> is my Xcore file:
>
> --
> package Sample
>
> class C {
> String s
> Boolean b
> int i
> org.eclipse.emf.ecore.xml.^type.Boolean eb
> }
> --
>
> And this is how I load the model (the code is run in Eclipse, that is,
> it is invoked from an action, so the resource factory registries are
> set up -- at least I assume that and most things work):
>
> --
> URI uri = URI.createFileURI(fileEditorInput.getPath().toString());
> ResourceSet rs = new ResourceSetImpl();
> res = rs.createResource(uri);
>
> List<EObject> content = res.getContents();
> Optional<EObject> optPackage =
> content.stream().filter(e -> e instanceof EPackage).findFirst();
> EPackage ePackage = (EPackage) optPackage.get();
> --
>
> Actually, the resource contains several models, that is:
> [0] XPackage
> [1] GenModel
> [2] EPackage -- the one I select
> [3] JvmGenericTypeImplCustom
> .. -- the "generated" Java classes
> [10]JvmGenericTypeImplCustom
>
> The EPackage "Sample" contains an EClass "C" as expected.
> And the EClass "C" contains four EAttributes: "s", "b", i", and "eb"
> -- as expected.
>
> But: The type of all attributes (EAttribute.eType, equals
> EAttribute.eAttributeType) refers to a single EDataTypeImpl instance
> with name "EJavaObject".
>
> This really surprises me: I would have expected unresolved proxies or
> something. But why do all attribute types refer to the very same
> instance? Even the last one (which I only added for demonstrating
> purposes, the type was suggested by content assist).
>
> Do I need to pre-load other models? Do I have to configure the
> resource set somehow? Do I have to pass some options when loading the
> resource?
>
> Regards,
> Jens
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: [Xcore]? Type of EAttributes always EJavaObject [message #1737947 is a reply to message #1737941] |
Thu, 14 July 2016 10:22 |
|
Dear Ed,
On 14.07.16 11:36, Ed Merks wrote:
> So this is a project in the workspace?
Yes.
> If you do Open With ->
> Reflective Xcore Model Editor, does the Ecore model look okay there?
Yes.
> Perhaps it's just a problem that you should open it with a
> platform:/resource URI because otherwise it won't know the IJavaProject
> and won't be able to resolve references based on the scope.
I tried that, unfortunately without success:
--
IFile file = fileEditorInput.getFile();
String fp = file.getFullPath().toPortableString();
URI platformURI = URI.createPlatformResourceURI(fp, true);
ResourceSet rs = new ResourceSetImpl();
res = rs.createResource(platformURI);
--
The uri is correctly set to "platform:/resource/XCP/model/Sample.xcore"
(my project is called XCP).
The strange thing: I do not get any errors...
|
|
|
Re: [Xcore]? Type of EAttributes always EJavaObject [message #1737949 is a reply to message #1737947] |
Thu, 14 July 2016 10:50 |
Ed Merks Messages: 33216 Registered: July 2009 |
Senior Member |
|
|
Jens,
Can you set a breakpoint in
org.eclipse.emf.ecore.xcore.util.XcoreEcoreBuilder.getEPackage(XPackage)?
It should call
org.eclipse.emf.ecore.xcore.ui.XcoreJavaProjectProvider.getJavaProject(ResourceSet).
That should create the class loader with the necessary classpath. Is
something going wrong here? Eventually
org.eclipse.emf.ecore.xcore.util.XcoreEcoreBuilder.link() and that
should link all the references, if they resolve.
I've also just noticed that you've only done a createResource, not a
getResource(uri, true). Somehow it was loaded anyway, but I wonder if
that's a problem too.
After you've loaded the resource (which it doesn't look like you're
doing explicitly), is the Ecore.genmodel in the resource set?
On 14.07.2016 12:22, Jens v.P. wrote:
> Dear Ed,
>
> On 14.07.16 11:36, Ed Merks wrote:
>> So this is a project in the workspace?
>
> Yes.
>
> > If you do Open With ->
>> Reflective Xcore Model Editor, does the Ecore model look okay there?
>
> Yes.
>
>> Perhaps it's just a problem that you should open it with a
>> platform:/resource URI because otherwise it won't know the IJavaProject
>> and won't be able to resolve references based on the scope.
>
> I tried that, unfortunately without success:
>
> --
> IFile file = fileEditorInput.getFile();
> String fp = file.getFullPath().toPortableString();
> URI platformURI = URI.createPlatformResourceURI(fp, true);
> ResourceSet rs = new ResourceSetImpl();
> res = rs.createResource(platformURI);
> --
>
> The uri is correctly set to
> "platform:/resource/XCP/model/Sample.xcore" (my project is called XCP).
>
> The strange thing: I do not get any errors...
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: [Xcore]? Type of EAttributes always EJavaObject [message #1737975 is a reply to message #1737949] |
Thu, 14 July 2016 15:33 |
|
Ed,
On 14.07.16 12:50, Ed Merks wrote:
> Jens,
>
> Can you set a breakpoint in
> org.eclipse.emf.ecore.xcore.util.XcoreEcoreBuilder.getEPackage(XPackage)? It
> should call
> org.eclipse.emf.ecore.xcore.ui.XcoreJavaProjectProvider.getJavaProject(ResourceSet).
> That should create the class loader with the necessary classpath. Is
> something going wrong here? Eventually
> org.eclipse.emf.ecore.xcore.util.XcoreEcoreBuilder.link() and that
> should link all the references, if they resolve.
All locations you mentioned are visited and no errors occur.
> I've also just noticed that you've only done a createResource, not a
> getResource(uri, true). Somehow it was loaded anyway, but I wonder if
> that's a problem too.
Again, this is how I load:
--
String fp = file.getFullPath().toPortableString();
URI platformURI = URI.createPlatformResourceURI(fp, true);
ResourceSet rs = new ResourceSetImpl();
res = rs.getResource(platformURI, true);
res.load(Collections.emptyMap());
EcoreUtil.resolveAll(res);
--
> After you've loaded the resource (which it doesn't look like you're
> doing explicitly), is the Ecore.genmodel in the resource set?
In
XcoreEcoreBuilder.getEGenericType(XGenericType)
the type is supposed to be set. The type in the XAttribute is
xGenericType is an XGenericTypeImpl, it's type is a GenDataTypeImpl (and
it is a proxy, e.g.
eProxyURI:
platform:/resource/org.eclipse.emf.ecore/model/Ecore.genmodel#//ecore/EBooleanObject)
This is never resolved correctly.
After the resolveAll call above, the resource set contains:
[0] XcoreResource with XPackage, GenModel (of Sample), EPackage (of
Sample) and some JvmGenericTypeImpls
[1] EcoreResourceFactoryImpl:
uri='platform:/resource/org.eclipse.emf.ecore/model/Ecore.genmodel'
--> ah! and this contains a valudation error:
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException:
org.eclipse.core.internal.resources.ResourceException: Resource
'/org.eclipse.emf.ecore/model/Ecore.genmodel' does not exist.
[2] EcoreResourceFactoryImpl:
uri:
uri='platform:/resource/org.eclipse.emf.ecore/model/XMLType.genmodel'
--> also with an error: Resource
'/org.eclipse.emf.ecore/model/XMLType.genmodel' does not exist.
Where do I have to set that URI? I thought that in the workspace, this
should be configured. I mean, the Xcore stuff is found and I have not
configured anything for that (my project even has no dependency to
Xcore...).
|
|
| | | | |
Goto Forum:
Current Time: Thu Sep 19 06:10:45 GMT 2024
Powered by FUDForum. Page generated in 0.04603 seconds
|