}
// 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);
}