Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » JvmModelInferrer - Generate a method call(How to generate a method call)
JvmModelInferrer - Generate a method call [message #1765379] Fri, 09 June 2017 00:58 Go to next message
Amit Yadav is currently offline Amit YadavFriend
Messages: 28
Registered: June 2017
Junior Member
Hello,

I am trying to write a small DSL which generates a Java Class. Within this class, I would like to add something like this

public static final Logger LOG = LoggerFactory.getLogger(blah.class);

I know how to generate ' LOG' filed using jvmtype builder toField API.

I also know that I can also write a setInitializer to initialize this field

typeBuilder.setInitializer(logger, appendable -> {
appendable.append("LoggerFactory.getLogger(");
appendable.append("blah");
appendable.append(".class)");
});

However this does not cause the import of LoggerFactory.

I am wondering how can achieve the same result with Model Inferrer recognizing the LoggerFactory type and generating a import statement for that?

Thanks
Re: JvmModelInferrer - Generate a method call [message #1765446 is a reply to message #1765379] Fri, 09 June 2017 14:58 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14075
Registered: July 2009
Senior Member
why not use xtend and StringConcatenationClient for that

initializer = '''┬ź LoggerFactory┬╗.getLogger(Blah.class)'''

dont know if it works if you do

appendable.append(LoggerFactory)


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: JvmModelInferrer - Generate a method call [message #1765471 is a reply to message #1765446] Sat, 10 June 2017 00:22 Go to previous message
Amit Yadav is currently offline Amit YadavFriend
Messages: 28
Registered: June 2017
Junior Member
Thanks Christian. That works and solves the problem
Previous Topic:Converting fragment from Antlr to Xtext
Next Topic:Compute another type from inferredType
Goto Forum:
  


Current Time: Mon Oct 18 17:53:38 GMT 2021

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

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

Back to the top