// first, see if we can convert the attribute name to a field name
String fieldName = toBackingFieldName(attrName);
// next, find the field in the managed type hierarchy
BCField field = null;
outer: for (BCClass bc = _pc; bc != null; bc = bc.getSuperclassBC()) {
BCField[] fields = AccessController
.doPrivileged(J2DoPrivHelper.getBCClassFieldsAction(bc,
fieldName));
for (int i = 0; i < fields.length; i++) {
field = fields[i];
// if we reach a field declared in this type, then this is the
// most-masking field, and is the one that we want.
if (fields[i].getDeclarer() == declarer) {
break outer;
}
}
}
if (getCreateSubclass() && code.getMethod().getDeclarer() == _pc
&& (field == null || !field.isPublic())) {
// we're creating the subclass, not redefining the user type.
// Reflection.getXXX(this, Reflection.findField(...));
code.classconstant().setClass(declarer);
code.constant().setValue(fieldName);
code.constant().setValue(true);
code.invokestatic().setMethod(Reflection.class,
"findField", Field.class, new Class[] {
Class.class, String.class, boolean.class });
Class type = _meta.getField(attrName).getDeclaredType();
try {
code.invokestatic().setMethod(
getReflectionGetterMethod(type, Field.class));
} catch (NoSuchMethodException e) {
// should never happen
throw new InternalException(e);
}
if (!type.isPrimitive() && type != Object.class)
code.checkcast().setType(type);
} else {
code.getfield().setField(declarer.getName(), fieldName,
field.getType().getName());
}
}