Package org.apache.bcel.classfile

Examples of org.apache.bcel.classfile.ConstantCP


    for( int i = 0; i < constants.length; i++ ) {
      Constant con = constants[i];

      // 2. Get field and method references
      if( con instanceof ConstantCP ) {
        ConstantCP cp = (ConstantCP) con;
        ConstantNameAndType nt = (ConstantNameAndType) constants[cp.getNameAndTypeIndex()];
        // 3. Create a unique key (string) for the field or method
        String key = cp.getClass( constantPool ) + '#' + nt.getName( constantPool ) + '#' + nt.getSignature( constantPool );

        if( con instanceof ConstantFieldref) {
          // Constant is a field reference

          // 4. Look if the field must be woven
View Full Code Here


            } else if (co instanceof ConstantFieldref) {
                // do nothing until we handle static fields defined in
                // interfaces
            } else if (co instanceof ConstantCP) {
                ConstantCP co2 = (ConstantCP) co;
                String className = getClassName(obj, co2.getClassIndex());

                // System.out.println("checking " + ref);
                if (className.equals(obj.getClassName()) || !defined.contains(className)) {
                    // System.out.println("Skipping check of " + ref);
                    continue checkConstant;
                }
                ConstantNameAndType nt = (ConstantNameAndType) cp.getConstant(co2.getNameAndTypeIndex());
                String name = ((ConstantUtf8) obj.getConstantPool().getConstant(nt.getNameIndex(), CONSTANT_Utf8)).getBytes();
                String signature = ((ConstantUtf8) obj.getConstantPool().getConstant(nt.getSignatureIndex(), CONSTANT_Utf8))
                        .getBytes();

                try {
View Full Code Here

    /** @return signature of referenced method/field.
     */
    public String getSignature( ConstantPoolGen cpg ) {
        ConstantPool cp = cpg.getConstantPool();
        ConstantCP cmr = (ConstantCP) cp.getConstant(index);
        ConstantNameAndType cnat = (ConstantNameAndType) cp.getConstant(cmr.getNameAndTypeIndex());
        return ((ConstantUtf8) cp.getConstant(cnat.getSignatureIndex())).getBytes();
    }
View Full Code Here

    /** @return name of referenced method/field.
     */
    public String getName( ConstantPoolGen cpg ) {
        ConstantPool cp = cpg.getConstantPool();
        ConstantCP cmr = (ConstantCP) cp.getConstant(index);
        ConstantNameAndType cnat = (ConstantNameAndType) cp.getConstant(cmr.getNameAndTypeIndex());
        return ((ConstantUtf8) cp.getConstant(cnat.getNameIndex())).getBytes();
    }
View Full Code Here

     *    the getReferenceType() method, which correctly distinguishes
     *    between class types and array types.
     */
    public String getClassName( ConstantPoolGen cpg ) {
        ConstantPool cp = cpg.getConstantPool();
        ConstantCP cmr = (ConstantCP) cp.getConstant(index);
        String className = cp.getConstantString(cmr.getClassIndex(),
                org.apache.bcel.Constants.CONSTANT_Class);
        if (className.startsWith("[")) {
            // Turn array classes into java.lang.Object.
            return "java.lang.Object";
        }
View Full Code Here

     *   or interface), or an ArrayType (if the referenced class
     *   type is an array class)
     */
    public ReferenceType getReferenceType( ConstantPoolGen cpg ) {
        ConstantPool cp = cpg.getConstantPool();
        ConstantCP cmr = (ConstantCP) cp.getConstant(index);
        String className = cp.getConstantString(cmr.getClassIndex(),
                org.apache.bcel.Constants.CONSTANT_Class);
        if (className.startsWith("[")) {
            return (ArrayType) Type.getType(className);
        } else {
            className = className.replace('/', '.');
View Full Code Here

                String key = u.getBytes();
                if (!utf8_table.containsKey(key)) {
                    utf8_table.put(key, new Index(i));
                }
            } else if (c instanceof ConstantCP) {
                ConstantCP m = (ConstantCP) c;
                ConstantClass clazz = (ConstantClass) constants[m.getClassIndex()];
                ConstantNameAndType n = (ConstantNameAndType) constants[m.getNameAndTypeIndex()];
                ConstantUtf8 u8 = (ConstantUtf8) constants[clazz.getNameIndex()];
                String class_name = u8.getBytes().replace('/', '.');
                u8 = (ConstantUtf8) constants[n.getNameIndex()];
                String method_name = u8.getBytes();
                u8 = (ConstantUtf8) constants[n.getSignatureIndex()];
View Full Code Here

            case Constants.CONSTANT_Integer:
                return addInteger(((ConstantInteger) c).getBytes());
            case Constants.CONSTANT_InterfaceMethodref:
            case Constants.CONSTANT_Methodref:
            case Constants.CONSTANT_Fieldref: {
                ConstantCP m = (ConstantCP) c;
                ConstantClass clazz = (ConstantClass) constants[m.getClassIndex()];
                ConstantNameAndType n = (ConstantNameAndType) constants[m.getNameAndTypeIndex()];
                ConstantUtf8 u8 = (ConstantUtf8) constants[clazz.getNameIndex()];
                String class_name = u8.getBytes().replace('/', '.');
                u8 = (ConstantUtf8) constants[n.getNameIndex()];
                String name = u8.getBytes();
                u8 = (ConstantUtf8) constants[n.getSignatureIndex()];
View Full Code Here

        JavaClass javaClass = classContext.getJavaClass();
        boolean skip = false;
        ConstantPool constantPool = javaClass.getConstantPool();
        for(Constant c : constantPool.getConstantPool() ) {
            if (c instanceof ConstantMethodref || c instanceof ConstantInterfaceMethodref) {
                ConstantCP m = (ConstantCP) c;
                @DottedClassName String clazz = m.getClass(constantPool);
                ConstantNameAndType nt = (ConstantNameAndType) constantPool.getConstant(m.getNameAndTypeIndex(), Constants.CONSTANT_NameAndType);
                String name = nt.getName(constantPool);
                if (name.equals("setAttribute") && clazz.equals("javax.servlet.http.HttpSession") || (name.equals("writeObject")
                        && (clazz.equals("java.io.ObjectOutput")
                                || clazz.equals("java.io.ObjectOutputStream")))) {
                    if (DEBUG) {
View Full Code Here

                            } else if (constantRefOperand instanceof ConstantString) {
                                int s = ((ConstantString) constantRefOperand).getStringIndex();

                                stringConstantOperand = getStringFromIndex(s);
                            } else if (constantRefOperand instanceof ConstantCP) {
                                ConstantCP cp = (ConstantCP) constantRefOperand;
                                ConstantClass clazz = (ConstantClass) getConstantPool().getConstant(cp.getClassIndex());
                                classConstantOperand = getStringFromIndex(clazz.getNameIndex());
                                referencedClass = DescriptorFactory.createClassDescriptor(classConstantOperand);
                                referencedXClass = null;
                                ConstantNameAndType sig = (ConstantNameAndType) getConstantPool().getConstant(
                                        cp.getNameAndTypeIndex());
                                nameConstantOperand = getStringFromIndex(sig.getNameIndex());
                                sigConstantOperand = getStringFromIndex(sig.getSignatureIndex());
                                refConstantOperand = null;
                            } else if (constantRefOperand instanceof ConstantInvokeDynamic) {
                                ConstantInvokeDynamic id = (ConstantInvokeDynamic) constantRefOperand;
View Full Code Here

TOP

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

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.