Package org.apache.bcel.classfile

Examples of org.apache.bcel.classfile.ConstantPool


                String sig = field.getSignature();
                if (type.equals(Utility.signatureToString(sig, false))) {
                    ConstantValue cval = field.getConstantValue();
                    if (cval != null) {
                        int index = cval.getConstantValueIndex();
                        ConstantPool cp = m_curClass.getConstantPool();
                        Constant cnst = cp.getConstant(index);
                        if (cnst instanceof ConstantString) {
                            Object value = ((ConstantString)cnst).
                                getConstantValue(cp);
                            if (init.equals(value)) {
                                return new ClassItem(name,this, field);
View Full Code Here


      return;

    String className = cls.getName();
    // 0. Get the BCEL constant pool object
    JavaClass bcelClass = HotSwapAspectInterfaceImpl.getBCELClassDefinition( cls );
    ConstantPool constantPool = bcelClass.getConstantPool();
    Constant[] constants = constantPool.getConstantPool();

    // Remember the class, so it doesn't get scanned again.
    scannedConstantPools.put( cls, dummyValue );

    // 1. Iterate through all constant pool entries
View Full Code Here

 
  private static final Log LOG = LogFactory.getLog(ClassIntermediateVisitor.class);
 
  @Override
  public void visitConstantClass(ConstantClass obj) {
    ConstantPool pool = javaClass.getConstantPool();
    String classVal = obj.getConstantValue(pool).toString();
    classVal = StringUtils.replace(classVal, "/", ".");

    if(StringUtils.equals(classVal, this.classBlock.getClassName())) {
      //skip adding class name.
View Full Code Here

            if (accessCount != 1) {
                access = null;
                return;
            }

            ConstantPool cp = javaClass.getConstantPool();
            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);
View Full Code Here

    }

    @Override
    public void visit(JavaClass obj) {
        compute();
        ConstantPool cp = obj.getConstantPool();
        Constant[] constants = cp.getConstantPool();
        checkConstant: for (int i = 0; i < constants.length; i++) {
            Constant co = constants[i];
            if (co instanceof ConstantDouble || co instanceof ConstantLong) {
                i++;
            }
            if (co instanceof ConstantClass) {
                String ref = getClassName(obj, i);
                if ((ref.startsWith("java") || ref.startsWith("org.w3c.dom")) && !defined.contains(ref)) {
                    bugReporter.reportBug(new BugInstance(this, "VR_UNRESOLVABLE_REFERENCE", NORMAL_PRIORITY).addClass(obj)
                            .addString(ref));
                }

            } 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

                if (gcInvocationPC < handler.getHandlerPC() || gcInvocationPC > handler.getHandlerPC() + OOM_CATCH_LEN) {
                    continue;
                }
                int catchTypeIndex = handler.getCatchType();
                if (catchTypeIndex > 0) {
                    ConstantPool cp = getThisClass().getConstantPool();
                    Constant constant = cp.getConstant(catchTypeIndex);
                    if (constant instanceof ConstantClass) {
                        String exClassName = (String) ((ConstantClass) constant).getConstantValue(cp);
                        if (exClassName.equals("java/lang/OutOfMemoryError")) {
                            outOfMemoryHandler = true;
                            break;
View Full Code Here

    private boolean safeCallToPrimateParseMethod(XMethod calledMethod, Location location) {
        int position = location.getHandle().getPosition();

        if (calledMethod.getClassName().equals("java.lang.Integer")) {

            ConstantPool constantPool = classContext.getJavaClass().getConstantPool();
            Code code = method.getCode();

            int catchSize;

            catchSize = Util.getSizeOfSurroundingTryBlock(constantPool, code, "java/lang/NumberFormatException", position);
View Full Code Here

        if (c instanceof ConstantFieldref) {
            fieldRef = (ConstantFieldref) c;

            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

        }
    }


    private void setValue( int index ) {
        ConstantPool cp = this.cp.getConstantPool();
        Constant c = cp.getConstant(index);
        value = ((ConstantObject) c).getConstantValue(cp);
    }
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

TOP

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

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.