Skip to main content



      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 07:26 Go to next message
Eclipse UserFriend
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 07:43 Go to previous messageGo to next message
Eclipse UserFriend
did you consider to set the type of getSomeStringWithType to StringConcatenationClient instead of String
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 08:08 Go to previous message
Eclipse UserFriend
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: Sun Jun 22 07:34:11 EDT 2025

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

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

Back to the top