Package org.apache.bcel.classfile

Examples of org.apache.bcel.classfile.ConstantNameAndType


                String short_method_class = Utility.compactClassName(method_class); // I.e., remove java.lang.
                short_method_class = Utility.compactClassName(method_class); // I.e., remove java.lang.
                short_method_class = Utility.compactClassName(short_method_class, class_package
                        + ".", true); // Remove class package prefix
                // Get method signature
                ConstantNameAndType c2 = (ConstantNameAndType) constant_pool.getConstant(
                        name_index, CONSTANT_NameAndType);
                String signature = constant_pool.constantToString(c2.getSignatureIndex(),
                        CONSTANT_Utf8);
                // Get array of strings containing the argument types
                String[] args = Utility.methodSignatureArgumentTypes(signature, false);
                // Get return type string
                String type = Utility.methodSignatureReturnType(signature, false);
                String ret_type = Class2HTML.referenceType(type);
                StringBuffer buf = new StringBuffer("(");
                for (int i = 0; i < args.length; i++) {
                    buf.append(Class2HTML.referenceType(args[i]));
                    if (i < args.length - 1) {
                        buf.append(",&nbsp;");
                    }
                }
                buf.append(")");
                String arg_types = buf.toString();
                if (method_class.equals(class_name)) {
                    ref = "<A HREF=\"" + class_name + "_code.html#method"
                            + getMethodNumber(method_name + signature) + "\" TARGET=Code>"
                            + html_method_name + "</A>";
                } else {
                    ref = "<A HREF=\"" + method_class + ".html" + "\" TARGET=_top>"
                            + short_method_class + "</A>." + html_method_name;
                }
                constant_ref[index] = ret_type + "&nbsp;<A HREF=\"" + class_name + "_cp.html#cp"
                        + class_index + "\" TARGET=Constants>" + short_method_class
                        + "</A>.<A HREF=\"" + class_name + "_cp.html#cp" + index
                        + "\" TARGET=ConstantPool>" + html_method_name + "</A>&nbsp;" + arg_types;
                file.println("<P><TT>" + ret_type + "&nbsp;" + ref + arg_types
                        + "&nbsp;</TT>\n<UL>" + "<LI><A HREF=\"#cp" + class_index
                        + "\">Class index(" + class_index + ")</A>\n" + "<LI><A HREF=\"#cp"
                        + name_index + "\">NameAndType index(" + name_index + ")</A></UL>");
                break;
            case CONSTANT_Fieldref:
                // Get class_index and name_and_type_index
                ConstantFieldref c3 = (ConstantFieldref) constant_pool.getConstant(index,
                        CONSTANT_Fieldref);
                class_index = c3.getClassIndex();
                name_index = c3.getNameAndTypeIndex();
                // Get method name and its class (compacted)
                String field_class = constant_pool.constantToString(class_index, CONSTANT_Class);
                String short_field_class = Utility.compactClassName(field_class); // I.e., remove java.lang.
                short_field_class = Utility.compactClassName(short_field_class,
                        class_package + ".", true); // Remove class package prefix
                String field_name = constant_pool
                        .constantToString(name_index, CONSTANT_NameAndType);
                if (field_class.equals(class_name)) {
                    ref = "<A HREF=\"" + field_class + "_methods.html#field" + field_name
                            + "\" TARGET=Methods>" + field_name + "</A>";
                } else {
                    ref = "<A HREF=\"" + field_class + ".html\" TARGET=_top>" + short_field_class
                            + "</A>." + field_name + "\n";
                }
                constant_ref[index] = "<A HREF=\"" + class_name + "_cp.html#cp" + class_index
                        + "\" TARGET=Constants>" + short_field_class + "</A>.<A HREF=\""
                        + class_name + "_cp.html#cp" + index + "\" TARGET=ConstantPool>"
                        + field_name + "</A>";
                file.println("<P><TT>" + ref + "</TT><BR>\n" + "<UL>" + "<LI><A HREF=\"#cp"
                        + class_index + "\">Class(" + class_index + ")</A><BR>\n"
                        + "<LI><A HREF=\"#cp" + name_index + "\">NameAndType(" + name_index
                        + ")</A></UL>");
                break;
            case CONSTANT_Class:
                ConstantClass c4 = (ConstantClass) constant_pool.getConstant(index, CONSTANT_Class);
                name_index = c4.getNameIndex();
                String class_name2 = constant_pool.constantToString(index, tag); // / -> .
                String short_class_name = Utility.compactClassName(class_name2); // I.e., remove java.lang.
                short_class_name = Utility.compactClassName(short_class_name, class_package + ".",
                        true); // Remove class package prefix
                ref = "<A HREF=\"" + class_name2 + ".html\" TARGET=_top>" + short_class_name
                        + "</A>";
                constant_ref[index] = "<A HREF=\"" + class_name + "_cp.html#cp" + index
                        + "\" TARGET=ConstantPool>" + short_class_name + "</A>";
                file.println("<P><TT>" + ref + "</TT><UL>" + "<LI><A HREF=\"#cp" + name_index
                        + "\">Name index(" + name_index + ")</A></UL>\n");
                break;
            case CONSTANT_String:
                ConstantString c5 = (ConstantString) constant_pool.getConstant(index,
                        CONSTANT_String);
                name_index = c5.getStringIndex();
                String str = Class2HTML.toHTML(constant_pool.constantToString(index, tag));
                file.println("<P><TT>" + str + "</TT><UL>" + "<LI><A HREF=\"#cp" + name_index
                        + "\">Name index(" + name_index + ")</A></UL>\n");
                break;
            case CONSTANT_NameAndType:
                ConstantNameAndType c6 = (ConstantNameAndType) constant_pool.getConstant(index,
                        CONSTANT_NameAndType);
                name_index = c6.getNameIndex();
                int signature_index = c6.getSignatureIndex();
                file.println("<P><TT>"
                        + Class2HTML.toHTML(constant_pool.constantToString(index, tag))
                        + "</TT><UL>" + "<LI><A HREF=\"#cp" + name_index + "\">Name index("
                        + name_index + ")</A>\n" + "<LI><A HREF=\"#cp" + signature_index
                        + "\">Signature index(" + signature_index + ")</A></UL>\n");
View Full Code Here


   
    ConstantClass classConst =
      (ConstantClass)constPoolGen.getConstant(
        methodConst.getClassIndex() );

    ConstantNameAndType ntConst =
      (ConstantNameAndType)constPoolGen.getConstant(
        methodConst.getNameAndTypeIndex() );
   
      return new CallInfo(
      ((ConstantUtf8)constPoolGen.getConstant(
        classConst.getNameIndex() )).getBytes(),
      ntConst.getName( constPoolGen.getConstantPool() ),
      ntConst.getSignature( constPoolGen.getConstantPool() ) );
  }
View Full Code Here

        return new ObjectType(sig.replace('/', '.'));
    }

    private Type[] getParamTypes(ConstantPool cp, int index) {
        ConstantCP cmr = (ConstantCP) cp.getConstant(index);
        ConstantNameAndType cnat = (ConstantNameAndType) cp.getConstant(cmr.getNameAndTypeIndex());
        String sig = ((ConstantUtf8) cp.getConstant(cnat.getSignatureIndex())).getBytes();
        return Type.getArgumentTypes(sig);
    }
View Full Code Here

        return Type.getArgumentTypes(sig);
    }

    private Type getReturnType(ConstantPool cp, int index) {
        ConstantCP cmr = (ConstantCP) cp.getConstant(index);
        ConstantNameAndType cnat = (ConstantNameAndType) cp.getConstant(cmr.getNameAndTypeIndex());
        String sig = ((ConstantUtf8) cp.getConstant(cnat.getSignatureIndex())).getBytes();
        return Type.getReturnType(sig);
    }
View Full Code Here

    return stack[index];
  }

  public TreeSet getField(int entryIndex) {
    ConstantFieldref cfr = (ConstantFieldref)cpoolgen.getConstant(entryIndex);
    ConstantNameAndType cnat = (ConstantNameAndType)cpoolgen
      .getConstant(cfr.getNameAndTypeIndex());
    int nameIndex = cnat.getNameIndex();
    return fields[nameIndex];
  }
View Full Code Here

  }

  public void addToField(Set s, int entryIndex) {
    //System.out.println("he wants index " + entryIndex);
    ConstantFieldref cfr = (ConstantFieldref)cpoolgen.getConstant(entryIndex);
    ConstantNameAndType cnat = (ConstantNameAndType)cpoolgen
      .getConstant(cfr.getNameAndTypeIndex());
    int nameIndex = cnat.getNameIndex();
    fields[nameIndex].addAll(s);
  }
View Full Code Here

                break;
            case Constants.CONSTANT_Methodref:
                ConstantMethodref cmethod = (ConstantMethodref) constant;
                if (cmethod.getClass(cpool.getConstantPool()).equals("java.lang.Integer"))
                {
                    ConstantNameAndType cnt = (ConstantNameAndType) cpool.getConstant(cmethod.getNameAndTypeIndex());

                    if (cnt.getName(cpool.getConstantPool()).equals("valueOf") &&
                        cnt.getSignature(cpool.getConstantPool()).equals("(I)Ljava/lang/Integer;"))
                    {
                        cmethod.setClassIndex(cpool.addClass("macromedia.asc.util.Boxing"));
                    }
                }
               
                else if (cmethod.getClass(cpool.getConstantPool()).equals("java.lang.Double"))
                {
                    ConstantNameAndType cnt = (ConstantNameAndType) cpool.getConstant(cmethod.getNameAndTypeIndex());

                    if (cnt.getName(cpool.getConstantPool()).equals("valueOf") &&
                        cnt.getSignature(cpool.getConstantPool()).equals("(D)Ljava/lang/Double;"))
                    {
                        cmethod.setClassIndex(cpool.addClass("macromedia.asc.util.Boxing"));
                    }
                }
                break;
View Full Code Here

            CPInstruction putfield = (CPInstruction) ih.getInstruction();
            Constant cc = cpool.getConstant(putfield.getIndex());
            if (cc.getTag() != CONSTANT_Fieldref)
                return false;
            ConstantFieldref cfield = (ConstantFieldref) cc;
            ConstantNameAndType cnt = (ConstantNameAndType) cpool.getConstant(cfield.getNameAndTypeIndex());
            if (!cnt.getName(cpool.getConstantPool()).equals("this$0"))
                return false;
            return true;
        }
View Full Code Here

                return false;

            ih = match[1];
            CPInstruction invokevirtual = (CPInstruction) ih.getInstruction();
            ConstantMethodref cm = (ConstantMethodref) cpool.getConstant(invokevirtual.getIndex());
            ConstantNameAndType cnt = (ConstantNameAndType) cpool.getConstant(cm.getNameAndTypeIndex());
            if (!cnt.getName(cpool.getConstantPool()).equals("desiredAssertionStatus"))
                return false;
            return true;
        }
View Full Code Here

                    result.append(c.getNameAndTypeIndex());
                    result.append(";\t//  ");
                    result.append(Utility.replace(
                            constPool.constantToString(c), " ", ":"));
                } else if (constant instanceof ConstantNameAndType) {
                    ConstantNameAndType c = (ConstantNameAndType) constant;
                    result.append("NameAndType\t#");
                    result.append(c.getNameIndex());
                    result.append(":#");
                    result.append(c.getSignatureIndex());
                    result.append(";\t//  ");
                    result.append(Utility.replace(
                            constPool.constantToString(c), " ", ":"));
                } else if (constant instanceof ConstantMethodref) {
                    ConstantMethodref c = (ConstantMethodref) constant;
                    result.append("Method\t#");
                    result.append(c.getClassIndex());
                    result.append(".#");
                    result.append(c.getNameAndTypeIndex());
                    result.append(";\t//  ");
                    result.append(Utility.replace(
                            constPool.constantToString(c), " ", ":"));
                } else if (constant instanceof ConstantInterfaceMethodref) {
                    ConstantInterfaceMethodref c = (ConstantInterfaceMethodref) constant;
                    result.append("InterfaceMethod\t#");
                    result.append(c.getClassIndex());
                    result.append(".#");
                    result.append(c.getNameAndTypeIndex());
                    result.append(";\t//  ");
                    result.append(Utility.replace(
                            constPool.constantToString(c), " ", ":"));
                } else if (constant instanceof ConstantDouble) {
                    ConstantDouble c = (ConstantDouble) constant;
                    result.append("double\t");
                    result.append(constPool.constantToString(c));
                    result.append(';');
                } else if (constant instanceof ConstantFloat) {
                    ConstantFloat c = (ConstantFloat) constant;
                    result.append("float\t");
                    result.append(constPool.constantToString(c));
                    result.append(';');
                } else if (constant instanceof ConstantInteger) {
                    ConstantInteger c = (ConstantInteger) constant;
                    result.append("int\t");
                    result.append(constPool.constantToString(c));
                    result.append(';');
                } else if (constant instanceof ConstantLong) {
                    ConstantLong c = (ConstantLong) constant;
                    result.append("long\t");
                    result.append(constPool.constantToString(c));
                    result.append(';');
                } else if (constant instanceof ConstantClass) {
                    ConstantClass c = (ConstantClass) constant;
                    result.append("class\t#");
                    result.append(c.getNameIndex());
                    result.append(";\t//  ");
                    result.append(constPool.constantToString(c));
                } else if (constant instanceof ConstantString) {
                    ConstantString c = (ConstantString) constant;
                    result.append("String\t#");
                    result.append(c.getStringIndex());
                    result.append(";\t//  ");
                    result.append(constPool.constantToString(c));
                }

                result.append(n);
View Full Code Here

TOP

Related Classes of org.apache.bcel.classfile.ConstantNameAndType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.