new OperatorExpression.Ternary (field, zero, one);
} else if (fieldType instanceof JavaTypeName.Primitive.Byte ||
fieldType instanceof JavaTypeName.Primitive.Char ||
fieldType instanceof JavaTypeName.Primitive.Short) {
fieldExpression =
new CastExpression(JavaTypeName.INT, field);
}else if (fieldType instanceof JavaTypeName.Primitive.Double) {
// long f = Double.doubleToLongBits(f);
// result = (int) (f ^ (f >>> 32));
JavaExpression.LocalVariable f =
new LocalVariable ("f", JavaTypeName.LONG);
JavaExpression initializeF =
new MethodInvocation.Static (
JavaTypeName.DOUBLE_OBJECT,
"doubleToLongBits",
field,
JavaTypeName.DOUBLE,
JavaTypeName.LONG);
LocalVariableDeclaration fVarDecl =
new LocalVariableDeclaration(f, initializeF);
thenBlock.addStatement(fVarDecl);
fieldExpression =
new OperatorExpression.Binary (
JavaOperator.SHIFTR_UNSIGNED_LONG,
f,
LiteralWrapper.make(new Integer (32)));
fieldExpression =
new OperatorExpression.Binary (
JavaOperator.BITWISE_XOR_LONG,
f,
fieldExpression);
fieldExpression =
new CastExpression (JavaTypeName.INT, fieldExpression);
} else if (fieldType instanceof JavaTypeName.Primitive.Float) {
fieldExpression =
new MethodInvocation.Static (
JavaTypeName.FLOAT_OBJECT,
"floatToIntBits",
field,
JavaTypeName.FLOAT,
JavaTypeName.INT);
} else if (fieldType instanceof JavaTypeName.Primitive.Int) {
fieldExpression = field;
} else if (fieldType instanceof JavaTypeName.Primitive.Long) {
fieldExpression =
new OperatorExpression.Binary (
JavaOperator.SHIFTR_UNSIGNED_LONG,
field,
LiteralWrapper.make(new Integer (32)));
fieldExpression =
new OperatorExpression.Binary (
JavaOperator.BITWISE_XOR_LONG,
field,
fieldExpression);
fieldExpression =
new CastExpression (JavaTypeName.INT, fieldExpression);
} else {
fieldExpression =
new MethodInvocation.Instance (field, "hashCode", JavaTypeName.INT, MethodInvocation.InvocationType.VIRTUAL);
}