Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Load Model
Load Model [message #1750160] Fri, 16 December 2016 14:35 Go to next message
Pascal Lacabanne is currently offline Pascal LacabanneFriend
Messages: 17
Registered: November 2016
Junior Member
Hello,

I have an issue when I load my model. I create a grammar
grammar org.xtext.Svc with org.eclipse.xtext.common.Terminals  

generate svc "http://www.xtext.org/Svc"

Domainmodel:
	(elements+=Element)*
;

Element:
   PackageDeclaration  | Environment | FaType | Exigence | Objective | Import;

PackageDeclaration :
   'package' name=QualifiedName '{'
        (elements+=Element)*
   '}';

QualifiedName:
   ID ('.' ID)*;

Import:
 'import' importedNamespace=QualifiedNameWithWildcard;
    
QualifiedNameWithWildcard:
    QualifiedName '.*'?;

Environment:
	'ENV_TYPE' name=ID
	'[BEGIN]'
	    '[BEG_DESC]'
	     (desc=STRING)
	    '[END_DESC]'
	'[END]' 
;

Exigence:
	'EXI_TYPE' name=ID
	'[BEGIN]'
	    '[BEG_DESC]'
	     (desc=STRING)?
	    '[END_DESC]'
	'[END]' 
;

FaType:
	'FAN_TYPE' name=ID 
	'[BEGIN]'
		'[BEG_OBJ]'
		 (objective+=[Objective] ("," objective+=[Objective])* )?
		'[END_OBJ]'
		'[BEG_ENV]'
		 (env=[Environment])?
		'[END_ENV]'
		'[BEG_MEANS]'
		 (means=STRING )?
		'[END_MEANS]'
		'[NOREG]'
		 (noreg=STRING )?
		'[END_NOREG]'
	'[END]'
;

Objective:
	'OBJ_TYPE' name=ID
	'[BEGIN]'
	    '[BEG_DESC]'
	     (desc=STRING)
	    '[END_DESC]'
	    '[BEG_CHCK]'
	     (checklist=STRING)?
	    '[END_CHCK]'
	'[END]' 
;


Next, I create 2 files:
Environment.svc
package environment {

ENV_TYPE E12
[BEGIN]
[BEG_DESC]
"My description"
[END_DESC]
[END]
}


FicheAnalyse.svc
package fan1 {
	
	import environment.E12
	
OBJ_TYPE objectif1 
[BEGIN]
[BEG_DESC]
"My first objective."
[END_DESC]
[BEG_CHCK]
[END_CHCK]
[END]


OBJ_TYPE objectif2
[BEGIN]
[BEG_DESC]
"My Second objective."
[END_DESC]
[BEG_CHCK]
[END_CHCK]
[END]


FAN_TYPE fan1
[BEGIN]
[BEG_OBJ]
objectif1,objectif2
[END_OBJ]
[BEG_ENV]
E12
[END_ENV]
[BEG_MEANS]
[END_MEANS]
[NOREG]
[END_NOREG]
[END]

}


When I try to retrieve my objects, I do this with Files is a string array:
for (int iFile = 0; iFile < files.length; iFile++) {
       String file = files[iFile];
       SvcRunner svcrunner = new SvcRunner();
      eleImpl = svcrunner.tradSvc("platform:/resource/" + project + "/" + src + "/" + file);
}

public List<ElementImplTex> tradSvc(String uri) {
      Injector injector = new SvcStandaloneSetup().createInjectorAndDoEMFRegistration();
     XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
    resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
    Resource resource = resourceSet.getResource(URI.createURI(uri), true);
    
......


I retrieve my object environment E12 correctly but when I retrieve my Fan1 Object, the environment E12 is empty (all this attribut are null)

I would like to retrieve my objects correctly. How I do that ?

Pascal
Re: Load Model [message #1750162 is a reply to message #1750160] Fri, 16 December 2016 14:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Never ever call standalonesetup from eclipse

http://koehnlein.blogspot.de/2012/11/xtext-tip-how-do-i-get-guice-injector.html?m=1

Use iresourcesetprovider to obtain a project specific resourceset

And don't use the resolve all load option


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Fri, 16 December 2016 14:47]

Report message to a moderator

Re: Load Model [message #1750971 is a reply to message #1750162] Tue, 03 January 2017 09:08 Go to previous message
Pascal Lacabanne is currently offline Pascal LacabanneFriend
Messages: 17
Registered: November 2016
Junior Member
Sorry for my late response (I return from holidays)
Thank you
Previous Topic:in-editor error message on the wrong cross-reference
Next Topic:Disable invokation of the generator when a generated file change
Goto Forum:
  


Current Time: Fri Mar 29 13:05:18 GMT 2024

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

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

Back to the top