public void inheritFields( PackageRegistry pkgRegistry,
AbstractClassTypeDeclarationDescr typeDescr,
Collection<AbstractClassTypeDeclarationDescr> sortedTypeDescriptors,
List<TypeDefinition> unresolvedTypes,
Map<String,AbstractClassTypeDeclarationDescr> unprocessableDescrs ) {
TypeDeclarationDescr tDescr = (TypeDeclarationDescr) typeDescr;
boolean isNovel = TypeDeclarationUtils.isNovelClass( typeDescr, pkgRegistry );
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 - NO LONGER SINCE DROOLS 6.x
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 = TypeDeclarationUtils.getExistingDeclarationClass( typeDescr, pkgRegistry );
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 ) {