ModuleTypeInfo typeInfo = workspaceManager.getModuleTypeInfo(moduleName);
if (typeInfo == null) {
iceLogger.log(Level.INFO, "The module " + moduleName + " does not exist.");
} else {
String typeName = qualifiedTypeName.getUnqualifiedName();
TypeConstructor typeCons = typeInfo.getTypeConstructor(typeName);
if (typeCons == null) {
iceLogger.log(Level.INFO, "The type constructor " + qualifiedTypeName + " does not exist.");
} else if (typeCons.getNDataConstructors() == 0) {
iceLogger.log(Level.INFO, "The type " + typeCons.getName() + " is not an algebraic type.");
} else {
SourceModel.TopLevelSourceElement[] decls =
DerivedInstanceFunctionGenerator.makeAlgebraicTypeInstanceFunctions(
typeInfo, typeCons, compact, workspaceManager.getModuleTypeInfo(CAL_Debug.MODULE_NAME));
for (final SourceModel.TopLevelSourceElement element : decls) {
// remove any unnecessary qualifications based on the visibility rules of the module
// where the type is defined
SourceModel.SourceElement decl =
SourceModelUtilities.UnnecessaryQualificationRemover.removeUnnecessaryQualifications(typeInfo, element);
// separate the instances with comments
if (decl instanceof SourceModel.InstanceDefn) {
SourceModel.InstanceDefn instanceDefn = (SourceModel.InstanceDefn)decl;
System.out.println("/**");
System.out.println(" * {@code " + instanceDefn.getTypeClassName().getUnqualifiedName() + "@} instance for {@code " + typeCons.getName().getUnqualifiedName() + "@}.");
System.out.println(" */");
}
System.out.println(decl.toSourceText());