Combining the IJvmModelInferrer with custom code generation [message #755749] |
Wed, 09 November 2011 08:21  |
Eclipse User |
|
|
|
Hi,
I am extending Xbase and use the IJvmModelInferrer to map my language to JVM Concepts. This works quite amazing with the resulting generated Java code.
However there are some things that need custom code and cannot be simply mapped.
So my question is how can I customize the code generation already done by Xtext?
~Goran
|
|
|
|
|
|
|
|
Re: Combining the IJvmModelInferrer with custom code generation [message #758940 is a reply to message #758849] |
Fri, 25 November 2011 06:04   |
Eclipse User |
|
|
|
On 11/24/2011 06:41 PM, Goran wrote:
> Thanks Lorenzo,
>
> That's a great blog post indeed. You described a switch to your custom
glad you enjoyed it :)
> generator instead of the JvmModelGenerator. What was not very clear to
> me is if we could still use the JvmModelInferrer when using the custom
> code generator you described. Do you know if this is possible?
>
well, I still haven't switched to JvmModelInferrer, but I think that
could be possible... actually I had pointed you to my post just for the
part concerning calling XbaseCompiler explicitly: I didn't mean to point
you to the part concerning using a custom code generator :)
> I was able to put the following into the JvmModelInferrer which helped:
>
>
> ..
> return element.toMethod(name, returnType)[
> for(p : element.advice.parameters.parameters) {
> parameters += p.toParameter(p.name, p.parameterType)
> }
> documentation = element.documentation
> final = element.^final
>
> val importManager = new ImportManager(true, getJvmType(aspectFQN))
> val mainMethod = compile(element.advice.body, importManager)
> body = ['''
> «mainMethod»
> System.out.println("Some generated custom statement besides the
> automatically generated statements");
> ''']
> )]
> ...
> def compile(XExpression xExpression, ImportManager importManager) {
> val result = new StringBuilderBasedAppendable(importManager)
> compiler.toJavaStatement(xExpression, result, true)
> result
> }
>
>
> However now I also would like to customize the import statements. I know
> how to do that according to your post however I would like to avoid
> throwing away my JvmModelInferrer xtend class.
--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net
|
|
|
Re: Combining the IJvmModelInferrer with custom code generation [message #759105 is a reply to message #758940] |
Sat, 26 November 2011 06:56  |
Eclipse User |
|
|
|
Thanks Lorenzo,
I was able to use both my JvmModelInferrer and custom generator.
I extended the org.eclipse.xtext.xbase.compiler.JvmModelGenerator with a custom implementation. Then I override relevant methods.
public class CustomJvmModelGenerator extends
org.eclipse.xtext.xbase.compiler.JvmModelGenerator {
@Inject
private TypeReferences references;
//override methods
....
}
And for the runtime module:
@SuppressWarnings("all")
public abstract class AbstractAspectJRuntimeModule extends DefaultRuntimeModule {
....
public Class<? extends org.eclipse.xtext.generator.IGenerator> bindIGenerator() {
// return org.eclipse.xtext.xbase.compiler.JvmModelGenerator.class;
return CustomJvmModelGenerator.class;
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.12457 seconds