Hi,
I've been looking for a way of generating equals and hashCode methods
differently to the built in IntelliJ feature and I have had success using your
plugin. The templates I'm using are shown below:
EqualsBuilder template:
public boolean equals(Object other) {
#set ($autoImportPackages = "org.apache.commons.lang.builder.EqualsBuilder")
if (other == null) {
return false;
}
if (other == this) {
return true;
}
if (other.getClass() != this.getClass()) {
return false;
}
$classname that = ($classname) other;
return new EqualsBuilder()
#foreach ($member in $members)
.append(this.$member.accessor, that.$member.accessor)
#end
.isEquals();
}
HashCodeBuilder template:
public int hashCode() {
#set ($autoImportPackages = "org.apache.commons.lang.builder.HashCodeBuilder")
return new HashCodeBuilder()
#foreach ($member in $members)
.append(this.$member.accessor)
#end
.toHashCode();
}
It seems to me that your plugin could be more widely applicable since it deals
to some extent with a limitation in the built in Live Template implementation
(namely that you can't do conditionals or loop over things like methods, fields
etc.)
Do you think there is scope to fork and extend your plugin to be a more general
purpose code generation tool? Effectively giving the power of live templates
but with additional language reflection capabilities as you have started to
implement? Maybe it is better for this to be a feature request to JetBrains
instead...
Alternatively, it might be cool to make a "Generate toString etc." plugin that
is smaller in scope but would allow things like equals and hashcode to be
generated more reliably and with a better context menu name.
I'm happy to help with any implementation if you feel this would be useful.
Thanks,
Toby
Original issue reported on code.google.com by tobyclem...@gmail.com on 13 Jul 2011 at 1:27
Original issue reported on code.google.com by
tobyclem...@gmail.com
on 13 Jul 2011 at 1:27