Using Xbase Expressions in JvmModelInferrer [message #1783851] |
Mon, 19 March 2018 09:32  |
Eclipse User |
|
|
|
Hello,
So i have a question about my xtext grammar, which i wanted to extend with Xbase.
So my xtext Grammar looks like that:
JoinExpr :
(NaturalJoinExpr | LeftOuterJoinExpr | ThetaJoinExpr) 'as' targetType=CPX_ID
NaturalJoinExpr:
...
;
LeftOuterJoinExpr:
...
;
ThetaJoinExpr:
'theta' 'join' left=[ecore::EClass|CPX_ID] 'with' right=[ecore::EClass|CPX_ID] 'where' condition = STRING
;
Now I want to validate the STRING part with xbase, so i extended xtext with xbase and replaced STRING with XExpression.
Do i use XExpression correctly in my grammar?
Seems like there could be a problem with 'as' targetType=CPX_ID which would be after the XExpression. So am i able to write:
where (condition) as ... ?
Where condition is any XExpression?
Now i should have the possibility to validate the XExpression in my JvmModelInferrer.
The XExpression should be validated to true or false.
So my Inferrer look like that:
acceptor.accept(element.toClass("edu.kit.ipd.sdq.mdsd.mj.Modelchecker" ) [
if (el instanceof ThetaJoinExpr) {
members += el.toMethod("isValid", el.newTypeRef(Boolean::TYPE)) [
parameters += el.left.toParameter("leftClass", el.left.newTypeRef(EClass))
parameters += el.right.toParameter("rightClass", el.right.newTypeRef(EClass))
body =
'''
«el.condition»
return true;
]
Does my condition now gets validated? Or how can i use Xbase Expressions in the jvmModelInferrer?
The condition in my query would be any condition as we know it from sql.
So I want that to be represented in the file generated from the inferrer as condition. How to achieve that?
Thx in advance
[Updated on: Mon, 19 March 2018 11:24] by Moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: Using Xbase Expressions in JvmModelInferrer [message #1784045 is a reply to message #1783937] |
Wed, 21 March 2018 17:52   |
Eclipse User |
|
|
|
One more question, is there also a possibility to just need the ecore model and not the genmodel for my jvmModelInferrer?
class MyDslJvmModelInferrer extends AbstractModelInferrer {
@Inject extension JvmTypesBuilder
def dispatch void infer(ThetaJoinExpr element, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {
var count = 0
acceptor.accept(element.toClass("edu.kit.ipd.sdq.mdsd.mj.Modelchecker" + count.toString)) [
members += element.toMethod("isValid", Boolean.TYPE.typeRef) [
// add org.eclipse.xtext.xtext.generator to deps or copy code
val leftName = GenModelUtil2.getJavaTypeName(element.left, element.eResource.resourceSet)
parameters += element.left.toParameter("leftElement", leftName.typeRef())
val rightName = GenModelUtil2.getJavaTypeName(element.left, element.eResource.resourceSet)
parameters += element.right.toParameter("rightElement", rightName.typeRef())
body = element.condition
]
]
}
}
This was your solution above, but therefore i need the genmodel, which somehow can't get loaded. Is there also a solution if i just have .ecore files?
|
|
|
|
Powered by
FUDForum. Page generated in 0.08747 seconds