Package org.apache.bcel.classfile

Examples of org.apache.bcel.classfile.ConstantNameAndType


      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


            ConstantFieldref fieldref = (ConstantFieldref) cp.getConstant(cpIndex);

            ConstantClass cls = (ConstantClass) cp.getConstant(fieldref.getClassIndex());
            String className = cls.getBytes(cp).replace('/', '.');

            ConstantNameAndType nameAndType = (ConstantNameAndType) cp.getConstant(fieldref.getNameAndTypeIndex());
            String fieldName = nameAndType.getName(cp);
            String fieldSig = nameAndType.getSignature(cp);


            XField xfield = Hierarchy.findXField(className, fieldName, fieldSig, isStatic);
            if (xfield != null && xfield.isStatic() == isStatic && isValidAccessMethod(methodSig, xfield, isLoad)) {
                access = new InnerClassAccess(methodName, methodSig, xfield, isLoad);
View Full Code Here

                // 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 {
                    JavaClass target = Repository.lookupClass(className);
                    if (!find(target, name, signature)) {
View Full Code Here

            String className = fieldRef.getClass(getConstantPool()).replace('.', '/');
            if (className.equals(this.getClassName())) {
                ConstantPool cp = getConstantPool();
                int nameAndTypeIdx = fieldRef.getNameAndTypeIndex();
                ConstantNameAndType ntc = (ConstantNameAndType) cp.getConstant(nameAndTypeIdx);
                int nameIdx = ntc.getNameIndex();

                Field[] flds = getClassContext().getJavaClass().getFields();

                for (Field fld : flds) {
                    if (fld.getNameIndex() == nameIdx) {
                        if (!fld.isStatic()) {
                            ConstantUtf8 nameCons = (ConstantUtf8) cp.getConstant(nameIdx);
                            ConstantUtf8 typeCons = (ConstantUtf8) cp.getConstant(ntc.getSignatureIndex());

                            if (alreadyReported.contains(nameCons.getBytes())) {
                                return;
                            }
                            alreadyReported.add(nameCons.getBytes());
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

        ObligationFactory factory = database.getFactory();

        JavaClass jclass = analysisCache.getClassAnalysis(JavaClass.class, classDescriptor);
        for (Constant c : jclass.getConstantPool().getConstantPool()) {
            if (c instanceof ConstantNameAndType) {
                ConstantNameAndType cnt = (ConstantNameAndType) c;
                String signature = cnt.getSignature(jclass.getConstantPool());
                if (factory.signatureInvolvesObligations(signature)) {
                    super.visitClass(classDescriptor);
                    return;
                }
            } else if (c instanceof ConstantClass) {
View Full Code Here

        if (! (c instanceof ConstantMethodref)){
          constraintViolated(o, "Indexing a constant that's not a CONSTANT_Methodref but a '"+c+"'.");
        }
        else{
          // Constants are okay due to pass2.
          ConstantNameAndType cnat = (ConstantNameAndType) (cpg.getConstant(((ConstantMethodref) c).getNameAndTypeIndex()));
          ConstantUtf8 cutf8 = (ConstantUtf8) (cpg.getConstant(cnat.getNameIndex()));
          if (cutf8.getBytes().equals(Constants.CONSTRUCTOR_NAME) && (!(o instanceof INVOKESPECIAL)) ){
            constraintViolated(o, "Only INVOKESPECIAL is allowed to invoke instance initialization methods.");
          }
          if ( (! (cutf8.getBytes().equals(Constants.CONSTRUCTOR_NAME)) ) && (cutf8.getBytes().startsWith("<")) ){
            constraintViolated(o, "No method with a name beginning with '<' other than the instance initialization methods may be called by the method invocation instructions.");
          }
        }
      }
      else{ //if (o instanceof INVOKEINTERFACE){
        Constant c = cpg.getConstant(o.getIndex());
        if (! (c instanceof ConstantInterfaceMethodref)){
          constraintViolated(o, "Indexing a constant that's not a CONSTANT_InterfaceMethodref but a '"+c+"'.");
        }
        // TODO: From time to time check if BCEL allows to detect if the
        // 'count' operand is consistent with the information in the
        // CONSTANT_InterfaceMethodref and if the last operand is zero.
        // By now, BCEL hides those two operands because they're superfluous.
       
        // Invoked method must not be <init> or <clinit>
        ConstantNameAndType cnat = (ConstantNameAndType) (cpg.getConstant(((ConstantInterfaceMethodref)c).getNameAndTypeIndex()));
        String name = ((ConstantUtf8) (cpg.getConstant(cnat.getNameIndex()))).getBytes();
        if (name.equals(Constants.CONSTRUCTOR_NAME)){
          constraintViolated(o, "Method to invoke must not be '"+Constants.CONSTRUCTOR_NAME+"'.");
        }
        if (name.equals(Constants.STATIC_INITIALIZER_NAME)){
          constraintViolated(o, "Method to invoke must not be '"+Constants.STATIC_INITIALIZER_NAME+"'.");
View Full Code Here

                String key = u8.getBytes();
                if (!class_table.containsKey(key)) {
                    class_table.put(key, new Index(i));
                }
            } else if (c instanceof ConstantNameAndType) {
                ConstantNameAndType n = (ConstantNameAndType) c;
                ConstantUtf8 u8 = (ConstantUtf8) constants[n.getNameIndex()];
                ConstantUtf8 u8_2 = (ConstantUtf8) constants[n.getSignatureIndex()];
                String key = u8.getBytes() + NAT_DELIM + u8_2.getBytes();
                if (!n_a_t_table.containsKey(key)) {
                    n_a_t_table.put(key, new Index(i));
                }
            } else if (c instanceof ConstantUtf8) {
                ConstantUtf8 u = (ConstantUtf8) c;
                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()];
                String signature = u8.getBytes();
                String delim = METHODREF_DELIM;
                if (c instanceof ConstantInterfaceMethodref) {
                    delim = IMETHODREF_DELIM;
                } else if (c instanceof ConstantFieldref) {
View Full Code Here

        }
        adjustSize();
        name_index = addUtf8(name);
        signature_index = addUtf8(signature);
        ret = index;
        constants[index++] = new ConstantNameAndType(name_index, signature_index);
        String key = name + NAT_DELIM + signature;
        if (!n_a_t_table.containsKey(key)) {
            n_a_t_table.put(key, new Index(ret));
        }
        return ret;
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.