Source:
String lookupName(ClassName className) { ClassName stackContext = null; for (TypeSpec typeSpec : typeSpecStack) { if (typeSpec.name == null) { continue; } if (stackContext == null) { stackContext = ClassName.get(packageName, typeSpec.name); } else { stackContext = stackContext.nestedClass(typeSpec.name); } } if (stackContext == null) { if (className.packageName().equals(packageName)) { return Util.join(".", className.simpleNames()); } else { } } else { if (className.equals(stackContext)) { return className.simpleName(); } if (isNestedClass(className, stackContext)) { return className.simpleName(); } if (isNestedClass(stackContext, className)) { return nestedName(stackContext, className); } } List<String> classNames = className.simpleNames(); if (className.packageName().equals(packageName)) { ClassName prefix = shortestUniqeReference(className); while (conflictsWithLocalName(prefix)) { prefix = prefix.enclosingClassName(); } if (prefix.enclosingClassName() != null) { return nestedName(prefix.enclosingClassName(), className); } else { referencedNames.add(classNames.get(0)); return Util.join(".", classNames); } } else { ClassName prefix = className; while (prefix != null && conflictsWithLocalName(prefix)) { prefix = prefix.enclosingClassName(); } if (prefix == null) { return className.canonicalName; } String importedName = importedTypes.get(prefix); if (importedName != null) { if (!javadoc) importableTypes.add(prefix); referencedNames.add(importedName); if (prefix.enclosingClassName() != null) { return nestedName(prefix.enclosingClassName(), className); } else { return Util.join(".", classNames); } } ClassName enclosingClassName = prefix.enclosingClassName(); if (enclosingClassName != null) { return lookupName(enclosingClassName) + "." + nestedName(enclosingClassName, className); } if (!javadoc) importableTypes.add(prefix); return className.canonicalName; } }

Target:
String lookupName(ClassName className) { ClassName stackContext = null; for (TypeSpec typeSpec : typeSpecStack) { if (typeSpec.name == null) { continue; } if (stackContext == null) { stackContext = ClassName.get(packageName, typeSpec.name); } else { stackContext = stackContext.nestedClass(typeSpec.name); } } if (stackContext != null) { if (className.equals(stackContext)) { return className.simpleName(); } if (isNestedClass(className, stackContext)) { return className.simpleName(); } if (isNestedClass(stackContext, className)) { return nestedName(stackContext, className); } } List<String> classNames = className.simpleNames(); if (className.packageName().equals(packageName)) { ClassName prefix = shortestUniqeReference(className); while (conflictsWithLocalName(prefix)) { prefix = prefix.enclosingClassName(); } if (prefix.enclosingClassName() != null) { return nestedName(prefix.enclosingClassName(), className); } else { referencedNames.add(classNames.get(0)); return Util.join(".", classNames); } } else { ClassName prefix = className; while (prefix != null && conflictsWithLocalName(prefix)) { prefix = prefix.enclosingClassName(); } if (prefix == null) { return className.canonicalName; } String importedName = importedTypes.get(prefix); if (importedName != null) { if (!javadoc) importableTypes.add(prefix); referencedNames.add(importedName); if (prefix.enclosingClassName() != null) { return nestedName(prefix.enclosingClassName(), className); } else { return Util.join(".", classNames); } } ClassName enclosingClassName = prefix.enclosingClassName(); if (enclosingClassName != null) { return lookupName(enclosingClassName) + "." + nestedName(enclosingClassName, className); } if (!javadoc) importableTypes.add(prefix); return className.canonicalName; } }