fmds = _meta.getFields();
else
fmds = _meta.getDeclaredFields();
Method meth;
BCMethod getter, setter;
BCField returned, assigned = null;
for (int i = 0; i < fmds.length; i++) {
if (!(fmds[i].getBackingMember() instanceof Method) ) {
// If not mixed access is not defined, flag the field members,
// otherwise do not process them because they are valid
// persistent attributes.
if (!_meta.isMixedAccess()) {
addViolation("property-bad-member",
new Object[]{ fmds[i], fmds[i].getBackingMember() },
true);
}
continue;
}
meth = (Method) fmds[i].getBackingMember();
// ##### this will fail if we override and don't call super.
BCClass declaringType = _managedType.getProject()
.loadClass(fmds[i].getDeclaringType());
getter = declaringType.getDeclaredMethod(meth.getName(),
meth.getParameterTypes());
if (getter == null) {
addViolation("property-no-getter", new Object[]{ fmds[i] },
true);
continue;
}
returned = getReturnedField(getter);
if (returned != null)
registerBackingFieldInfo(fmds[i], getter, returned);
setter = declaringType.getDeclaredMethod(getSetterName(fmds[i]),
new Class[]{ fmds[i].getDeclaredType() });
if (setter == null) {
if (returned == null) {
addViolation("property-no-setter",
new Object[]{ fmds[i] }, true);
continue;
} else if (!getRedefine()) {
// create synthetic setter
setter = _managedType.declareMethod(getSetterName(fmds[i]),
void.class, new Class[]{ fmds[i].getDeclaredType() });
setter.makePrivate();
Code code = setter.getCode(true);
code.aload().setThis();
code.xload().setParam(0);
code.putfield().setField(returned);
code.vreturn();
code.calculateMaxStack();
code.calculateMaxLocals();
}
}
if (setter != null)
assigned = getAssignedField(setter);
if (assigned != null) {
if (setter != null)
registerBackingFieldInfo(fmds[i], setter, assigned);
if (assigned != returned)
addViolation("property-setter-getter-mismatch", new Object[]
{ fmds[i], assigned.getName(), (returned == null)
? null : returned.getName() }, false);
}
}
}