HierarchySorter<QualifiedName> sorter = new HierarchySorter<QualifiedName>();
Map<QualifiedName, Collection<QualifiedName>> taxonomy = new HashMap<QualifiedName, Collection<QualifiedName>>();
Map<QualifiedName, AbstractClassTypeDeclarationDescr> cache = new HashMap<QualifiedName, AbstractClassTypeDeclarationDescr>();
for ( AbstractClassTypeDeclarationDescr tdescr : typeDeclarations ) {
QualifiedName name = tdescr.getType();
cache.put( name, tdescr );
if ( taxonomy.get( name ) == null ) {
taxonomy.put( name, new ArrayList<QualifiedName>() );
} else {
this.results.add( new TypeDeclarationError( tdescr,
"Found duplicate declaration for type " + tdescr.getTypeName() ) );
}
Collection<QualifiedName> supers = taxonomy.get( name );
boolean circular = false;
for ( QualifiedName sup : tdescr.getSuperTypes() ) {
if ( ! Object.class.getName().equals( name.getFullName() ) ) {
if ( ! hasCircularDependency( tdescr.getType(), sup, taxonomy ) ) {
supers.add( sup );
} else {
circular = true;
this.results.add( new TypeDeclarationError( tdescr,
"Found circular dependency for type " + tdescr.getTypeName() ) );
break;
}
}
}
if ( circular ) {
tdescr.getSuperTypes().clear();
}
for ( TypeFieldDescr field : tdescr.getFields().values() ) {
QualifiedName typeName = new QualifiedName( field.getPattern().getObjectType() );
if ( ! hasCircularDependency( name, typeName, taxonomy ) ) {
supers.add( typeName );
}
}