Wednesday, 28 August 2013

Xtext:xtend: How to generate constructors and commentary lines with JvmModelInferrer.xtend?

Xtext:xtend: How to generate constructors and commentary lines with
JvmModelInferrer.xtend?

i tried the five simple steps to your JVM language example on
http://www.eclipse.org/Xtext/documentation.html#JvmDomainmodel. There you
can find the DSL file.
I generate my dsl entity instances into Java code via
DomaninModelInferrer.xtend. The actual file looks like this:
DomainmodelJvmModelInferrer.xtend
To generate Javadoc descriptions for methods i did this
(setDocumentation(...)):
Operation:{
members+=feature.toMethod(feature.name,feature.type)[
setDocumentation(it, feature.documentation) // Javadoc
Method
if (feature.static == true)
{
setStatic(true);
}
for (p:feature.params){
parameters+=p.toParameter(p.name,p.parameterType)
}
body=feature.body
]
}
I wanted to add an constructor too for my entity element, but i really
dont know how to realise it. There is a method in JvmTypesBuilder
toConstructor:
JvmConstructor JvmTypesBuilder.toConstructor(EObject sourceElement,
Procedure1<? super JvmConstructor> initializer)
But i dont know how to use it :/. Can someone explain? The Xtext online
documentation is okay, for understanding the theory thing, but there are
less code examples :(




Second Question: How to generate commentary lines? For Example, i write
something like this in my model:
op getFriendsSortedByFullName():List<Person>
{
// this is a test comment
return friends.sortBy(f | f.fullName);
}
DSL code for Operations:
Operation:
(static?='static')? 'op' name=ValidID
'('(params+=FullJvmFormalParameter
(',' params+=FullJvmFormalParameter)*)?')'
':' type=JvmTypeReference
body=XBlockExpression
The
body=XBlockExpression
doesnt allow commentary lines between the method hull. So it doesnt
generate comment lines.
I hope someone can help me :/

No comments:

Post a Comment