public void loadConstant(TypeDesc type) throws IllegalStateException { if (type == null) { loadNull(); return; } if (type.isPrimitive()) { if (mTarget < 0x00010001) { throw new IllegalStateException ("Loading constant primitive classes not supported below target version 1.1"); } loadStaticField(type.toObjectType(), "TYPE", TypeDesc.forClass(Class.class)); } else { if (mTarget < 0x00010005) { throw new IllegalStateException ("Loading constant object classes not supported below target version 1.5"); } ConstantInfo info = mCp.addConstantClass(type); mInstructions.new LoadConstantInstruction(1, TypeDesc.forClass(Class.class), info); } }
private void toBoolean(boolean box) { if (box && mTarget >= 0x00010004) { // Call the new valueOf method. invokeStatic("java.lang.Boolean", "valueOf", TypeDesc.BOOLEAN.toObjectType(), new TypeDesc[] {TypeDesc.BOOLEAN}); return; } Label nonZero = createLabel(); Label done = createLabel(); ifZeroComparisonBranch(nonZero, "!="); if (box) { TypeDesc newType = TypeDesc.BOOLEAN.toObjectType(); loadStaticField(newType.getRootName(), "FALSE", newType); branch(done); nonZero.setLocation(); loadStaticField(newType.getRootName(), "TRUE", newType); } else { loadConstant(false); branch(done); nonZero.setLocation(); loadConstant(true); } done.setLocation(); }
b.invoke(bp.getReadMethod()); TypeDesc type = TypeDesc.forClass(bp.getType()); b.convert(type, type.toObjectType()); b.returnValue(TypeDesc.OBJECT); break; b.loadLocal(valueVar); TypeDesc type = TypeDesc.forClass(bp.getType()); b.checkCast(type.toObjectType()); b.convert(type.toObjectType(), type); b.invoke(bp.getWriteMethod()); if (methodType == WRITE_METHOD) {
/** * @param fieldType must be an object type * @return null if compareTo should not be called */ private static TypeDesc compareToType(TypeDesc fieldType) { if (fieldType.toPrimitiveType() == TypeDesc.FLOAT) { // Special treatment to handle NaN. return TypeDesc.FLOAT.toObjectType(); } else if (fieldType.toPrimitiveType() == TypeDesc.DOUBLE) { // Special treatment to handle NaN. return TypeDesc.DOUBLE.toObjectType(); } else if (BigDecimal.class.isAssignableFrom(fieldType.toClass())) { // Call compareTo to disregard scale. return TypeDesc.forClass(BigDecimal.class); } else { return null; } }
/** * @param fieldType must be an object type * @return null if compareTo should not be called */ private static TypeDesc compareToType(TypeDesc fieldType) { if (fieldType.toPrimitiveType() == TypeDesc.FLOAT) { // Special treatment to handle NaN. return TypeDesc.FLOAT.toObjectType(); } else if (fieldType.toPrimitiveType() == TypeDesc.DOUBLE) { // Special treatment to handle NaN. return TypeDesc.DOUBLE.toObjectType(); } else if (BigDecimal.class.isAssignableFrom(fieldType.toClass())) { // Call compareTo to disregard scale. return TypeDesc.forClass(BigDecimal.class); } else { return null; } }
/** * Returns the actual field type used to store the given property * type. Floating point values are represented in their "bit" form, in * order to compare against NaN. */ private static TypeDesc actualFieldType(TypeDesc type) { if (type.toPrimitiveType() == FLOAT) { if (type.isPrimitive()) { type = INT; } else { type = INT.toObjectType(); } } else if (type.toPrimitiveType() == DOUBLE) { if (type.isPrimitive()) { type = LONG; } else { type = LONG.toObjectType(); } } return type; }
/** * Returns the actual field type used to store the given property * type. Floating point values are represented in their "bit" form, in * order to compare against NaN. */ private static TypeDesc actualFieldType(TypeDesc type) { if (type.toPrimitiveType() == FLOAT) { if (type.isPrimitive()) { type = INT; } else { type = INT.toObjectType(); } } else if (type.toPrimitiveType() == DOUBLE) { if (type.isPrimitive()) { type = LONG; } else { type = LONG.toObjectType(); } } return type; }
builder.loadFromArray(TypeDesc.forClass(Comparator.class)); builder.loadLocal(p1); builder.convert(propertyType, propertyType.toObjectType()); builder.loadLocal(p2); builder.convert(propertyType, propertyType.toObjectType()); builder.invoke(compareMethod); } else {
/** * Returns the type of the ChainedProperty property, boxed into an object * if primitive. */ public Class<?> getBoxedType() { if (mBoxedType == null) { mBoxedType = TypeDesc.forClass(getType()).toObjectType().toClass(); } return mBoxedType; }
/** * Returns the type of the ChainedProperty property, boxed into an object * if primitive. */ public Class<?> getBoxedType() { if (mBoxedType == null) { mBoxedType = TypeDesc.forClass(getType()).toObjectType().toClass(); } return mBoxedType; }
private void branchIfNaN(CodeBuilder b, LocalVariable value, Label isNaN) { TypeDesc type = value.getType(); if (type == TypeDesc.FLOAT || type == TypeDesc.DOUBLE) { b.loadLocal(value); if (type == TypeDesc.FLOAT) { b.invokeStatic(TypeDesc.FLOAT.toObjectType(), "isNaN", TypeDesc.BOOLEAN, new TypeDesc[] {TypeDesc.FLOAT}); b.ifZeroComparisonBranch(isNaN, "!="); } else { b.invokeStatic(TypeDesc.DOUBLE.toObjectType(), "isNaN", TypeDesc.BOOLEAN, new TypeDesc[] {TypeDesc.DOUBLE}); b.ifZeroComparisonBranch(isNaN, "!="); } } }
private void branchIfNaN(CodeBuilder b, LocalVariable value, Label isNaN) { TypeDesc type = value.getType(); if (type == TypeDesc.FLOAT || type == TypeDesc.DOUBLE) { b.loadLocal(value); if (type == TypeDesc.FLOAT) { b.invokeStatic(TypeDesc.FLOAT.toObjectType(), "isNaN", TypeDesc.BOOLEAN, new TypeDesc[] {TypeDesc.FLOAT}); b.ifZeroComparisonBranch(isNaN, "!="); } else { b.invokeStatic(TypeDesc.DOUBLE.toObjectType(), "isNaN", TypeDesc.BOOLEAN, new TypeDesc[] {TypeDesc.DOUBLE}); b.ifZeroComparisonBranch(isNaN, "!="); } } }
toType = fromType.toObjectType(); } else { return; case TypeDesc.DOUBLE_CODE: if (fromType.isPrimitive()) { toType = fromType.toObjectType(); } else { return;
private String addFilterField(PropertyFilter filter, TypeDesc type) { final int propertyOrdinal = mPropertyOrdinalMap.get(filter); final String fieldName = FIELD_PREFIX + propertyOrdinal; if (mGeneratedPropertyFilters.containsKey(filter)) { return fieldName; } final TypeDesc fieldType = actualFieldType(type); mClassFile.addField(Modifiers.PRIVATE.toFinal(true), fieldName, fieldType); // Add code to constructor to store value into field. { CodeBuilder b = mCtorBuilder; b.loadThis(); b.loadLocal(b.getParameter(1)); b.loadConstant(propertyOrdinal); b.loadFromArray(OBJECT); if (type != OBJECT) { b.checkCast(type.toObjectType()); convertProperty(b, type.toObjectType(), fieldType); } b.storeField(fieldName, fieldType); } mGeneratedPropertyFilters.put(filter, filter); return fieldName; }
public void loadConstant(TypeDesc type) throws IllegalStateException { if (type == null) { loadNull(); return; } if (type.isPrimitive()) { if (mTarget < 0x00010001) { throw new IllegalStateException ("Loading constant primitive classes not supported below target version 1.1"); } loadStaticField(type.toObjectType(), "TYPE", TypeDesc.forClass(Class.class)); } else { if (mTarget < 0x00010005) { throw new IllegalStateException ("Loading constant object classes not supported below target version 1.5"); } ConstantInfo info = mCp.addConstantClass(type); mInstructions.new LoadConstantInstruction(1, TypeDesc.forClass(Class.class), info); } }
private String addFilterField(PropertyFilter filter, TypeDesc type) { final int propertyOrdinal = mPropertyOrdinalMap.get(filter); final String fieldName = FIELD_PREFIX + propertyOrdinal; if (mGeneratedPropertyFilters.containsKey(filter)) { return fieldName; } final TypeDesc fieldType = actualFieldType(type); mClassFile.addField(Modifiers.PRIVATE.toFinal(true), fieldName, fieldType); // Add code to constructor to store value into field. { CodeBuilder b = mCtorBuilder; b.loadThis(); b.loadLocal(b.getParameter(1)); b.loadConstant(propertyOrdinal); b.loadFromArray(OBJECT); if (type != OBJECT) { b.checkCast(type.toObjectType()); convertProperty(b, type.toObjectType(), fieldType); } b.storeField(fieldName, fieldType); } mGeneratedPropertyFilters.put(filter, filter); return fieldName; }
/** * Creates code to call set method. Assumes Storable and property value * are already on the stack. */ private static void callSetPropertyValue(CodeBuilder b, OrderedProperty<?> op) { StorableProperty<?> property = op.getChainedProperty().getLastProperty(); TypeDesc propType = TypeDesc.forClass(property.getType()); if (propType != TypeDesc.OBJECT) { TypeDesc objectType = propType.toObjectType(); b.checkCast(objectType); // Potentially unbox primitive. b.convert(objectType, propType); } b.invoke(property.getWriteMethod()); } }
/** * Creates code to call set method. Assumes Storable and property value * are already on the stack. */ private static void callSetPropertyValue(CodeBuilder b, OrderedProperty<?> op) { StorableProperty<?> property = op.getChainedProperty().getLastProperty(); TypeDesc propType = TypeDesc.forClass(property.getType()); if (propType != TypeDesc.OBJECT) { TypeDesc objectType = propType.toObjectType(); b.checkCast(objectType); // Potentially unbox primitive. b.convert(objectType, propType); } b.invoke(property.getWriteMethod()); } }
@Override public Object visit(PropertyFilter<S> filter, Object param) { ChainedProperty<S> chained = filter.getChainedProperty(); switch (filter.getOperator()) { case EQ: case NE: // Use equals() method instead of comparator. break; default: TypeDesc typeDesc = TypeDesc.forClass(chained.getType()).toObjectType(); if (!Comparable.class.isAssignableFrom(typeDesc.toClass()) && (!typeDesc.isArray() || Comparators.arrayComparator(typeDesc.toClass(), true) == null)) { throw new UnsupportedOperationException ("Property \"" + chained + "\" does not implement Comparable"); } break; } // Follow the chain, verifying that each property has an accessible // read method. checkForReadMethod(chained, chained.getPrimeProperty()); for (int i=0; i<chained.getChainCount(); i++) { checkForReadMethod(chained, chained.getChainedProperty(i)); } return null; }
private void toBoolean(boolean box) { if (box && mTarget >= 0x00010004) { // Call the new valueOf method. invokeStatic("java.lang.Boolean", "valueOf", TypeDesc.BOOLEAN.toObjectType(), new TypeDesc[] {TypeDesc.BOOLEAN}); return; } Label nonZero = createLabel(); Label done = createLabel(); ifZeroComparisonBranch(nonZero, "!="); if (box) { TypeDesc newType = TypeDesc.BOOLEAN.toObjectType(); loadStaticField(newType.getRootName(), "FALSE", newType); branch(done); nonZero.setLocation(); loadStaticField(newType.getRootName(), "TRUE", newType); } else { loadConstant(false); branch(done); nonZero.setLocation(); loadConstant(true); } done.setLocation(); }