* Notice that local variables need to be "unboxed".
*/
private void compileFilter(ClassGenerator classGen,
MethodGenerator methodGen) {
TestGenerator testGen;
LocalVariableGen local;
FilterGenerator filterGen;
_className = getXSLTC().getHelperClassName();
filterGen = new FilterGenerator(_className,
"java.lang.Object",
toString(),
ACC_PUBLIC | ACC_SUPER,
new String[] {
CURRENT_NODE_LIST_FILTER
},
classGen.getStylesheet());
final ConstantPoolGen cpg = filterGen.getConstantPool();
final int length = (_closureVars == null) ? 0 : _closureVars.size();
// Add a new instance variable for each var in closure
for (int i = 0; i < length; i++) {
VariableBase var = ((VariableRefBase) _closureVars.get(i)).getVariable();
filterGen.addField(new Field(ACC_PUBLIC,
cpg.addUtf8(var.getEscapedName()),
cpg.addUtf8(var.getType().toSignature()),
null, cpg.getConstantPool()));
}
final InstructionList il = new InstructionList();
testGen = new TestGenerator(ACC_PUBLIC | ACC_FINAL,
org.apache.bcel.generic.Type.BOOLEAN,
new org.apache.bcel.generic.Type[] {
org.apache.bcel.generic.Type.INT,
org.apache.bcel.generic.Type.INT,
org.apache.bcel.generic.Type.INT,
org.apache.bcel.generic.Type.INT,
Util.getJCRefType(TRANSLET_SIG),
Util.getJCRefType(NODE_ITERATOR_SIG)
},
new String[] {
"node",
"position",
"last",
"current",
"translet",
"iterator"
},
"test", _className, il, cpg);
// Store the dom in a local variable
local = testGen.addLocalVariable("document",
Util.getJCRefType(DOM_INTF_SIG),
null, null);
final String className = classGen.getClassName();
il.append(filterGen.loadTranslet());
il.append(new CHECKCAST(cpg.addClass(className)));
il.append(new GETFIELD(cpg.addFieldref(className,
DOM_FIELD, DOM_INTF_SIG)));
il.append(new ASTORE(local.getIndex()));
// Store the dom index in the test generator
testGen.setDomIndex(local.getIndex());
_exp.translate(filterGen, testGen);
il.append(IRETURN);
testGen.stripAttributes(true);