com.sun.org.apache.bcel.internal.classfile.Field Java Examples

The following examples show how to use com.sun.org.apache.bcel.internal.classfile.Field. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FieldGen.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Instantiate from existing field.
 *
 * @param field Field object
 * @param cp constant pool (must contain the same entries as the field's constant pool)
 */
public FieldGen(final Field field, final ConstantPoolGen cp) {
    this(field.getAccessFlags(), Type.getType(field.getSignature()), field.getName(), cp);
    final Attribute[] attrs = field.getAttributes();
    for (final Attribute attr : attrs) {
        if (attr instanceof ConstantValue) {
            setValue(((ConstantValue) attr).getConstantValueIndex());
        } else if (attr instanceof Annotations) {
            final Annotations runtimeAnnotations = (Annotations)attr;
            final AnnotationEntry[] annotationEntries = runtimeAnnotations.getAnnotationEntries();
            for (final AnnotationEntry element : annotationEntries) {
                addAnnotationEntry(new AnnotationEntryGen(element,cp,false));
            }
        } else {
            addAttribute(attr);
        }
    }
}
 
Example #2
Source File: MethodHTML.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Print field of class.
 *
 * @param field field to print
 * @throws java.io.IOException
 */
private void writeField( final Field field ) throws IOException {
    final String type = Utility.signatureToString(field.getSignature());
    final String name = field.getName();
    String access = Utility.accessToString(field.getAccessFlags());
    Attribute[] attributes;
    access = Utility.replace(access, " ", " ");
    file.print("<TR><TD><FONT COLOR=\"#FF0000\">" + access + "</FONT></TD>\n<TD>"
            + Class2HTML.referenceType(type) + "</TD><TD><A NAME=\"field" + name + "\">" + name
            + "</A></TD>");
    attributes = field.getAttributes();
    // Write them to the Attributes.html file with anchor "<name>[<i>]"
    for (int i = 0; i < attributes.length; i++) {
        attribute_html.writeAttribute(attributes[i], name + "@" + i);
    }
    for (int i = 0; i < attributes.length; i++) {
        if (attributes[i].getTag() == Const.ATTR_CONSTANT_VALUE) { // Default value
            final String str = ((ConstantValue) attributes[i]).toString();
            // Reference attribute in _attributes.html
            file.print("<TD>= <A HREF=\"" + class_name + "_attributes.html#" + name + "@" + i
                    + "\" TARGET=\"Attributes\">" + str + "</TD>\n");
            break;
        }
    }
    file.println("</TR>");
}
 
Example #3
Source File: ClassGen.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * @return the (finally) built up Java class object.
 */
public JavaClass getJavaClass() {
    final int[] interfaces = getInterfaces();
    final Field[] fields = getFields();
    final Method[] methods = getMethods();
    Attribute[] attributes = null;
    if (annotation_vec.isEmpty()) {
        attributes = getAttributes();
    } else {
        // TODO: Sometime later, trash any attributes called 'RuntimeVisibleAnnotations' or 'RuntimeInvisibleAnnotations'
        final Attribute[] annAttributes  = AnnotationEntryGen.getAnnotationAttributes(cp, getAnnotationEntries());
        attributes = new Attribute[attribute_vec.size()+annAttributes.length];
        attribute_vec.toArray(attributes);
        System.arraycopy(annAttributes,0,attributes,attribute_vec.size(),annAttributes.length);
    }
    // Must be last since the above calls may still add something to it
    final ConstantPool _cp = this.cp.getFinalConstantPool();
    return new JavaClass(class_name_index, superclass_name_index, file_name, major, minor,
            super.getAccessFlags(), _cp, interfaces, fields, methods, attributes);
}
 
Example #4
Source File: MethodHTML.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
MethodHTML(final String dir, final String class_name, final Method[] methods, final Field[] fields,
        final ConstantHTML constant_html, final AttributeHTML attribute_html) throws IOException {
    this.class_name = class_name;
    this.attribute_html = attribute_html;
    this.constant_html = constant_html;
    file = new PrintWriter(new FileOutputStream(dir + class_name + "_methods.html"));
    file.println("<HTML><BODY BGCOLOR=\"#C0C0C0\"><TABLE BORDER=0>");
    file.println("<TR><TH ALIGN=LEFT>Access&nbsp;flags</TH><TH ALIGN=LEFT>Type</TH>"
            + "<TH ALIGN=LEFT>Field&nbsp;name</TH></TR>");
    for (final Field field : fields) {
        writeField(field);
    }
    file.println("</TABLE>");
    file.println("<TABLE BORDER=0><TR><TH ALIGN=LEFT>Access&nbsp;flags</TH>"
            + "<TH ALIGN=LEFT>Return&nbsp;type</TH><TH ALIGN=LEFT>Method&nbsp;name</TH>"
            + "<TH ALIGN=LEFT>Arguments</TH></TR>");
    for (int i = 0; i < methods.length; i++) {
        writeMethod(methods[i], i);
    }
    file.println("</TABLE></BODY></HTML>");
    file.close();
}
 
Example #5
Source File: BCELifier.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
@Override
public void visitField( final Field field ) {
    _out.println();
    _out.println("    field = new FieldGen(" + printFlags(field.getAccessFlags()) + ", "
            + printType(field.getSignature()) + ", \"" + field.getName() + "\", _cp);");
    final ConstantValue cv = field.getConstantValue();
    if (cv != null) {
        final String value = cv.toString();
        _out.println("    field.setInitValue(" + value + ")");
    }
    _out.println("    _cg.addField(field.getField());");
}
 
Example #6
Source File: BCELifier.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
private void printCreate() {
    _out.println("  public void create(OutputStream out) throws IOException {");
    final Field[] fields = _clazz.getFields();
    if (fields.length > 0) {
        _out.println("    createFields();");
    }
    final Method[] methods = _clazz.getMethods();
    for (int i = 0; i < methods.length; i++) {
        _out.println("    createMethod_" + i + "();");
    }
    _out.println("    _cg.getJavaClass().dump(out);");
    _out.println("  }");
    _out.println();
}
 
Example #7
Source File: BytecodeTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void visitField(Field obj) {
            if (obj.isStatic()) {
//                System.out.println("signature "+obj.getSignature());
                Type name = Type.getReturnType(obj.getSignature());
                if (pdType.equals(name) ||
                        bdType.equals(name) ||
                        mdType.equals(name) ||
                        edType.equals(name)) {
                    hasDescFields = true;
                }
            }
        }
 
Example #8
Source File: BytecodeTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override public void visitField(Field obj) {
            if (obj.isStatic()) {
//                System.out.println("signature "+obj.getSignature());
                Type name = Type.getReturnType(obj.getSignature());
                if (imageType.equals(name) ||
                        image1Type.equals(name) ||
                        image2Type.equals(name)) {
                    hasImageFields = true;
                }
                if (bType.equals(name) ||
                        b2Type.equals(name)) {
                    hasPropFields = true;
                }
            }
        }
 
Example #9
Source File: ClassGen.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/** Replace given field with new one. If the old one does not exist
 * add the new_ field to the class anyway.
 */
public void replaceField( final Field old, final Field new_ ) {
    if (new_ == null) {
        throw new ClassGenException("Replacement method must not be null");
    }
    final int i = field_vec.indexOf(old);
    if (i < 0) {
        field_vec.add(new_);
    } else {
        field_vec.set(i, new_);
    }
}
 
Example #10
Source File: ClassGen.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/** @return field object with given name, or null
 */
public Field containsField( final String name ) {
    for (final Field f : field_vec) {
        if (f.getName().equals(name)) {
            return f;
        }
    }
    return null;
}
 
Example #11
Source File: ClassGen.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize with existing class.
 * @param clazz JavaClass object (e.g. read from file)
 */
public ClassGen(final JavaClass clazz) {
    super(clazz.getAccessFlags());
    class_name_index = clazz.getClassNameIndex();
    superclass_name_index = clazz.getSuperclassNameIndex();
    class_name = clazz.getClassName();
    super_class_name = clazz.getSuperclassName();
    file_name = clazz.getSourceFileName();
    cp = new ConstantPoolGen(clazz.getConstantPool());
    major = clazz.getMajor();
    minor = clazz.getMinor();
    final Attribute[] attributes = clazz.getAttributes();
    // J5TODO: Could make unpacking lazy, done on first reference
    final AnnotationEntryGen[] annotations = unpackAnnotations(attributes);
    final Method[] methods = clazz.getMethods();
    final Field[] fields = clazz.getFields();
    final String[] interfaces = clazz.getInterfaceNames();
    for (final String interface1 : interfaces) {
        addInterface(interface1);
    }
    for (final Attribute attribute : attributes) {
        if (!(attribute instanceof Annotations)) {
            addAttribute(attribute);
        }
    }
    for (final AnnotationEntryGen annotation : annotations) {
        addAnnotationEntry(annotation);
    }
    for (final Method method : methods) {
        addMethod(method);
    }
    for (final Field field : fields) {
        addField(field);
    }
}
 
Example #12
Source File: FieldGen.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Get field object after having set up all necessary values.
 */
public Field getField() {
    final String signature = getSignature();
    final int name_index = super.getConstantPool().addUtf8(super.getName());
    final int signature_index = super.getConstantPool().addUtf8(signature);
    if (value != null) {
        checkType(super.getType());
        final int index = addConstant();
        addAttribute(new ConstantValue(super.getConstantPool().addUtf8("ConstantValue"), 2, index,
                super.getConstantPool().getConstantPool())); // sic
    }
    addAnnotationsAsAttribute(super.getConstantPool());
    return new Field(super.getAccessFlags(), name_index, signature_index, getAttributes(),
            super.getConstantPool().getConstantPool()); // sic
}
 
Example #13
Source File: Variable.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // Don't generate code for unreferenced variables
    if (_refs.isEmpty()) {
        _ignore = true;
    }

    // Make sure that a variable instance is only compiled once
    if (_ignore) return;
    _ignore = true;

    final String name = getEscapedName();

    if (isLocal()) {
        // Compile variable value computation
        translateValue(classGen, methodGen);

        // Add a new local variable and store value
        boolean createLocal = _local == null;
        if (createLocal) {
            mapRegister(methodGen);
        }
        InstructionHandle storeInst =
        il.append(_type.STORE(_local.getIndex()));

        // If the local is just being created, mark the store as the start
        // of its live range.  Note that it might have been created by
        // initializeVariables already, which would have set the start of
        // the live range already.
        if (createLocal) {
            _local.setStart(storeInst);
    }
    }
    else {
        String signature = _type.toSignature();

        // Global variables are store in class fields
        if (classGen.containsField(name) == null) {
            classGen.addField(new Field(ACC_PUBLIC,
                                        cpg.addUtf8(name),
                                        cpg.addUtf8(signature),
                                        null, cpg.getConstantPool()));

            // Push a reference to "this" for putfield
            il.append(classGen.loadTranslet());
            // Compile variable value computation
            translateValue(classGen, methodGen);
            // Store the variable in the allocated field
            il.append(new PUTFIELD(cpg.addFieldref(classGen.getClassName(),
                                                   name, signature)));
        }
    }
}
 
Example #14
Source File: ClassGen.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
public Field[] getFields() {
    return field_vec.toArray(new Field[field_vec.size()]);
}
 
Example #15
Source File: Sort.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create a new auxillary class extending NodeSortRecord.
 */
private static String compileSortRecord(Vector<Sort> sortObjects,
                                        ClassGenerator classGen,
                                        MethodGenerator methodGen) {
    final XSLTC  xsltc = sortObjects.firstElement().getXSLTC();
    final String className = xsltc.getHelperClassName();

    // This generates a new class for handling this specific sort
    final NodeSortRecordGenerator sortRecord =
        new NodeSortRecordGenerator(className,
                                    NODE_SORT_RECORD,
                                    "sort$0.java",
                                    ACC_PUBLIC | ACC_SUPER | ACC_FINAL,
                                    new String[] {},
                                    classGen.getStylesheet());

    final ConstantPoolGen cpg = sortRecord.getConstantPool();

    // Add a new instance variable for each var in closure
    final int nsorts = sortObjects.size();
    final ArrayList<VariableRefBase> dups = new ArrayList<>();

    for (int j = 0; j < nsorts; j++) {
        final Sort sort = sortObjects.get(j);

        // Set the name of the inner class in this sort object
        sort.setInnerClassName(className);

        final int length = (sort._closureVars == null) ? 0 :
            sort._closureVars.size();
        for (int i = 0; i < length; i++) {
            final VariableRefBase varRef = (VariableRefBase) sort._closureVars.get(i);

            // Discard duplicate variable references
            if (dups.contains(varRef)) continue;

            final VariableBase var = varRef.getVariable();
            sortRecord.addField(new Field(ACC_PUBLIC,
                                cpg.addUtf8(var.getEscapedName()),
                                cpg.addUtf8(var.getType().toSignature()),
                                null, cpg.getConstantPool()));
            dups.add(varRef);
        }
    }

    MethodGenerator init = compileInit(sortRecord, cpg, className);
    MethodGenerator extract = compileExtract(sortObjects, sortRecord,
                                    cpg, className);
    sortRecord.addMethod(init);
    sortRecord.addMethod(extract);

    xsltc.dumpClass(sortRecord.getJavaClass());
    return className;
}
 
Example #16
Source File: StepPattern.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private void translateGeneralContext(ClassGenerator classGen,
                                     MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    int iteratorIndex = 0;
    BranchHandle ifBlock = null;
    LocalVariableGen iter, node, node2;
    final String iteratorName = getNextFieldName();

    // Store node on the stack into a local variable
    node = methodGen.addLocalVariable("step_pattern_tmp1",
                                      Util.getJCRefType(NODE_SIG),
                                      null, null);
    node.setStart(il.append(new ISTORE(node.getIndex())));

    // Create a new local to store the iterator
    iter = methodGen.addLocalVariable("step_pattern_tmp2",
                                      Util.getJCRefType(NODE_ITERATOR_SIG),
                                      null, null);

    // Add a new private field if this is the main class
    if (!classGen.isExternal()) {
        final Field iterator =
            new Field(ACC_PRIVATE,
                      cpg.addUtf8(iteratorName),
                      cpg.addUtf8(NODE_ITERATOR_SIG),
                      null, cpg.getConstantPool());
        classGen.addField(iterator);
        iteratorIndex = cpg.addFieldref(classGen.getClassName(),
                                        iteratorName,
                                        NODE_ITERATOR_SIG);

        il.append(classGen.loadTranslet());
        il.append(new GETFIELD(iteratorIndex));
        il.append(DUP);
        iter.setStart(il.append(new ASTORE(iter.getIndex())));
        ifBlock = il.append(new IFNONNULL(null));
        il.append(classGen.loadTranslet());
    }

    // Compile the step created at type checking time
    _step.translate(classGen, methodGen);
    InstructionHandle iterStore = il.append(new ASTORE(iter.getIndex()));

    // If in the main class update the field too
    if (!classGen.isExternal()) {
        il.append(new ALOAD(iter.getIndex()));
        il.append(new PUTFIELD(iteratorIndex));
        ifBlock.setTarget(il.append(NOP));
    } else {
        // If class is not external, start of range for iter variable was
        // set above
        iter.setStart(iterStore);
    }

    // Get the parent of the node on the stack
    il.append(methodGen.loadDOM());
    il.append(new ILOAD(node.getIndex()));
    int index = cpg.addInterfaceMethodref(DOM_INTF,
                                          GET_PARENT, GET_PARENT_SIG);
    il.append(new INVOKEINTERFACE(index, 2));

    // Initialize the iterator with the parent
    il.append(new ALOAD(iter.getIndex()));
    il.append(SWAP);
    il.append(methodGen.setStartNode());

    /*
     * Inline loop:
     *
     * int node2;
     * while ((node2 = iter.next()) != NodeIterator.END
     *                && node2 < node);
     * return node2 == node;
     */
    BranchHandle skipNext;
    InstructionHandle begin, next;
    node2 = methodGen.addLocalVariable("step_pattern_tmp3",
                                       Util.getJCRefType(NODE_SIG),
                                       null, null);

    skipNext = il.append(new GOTO(null));
    next = il.append(new ALOAD(iter.getIndex()));
    node2.setStart(next);
    begin = il.append(methodGen.nextNode());
    il.append(DUP);
    il.append(new ISTORE(node2.getIndex()));
    _falseList.add(il.append(new IFLT(null)));      // NodeIterator.END

    il.append(new ILOAD(node2.getIndex()));
    il.append(new ILOAD(node.getIndex()));
    iter.setEnd(il.append(new IF_ICMPLT(next)));

    node2.setEnd(il.append(new ILOAD(node2.getIndex())));
    node.setEnd(il.append(new ILOAD(node.getIndex())));
    _falseList.add(il.append(new IF_ICMPNE(null)));

    skipNext.setTarget(begin);
}
 
Example #17
Source File: Number.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
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));
}
 
Example #18
Source File: Param.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    if (_ignore) return;
    _ignore = true;

    /*
     * To fix bug 24518 related to setting parameters of the form
     * {namespaceuri}localName which will get mapped to an instance
     * variable in the class.
     */
    final String name = BasisLibrary.mapQNameToJavaName(_name.toString());
    final String signature = _type.toSignature();
    final String className = _type.getClassName();

    if (isLocal()) {
        /*
          * If simple named template then generate a conditional init of the
          * param using its default value:
          *       if (param == null) param = <default-value>
          */
        if (_isInSimpleNamedTemplate) {
            il.append(loadInstruction());
            BranchHandle ifBlock = il.append(new IFNONNULL(null));
            translateValue(classGen, methodGen);
            il.append(storeInstruction());
            ifBlock.setTarget(il.append(NOP));
            return;
        }

        il.append(classGen.loadTranslet());
        il.append(new PUSH(cpg, name));
        translateValue(classGen, methodGen);
        il.append(new PUSH(cpg, true));

        // Call addParameter() from this class
        il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS,
                                                     ADD_PARAMETER,
                                                     ADD_PARAMETER_SIG)));
        if (className != EMPTYSTRING) {
            il.append(new CHECKCAST(cpg.addClass(className)));
        }

        _type.translateUnBox(classGen, methodGen);

        if (_refs.isEmpty()) { // nobody uses the value
            il.append(_type.POP());
            _local = null;
        }
        else {              // normal case
            _local = methodGen.addLocalVariable2(name,
                                                 _type.toJCType(),
                                                 il.getEnd());
            // Cache the result of addParameter() in a local variable
            il.append(_type.STORE(_local.getIndex()));
        }
    }
    else {
        if (classGen.containsField(name) == null) {
            classGen.addField(new Field(ACC_PUBLIC, cpg.addUtf8(name),
                                        cpg.addUtf8(signature),
                                        null, cpg.getConstantPool()));
            il.append(classGen.loadTranslet());
            il.append(DUP);
            il.append(new PUSH(cpg, name));
            translateValue(classGen, methodGen);
            il.append(new PUSH(cpg, true));

            // Call addParameter() from this class
            il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS,
                                                 ADD_PARAMETER,
                                                 ADD_PARAMETER_SIG)));

            _type.translateUnBox(classGen, methodGen);

            // Cache the result of addParameter() in a field
            if (className != EMPTYSTRING) {
                il.append(new CHECKCAST(cpg.addClass(className)));
            }
            il.append(new PUTFIELD(cpg.addFieldref(classGen.getClassName(),
                                                   name, signature)));
        }
    }
}
 
Example #19
Source File: StepPattern.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private void translateGeneralContext(ClassGenerator classGen,
                                     MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    int iteratorIndex = 0;
    BranchHandle ifBlock = null;
    LocalVariableGen iter, node, node2;
    final String iteratorName = getNextFieldName();

    // Store node on the stack into a local variable
    node = methodGen.addLocalVariable("step_pattern_tmp1",
                                      Util.getJCRefType(NODE_SIG),
                                      null, null);
    node.setStart(il.append(new ISTORE(node.getIndex())));

    // Create a new local to store the iterator
    iter = methodGen.addLocalVariable("step_pattern_tmp2",
                                      Util.getJCRefType(NODE_ITERATOR_SIG),
                                      null, null);

    // Add a new private field if this is the main class
    if (!classGen.isExternal()) {
        final Field iterator =
            new Field(ACC_PRIVATE,
                      cpg.addUtf8(iteratorName),
                      cpg.addUtf8(NODE_ITERATOR_SIG),
                      null, cpg.getConstantPool());
        classGen.addField(iterator);
        iteratorIndex = cpg.addFieldref(classGen.getClassName(),
                                        iteratorName,
                                        NODE_ITERATOR_SIG);

        il.append(classGen.loadTranslet());
        il.append(new GETFIELD(iteratorIndex));
        il.append(DUP);
        iter.setStart(il.append(new ASTORE(iter.getIndex())));
        ifBlock = il.append(new IFNONNULL(null));
        il.append(classGen.loadTranslet());
    }

    // Compile the step created at type checking time
    _step.translate(classGen, methodGen);
    InstructionHandle iterStore = il.append(new ASTORE(iter.getIndex()));

    // If in the main class update the field too
    if (!classGen.isExternal()) {
        il.append(new ALOAD(iter.getIndex()));
        il.append(new PUTFIELD(iteratorIndex));
        ifBlock.setTarget(il.append(NOP));
    } else {
        // If class is not external, start of range for iter variable was
        // set above
        iter.setStart(iterStore);
    }

    // Get the parent of the node on the stack
    il.append(methodGen.loadDOM());
    il.append(new ILOAD(node.getIndex()));
    int index = cpg.addInterfaceMethodref(DOM_INTF,
                                          GET_PARENT, GET_PARENT_SIG);
    il.append(new INVOKEINTERFACE(index, 2));

    // Initialize the iterator with the parent
    il.append(new ALOAD(iter.getIndex()));
    il.append(SWAP);
    il.append(methodGen.setStartNode());

    /*
     * Inline loop:
     *
     * int node2;
     * while ((node2 = iter.next()) != NodeIterator.END
     *                && node2 < node);
     * return node2 == node;
     */
    BranchHandle skipNext;
    InstructionHandle begin, next;
    node2 = methodGen.addLocalVariable("step_pattern_tmp3",
                                       Util.getJCRefType(NODE_SIG),
                                       null, null);

    skipNext = il.append(new GOTO(null));
    next = il.append(new ALOAD(iter.getIndex()));
    node2.setStart(next);
    begin = il.append(methodGen.nextNode());
    il.append(DUP);
    il.append(new ISTORE(node2.getIndex()));
    _falseList.add(il.append(new IFLT(null)));      // NodeIterator.END

    il.append(new ILOAD(node2.getIndex()));
    il.append(new ILOAD(node.getIndex()));
    iter.setEnd(il.append(new IF_ICMPLT(next)));

    node2.setEnd(il.append(new ILOAD(node2.getIndex())));
    node.setEnd(il.append(new ILOAD(node.getIndex())));
    _falseList.add(il.append(new IF_ICMPNE(null)));

    skipNext.setTarget(begin);
}
 
Example #20
Source File: Variable.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // Don't generate code for unreferenced variables
    if (_refs.isEmpty()) {
        _ignore = true;
    }

    // Make sure that a variable instance is only compiled once
    if (_ignore) return;
    _ignore = true;

    final String name = getEscapedName();

    if (isLocal()) {
        // Compile variable value computation
        translateValue(classGen, methodGen);

        // Add a new local variable and store value
        boolean createLocal = _local == null;
        if (createLocal) {
            mapRegister(methodGen);
        }
        InstructionHandle storeInst =
        il.append(_type.STORE(_local.getIndex()));

        // If the local is just being created, mark the store as the start
        // of its live range.  Note that it might have been created by
        // initializeVariables already, which would have set the start of
        // the live range already.
        if (createLocal) {
            _local.setStart(storeInst);
    }
    }
    else {
        String signature = _type.toSignature();

        // Global variables are store in class fields
        if (classGen.containsField(name) == null) {
            classGen.addField(new Field(ACC_PUBLIC,
                                        cpg.addUtf8(name),
                                        cpg.addUtf8(signature),
                                        null, cpg.getConstantPool()));

            // Push a reference to "this" for putfield
            il.append(classGen.loadTranslet());
            // Compile variable value computation
            translateValue(classGen, methodGen);
            // Store the variable in the allocated field
            il.append(new PUTFIELD(cpg.addFieldref(classGen.getClassName(),
                                                   name, signature)));
        }
    }
}
 
Example #21
Source File: Sort.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create a new auxillary class extending NodeSortRecord.
 */
private static String compileSortRecord(Vector sortObjects,
                                        ClassGenerator classGen,
                                        MethodGenerator methodGen) {
    final XSLTC  xsltc = ((Sort)sortObjects.firstElement()).getXSLTC();
    final String className = xsltc.getHelperClassName();

    // This generates a new class for handling this specific sort
    final NodeSortRecordGenerator sortRecord =
        new NodeSortRecordGenerator(className,
                                    NODE_SORT_RECORD,
                                    "sort$0.java",
                                    ACC_PUBLIC | ACC_SUPER | ACC_FINAL,
                                    new String[] {},
                                    classGen.getStylesheet());

    final ConstantPoolGen cpg = sortRecord.getConstantPool();

    // Add a new instance variable for each var in closure
    final int nsorts = sortObjects.size();
    final ArrayList dups = new ArrayList();

    for (int j = 0; j < nsorts; j++) {
        final Sort sort = (Sort) sortObjects.get(j);

        // Set the name of the inner class in this sort object
        sort.setInnerClassName(className);

        final int length = (sort._closureVars == null) ? 0 :
            sort._closureVars.size();
        for (int i = 0; i < length; i++) {
            final VariableRefBase varRef = (VariableRefBase) sort._closureVars.get(i);

            // Discard duplicate variable references
            if (dups.contains(varRef)) continue;

            final VariableBase var = varRef.getVariable();
            sortRecord.addField(new Field(ACC_PUBLIC,
                                cpg.addUtf8(var.getEscapedName()),
                                cpg.addUtf8(var.getType().toSignature()),
                                null, cpg.getConstantPool()));
            dups.add(varRef);
        }
    }

    MethodGenerator init = compileInit(sortObjects, sortRecord,
                                     cpg, className);
    MethodGenerator extract = compileExtract(sortObjects, sortRecord,
                                    cpg, className);
    sortRecord.addMethod(init);
    sortRecord.addMethod(extract);

    xsltc.dumpClass(sortRecord.getJavaClass());
    return className;
}
 
Example #22
Source File: Number.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
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));
}
 
Example #23
Source File: Param.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    if (_ignore) return;
    _ignore = true;

    /*
     * To fix bug 24518 related to setting parameters of the form
     * {namespaceuri}localName which will get mapped to an instance
     * variable in the class.
     */
    final String name = BasisLibrary.mapQNameToJavaName(_name.toString());
    final String signature = _type.toSignature();
    final String className = _type.getClassName();

    if (isLocal()) {
        /*
          * If simple named template then generate a conditional init of the
          * param using its default value:
          *       if (param == null) param = <default-value>
          */
        if (_isInSimpleNamedTemplate) {
            il.append(loadInstruction());
            BranchHandle ifBlock = il.append(new IFNONNULL(null));
            translateValue(classGen, methodGen);
            il.append(storeInstruction());
            ifBlock.setTarget(il.append(NOP));
            return;
        }

        il.append(classGen.loadTranslet());
        il.append(new PUSH(cpg, name));
        translateValue(classGen, methodGen);
        il.append(new PUSH(cpg, true));

        // Call addParameter() from this class
        il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS,
                                                     ADD_PARAMETER,
                                                     ADD_PARAMETER_SIG)));
        if (className != EMPTYSTRING) {
            il.append(new CHECKCAST(cpg.addClass(className)));
        }

        _type.translateUnBox(classGen, methodGen);

        if (_refs.isEmpty()) { // nobody uses the value
            il.append(_type.POP());
            _local = null;
        }
        else {              // normal case
            _local = methodGen.addLocalVariable2(name,
                                                 _type.toJCType(),
                                                 il.getEnd());
            // Cache the result of addParameter() in a local variable
            il.append(_type.STORE(_local.getIndex()));
        }
    }
    else {
        if (classGen.containsField(name) == null) {
            classGen.addField(new Field(ACC_PUBLIC, cpg.addUtf8(name),
                                        cpg.addUtf8(signature),
                                        null, cpg.getConstantPool()));
            il.append(classGen.loadTranslet());
            il.append(DUP);
            il.append(new PUSH(cpg, name));
            translateValue(classGen, methodGen);
            il.append(new PUSH(cpg, true));

            // Call addParameter() from this class
            il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS,
                                                 ADD_PARAMETER,
                                                 ADD_PARAMETER_SIG)));

            _type.translateUnBox(classGen, methodGen);

            // Cache the result of addParameter() in a field
            if (className != EMPTYSTRING) {
                il.append(new CHECKCAST(cpg.addClass(className)));
            }
            il.append(new PUTFIELD(cpg.addFieldref(classGen.getClassName(),
                                                   name, signature)));
        }
    }
}
 
Example #24
Source File: StepPattern.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private void translateGeneralContext(ClassGenerator classGen,
                                     MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    int iteratorIndex = 0;
    BranchHandle ifBlock = null;
    LocalVariableGen iter, node, node2;
    final String iteratorName = getNextFieldName();

    // Store node on the stack into a local variable
    node = methodGen.addLocalVariable("step_pattern_tmp1",
                                      Util.getJCRefType(NODE_SIG),
                                      null, null);
    node.setStart(il.append(new ISTORE(node.getIndex())));

    // Create a new local to store the iterator
    iter = methodGen.addLocalVariable("step_pattern_tmp2",
                                      Util.getJCRefType(NODE_ITERATOR_SIG),
                                      null, null);

    // Add a new private field if this is the main class
    if (!classGen.isExternal()) {
        final Field iterator =
            new Field(ACC_PRIVATE,
                      cpg.addUtf8(iteratorName),
                      cpg.addUtf8(NODE_ITERATOR_SIG),
                      null, cpg.getConstantPool());
        classGen.addField(iterator);
        iteratorIndex = cpg.addFieldref(classGen.getClassName(),
                                        iteratorName,
                                        NODE_ITERATOR_SIG);

        il.append(classGen.loadTranslet());
        il.append(new GETFIELD(iteratorIndex));
        il.append(DUP);
        iter.setStart(il.append(new ASTORE(iter.getIndex())));
        ifBlock = il.append(new IFNONNULL(null));
        il.append(classGen.loadTranslet());
    }

    // Compile the step created at type checking time
    _step.translate(classGen, methodGen);
    InstructionHandle iterStore = il.append(new ASTORE(iter.getIndex()));

    // If in the main class update the field too
    if (!classGen.isExternal()) {
        il.append(new ALOAD(iter.getIndex()));
        il.append(new PUTFIELD(iteratorIndex));
        ifBlock.setTarget(il.append(NOP));
    } else {
        // If class is not external, start of range for iter variable was
        // set above
        iter.setStart(iterStore);
    }

    // Get the parent of the node on the stack
    il.append(methodGen.loadDOM());
    il.append(new ILOAD(node.getIndex()));
    int index = cpg.addInterfaceMethodref(DOM_INTF,
                                          GET_PARENT, GET_PARENT_SIG);
    il.append(new INVOKEINTERFACE(index, 2));

    // Initialize the iterator with the parent
    il.append(new ALOAD(iter.getIndex()));
    il.append(SWAP);
    il.append(methodGen.setStartNode());

    /*
     * Inline loop:
     *
     * int node2;
     * while ((node2 = iter.next()) != NodeIterator.END
     *                && node2 < node);
     * return node2 == node;
     */
    BranchHandle skipNext;
    InstructionHandle begin, next;
    node2 = methodGen.addLocalVariable("step_pattern_tmp3",
                                       Util.getJCRefType(NODE_SIG),
                                       null, null);

    skipNext = il.append(new GOTO(null));
    next = il.append(new ALOAD(iter.getIndex()));
    node2.setStart(next);
    begin = il.append(methodGen.nextNode());
    il.append(DUP);
    il.append(new ISTORE(node2.getIndex()));
    _falseList.add(il.append(new IFLT(null)));      // NodeIterator.END

    il.append(new ILOAD(node2.getIndex()));
    il.append(new ILOAD(node.getIndex()));
    iter.setEnd(il.append(new IF_ICMPLT(next)));

    node2.setEnd(il.append(new ILOAD(node2.getIndex())));
    node.setEnd(il.append(new ILOAD(node.getIndex())));
    _falseList.add(il.append(new IF_ICMPNE(null)));

    skipNext.setTarget(begin);
}
 
Example #25
Source File: Sort.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create a new auxillary class extending NodeSortRecord.
 */
private static String compileSortRecord(Vector sortObjects,
                                        ClassGenerator classGen,
                                        MethodGenerator methodGen) {
    final XSLTC  xsltc = ((Sort)sortObjects.firstElement()).getXSLTC();
    final String className = xsltc.getHelperClassName();

    // This generates a new class for handling this specific sort
    final NodeSortRecordGenerator sortRecord =
        new NodeSortRecordGenerator(className,
                                    NODE_SORT_RECORD,
                                    "sort$0.java",
                                    ACC_PUBLIC | ACC_SUPER | ACC_FINAL,
                                    new String[] {},
                                    classGen.getStylesheet());

    final ConstantPoolGen cpg = sortRecord.getConstantPool();

    // Add a new instance variable for each var in closure
    final int nsorts = sortObjects.size();
    final ArrayList dups = new ArrayList();

    for (int j = 0; j < nsorts; j++) {
        final Sort sort = (Sort) sortObjects.get(j);

        // Set the name of the inner class in this sort object
        sort.setInnerClassName(className);

        final int length = (sort._closureVars == null) ? 0 :
            sort._closureVars.size();
        for (int i = 0; i < length; i++) {
            final VariableRefBase varRef = (VariableRefBase) sort._closureVars.get(i);

            // Discard duplicate variable references
            if (dups.contains(varRef)) continue;

            final VariableBase var = varRef.getVariable();
            sortRecord.addField(new Field(ACC_PUBLIC,
                                cpg.addUtf8(var.getEscapedName()),
                                cpg.addUtf8(var.getType().toSignature()),
                                null, cpg.getConstantPool()));
            dups.add(varRef);
        }
    }

    MethodGenerator init = compileInit(sortObjects, sortRecord,
                                     cpg, className);
    MethodGenerator extract = compileExtract(sortObjects, sortRecord,
                                    cpg, className);
    sortRecord.addMethod(init);
    sortRecord.addMethod(extract);

    xsltc.dumpClass(sortRecord.getJavaClass());
    return className;
}
 
Example #26
Source File: Sort.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create a new auxillary class extending NodeSortRecord.
 */
private static String compileSortRecord(Vector<Sort> sortObjects,
                                        ClassGenerator classGen,
                                        MethodGenerator methodGen) {
    final XSLTC  xsltc = sortObjects.firstElement().getXSLTC();
    final String className = xsltc.getHelperClassName();

    // This generates a new class for handling this specific sort
    final NodeSortRecordGenerator sortRecord =
        new NodeSortRecordGenerator(className,
                                    NODE_SORT_RECORD,
                                    "sort$0.java",
                                    ACC_PUBLIC | ACC_SUPER | ACC_FINAL,
                                    new String[] {},
                                    classGen.getStylesheet());

    final ConstantPoolGen cpg = sortRecord.getConstantPool();

    // Add a new instance variable for each var in closure
    final int nsorts = sortObjects.size();
    final ArrayList<VariableRefBase> dups = new ArrayList<>();

    for (int j = 0; j < nsorts; j++) {
        final Sort sort = sortObjects.get(j);

        // Set the name of the inner class in this sort object
        sort.setInnerClassName(className);

        final int length = (sort._closureVars == null) ? 0 :
            sort._closureVars.size();
        for (int i = 0; i < length; i++) {
            final VariableRefBase varRef = (VariableRefBase) sort._closureVars.get(i);

            // Discard duplicate variable references
            if (dups.contains(varRef)) continue;

            final VariableBase var = varRef.getVariable();
            sortRecord.addField(new Field(ACC_PUBLIC,
                                cpg.addUtf8(var.getEscapedName()),
                                cpg.addUtf8(var.getType().toSignature()),
                                null, cpg.getConstantPool()));
            dups.add(varRef);
        }
    }

    MethodGenerator init = compileInit(sortRecord, cpg, className);
    MethodGenerator extract = compileExtract(sortObjects, sortRecord,
                                    cpg, className);
    sortRecord.addMethod(init);
    sortRecord.addMethod(extract);

    xsltc.dumpClass(sortRecord.getJavaClass());
    return className;
}
 
Example #27
Source File: Variable.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // Don't generate code for unreferenced variables
    if (_refs.isEmpty()) {
        _ignore = true;
    }

    // Make sure that a variable instance is only compiled once
    if (_ignore) return;
    _ignore = true;

    final String name = getEscapedName();

    if (isLocal()) {
        // Compile variable value computation
        translateValue(classGen, methodGen);

        // Add a new local variable and store value
        boolean createLocal = _local == null;
        if (createLocal) {
            mapRegister(methodGen);
        }
        InstructionHandle storeInst =
        il.append(_type.STORE(_local.getIndex()));

        // If the local is just being created, mark the store as the start
        // of its live range.  Note that it might have been created by
        // initializeVariables already, which would have set the start of
        // the live range already.
        if (createLocal) {
            _local.setStart(storeInst);
    }
    }
    else {
        String signature = _type.toSignature();

        // Global variables are store in class fields
        if (classGen.containsField(name) == null) {
            classGen.addField(new Field(ACC_PUBLIC,
                                        cpg.addUtf8(name),
                                        cpg.addUtf8(signature),
                                        null, cpg.getConstantPool()));

            // Push a reference to "this" for putfield
            il.append(classGen.loadTranslet());
            // Compile variable value computation
            translateValue(classGen, methodGen);
            // Store the variable in the allocated field
            il.append(new PUTFIELD(cpg.addFieldref(classGen.getClassName(),
                                                   name, signature)));
        }
    }
}
 
Example #28
Source File: Number.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
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));
}
 
Example #29
Source File: BCELifier.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
@Override
public void visitJavaClass( final JavaClass clazz ) {
    String class_name = clazz.getClassName();
    final String super_name = clazz.getSuperclassName();
    final String package_name = clazz.getPackageName();
    final String inter = Utility.printArray(clazz.getInterfaceNames(), false, true);
    if (!"".equals(package_name)) {
        class_name = class_name.substring(package_name.length() + 1);
        _out.println("package " + package_name + ";");
        _out.println();
    }
    _out.println("import " + BASE_PACKAGE + ".generic.*;");
    _out.println("import " + BASE_PACKAGE + ".classfile.*;");
    _out.println("import " + BASE_PACKAGE + ".*;");
    _out.println("import java.io.*;");
    _out.println();
    _out.println("public class " + class_name + "Creator {");
    _out.println("  private InstructionFactory _factory;");
    _out.println("  private ConstantPoolGen    _cp;");
    _out.println("  private ClassGen           _cg;");
    _out.println();
    _out.println("  public " + class_name + "Creator() {");
    _out.println("    _cg = new ClassGen(\""
            + (("".equals(package_name)) ? class_name : package_name + "." + class_name)
            + "\", \"" + super_name + "\", " + "\"" + clazz.getSourceFileName() + "\", "
            + printFlags(clazz.getAccessFlags(), FLAGS.CLASS) + ", "
            + "new String[] { " + inter + " });");
    _out.println();
    _out.println("    _cp = _cg.getConstantPool();");
    _out.println("    _factory = new InstructionFactory(_cg, _cp);");
    _out.println("  }");
    _out.println();
    printCreate();
    final Field[] fields = clazz.getFields();
    if (fields.length > 0) {
        _out.println("  private void createFields() {");
        _out.println("    FieldGen field;");
        for (final Field field : fields) {
            field.accept(this);
        }
        _out.println("  }");
        _out.println();
    }
    final Method[] methods = clazz.getMethods();
    for (int i = 0; i < methods.length; i++) {
        _out.println("  private void createMethod_" + i + "() {");
        methods[i].accept(this);
        _out.println("  }");
        _out.println();
    }
    printMain();
    _out.println("}");
}
 
Example #30
Source File: ClassGen.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
public boolean containsField( final Field f ) {
    return field_vec.contains(f);
}