/** * Translates an external (primitive) Java type into a string. * * @see com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateFrom */ public void translateFrom(ClassGenerator classGen, MethodGenerator methodGen, Class clazz) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); if (clazz.getName().equals("java.lang.String")) { // same internal representation, convert null to "" il.append(DUP); final BranchHandle ifNonNull = il.append(new IFNONNULL(null)); il.append(POP); il.append(new PUSH(cpg, "")); ifNonNull.setTarget(il.append(NOP)); } else { ErrorMsg err = new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR, toString(), clazz.getName()); classGen.getParser().reportError(Constants.FATAL, err); } }
private void compileDefault(ClassGenerator classGen, MethodGenerator methodGen) { int index; ConstantPoolGen cpg = classGen.getConstantPool(); InstructionList il = methodGen.getInstructionList(); int[] fieldIndexes = getXSLTC().getNumberFieldIndexes(); if (fieldIndexes[_level] == -1) { Field defaultNode = new Field(ACC_PRIVATE, cpg.addUtf8(FieldNames[_level]), cpg.addUtf8(NODE_COUNTER_SIG), null, cpg.getConstantPool()); // Add a new private field to this class classGen.addField(defaultNode); // Get a reference to the newly added field fieldIndexes[_level] = cpg.addFieldref(classGen.getClassName(), FieldNames[_level], NODE_COUNTER_SIG); } // Check if field is initialized (runtime) il.append(classGen.loadTranslet()); il.append(new GETFIELD(fieldIndexes[_level])); final BranchHandle ifBlock1 = il.append(new IFNONNULL(null)); // Create an instance of DefaultNodeCounter index = cpg.addMethodref(ClassNames[_level], "getDefaultNodeCounter", "(" + TRANSLET_INTF_SIG + DOM_INTF_SIG + NODE_ITERATOR_SIG + ")" + NODE_COUNTER_SIG); il.append(classGen.loadTranslet()); il.append(methodGen.loadDOM()); il.append(methodGen.loadIterator()); il.append(new INVOKESTATIC(index)); il.append(DUP); // Store the node counter in the field il.append(classGen.loadTranslet()); il.append(SWAP); il.append(new PUTFIELD(fieldIndexes[_level])); final BranchHandle ifBlock2 = il.append(new GOTO(null)); // Backpatch conditionals ifBlock1.setTarget(il.append(classGen.loadTranslet())); il.append(new GETFIELD(fieldIndexes[_level])); ifBlock2.setTarget(il.append(NOP)); }