Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Xcore]? Type of EAttributes always EJavaObject
[Xcore]? Type of EAttributes always EJavaObject [message #1737926] Thu, 14 July 2016 08:33 Go to next message
Jens von Pilgrim is currently offline Jens von PilgrimFriend
Messages: 313
Registered: July 2009
Senior Member
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 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
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 Go to previous messageGo to next message
Jens von Pilgrim is currently offline Jens von PilgrimFriend
Messages: 313
Registered: July 2009
Senior Member
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 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
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 Go to previous messageGo to next message
Jens von Pilgrim is currently offline Jens von PilgrimFriend
Messages: 313
Registered: July 2009
Senior Member
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...).
Re: [Xcore]? Type of EAttributes always EJavaObject [message #1737976 is a reply to message #1737975] Thu, 14 July 2016 15:43 Go to previous messageGo to next message
Jens von Pilgrim is currently offline Jens von PilgrimFriend
Messages: 313
Registered: July 2009
Senior Member
As a hack, I added the following line (after creating the resource set):

rs.getURIConverter().getURIMap().putAll(EcorePlugin.computePlatformURIMap(true));

Now it works. Hmm... how am I supposed to do that correctly?
Re: [Xcore]? Type of EAttributes always EJavaObject [message #1737984 is a reply to message #1737976] Thu, 14 July 2016 16:24 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Jens,

That is exactly what the EcoreEditor does:

public void createModel()
{
boolean isReflective = getActionBarContributor() instanceof
EcoreActionBarContributor.Reflective;

final ResourceSet resourceSet = editingDomain.getResourceSet();
final EPackage.Registry packageRegistry =
resourceSet.getPackageRegistry();
resourceSet.getURIConverter().getURIMap().putAll(EcorePlugin.computePlatformURIMap(true));

This is also done in
org.eclipse.xtext.ui.resource.JavaProjectResourceSetInitializer.computePlatformURIMap(IJavaProject)
which is why Xcore normally just works in the Xcore editor (I assume).
It's also done in
org.eclipse.emf.ecore.xcore.exporter.XcoreExporter.doExport(Monitor,
ExportData).

That is the correct way. :-)

I think alternatively you'd create a resource set using the right
injector...



On 14.07.2016 17:43, Jens v.P. wrote:
> As a hack, I added the following line (after creating the resource set):
>
> rs.getURIConverter().getURIMap().putAll(EcorePlugin.computePlatformURIMap(true));
>
>
> Now it works. Hmm... how am I supposed to do that correctly?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [Xcore]? Type of EAttributes always EJavaObject [message #1737986 is a reply to message #1737984] Thu, 14 July 2016 17:09 Go to previous messageGo to next message
Jens von Pilgrim is currently offline Jens von PilgrimFriend
Messages: 313
Registered: July 2009
Senior Member
Ed,

Thank you very much! Now I feel much better -- knowing my hack is the
correct way :-)

When I'm done, we will have a tool to create OmniGraffle diagrams from
Xcore files.

Cheers,
Jens
Re: [Xcore]? Type of EAttributes always EJavaObject [message #1738004 is a reply to message #1737986] Thu, 14 July 2016 20:50 Go to previous message
Jens von Pilgrim is currently offline Jens von PilgrimFriend
Messages: 313
Registered: July 2009
Senior Member
Just updated the update site of j2og (Java2OmniGraffle). The tool can
now not only create diagrams from Java sources, but from ecore or xcore
models as well. It recognizes some EMF specific features (containment,
derived attributes) and allows for some configuration (e.g., hide
operations etc.).

See http://jpilgrim.github.io/eclipsetools/j2og/ for details.

Cheers,
Jens
Previous Topic:CDO failed to register channel eclipse on Neon
Next Topic:Tool support for the generation of the instance model of an Ecore model
Goto Forum:
  


Current Time: Thu Apr 25 08:37:16 GMT 2024

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

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

Back to the top