protected void buildKeyedHashCode( ClassVisitor cw,
ClassDefinition classDef,
String proxyType ) {
MethodVisitor mv;
{
mv = cw.visitMethod( ACC_PUBLIC, "hashCode", "()I", null, null );
mv.visitCode();
mv.visitIntInsn( BIPUSH, 31 );
mv.visitVarInsn( ISTORE, 1 );
int count = 0;
int x = 2;
int y = 2;
for ( FieldDefinition field : classDef.getFieldsDefinitions() ) {
if ( field.isKey() ) {
count++;
if ( ! BuildUtils.isPrimitive( field.getTypeName() ) ) {
mv.visitIntInsn( BIPUSH, 31 );
mv.visitVarInsn( ILOAD, 1 );
mv.visitInsn( IMUL );
mv.visitVarInsn( ALOAD, 0 );
mv.visitMethodInsn( INVOKEVIRTUAL, proxyType, BuildUtils.getterName( field.getName(), field.getTypeName() ),
"()" + BuildUtils.getTypeDescriptor( field.getTypeName() ) );
Label l8 = new Label();
mv.visitJumpInsn( IFNULL, l8 );
mv.visitVarInsn( ALOAD, 0 );
mv.visitMethodInsn( INVOKEVIRTUAL, proxyType, BuildUtils.getterName( field.getName(), field.getTypeName() ),
"()" + BuildUtils.getTypeDescriptor( field.getTypeName() ) );
mv.visitMethodInsn( INVOKEVIRTUAL, BuildUtils.getInternalType( field.getTypeName() ), "hashCode", "()I" );
Label l9 = new Label();
mv.visitJumpInsn( GOTO, l9 );
mv.visitLabel( l8 );
mv.visitInsn( ICONST_0 );
mv.visitLabel( l9 );
mv.visitInsn( IADD );
mv.visitVarInsn( ISTORE, 1 );
} else if ( "double".equals( field.getTypeName() ) ) {
mv.visitVarInsn( ALOAD, 0 );
mv.visitMethodInsn( INVOKEVIRTUAL, proxyType, BuildUtils.getterName( field.getName(), field.getTypeName() ),
"()" + BuildUtils.getTypeDescriptor( field.getTypeName() ) );
mv.visitInsn( DCONST_0 );
mv.visitInsn( DCMPL );
Label l2 = new Label();
mv.visitJumpInsn( IFEQ, l2 );
mv.visitVarInsn( ALOAD, 0 );
mv.visitMethodInsn( INVOKEVIRTUAL, proxyType, BuildUtils.getterName( field.getName(), field.getTypeName() ),
"()" + BuildUtils.getTypeDescriptor( field.getTypeName() ) );
mv.visitMethodInsn( INVOKESTATIC, Type.getInternalName( Double.class ), "doubleToLongBits", "(D)J" );
Label l3 = new Label();
mv.visitJumpInsn( GOTO, l3 );
mv.visitLabel( l2 );
mv.visitInsn( LCONST_0 );
mv.visitLabel( l3 );
mv.visitVarInsn( LSTORE, 2 );
mv.visitIntInsn( BIPUSH, 31 );
mv.visitVarInsn( ILOAD, 1 );
mv.visitInsn( IMUL );
mv.visitVarInsn( LLOAD, 2 );
mv.visitVarInsn( LLOAD, 2 );
mv.visitIntInsn( BIPUSH, 32 );
mv.visitInsn( LUSHR );
mv.visitInsn( LXOR );
mv.visitInsn( L2I );
mv.visitInsn( IADD);
mv.visitVarInsn( ISTORE, 1 );
x = Math.max( 6, x );
y = Math.max( 4, y );
} else if ( "boolean".equals( field.getTypeName() ) ) {
mv.visitIntInsn( BIPUSH, 31 );
mv.visitVarInsn( ILOAD, 1 );
mv.visitInsn( IMUL );
mv.visitVarInsn( ALOAD, 0 );
mv.visitMethodInsn( INVOKEVIRTUAL, proxyType, BuildUtils.getterName( field.getName(), field.getTypeName() ),
"()" + BuildUtils.getTypeDescriptor( field.getTypeName() ) );
Label l4 = new Label();
mv.visitJumpInsn( IFEQ, l4 );
mv.visitInsn( ICONST_1 );
Label l5 = new Label();
mv.visitJumpInsn( GOTO, l5 );
mv.visitLabel( l4 );
mv.visitInsn( ICONST_0 );
mv.visitLabel( l5 );
mv.visitInsn( IADD );
mv.visitVarInsn( ISTORE, 1 );
} else if ( "float".equals( field.getTypeName() ) ) {
mv.visitIntInsn( BIPUSH, 31 );
mv.visitVarInsn( ILOAD, 1 );
mv.visitInsn( IMUL );
mv.visitVarInsn( ALOAD, 0 );
mv.visitMethodInsn( INVOKEVIRTUAL, proxyType, BuildUtils.getterName( field.getName(), field.getTypeName() ),
"()" + BuildUtils.getTypeDescriptor( field.getTypeName() ) );
mv.visitInsn( FCONST_0 );
mv.visitInsn( FCMPL );
Label l6 = new Label();
mv.visitJumpInsn( IFEQ, l6 );
mv.visitVarInsn( ALOAD, 0 );
mv.visitMethodInsn( INVOKEVIRTUAL, proxyType, BuildUtils.getterName( field.getName(), field.getTypeName() ),
"()" + BuildUtils.getTypeDescriptor( field.getTypeName() ) );
mv.visitMethodInsn( INVOKESTATIC, Type.getInternalName( Float.class ), "floatToIntBits", "(F)I" );
Label l7 = new Label();
mv.visitJumpInsn( GOTO, l7 );
mv.visitLabel( l6 );
mv.visitInsn( ICONST_0 );
mv.visitLabel( l7 );
mv.visitInsn( IADD );
mv.visitVarInsn( ISTORE, 1 );
x = Math.max( 3, x );
} else if ( "long".equals( field.getTypeName() ) ) {
mv.visitIntInsn( BIPUSH, 31 );
mv.visitVarInsn( ILOAD, 1 );
mv.visitInsn( IMUL );
mv.visitVarInsn( ALOAD, 0 );
mv.visitMethodInsn( INVOKEVIRTUAL, proxyType, BuildUtils.getterName( field.getName(), field.getTypeName() ),
"()" + BuildUtils.getTypeDescriptor( field.getTypeName() ) );
mv.visitVarInsn( ALOAD, 0 );
mv.visitMethodInsn( INVOKEVIRTUAL, proxyType, BuildUtils.getterName( field.getName(), field.getTypeName() ),
"()" + BuildUtils.getTypeDescriptor( field.getTypeName() ) );
mv.visitIntInsn( BIPUSH, 32 );
mv.visitInsn( LUSHR );
mv.visitInsn( LXOR );
mv.visitInsn( L2I );
mv.visitInsn( IADD );
mv.visitVarInsn( ISTORE, 1 );
x = Math.max( 6, x );
} else {
mv.visitIntInsn( BIPUSH, 31 );
mv.visitVarInsn( ILOAD, 1 );
mv.visitInsn( IMUL );
mv.visitVarInsn( ALOAD, 0 );
mv.visitMethodInsn( INVOKEVIRTUAL, proxyType, BuildUtils.getterName( field.getName(), field.getTypeName() ),
"()" + BuildUtils.getTypeDescriptor( field.getTypeName() ) ) ;
mv.visitInsn( IADD );
mv.visitVarInsn( ISTORE, 1 );
}
}
}
mv.visitVarInsn( ILOAD, 1 );
mv.visitInsn( IRETURN );
// mv.visitMaxs( x, y );
mv.visitMaxs( 0, 0 );
mv.visitEnd();
}
}