// is exactly compatible with the old class, otherwise an
// IncompatibleClassChange exception will be thrown
while (it.hasNext()) {
FieldInfo m = (FieldInfo) it.next();
FieldData md = null;
for (FieldData i : fields) {
if (i.getName().equals(m.getName()) && i.getType().equals(m.getDescriptor()) && i.getAccessFlags() == m.getAccessFlags()) {
try {
Field field = i.getField(oldClass);
AnnotationDataStore.recordFieldAnnotations(field, (AnnotationsAttribute) m.getAttribute(AnnotationsAttribute.visibleTag));
// now revert the annotations:
m.addAttribute(AnnotationReplacer.duplicateAnnotationsAttribute(file.getConstPool(), field));
} catch (Exception e) {
throw new RuntimeException(e);
}
md = i;
break;
} else if (i.getName().equals(m.getName()) && i.getType().equals(m.getDescriptor())) {
// we have a field whoes access modifiers have changed.
if ((i.getAccessFlags() | AccessFlag.STATIC) == (m.getAccessFlags() | AccessFlag.STATIC)) {
// change from / to static can be handled fine
}
}
}
// This is a newly added field.
if (md == null) {
if ((m.getAccessFlags() & AccessFlag.STATIC) != 0) {
addStaticField(file, loader, m, builder, oldClass);
} else {
int fieldNo = addInstanceField(file, loader, m, builder, oldClass);
addedFields.add(new AddedFieldData(fieldNo, m.getName(), m.getDescriptor(), file.getName(), loader));
noAddedFields++;
}
it.remove();
} else {
fields.remove(md);
}
}
// these fields have been removed,
// TODO: rewrite classes that access them to throw a NoSuchFieldError
for (FieldData md : fields) {
if (md.getMemberType() == MemberType.NORMAL) {
FieldInfo old = new FieldInfo(file.getConstPool(), md.getName(), md.getType());
old.setAccessFlags(md.getAccessFlags());
builder.removeField(md);
try {
Field field = md.getField(oldClass);
file.addField(old);
old.addAttribute(AnnotationReplacer.duplicateAnnotationsAttribute(file.getConstPool(), field));
} catch (DuplicateMemberException e) {
// this should not happen
throw new RuntimeException(e);