Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Postprocessing set field
Postprocessing set field [message #841573] Wed, 11 April 2012 13:35 Go to next message
Thomas Hergenröder is currently offline Thomas HergenröderFriend
Messages: 22
Registered: February 2012
Junior Member
We have a field in our dsl,
that's value automatically get a different value if another field is true,
before the output of the dsl is generated.
The source will not be changed.
That field with the condition would be a global configurations field.

If interpretEmptyStringAsNull is true
ProfileSettingsData:
	& 'dataobject-metamodel-suffix' '=' metamodelSuffix = STRING
	& 'exceptions' '{' exceptions = ExceptionSettings '}'
	& interpretEmptyStringAsNull?='interpret-empty-string-submitted-values-as-null'?
// more similar ones left out for better reading
;
All LengthElement should have a minLength with < 0.
LengthElement : 
	'with-length' '=' '(' ((maxLength = INT) (fixedLength ?= 'fixed')? | (minLength = INT '-' maxLength = INT) ) ')'
;


I tried to use the MyDSLPostProcessor.ext approach, with the following, but nothing happend:
import ecore;
import xtext;

process(xtext::GeneratedMetamodel this) :
  process(ePackage)
;

process(ecore::EPackage this) :
	this.eClassifiers.typeSelect(ecore::EClass).process()
;

process(EClass this) :
    switch (name) {
        case "LengthElement": (eAllAttributes.setMinLength(9))
        default:    null
    }
;

EDataType getEcoreDataType(String name) :
    org::eclipse::emf::ecore::EcorePackage::eINSTANCE.getEClassifier(name)
;
I did not check for the condition here.

In the end I want to do something like this:
if (interpretEmptyStringAsNull && lengthElementInstance.getMinLength() < 1) {
    lengthElementInstance.setMinLengthElement(1);
}
There is only one interpretEmptyStringAsNull
but many LengthElement's.

In other words when the flag is set every length should be at least 1.

Anyone an idea?
Re: Postprocessing set field [message #842885 is a reply to message #841573] Thu, 12 April 2012 17:55 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
hi,

with postprocessing you change the metamodel (ecore) not the model (.mydsl)

so one would add a derived eoperation (getMinLengthElement) to the metamodel (EClass) that calculates the semantic length and is used from the uses that want to use the semantic length

you can find an example (this is using Xtend 2 not Xtend 1) you can find here http://christiandietrich.wordpress.com/2011/07/22/customizing-xtext-metamodel-inference-using-xtend2/

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Postprocessing set field [message #848503 is a reply to message #842885] Wed, 18 April 2012 09:34 Go to previous message
Thomas Hergenröder is currently offline Thomas HergenröderFriend
Messages: 22
Registered: February 2012
Junior Member
Sorry, for answering so late, I thought I would get automatic email (I changed it).
I think I would need something more along the lines of a pre-processing,
as I would need something that is before the validator comes by.
Previous Topic:Xtext 1.x-&gt;2x: relative vs. absolute XMI references in ecore file
Next Topic:not-xtext builder for my dsl ?
Goto Forum:
  


Current Time: Sat Apr 20 06:58:22 GMT 2024

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

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

Back to the top