/** * Translates an integer into the Java type denoted by <code>clazz</code>. Expects an integer on * the stack and pushes a number of the appropriate type after coercion. */ public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, Class clazz) { final InstructionList il = methodGen.getInstructionList(); if (clazz == Character.TYPE) { il.append(I2C); } else if (clazz == Byte.TYPE) { il.append(I2B); } else if (clazz == Short.TYPE) { il.append(I2S); } else if (clazz == Integer.TYPE) { il.append(NOP); } else if (clazz == Long.TYPE) { il.append(I2L); } else if (clazz == Float.TYPE) { il.append(I2F); } else if (clazz == Double.TYPE) { il.append(I2D); } // Is Double <: clazz? I.e. clazz in { Double, Number, Object } else if (clazz.isAssignableFrom(java.lang.Double.class)) { il.append(I2D); Type.Real.translateTo(classGen, methodGen, Type.Reference); } else { ErrorMsg err = new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR, toString(), clazz.getName()); classGen.getParser().reportError(Constants.FATAL, err); } }
/** * Translates a void into an object of internal type <code>type</code>. This translation is needed * when calling external functions that return void. * * @see org.apache.xalan.xsltc.compiler.util.Type#translateTo */ public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, Type type) { if (type == Type.String) { translateTo(classGen, methodGen, (StringType) type); } else { ErrorMsg err = new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR, toString(), type.toString()); classGen.getParser().reportError(Constants.FATAL, err); } }
/** * Translates an external (primitive) Java type into a void. Only an external "void" can be * converted to this class. */ public void translateFrom(ClassGenerator classGen, MethodGenerator methodGen, Class clazz) { if (!clazz.getName().equals("void")) { ErrorMsg err = new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR, toString(), clazz.getName()); classGen.getParser().reportError(Constants.FATAL, err); } }