Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Data annotation overrides toString from parent class(Is it possible to keep the behaviour of the parent class?)
Data annotation overrides toString from parent class [message #1850542] Tue, 08 March 2022 09:30 Go to next message
Eclipse UserFriend
When annotating a class with @Data, the documentation says that the `toString` method will only be generated if it does not yet exist. However, when extending another class that already overrides `toString`, it is still overridden. I would like to keep the behaviour of the parent class. Is there a way to do this?

E.g.,

class Parent {
  override String toString() {
    "My custom toString"
  }
}

@Data
class Child extends Parent {
  val String name
  // I want to keep the behaviour of Parent::toString
}
Re: Data annotation overrides toString from parent class [message #1850546 is a reply to message #1850542] Tue, 08 March 2022 10:01 Go to previous messageGo to next message
Eclipse UserFriend
i assume you need to check the code of the processor and write your own
Re: Data annotation overrides toString from parent class [message #1850552 is a reply to message #1850546] Tue, 08 March 2022 11:52 Go to previous messageGo to next message
Eclipse UserFriend
Okay thanks, I'll take a look at the source of `Data` then.
Re: Data annotation overrides toString from parent class [message #1850591 is a reply to message #1850542] Wed, 09 March 2022 10:34 Go to previous message
Eclipse UserFriend
If it's a one off, what about creating a toString() method in the child class and call the parent one? This way the @Data annotation will not generate a new one.
Previous Topic:Generate Files outside of the xtext project, relative to the projects location
Next Topic:Trigger validator(builder) for multiple files
Goto Forum:
  


Current Time: Thu Feb 13 10:33:26 GMT 2025

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

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

Back to the top