Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Active Annotations: Import type references made in template strings defined in method
Active Annotations: Import type references made in template strings defined in method [message #1793058] Mon, 30 July 2018 11:26 Go to next message
Johannes Dorn is currently offline Johannes DornFriend
Messages: 61
Registered: June 2013
Member
I am generating a method declaration in which I use the result of a private method that returns a String.
In that method, I want to add type references.

However, the necessary imports are not added to the generated class, presumably because the method is not part of the method's body assignment.

Here is some nonsense code that demonstrates the problem:
val myClass = findClass(className)
myClass.addMethod("myMethod", [
  body = '''
    «SomeType» s  = new «SomeType»(); // This imports just fine
    «getSomeStringWithType()» 
  '''
])

private static def String getSomeStringWithType() {
  return '''
    «SomeOtherType» s2 = new «SomeOtherType»(); // This is not imported
  '''
}


How can I get SomeOtherType to be imported?
Perhaps there is a way to programmatically add imports to a MutableClassDeclaration?
Re: Active Annotations: Import type references made in template strings defined in method [message #1793061 is a reply to message #1793058] Mon, 30 July 2018 11:43 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
did you consider to set the type of getSomeStringWithType to StringConcatenationClient instead of String

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Active Annotations: Import type references made in template strings defined in method [message #1793065 is a reply to message #1793061] Mon, 30 July 2018 12:08 Go to previous message
Johannes Dorn is currently offline Johannes DornFriend
Messages: 61
Registered: June 2013
Member
No, I hadn't as I wasn't aware of it.

It looks like it's doing exactly what I need.

Thanks, Christian!
Previous Topic:mismatched input '<EOF>' expecting 'configuration error type
Next Topic:How to notified that the building of all my files finished ?
Goto Forum:
  


Current Time: Fri Apr 19 13:32:51 GMT 2024

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

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

Back to the top