Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Split model(Model)
Split model [message #1153217] Thu, 24 October 2013 09:05 Go to next message
Eclipse UserFriend
Hi,
I want to split my model in separate logical documents and then import them to one
main model.
Is this possible? If it is how should I do it?
/Gunnar
Re: Split model [message #1153286 is a reply to message #1153217] Thu, 24 October 2013 10:04 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

i am not quite sure what you mean.

"the model" is the sum of all files of a specific dsl.

the question is: what do you do with "the model".
you may have a look at http://kthoms.wordpress.com/2011/07/12/xtend-generating-from-multiple-input-models/ if this is your question
Re: Split model [message #1154553 is a reply to message #1153286] Fri, 25 October 2013 05:21 Go to previous messageGo to next message
Eclipse UserFriend
Hi Christian,
You are right!

The problem I have is actually with validation.
I have a list of accounts which are defined by a name=ID

Then I have two checks for accounts.
The first is that the account ID is unique.
This works fine if I have all accounts in one file,
but if they are split in two the uniqueness check fails.

The other check (a warning) is that the account should be used later on in the model.
This also fails when the accounts is in one file and another file contains the part of the model where the account is used. In this case I get a warning for all my accounts.

Regards
/Gunnar
Re: Split model [message #1154554 is a reply to message #1154553] Fri, 25 October 2013 05:23 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

have a look at http://www.eclipse.org/forums/index.php/m/766678/
Re: Split model [message #1154739 is a reply to message #1154554] Fri, 25 October 2013 08:17 Go to previous messageGo to next message
Eclipse UserFriend
Hi Christian,
Thanks for your help!
I can now check for duplicate account but not verify that they are used.
I can get a list of all settlements where the accounts should be used.
The problem is that the settlements does not contain any data (except for the default value of an enum.
Regards
Gunnar
Re: Split model [message #1154764 is a reply to message #1154739] Fri, 25 October 2013 08:39 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

you can traverste the index for references too...

@Inject
private ResourceDescriptionsProvider resourceDescriptionsProvider;
public boolean isReferenced(final EObject object) {
		if (object.eIsProxy()) {
			return false; 
		final IResourceDescriptions descriptions = getResourceDescriptions(object);
		if (descriptions == null) {
			LOG.error("'resourceDescriptions' wurden nicht gefunden.", new IllegalStateException());
		} else {
			final URI objectUri = EcoreUtil.getURI(object);
			if (objectUri != null) {
				final Iterable<IResourceDescription> allResourceDescriptions = descriptions
						.getAllResourceDescriptions();
				for (final IResourceDescription rd : allResourceDescriptions) {
					for (final IReferenceDescription refd : rd.getReferenceDescriptions()) {
						final URI targetEObjectUri = refd.getTargetEObjectUri();
						if (objectUri.equals(targetEObjectUri)) {
							return true;
						}
					}
				}
			}
		}
		return false;
	}

	public IResourceDescriptions getResourceDescriptions(final EObject object) {
		Resource resource = object.eResource();
		if (resource != null) {
			return resourceDescriptionsProvider.getResourceDescriptions(resource);
		} else {
			//TODO
return null;
		}
	}
Re: Split model [message #1159067 is a reply to message #1154764] Mon, 28 October 2013 05:18 Go to previous messageGo to next message
Eclipse UserFriend
Hi Christian,
I've adapted the code to my xtend validator and call it from a @Check method.
It works but the warning message does not appear if I just add extra characters
to the account name. It appears when I add a character to another account.

A similar behavior happens when I remove characters and the account should not show any warning.

It seems like the model is not updated as I expect.
shall the model be updated for each keystroke?


When a "@Check method" is called and I have the model as the parameter only part of the model is filled. When I change the accounts page I only get the accounts and when I change the settlement page only settlements are filled.
Is this the expected behavior?
How can i navigate from account -> accounts -> model -> settlements?

/Gunnar
Re: Split model [message #1159087 is a reply to message #1159067] Mon, 28 October 2013 05:32 Go to previous messageGo to next message
Eclipse UserFriend
No,

it is only upated on save. thus you should change it it @check(tychecktype.normal)
Re: Split model [message #1159119 is a reply to message #1159087] Mon, 28 October 2013 05:58 Go to previous messageGo to next message
Eclipse UserFriend
Hi,
That will just change when the check is called (to save time) but
the problems about when the warnings appears and disappears are still the same.
Also that the model is not fully populated remains.
/Gunnar
Re: Split model [message #1159125 is a reply to message #1159119] Mon, 28 October 2013 06:01 Go to previous messageGo to next message
Eclipse UserFriend
As said before:
You have to take care yourself to collect all information from the
split up model (e.g. in the generator)

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Re: Split model [message #1159319 is a reply to message #1159125] Mon, 28 October 2013 08:51 Go to previous messageGo to next message
Eclipse UserFriend
Hi,
It feels like Xtext will punish me when I want to split the model!
If I have the whole model in one page the @Check validator methods are called as expected,
but if I split the model in different pages I get a different behavior!

/Gunnar
Re: Split model [message #1159345 is a reply to message #1159319] Mon, 28 October 2013 09:11 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

without any sample code hard to tell anything.

~Christian
Re: Split model [message #1160614 is a reply to message #1159345] Tue, 29 October 2013 04:32 Go to previous messageGo to next message
Eclipse UserFriend
Hi Christian,
I have uploaded a small test project.
The model looks like this:
Model:
{Model}
('Accounts' accounts+=Account*)?
('Settlements' settlements+=Settlement*)?;
Account:
name=ID ';';
Settlement:
name=ID account=[Account]';';

The test data is :
Accounts
a1;
b2;
c3;
and
Settlements
s1 a1;
s2 b2;
s3 c3;

If the accounts and settlements are in the same file model.mydsl then the editor complains that the accounts are not used.

If I debug the checkUniqueAccounts method which takes the model as in parameter, the model entries accounts and settlements are different if I change a file with only, accounts, only settlements or have both.

/Gunnar


  • Attachment: mydsl.zip
    (Size: 1.56MB, Downloaded 216 times)
Re: Split model [message #1160622 is a reply to message #1160614] Tue, 29 October 2013 04:40 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

i think we dont talk on the same thing.

the logical model is all model files.
physically you have 3 files.

you have to deal with that yourself (NO MAGIC)
Re: Split model [message #1160746 is a reply to message #1160622] Tue, 29 October 2013 06:24 Go to previous messageGo to next message
Eclipse UserFriend
Hi Christian,
Thanks for your help!
I think i'm confused by the terminology here and as you say we don't talk about the same thing.

The model is as I understand it what is defined in the file with xtext extension: MyDsl.xtext.

Then I start the "debug as Eclipse Application" where I create a new project with Xtext nature.

In this project I have created and played around with three files with extension mydsl:
Accounts.mydsl, Settlements.mydsl and Both.mydsl.

The behavior of the editor is different depending on where I have the accounts and settlements which I try to understand.

1) If Accounts.mydsl and Settlements.mydsl are both empty and the file Both.mydsl contains accounts and settlements then the checkNotUsedAccounts will give a warning that the accounts is not used in a settlement. When I debug the checkUniqueAccounts which takes the Model as a parameter I can see all accounts and settlements.

2) If Accounts.mydsl contains the accounts, the Settlements.mydsl contains the settlements and file Both.mydsl is empty then the checkNotUsedAccounts will not give any warnings. When I debug the checkUniqueAccounts which takes the Model as a parameter I can see all accounts if I save the Accounts.mydsl file but no settlements. If I save the Settlements.mydsl file I can see the settlements but no accounts.

I would like to have just the Accounts.mydsl and Settlements.mydsl files, and when the checkUniqueAccounts method is called the model argument should contain both accounts and settlements.

Is this possible?
/Gunnar
Re: Split model [message #1160752 is a reply to message #1160746] Tue, 29 October 2013 06:27 Go to previous messageGo to next message
Eclipse UserFriend
Depends on your implementation of checkUniqueAccounts
(if you set it to CheckType.NORMAL and use the index as i sugessted it should work)

same for the checkNotUsedAccounts (maybe it is better to make this check expensive)
Re: Split model [message #1160834 is a reply to message #1160752] Tue, 29 October 2013 07:34 Go to previous messageGo to next message
Eclipse UserFriend
Hi,
I've uploaded the xtext model project. As you can see there I've used the code that you proposed for checkNotUsedAccount and it is marked as CheckType.Normal. That code does bot work if accounts and settlements are in the same .mydsl file!

What do you mean by "maybe it is better to make this check expensive"?

CheckUniqueAccounts works fine for checking unique accounts, because they are all in the same file.
I only used that show that the root Model data is not filled with all data as I expect it to be.
/Gunnar
Re: Split model [message #1160894 is a reply to message #1160834] Tue, 29 October 2013 08:27 Go to previous messageGo to next message
Eclipse UserFriend
I will see if i find the time to download the zip and have a look (works only at home)
Re: Split model [message #1160905 is a reply to message #1160894] Tue, 29 October 2013 08:40 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

i got it to download the zip.
it works as expected.
if i add an account to acounts and save it i get the warning as expected.

P.S: you have to retouch the account file if you added it to a settlement or
run a clean build on the project

P.PS: has your sample project any spaces in the name? or umlauts? maybe the normalzing/comparing of uris doesnt work as expected.

[Updated on: Tue, 29 October 2013 08:43] by Moderator

Re: Split model [message #1160943 is a reply to message #1160905] Tue, 29 October 2013 09:15 Go to previous messageGo to next message
Eclipse UserFriend
Hi,
I don't use any spaces or special characters.
The path to the project is /big/proj/workspaces/runtime-EclipseXtext/MyDsl
I'm using Ubuntu 12.04, if that matters.

Have you got it to work with accounts and settlements in the same file?

What about the calls to checkUniqueAccounts and the different content of the model argument?

I often have to change and save one or more files.

/Gunnar
Re: Split model [message #1161020 is a reply to message #1160943] Tue, 29 October 2013 10:22 Go to previous messageGo to next message
Eclipse UserFriend
hmm strange,

no i dont have them in the same file.
Re: Split model [message #1161052 is a reply to message #1161020] Tue, 29 October 2013 10:47 Go to previous messageGo to next message
Eclipse UserFriend
Hi,
Another question:
Assume that I have a check method that takes an Account as parameter.
How can I navigate to the settlements?
I.e account -> accounts -> Model -> settlements

I've tried to do it but I'm failing.
/Gunnar
Re: Split model [message #1161063 is a reply to message #1161052] Tue, 29 October 2013 10:58 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

you want to get all settelments? what do you exactly want to do? please note: on a bug model it may be very slow to load all
settlements.
Re: Split model [message #1161077 is a reply to message #1161063] Tue, 29 October 2013 11:07 Go to previous messageGo to next message
Eclipse UserFriend
p.s.
maybe this one helps

import java.util.HashSet;
import java.util.Set;

import javax.inject.Inject;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.xtext.resource.IContainer;
import org.eclipse.xtext.resource.IEObjectDescription;
import org.eclipse.xtext.resource.IResourceDescription;
import org.eclipse.xtext.resource.IResourceDescriptions;
import org.eclipse.xtext.resource.impl.ResourceDescriptionsProvider;

public class Util {
	@Inject
	private IContainer.Manager containerManager;

	@Inject
	private ResourceDescriptionsProvider rdp;

	public <T extends EObject> Set<T> getFromIndex(EObject ctx, final EClass type) {
		final Set<T> result = new HashSet<T>();

		ResourceSet rs = ctx.eResource().getResourceSet();

		final IResourceDescriptions resDesc = rdp.getResourceDescriptions(rs);

		final IResourceDescription resourceDescription = resDesc.getResourceDescription(ctx.eResource().getURI());
		if (resourceDescription == null) {
			return result;
		}
		final IContainer container = containerManager.getContainer(resourceDescription, resDesc);

		for (final IResourceDescription indexedResourceDesc : container.getResourceDescriptions()) {
			for (final IEObjectDescription ieod : indexedResourceDesc.getExportedObjectsByType(type)) {
				if (ieod.getEClass().eIsProxy()) {
					continue;
				}
				EObject proxy = ieod.getEObjectOrProxy();
				rs.getResource(ieod.getEObjectURI().trimFragment(), true);
				proxy = EcoreUtil.resolve(proxy, rs);
				if (!proxy.eIsProxy()) {
					result.add((T) proxy);
				}
			}
		}
		return result;
	}

}
Re: Split model [message #1169738 is a reply to message #1161020] Mon, 04 November 2013 01:44 Go to previous messageGo to next message
Eclipse UserFriend
Christian Dietrich wrote on Tue, 29 October 2013 10:22
hmm strange,

no i dont have them in the same file.


Please put accounts and settlements in the same file.
I expect that you will not get the same result.
/Gunnar
Re: Split model [message #1169785 is a reply to message #1169738] Mon, 04 November 2013 02:27 Go to previous messageGo to next message
Eclipse UserFriend
Can you please share your test model. I will have a look this evening

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Re: Split model [message #1169897 is a reply to message #1169785] Mon, 04 November 2013 04:10 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

The model is the same as I uploaded earlier.

Here is the test data.
Accounts
a1;
b2;
c3;
c5;

Settlements
s1 a1;
s2 b2;
s3 c3;
s4 c5;

/Gunnar
Re: Split model [message #1169909 is a reply to message #1169897] Mon, 04 November 2013 04:18 Go to previous messageGo to next message
Eclipse UserFriend
And what is that bad behaviour?

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Re: Split model [message #1169936 is a reply to message #1169909] Mon, 04 November 2013 04:42 Go to previous messageGo to next message
Eclipse UserFriend
Hi,
There is a warning for all accounts that they are not used in any settlement
if settlements and accounts are defined in the same file.

When debugging the method getAllResourceDescriptions() returns different results depending on if accounts and settlements are defined in the same file or not.
Is this a bug or expected behavior?

/Gunnar
Re: Split model [message #1169937 is a reply to message #1169936] Mon, 04 November 2013 04:44 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

please specify what you mean by "different results".
each file gives a IResourceDescription.
Re: Split model [message #1169950 is a reply to message #1169937] Mon, 04 November 2013 04:51 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

You have all the code in the uploaded project.

The result form getAllResourceDescriptions when accounts and settlements are in the same file:

[org.eclipse.xtext.builder.builderState.impl.ResourceDescriptionImpl@6c08ae6f (URI: platform:/resource/MyDsl/Both.mydsl, importedNames: null)]


The result form getAllResourceDescriptions when accounts and settlements are in different files:

[org.eclipse.xtext.builder.builderState.impl.ResourceDescriptionImpl@5afbfbc2 (URI: platform:/resource/MyDsl/Both.mydsl, importedNames: [c3, b2, a1, c5]), org.eclipse.xtext.builder.builderState.impl.ResourceDescriptionImpl@554dac38 (URI: platform:/resource/MyDsl/Accounts.mydsl, importedNames: null), org.eclipse.xtext.builder.builderState.impl.ResourceDescriptionImpl@5e65bc48 (URI: platform:/resource/MyDsl/Settlements.mydsl, importedNames: [])]

/Gunnar
Re: Split model [message #1169975 is a reply to message #1169950] Mon, 04 November 2013 05:12 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

i still do not get what your actual problerm is?
Re: Split model [message #1170063 is a reply to message #1169975] Mon, 04 November 2013 06:32 Go to previous messageGo to next message
Eclipse UserFriend
Hi,
The main problem is that the code behaves differently if the dsl is split or not in different files.
I would like that the customer should be able to do the choice.
Perhaps I have missed something important.
/Gunnar


Re: Split model [message #1170154 is a reply to message #1170063] Mon, 04 November 2013 07:50 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

sorry, but i still do not understand. what do you mean with "the code"
Re: Split model [message #1170190 is a reply to message #1170154] Mon, 04 November 2013 08:12 Go to previous messageGo to next message
Eclipse UserFriend
Hi,
I.e MyDslValidator @Check methods
I've adapted the isReferenced method you provided. Please look in the project uploaded.
/Gunnar
Re: Split model [message #1170673 is a reply to message #1170190] Mon, 04 November 2013 15:18 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

ok, i now see the problem.
the problem is that local references are actually not indexed. you have to check them yourself.
(you may have a look at org.eclipse.xtext.ui.editor.findrefs.DefaultReferenceFinder.findReferences(Iterable<URI>, Iterable<URI>, ILocalResourceAccess, IAcceptor<IReferenceDescription>, IProgressMonitor))
Re: Split model [message #1171396 is a reply to message #1170673] Tue, 05 November 2013 02:50 Go to previous messageGo to next message
Eclipse UserFriend
Hi,
Thanks for the help!
I will look into the class/method.
The follow up question is:
Why are not local references indexed? Is it by design, a bug or should I file a feature request?
/Gunnar
Re: Split model [message #1171509 is a reply to message #1171396] Tue, 05 November 2013 04:26 Go to previous message
Eclipse UserFriend
Hi the indexing code implies it is a feature but does not say why

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Previous Topic:Resolving correct inferred variable
Next Topic:Format multiple files at once
Goto Forum:
  


Current Time: Wed Jul 23 13:44:55 EDT 2025

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

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

Back to the top