Package org.apache.bcel.classfile

Examples of org.apache.bcel.classfile.ConstantValue


            Field field = fields[i];
            if (field.getName().equals(name) &&
                field.getAccessFlags() == access) {
                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);
View Full Code Here


        if( ! nf.getSignature().equals( of.getSignature() ) ) {
          System.out.println( "Field signature changed for " + oldName + "( old: " + of.getSignature() + ", new: " + nf.getSignature() + ")" );
          retval = false;
        }
        // Constant value (may be 'null')
        ConstantValue oldConst = of.getConstantValue();
        ConstantValue newConst = nf.getConstantValue();
        if( oldConst != newConst ) {
          if( null == oldConst ) {
            System.out.println( "Changed constant field to modifiable field " + oldName );
            retval = false;
          }
          else if( null == newConst ) {
            System.out.println( "Changed modifiable field to constant field " + oldName );
            retval = false;
          }
          else if( ! oldConst.toString().equals( newConst.toString() ) ) {
            System.out.println( "Changed " + oldConst.toString() + " to " + newConst.toString() );
            retval = false;
          }
        }
        // Attributes
        Attribute newAttributes[] = nf.getAttributes();
View Full Code Here

        if( ! nf.getSignature().equals( of.getSignature() ) ) {
          System.out.println( "Field signature changed for " + oldName + "( old: " + of.getSignature() + ", new: " + nf.getSignature() + ")" );
          retval = false;
        }
        // Constant value (may be 'null')
        ConstantValue oldConst = of.getConstantValue();
        ConstantValue newConst = nf.getConstantValue();
        if( oldConst != newConst ) {
          if( null == oldConst ) {
            System.out.println( "Changed constant field to modifiable field " + oldName );
            retval = false;
          }
          else if( null == newConst ) {
            System.out.println( "Changed modifiable field to constant field " + oldName );
            retval = false;
          }
          else if( ! oldConst.toString().equals( newConst.toString() ) ) {
            System.out.println( "Changed " + oldConst.toString() + " to " + newConst.toString() );
            retval = false;
          }
        }
        // Attributes
        Attribute newAttributes[] = nf.getAttributes();
View Full Code Here

        return method.getName().startsWith("test");
    }

    @Override
    public void visit(Field field) {
        ConstantValue value = field.getConstantValue();
        if (value == null) {
            return;
        }
        Constant c = getConstantPool().getConstant(value.getConstantValueIndex());

        if (testingEnabled && c instanceof ConstantLong && ((ConstantLong)c).getBytes() == MICROS_PER_DAY_OVERFLOWED_AS_INT) {
            bugReporter.reportBug( new BugInstance(this, "TESTING", HIGH_PRIORITY).addClass(this).addField(this)
                    .addString("Did you mean MICROS_PER_DAY")
                    .addInt(MICROS_PER_DAY_OVERFLOWED_AS_INT)
View Full Code Here

        final JavaClass javaClass = parser.parse();
        final Field[] fields = javaClass.getFields();
        for (int i = 0; i < fields.length; i++) {
            final Field field = fields[i];
            if (field != null) {
                final ConstantValue cv = field.getConstantValue();
                if (cv != null) {
                    String cvs = cv.toString();
                    //Remove start and end quotes if field is a String
                    if (cvs.startsWith("\"") && cvs.endsWith("\"")) {
                        cvs = cvs.substring(1, cvs.length() - 1);
                    }
                    sb.append(field.getName());
View Full Code Here

        int name_index = cp.addUtf8(name);
        int signature_index = cp.addUtf8(signature);
        if (value != null) {
            checkType(type);
            int index = addConstant();
            addAttribute(new ConstantValue(cp.addUtf8("ConstantValue"), 2, index, cp
                    .getConstantPool()));
        }
        return new Field(access_flags, name_index, signature_index, getAttributes(), cp
                .getConstantPool());
    }
View Full Code Here

    public void visitField( Field field ) {
        _out.println();
        _out.println("    field = new FieldGen(" + printFlags(field.getAccessFlags()) + ", "
                + printType(field.getSignature()) + ", \"" + field.getName() + "\", _cp);");
        ConstantValue cv = field.getConstantValue();
        if (cv != null) {
            String value = cv.toString();
            _out.println("    field.setInitValue(" + value + ")");
        }
        _out.println("    _cg.addField(field.getField());");
    }
View Full Code Here

        final JavaClass javaClass = parser.parse();
        final Field[] fields = javaClass.getFields();
        for (int i = 0; i < fields.length; i++) {
            final Field field = fields[i];
            if (field != null) {
                final ConstantValue cv = field.getConstantValue();
                if (cv != null) {
                    String cvs = cv.toString();
                    //Remove start and end quotes if field is a String
                    if (cvs.startsWith("\"") && cvs.endsWith("\"")) {
                        cvs = cvs.substring(1, cvs.length() - 1);
                    }
                    sb.append(field.getName());
View Full Code Here

        final JavaClass javaClass = parser.parse();
        final Field[] fields = javaClass.getFields();
        for (int i = 0; i < fields.length; i++) {
            final Field field = fields[i];
            if (field != null) {
                final ConstantValue cv = field.getConstantValue();
                if (cv != null) {
                    String cvs = cv.toString();
                    //Remove start and end quotes if field is a String
                    if (cvs.startsWith("\"") && cvs.endsWith("\"")) {
                        cvs = cvs.substring(1, cvs.length() - 1);
                    }
                    sb.append(field.getName());
View Full Code Here

        final JavaClass javaClass = parser.parse();
        final Field[] fields = javaClass.getFields();
        for (int i = 0; i < fields.length; i++) {
            final Field field = fields[i];
            if (field != null) {
                final ConstantValue cv = field.getConstantValue();
                if (cv != null) {
                    String cvs = cv.toString();
                    //Remove start and end quotes if field is a String
                    if (cvs.startsWith("\"") && cvs.endsWith("\"")) {
                        cvs = cvs.substring(1, cvs.length() - 1);
                    }
                    sb.append(field.getName());
View Full Code Here

TOP

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

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.