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
Simon Cockx is currently offline Simon CockxFriend
Messages: 69
Registered: October 2021
Member
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
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14729
Registered: July 2009
Senior Member
i assume you need to check the code of the processor and write your own

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
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
Simon Cockx is currently offline Simon CockxFriend
Messages: 69
Registered: October 2021
Member
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
Elie Richa is currently offline Elie RichaFriend
Messages: 72
Registered: February 2016
Member
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.

Elie Richa, Ph.D
Software Engineer, AdaCore
https://www.adacore.com
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: Sat Nov 09 02:07:06 GMT 2024

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

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

Back to the top