Package org.apache.bcel.classfile

Examples of org.apache.bcel.classfile.Field


       
        // process all non-final/non-static/non-transient fields of class
        JavaClass clas = cf.getRawClass();
        Field[] fields = clas.getFields();
        for (int i = 0; i < fields.length; i++) {
            Field field = fields[i];
            if (!field.isFinal() && !field.isStatic() && !field.isTransient()) {
               
                // find type of handling needed for field type
                boolean simple = false;
                boolean object = true;
                boolean attribute = true;
                String fname = field.getName();
                String tname = field.getType().toString();
                if (ClassItem.isPrimitive(tname)) {
                    simple = true;
                    object = false;
                } else if (s_objectPrimitiveSet.contains(tname)) {
                    simple = true;
View Full Code Here


            return EMPTY_CLASS_ITEMS;
        } else {
            Field[] fields = m_curClass.getFields();
            ClassItem[] items = new ClassItem[fields.length];
            for (int i = 0; i < fields.length; i++) {
                Field field = fields[i];
                items[i] = new ClassItem(field.getName(), this, field);
            }
            return items;
        }
    }
View Full Code Here

        if (m_curClass == null) {
            return null;
        } else {
   
            // check for match to field name defined in class
            Field field = getDefinedField(name);
            if (field == null) {
       
                // try match to field inherited from superclass
                if (m_superClass != null) {
                    field = m_superClass.getAccessibleField(name);
                    if (field != null && (!m_isSamePackage ||
                        field.isPrivate()) && !field.isPublic() &&
                        !field.isProtected()) {
                        field = null;
                    }
                }
               
            }
View Full Code Here

     *
     * @param name field name
     * @return field information, or <code>null</code> if field not found
     */
    public ClassItem getDirectField(String name) {
        Field field = getAccessibleField(name);
        if (field == null) {
            return null;
        } else {
            ClassItem item = (ClassItem)m_itemMap.get(field);
            if (item == null) {
View Full Code Here

     * @param name field name
     * @return field information
     * @throws JiBXException if field not found
     */
    public ClassItem getField(String name) throws JiBXException {
        Field field = getAccessibleField(name);
        if (field == null) {
            throw new JiBXException("Field " + name +
                " not found in class " + m_name);
        } else {
            ClassItem item = (ClassItem)m_itemMap.get(field);
View Full Code Here

        }
        deleteField(name);
        FieldGen fgen = new FieldGen(access,
            Type.getType(Utility.getSignature(type)), name, getConstPoolGen());
        fgen.setInitValue(init);
        Field field = fgen.getField();
        getClassGen().addField(field);
        m_isModified = true;
        m_isHashCurrent = false;
        return new ClassItem(name, this, field);
    }
View Full Code Here

    public ClassItem addField(String type, String name, int access, int init) {
        deleteField(name);
        FieldGen fgen = new FieldGen(access,
            Type.getType(Utility.getSignature(type)), name, getConstPoolGen());
        fgen.setInitValue(init);
        Field field = fgen.getField();
        getClassGen().addField(field);
        m_isModified = true;
        m_isHashCurrent = false;
        return new ClassItem(name, this, field);
    }
View Full Code Here

        }
       
        // first check for match with existing field
        Field[] fields = m_curClass.getFields();
        for (int i = 0; i < fields.length; i++) {
            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);
                            if (init.equals(value)) {
                                return new ClassItem(name,this, field);
                            }
                        }
                    }
                }
            }
        }
       
        // no exact match, so replace any existing field with same name
        deleteField(name);
        FieldGen fgen = new FieldGen(access,
            Type.getType(Utility.getSignature(type)), name, getConstPoolGen());
        fgen.setInitValue(init);
        Field field = fgen.getField();
        getClassGen().addField(field);
        m_isModified = true;
        m_isHashCurrent = false;
        return new ClassItem(name, this, field);
    }
View Full Code Here

     */
    public ClassItem addField(String type, String name, int access) {
        deleteField(name);
        FieldGen fgen = new FieldGen(access,
            Type.getType(Utility.getSignature(type)), name, getConstPoolGen());
        Field field = fgen.getField();
        getClassGen().addField(field);
        m_isModified = true;
        m_isHashCurrent = false;
        return new ClassItem(name, this, field);
    }
View Full Code Here

     * @param name field name
     * @return <code>true</code> if field was present, <code>false</code> if not
     */
    public boolean deleteField(String name) {
        ClassGen cg = getClassGen();
        Field field = cg.containsField(name);
        if (field == null) {
            return false;
        } else {
            cg.removeField(field);
            m_isModified = true;
View Full Code Here

TOP

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

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.