Skip to main content



      Home
Home » Modeling » TMF (Xtext) » JvmModelInferrer - Generate a method call(How to generate a method call)
JvmModelInferrer - Generate a method call [message #1765379] Thu, 08 June 2017 20:58 Go to next message
Eclipse UserFriend
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 10:58 Go to previous messageGo to next message
Eclipse UserFriend
why not use xtend and StringConcatenationClient for that

initializer = '''« LoggerFactory».getLogger(Blah.class)'''

dont know if it works if you do

appendable.append(LoggerFactory)
Re: JvmModelInferrer - Generate a method call [message #1765471 is a reply to message #1765446] Fri, 09 June 2017 20:22 Go to previous message
Eclipse UserFriend
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: Sun Jul 06 00:03:37 EDT 2025

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

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

Back to the top