Equals and HashCode live template

This has been discussed before but I couldn't find any answers.

Is there a way to create a template that iterates all the variables of a class?
This would be helpful to create custom equals/hashcode implementations.

For example:

public boolean equals(Object other) {     if (other == null) {         return false;     }     if (other == this) {         return true;     }     if (other.getClass() != this.getClass()) {         return false;     }     $classname that = ($classname) other;     return new org.apache.commons.lang.builder.EqualsBuilder()      $foreach ($member in $members)             .append(this.$member, that.$member)      $end             .isEquals(); }

would be really nice. (made up the syntax so fee free to critize)
Comment actions Permalink

No, this is currently not possible via live templates. Similar functionality can be implemented in plugins, and there's already a plugin that seems to do what you want:

Comment actions Permalink

Hey Dmitry. Yea I know there's a plugin for it but I was using equals/hashcode as an example. There are a few other places that this would be handy (custom toString generators -- test code generation etc). I realize that plugins have this capability but it's rather inconvenient to have to write a plugin to access these features if one doesn't already exist that does what you want :p


Please sign in to leave a comment.