JavaClass jc = Repository.lookupClass(o.getClassType(cpg).getClassName());
Field[] fields = jc.getFields();
Field f = null;
for (int i=0; i<fields.length; i++){
if (fields[i].getName().equals(field_name)){
Type f_type = Type.getType(fields[i].getSignature());
Type o_type = o.getType(cpg);
/* TODO: Check if assignment compatibility is sufficient.
* What does Sun do?
*/
if (f_type.equals(o_type)){
f = fields[i];
break;
}
}
}
if (f == null){
JavaClass[] superclasses = jc.getSuperClasses();
outer:
for (int j=0; j<superclasses.length; j++){
fields = superclasses[j].getFields();
for (int i=0; i<fields.length; i++){
if (fields[i].getName().equals(field_name)){
Type f_type = Type.getType(fields[i].getSignature());
Type o_type = o.getType(cpg);
if (f_type.equals(o_type)){
f = fields[i];
if ((f.getAccessFlags() & (Constants.ACC_PUBLIC | Constants.ACC_PROTECTED)) == 0) {
f = null;
}
break outer;
}
}
}
}
if (f == null) {
constraintViolated(o, "Referenced field '"+field_name+"' does not exist in class '"+jc.getClassName()+"'.");
}
}
else{
/* TODO: Check if assignment compatibility is sufficient.
What does Sun do? */
Type f_type = Type.getType(f.getSignature());
Type o_type = o.getType(cpg);
// Argh. Sun's implementation allows us to have multiple fields of
// the same name but with a different signature.
//if (! f_type.equals(o_type)){
// constraintViolated(o, "Referenced field '"+field_name+"' has type '"+f_type+"' instead of '"+o_type+"' as expected.");