Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » name auto generation
name auto generation [message #1732292] Sun, 15 May 2016 07:27 Go to next message
Parisa Moosavi is currently offline Parisa MoosaviFriend
Messages: 81
Registered: June 2015
Member
Hi,

I need to auto generate the value of name in this rule:
Sequence returns Sequence:
	'Sequence'
	name=EString
	'{'
		('permissions' '{' permissions+=Permission ( "," permissions+=Permission)* '}' )?
		 body=Task
		 follower=Task
	'}';


I tried to implement it in validation
class XwcoreValidator extends AbstractXwcoreValidator {



	@Check
	def CheckNullNameForSequence(Sequence sequence){
		if (sequence.name.empty){
			sequence.setName("example_name")
		}
	}
}


but it's not possible. How can I do it? I need to generate name for some rules automatically when the user the keyword of the rule for example 'Sequence'.
Re: name auto generation [message #1732293 is a reply to message #1732292] Sun, 15 May 2016 07:36 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13219
Registered: July 2009
Senior Member
Do you need to set it physically ( that would be a usecase for iderivedstatecomputer) or just logically (e.g. To be able to reference it - then simply adapt your iqualifiednameprovider) so give us some hints WHY you need that name

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: name auto generation [message #1732295 is a reply to message #1732293] Sun, 15 May 2016 08:22 Go to previous messageGo to next message
Parisa Moosavi is currently offline Parisa MoosaviFriend
Messages: 81
Registered: June 2015
Member
- it would be used later to with code generator. I need to the names because it's not easy for user to write name for each sequence because there will be many sequences in eachother.

I prefer to generate the name automatically and don't show it to user to make the dsl easier to write and understand for user.

and behind this grammatic I have a metamodel which I can't change or modify it. here is an example:

			Sequence seq96 {
			Create BegriffEingabeErzeugen {
				BegriffEingabe :=  new ecoreI.BegriffEingabe
			}
			Sequence seq960 {
			InvokeGUI BegriffEditieren {
				( BegriffEingabe ) <- page gcoreI.EditiereBegriff ( BegriffEingabe )
			}
			Sequence seq94 {
			Create BegriffErzeugen {
				Begriff :=  ecoreI.BegriffContainer.alleBegriffe + new ecoreI.Begriff 
			}
			Sequence seq93 {
			InvokeOperation ImportEingabe {
				context Begriff ecoreI.Begriff.importBegriffEingabe ( BegriffEingabe )
			}
			Sequence seq92 { 
			Create ErzeugeThema {
				Thema := ecoreI.BegriffContainer.alleThemen + new ecoreI.Thema 
			}
			Sequence seq91 {
			InvokeOperation SetzeThema {
				context Thema  ecoreI.Thema.setThema0  ( EIGENES )
			}
			Sequence seq90 {
			InvokeOperation SetzeThemaBegriff {
				context Begriff  ecoreI.Begriff.setzeThema ( Thema )
			}
			Sequence seq89 {
			Create BildAnlegenErzeugen {
				BildAnlegen := new ecoreI.BildAnlegen
			}
			Sequence seq88 {
			InvokeGUI BildAnlegenJaNein {
				( BildAnlegen ) <- page gcoreI.BildAnlegenJaNein ( BildAnlegen )
			}
			Sequence seq87 {
			InvokeOperation GetTrue {
				context BegriffContainer  ecoreI.BegriffContainer.getTrue ( TRUE )
			}
			Sequence seq86 {
			InvokeOperation GetBildAnlegenResult {
				context BildAnlegen  ecoreI.BildAnlegen.getBooleanBild return
				Ergebnis
			}
			Sequence seq85 {
			If Cond0 {
				condition  ( Ergebnis ==  TRUE )
				body Sequence seq4 {
				synchronized InvokeProcess AufrufCBild {
					subProcess CBild return ( Bild )
				} //AufrufCBild
				//Sequence SetzeBild {
				InvokeOperation SetzeBild {
					context Begriff  ecoreI.Begriff.setzeBild  ( Bild )
				}
				//} //SetzeBild

			} //seq4

			} //IF
			Sequence seq84 {
			Create AudioAnlegenErzeugen {
				AudioAnlegen := new ecoreI.AudioAnlegen
			}
			Sequence seq83 {
			InvokeGUI AudioAnlegenJaNein {
				( AudioAnlegen ) <- page gcoreI.AudioAnlegenJaNein ( AudioAnlegen )
			}
			Sequence seq82 {
			InvokeOperation GetAudioAnlegenResult {
				context AudioAnlegen ecoreI.AudioAnlegen.getBooleanAudio
				return Ergebnis
			}
			Sequence seq81 {
			If Cond1 {
				condition  ( Ergebnis ==  TRUE)
				body Sequence seq8 {
				synchronized InvokeProcess AufrufCAudio {
					subProcess CAudio return ( Audio )
				} //AufrufCAudio
				InvokeOperation SetzeAudio {
					context wcoreI.WortAnlegen.AntwortenAnlegen ecoreI.Begriff.setzeAudio  ( Audio )
				} //SetzeAudio

			} //seq8

			} //if
			Sequence seq100 {
			Create AntwortenAnlegenErzeugen {
				AntwortenAnlegen := new ecoreI.AntwortenAnlegen
			} // Create AntwortenAnlegenErzeugen
			Sequence seq110 {
			InvokeGUI AntwortenAnlegenJaNein {
				( AntwortenAnlegen ) <- page gcoreI.AntwortenAnlegenJaNein (
				AntwortenAnlegen )
			} //InvokeGUI AntwortenAnlegenJaNein
			Sequence seq111 {
			InvokeOperation GetAntwortenAnlegenResult {
				context AntwortenAnlegen 
				ecoreI.AntwortenAnlegen.getBooleanAntworten return Ergebnis
			} //InvokeOperation GetAntwortenAnlegenResult
			If Cond100 {
				condition ( Ergebnis== TRUE)
				body Sequence seq112 {
				synchronized InvokeProcess CAntwort {
					subProcess CAntwort arguments ( AntwortListe ) return ( AntwortListe )
				} //InvokeProcess CAntwort
				Sequence seq113 {
				synchronized InvokeProcess CAntwort1 {
					subProcess CAntwort1 arguments ( AntwortListe ) return ( AntwortListe )
				} //InvokeProcess CAntwort1
				InvokeOperation AntwortListeInBegriff {
					context Begriff  ecoreI.Begriff.setzeAntworten  ( AntwortListe )
				} //InvokeOperation AntwortListeInBegriff

			} //Sequence seq113

			} //seq112

			} // If Cond100

		} //Sequence seq111 

		} //seq110

		} //seq100

		} //seq81

		} //seq82

		} //seq83

		} //seq84

		} //seq85

		} //seq86

		} //seq87

		} //seq88

		} //seq89

		} //seq90

		} //seq91

		} //seq92

		} //seq93

		} //seq94

		} //seq95

		} //seq96



I'm trying to make it as easy as possible through the xtext's abilities.
Re: name auto generation [message #1732297 is a reply to message #1732295] Sun, 15 May 2016 08:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13219
Registered: July 2009
Senior Member
sounds more like a derivedstatecomputer

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: name auto generation [message #1732298 is a reply to message #1732297] Sun, 15 May 2016 08:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13219
Registered: July 2009
Senior Member
or alternativeley and more hacky to adapt org.eclipse.xtext.parser.DefaultEcoreElementFactory

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: name auto generation [message #1732299 is a reply to message #1732298] Sun, 15 May 2016 08:46 Go to previous messageGo to next message
Parisa Moosavi is currently offline Parisa MoosaviFriend
Messages: 81
Registered: June 2015
Member
the sequences are the steps which should be done after each other in a method. Is it possible to change the visibilities of name to false ?

If it's possible then I can generate the names and assign them an user don't see the names and then I can omit 'Sequence'. But I don't know if I can do it with validation or not. I will try it!
Re: name auto generation [message #1732307 is a reply to message #1732298] Sun, 15 May 2016 12:36 Go to previous messageGo to next message
Parisa Moosavi is currently offline Parisa MoosaviFriend
Messages: 81
Registered: June 2015
Member
although I set the value but it doesn't change!
	@Check
	def CheckNullNameForSequence(Sequence sequence){
		println(sequence.name)
		if (sequence.name == null){
			sequence.setName("example_name")
		}
	}

why it doesn't change?
Re: name auto generation [message #1732308 is a reply to message #1732307] Sun, 15 May 2016 12:44 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13219
Registered: July 2009
Senior Member
Cause the validator is not the place for that. I named you two other possible places

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: name auto generation [message #1732311 is a reply to message #1732308] Sun, 15 May 2016 15:20 Go to previous message
Parisa Moosavi is currently offline Parisa MoosaviFriend
Messages: 81
Registered: June 2015
Member
thanks for helps,
I have done it with
class MyDerivedStateComputer implements IDerivedStateComputer {
	
	override discardDerivedState(DerivedStateAwareResource resource) {
		resource.allContents.filter(typeof(Sequence)).forEach[name = ""]
	}
	
	override installDerivedState(DerivedStateAwareResource resource, boolean preLinkingPhase) {

		resource.allContents.filter(typeof(Sequence)).forEach[
			name = "seq_" + body.name
		]
	}
	
}

and change the grammar to
Sequence returns Sequence:

	'Sequence'
	(name=EString)?
	'{'
		('permissions' '{' permissions+=Permission ( "," permissions+=Permission)* '}' )?
		 body=Task
		 follower=Task
	'}';

that the user doesn't need to input the name.
But finally I would write a book "Xtext in Practice" Smile and when I start it, I will let you know.
Previous Topic:Xtext recursive statement
Next Topic:How to show a word as a keyword inside a statement
Goto Forum:
  


Current Time: Thu Nov 21 19:45:22 GMT 2019

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

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

Back to the top