Here are the examples of the java api class com.sun.org.apache.xalan.internal.xsltc.compiler.util.NodeCounterGenerator taken from open source projects.
1. Number#compilePatterns()
Project: openjdk
File: Number.java
File: Number.java
private void compilePatterns(ClassGenerator classGen, MethodGenerator methodGen) { int current; int field; LocalVariableGen local; MatchGenerator matchGen; NodeCounterGenerator nodeCounterGen; _className = getXSLTC().getHelperClassName(); nodeCounterGen = new NodeCounterGenerator(_className, ClassNames[_level], toString(), ACC_PUBLIC | ACC_SUPER, null, classGen.getStylesheet()); InstructionList il = null; ConstantPoolGen cpg = nodeCounterGen.getConstantPool(); // Add a new instance variable for each var in closure final int closureLen = (_closureVars == null) ? 0 : _closureVars.size(); for (int i = 0; i < closureLen; i++) { VariableBase var = ((VariableRefBase) _closureVars.get(i)).getVariable(); nodeCounterGen.addField(new Field(ACC_PUBLIC, cpg.addUtf8(var.getEscapedName()), cpg.addUtf8(var.getType().toSignature()), null, cpg.getConstantPool())); } // Add a single constructor to the class compileConstructor(nodeCounterGen); /* * Compile method matchesFrom() */ if (_from != null) { il = new InstructionList(); matchGen = new MatchGenerator(ACC_PUBLIC | ACC_FINAL, com.sun.org.apache.bcel.internal.generic.Type.BOOLEAN, new com.sun.org.apache.bcel.internal.generic.Type[] { com.sun.org.apache.bcel.internal.generic.Type.INT }, new String[] { "node" }, "matchesFrom", _className, il, cpg); compileLocals(nodeCounterGen, matchGen, il); // Translate Pattern il.append(matchGen.loadContextNode()); _from.translate(nodeCounterGen, matchGen); _from.synthesize(nodeCounterGen, matchGen); il.append(IRETURN); nodeCounterGen.addMethod(matchGen); } /* * Compile method matchesCount() */ if (_count != null) { il = new InstructionList(); matchGen = new MatchGenerator(ACC_PUBLIC | ACC_FINAL, com.sun.org.apache.bcel.internal.generic.Type.BOOLEAN, new com.sun.org.apache.bcel.internal.generic.Type[] { com.sun.org.apache.bcel.internal.generic.Type.INT }, new String[] { "node" }, "matchesCount", _className, il, cpg); compileLocals(nodeCounterGen, matchGen, il); // Translate Pattern il.append(matchGen.loadContextNode()); _count.translate(nodeCounterGen, matchGen); _count.synthesize(nodeCounterGen, matchGen); il.append(IRETURN); nodeCounterGen.addMethod(matchGen); } getXSLTC().dumpClass(nodeCounterGen.getJavaClass()); // Push an instance of the newly created class cpg = classGen.getConstantPool(); il = methodGen.getInstructionList(); final int index = cpg.addMethodref(_className, "<init>", "(" + TRANSLET_INTF_SIG + DOM_INTF_SIG + NODE_ITERATOR_SIG + "Z)V"); il.append(new NEW(cpg.addClass(_className))); il.append(DUP); il.append(classGen.loadTranslet()); il.append(methodGen.loadDOM()); il.append(methodGen.loadIterator()); il.append(_from != null ? ICONST_1 : ICONST_0); il.append(new INVOKESPECIAL(index)); // Initialize closure variables for (int i = 0; i < closureLen; i++) { final VariableRefBase varRef = (VariableRefBase) _closureVars.get(i); final VariableBase var = varRef.getVariable(); final Type varType = var.getType(); // Store variable in new closure il.append(DUP); il.append(var.loadInstruction()); il.append(new PUTFIELD(cpg.addFieldref(_className, var.getEscapedName(), varType.toSignature()))); } }