Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to change a resource(Adding, removing nodes of AST)
How to change a resource [message #1726195] Thu, 10 March 2016 13:46 Go to next message
Grigory Boytsov is currently offline Grigory BoytsovFriend
Messages: 5
Registered: March 2016
Junior Member
Hello,

I have a resourceset, that I've copied using the method EcoreUtil2::clone(newResSet, currentResSet). And than, I'm trying to change the resource of the new resource set newResSet.
Can I add, remove or replace a node of AST in this resource?

Thanks,
Grigory
Re: How to change a resource [message #1726204 is a reply to message #1726195] Thu, 10 March 2016 14:24 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14062
Registered: July 2009
Senior Member
Hi,

i am not sure if i get you. but yes you can manipulate the ast (YourDslFactory has methods for creating new Stuff)
if you then save the resource it will be serialized.


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to change a resource [message #1726211 is a reply to message #1726204] Thu, 10 March 2016 14:41 Go to previous messageGo to next message
Grigory Boytsov is currently offline Grigory BoytsovFriend
Messages: 5
Registered: March 2016
Junior Member
Thanks for answer.
I mean, that I want to replace the node of my AST. I've an AST and I need to replace some of nodes to my own nodes, which have other types.
Re: How to change a resource [message #1726217 is a reply to message #1726211] Thu, 10 March 2016 15:01 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14062
Registered: July 2009
Senior Member
yes this should be no Problem. can you share a small example grammar and code (Java main/unit test)?

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to change a resource [message #1726291 is a reply to message #1726217] Fri, 11 March 2016 07:00 Go to previous messageGo to next message
Grigory Boytsov is currently offline Grigory BoytsovFriend
Messages: 5
Registered: March 2016
Junior Member
This is a grammar:

var_typedef_declaration:	
	(type_def ?= 'typedef')? var = variable_declaration
;

function_prototype:
	var = variable_declaration
;



Code:


@Check
def validateModel(Model model)
{
		
	var ResourceSet newResSet = null;
	var LazyLinkingResource res = null;
	newResSet = new ResourceSetImpl();
	var ResourceSet curResSet = model.eResource.resourceSet;
				
	EcoreUtil2::clone(newResSet, curResSet);
	res = newResSet.resources.get(0) as LazyLinkingResource;

        ...

	var f_prop = EmbeddecyFactory.eINSTANCE.createfunction_prototype;
	res.allContents.toList.set(i, f_prop);  // doesn't work
}



I want to replace var_typedef_declaration with function_prototype.
Re: How to change a resource [message #1726292 is a reply to message #1726291] Fri, 11 March 2016 07:07 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14062
Registered: July 2009
Senior Member
hi,

but why in a check?
what should be the outcome of this?
you want to edit inplace the model the user Edits?


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Fri, 11 March 2016 07:08]

Report message to a moderator

Re: How to change a resource [message #1726293 is a reply to message #1726292] Fri, 11 March 2016 07:14 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14062
Registered: July 2009
Senior Member
btw to list creates a copy.

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to change a resource [message #1726343 is a reply to message #1726293] Fri, 11 March 2016 15:05 Go to previous messageGo to next message
Grigory Boytsov is currently offline Grigory BoytsovFriend
Messages: 5
Registered: March 2016
Junior Member
I need to modify the tree to make it easier to perform validation and generation.

res.contents.set(i, f_prop)  //contents may be directly modified. It works!


But this list (res.contents) contains only the root of the tree.
Re: How to change a resource [message #1726347 is a reply to message #1726343] Fri, 11 March 2016 15:25 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14062
Registered: July 2009
Senior Member
Id use a derived state computer for that instead of doing a clone or in
place trading

http://xtextcasts.org/episodes/18-model-optimization


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to change a resource [message #1727012 is a reply to message #1726347] Fri, 18 March 2016 09:24 Go to previous message
Grigory Boytsov is currently offline Grigory BoytsovFriend
Messages: 5
Registered: March 2016
Junior Member
Thanks a lot Christian!
Previous Topic:XText grammar for .xtext files
Next Topic:Upgrading from 2.8 to 2.9
Goto Forum:
  


Current Time: Tue Sep 21 12:14:08 GMT 2021

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

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

Back to the top