Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Code generator for Smalljava example
Code generator for Smalljava example [message #1690311] Thu, 26 March 2015 10:34 Go to next message
Eclipse UserFriend
Hello all

I was wondering whether there is a code generator for Smalljava example of the book, to generate actual Java code from the examples.

Thanks
Re: Code generator for Smalljava example [message #1690313 is a reply to message #1690311] Thu, 26 March 2015 10:38 Go to previous messageGo to next message
Eclipse UserFriend
No there is not. but it should not be too much work to create one

[Updated on: Thu, 26 March 2015 10:38] by Moderator

Re: Code generator for Smalljava example [message #1690314 is a reply to message #1690313] Thu, 26 March 2015 10:41 Go to previous messageGo to next message
Eclipse UserFriend
Thanks, in fact I am trying to make one. When it comes to generate code from expressions, I do not know how to access information about statements within the body of the methods. Can you give an example?

public class «it.name» {
«FOR m:it.members»
«IF m instanceof SJField»
«m.access.literal» «m.type.name» «m.name»;
«ELSE»
«IF m instanceof SJMethod»
«m.access.literal» «m.type.name» «m.name» (
«FOR p:m.params»
«p.type.name» «p.name» ,
«ENDFOR»

) {
«FOR s: m.body.statements»
//Can you give an example how to generate code for one statement....
«ENDFOR»
}
«ENDIF»
Re: Code generator for Smalljava example [message #1690316 is a reply to message #1690314] Thu, 26 March 2015 10:48 Go to previous message
Eclipse UserFriend
Hi have a look at the dispatch methods in Xtend


def dispatch toJavaStatement(SJVariableDeclaration it) '''
//TODO
'''
def dispatch toJavaStatement(SJReturn it) '''
return «expression.toJavaStatement»;
'''
def dispatch toJavaStatement(SJStringConstant it) '''
"«value»"
'''
//TODO other SJExpressions

def dispatch toJavaStatement(SJIfStatement it) '''
//TODO
'''
Previous Topic:cann't reference the instance in jar file or classpath model
Next Topic:Logical expressions within XExpressionOrVarDeclaration
Goto Forum:
  


Current Time: Sun Jul 13 20:33:06 EDT 2025

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

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

Back to the top