Glen Stampoultzis wrote:
> > PS:
> >
> > I have requested many times a "insert canonical methods" (equals,
> hashcode, toString) tool.
> > Using doclets, it's really easy to implement by yourself.
> >
>
> How would this be different from pressing ctrl-o to override those
> methods?
Overriding doesn't generate any valuable code; just a call to the super class method().
"insert canonical methods" generates sensible default code (see below), like "insert
constructor" does, using
all the private instance members.
(equals() and hashCode() code is based on "Effective Java" recipes, by Joshua Bloch).
example : class Canonicizer
...
private byte __byte0 ;
private char __char1 ;
private int __int2 ;
private long __long3 ;
private float __float4 ;
private double __double5 ;
private String __string6 ;
private boolean __boolean7 ;
// ----------------------------------------------
public String toString ()
// ----------------------------------------------
{
return "[Canonicizer: "
+ __byte0
+ "," + __char1
+ "," + __int2
+ "," + __long3
+ "," + __float4
+ "," + __double5
+ "," + __string6
+ "," + __boolean7
+ "]" ;
}
// ----------------------------------------------
public boolean equals (Object o)
// ----------------------------------------------
{
if (this == o) return true ;
if (! (o instanceof Canonicizer )) return false ;
final Canonicizer obj = (Canonicizer) o;
return
obj.__byte0 == this.__byte0
&& obj.__char1 == this.__char1
&& obj.__int2 == this.__int2
&& obj.__long3 == this.__long3
&& obj.Float.floatToIntBits(__float4) ==
this.Float.floatToIntBits(__float4)
&& obj.Double.doubleToLongBits(__double5) ==
this.Double.doubleToLongBits(__double5)
&& obj.__string6 .equals( this.__string6 )
&& obj.__boolean7 == this.__boolean7
;
}
// ----------------------------------------------
public int hashCode ()
// ----------------------------------------------
{
int result = 17;
result = 37 * result + (int)__byte0 ;
result = 37 * result + (int)__char1 ;
result = 37 * result + (int)__int2 ;
result = 37 * result + (int)( __long3 ^ ( __long3>>>32) ) ;
result = 37 * result + Float.floatToIntBits(__float4);
{
long f = Double.doubleToLongBits( __double5 );
result = 37 * result + (int)( f ^ ( f>>>32 )) ;
}
result = 37 * result + __string6.hashCode() ;
result = 37 * result + (__boolean7 ? 0:1) ;
return result ;
}
--Alain Ravet
_______________________________________________
Eap-features mailing list
[EMAIL PROTECTED]
http://www.intellij.com/mailman/listinfo/eap-features