Set<ModuleName> importsThatProduceConflicts = new HashSet<ModuleName>();
boolean noConflicts = updateWithUnimportedModules(unimportedModules, importsThatProduceConflicts, moduleTypeInfo, typeExpr);
if (noConflicts) {
TypeSignature typeSignature = typeExpr.toSourceModel(null, namingPolicy);
FunctionTypeDeclaration typeDecl = FunctionTypeDeclaration.make(function.getName(), typeSignature);
SourcePosition insertionPosition = function.getSourceRangeExcludingCaldoc().getStartSourcePosition();
String insertionText = makeIndentedSourceElementText(typeDecl, insertionPosition, sourceText, false);
sourceModifier.addSourceModification(new SourceModification.InsertText(insertionText, insertionPosition));
if(refactoringStatistics != null) {
refactoringStatistics.recordAddedToplevelTypeDeclaration(containsClassConstraints(typeExpr));
}
} else {
if(refactoringStatistics != null) {
refactoringStatistics.recordTypeDeclarationNotAddedDueToPotentialImportConflict(importsThatProduceConflicts);
}
}
}
// Add SourceModifications for unannotated local functions
LinkedHashSet<LocalFunctionIdentifier> unannotatedLocalFunctions = visitor.getUnannotatedLocalFunctions();
for (final LocalFunctionIdentifier identifier : unannotatedLocalFunctions) {
TypeExpr typeExpr = computeLocalTypeExpr(moduleTypeInfo, identifier);
if(typeExpr == null) {
if(refactoringStatistics != null) {
refactoringStatistics.recordLocalTypeDeclarationNotAdded();
}
continue;
}
LocalDefn localDefn = visitor.getLocalDefn(identifier);
if (sourceRange != null){
final SourceRange functionSourceRange = localDefn.getSourceRange();
if (functionSourceRange != null){
if (!sourceRange.overlaps(functionSourceRange)){
continue;
}
}
}
Set<ModuleName> importsThatProduceConflicts = new HashSet<ModuleName>();
boolean noConflicts = updateWithUnimportedModules(unimportedModules, importsThatProduceConflicts, moduleTypeInfo, typeExpr);
if (noConflicts) {
TypeSignature typeSignature = typeExpr.toSourceModel(null, namingPolicy);
LocalDefn.Function.TypeDeclaration typeDecl = LocalDefn.Function.TypeDeclaration.make(identifier.getLocalFunctionName(), typeSignature);
boolean noLeadingNewline = visitor.doesTypeDeclNeedLeadingNewline(identifier);
final SourcePosition insertionPosition;
if (localDefn instanceof LocalDefn.Function.Definition) {