Collection<AbstractClassTypeDeclarationDescr> sortedTypeDescriptors,
List<TypeDefinition> unresolvedTypes,
Map<String, TypeDeclarationDescr> unprocessableDescrs ) {
//descriptor needs fields inherited from superclass
if (typeDescr instanceof TypeDeclarationDescr) {
TypeDeclarationDescr tDescr = (TypeDeclarationDescr) typeDescr;
boolean isNovel = isNovelClass( typeDescr );
boolean inferFields = ! isNovel && typeDescr.getFields().isEmpty();
for (QualifiedName qname : tDescr.getSuperTypes()) {
//descriptor needs fields inherited from superclass
if (mergeInheritedFields(tDescr, unresolvedTypes, unprocessableDescrs, pkgRegistry.getTypeResolver())) {
//descriptor also needs metadata from superclass
for (AbstractClassTypeDeclarationDescr descr : sortedTypeDescriptors) {
// sortedTypeDescriptors are sorted by inheritance order, so we'll always find the superClass (if any) before the subclass
if (qname.equals(descr.getType())) {
typeDescr.getAnnotations().putAll(descr.getAnnotations());
break;
} else if (typeDescr.getType().equals(descr.getType())) {
break;
}
}
}
}
if ( inferFields ) {
// not novel, but only an empty declaration was provided.
// after inheriting the fields from supertypes, now we fill in the locally declared fields
try {
Class existingClass = getExistingDeclarationClass( typeDescr );
ClassFieldInspector inspector = new ClassFieldInspector( existingClass );
for (String name : inspector.getGetterMethods().keySet()) {
// classFieldAccessor requires both getter and setter
if (inspector.getSetterMethods().containsKey(name)) {
if (!inspector.isNonGetter(name) && !"class".equals(name)) {
TypeFieldDescr inheritedFlDescr = new TypeFieldDescr(
name,
new PatternDescr(
inspector.getFieldTypes().get(name).getName()));
inheritedFlDescr.setInherited(!Modifier.isAbstract(inspector.getGetterMethods().get(name).getModifiers()));
if (!tDescr.getFields().containsKey(inheritedFlDescr.getFieldName()))
tDescr.getFields().put(inheritedFlDescr.getFieldName(),
inheritedFlDescr);
}
}
}
} catch ( Exception e ) {