Repository: JetBrains/kotlin
File: core/descriptors.runtime/src/org/jetbrains/kotlin/descriptors/runtime/components/ReflectKotlinClass.kt (Kotlin)

Code before:
            }
            clazz.isEnumClassOrSpecializedEnumEntryClass() -> {
                // isEnum returns false for specialized enum constants (enum entries which are anonymous enum subclasses)
                val classId = (if (clazz.isEnum) clazz else clazz.enclosingClass).classId
                visitor.visitEnum(name, classId, Name.identifier((value as Enum<*>).name))
            }
            Annotation::class.java.isAssignableFrom(clazz) -> {
                val annotationClass = clazz.interfaces.single()
                val v = visitor.visitAnnotation(name, annotationClass.classId) ?: return
                processAnnotationArguments(v, value as Annotation, annotationClass)
            }
            clazz.isArray -> {
                val v = visitor.visitArray(name) ?: return
                val componentType = clazz.componentType
                when {
                    componentType.isEnum -> {
                        val enumClassId = componentType.classId
                        for (element in value as Array<*>) {
                            v.visitEnum(enumClassId, Name.identifier((element as Enum<*>).name))
                        }
                    }
                    componentType == Class::class.java -> for (element in value as Array<*>) {
                        v.visitClassLiteral((element as Class<*>).classLiteralValue())
                    }
                    Annotation::class.java.isAssignableFrom(componentType) -> for (element in value as Array<*>) {
                        val vv = v.visitAnnotation(componentType.classId) ?: return
                        processAnnotationArguments(vv, element as Annotation, componentType)
                    }
                    else -> for (element in value as Array<*>) {
                        v.visit(element)
                    }
                }
                v.visitEnd()
            }
            else -> {
                throw UnsupportedOperationException("Unsupported annotation argument value ($clazz): $value")
            }
        }
    }
}

private object SignatureSerializer {
    fun methodDesc(method: Method): String {
        val sb = StringBuilder()
        sb.append("(")
        for (parameterType in method.parameterTypes) {
            sb.append(parameterType.desc)
        }
        sb.append(")")
        sb.append(method.returnType.desc)
        return sb.toString()

Review comment (refactor):
It seems like `?: continue` would make more sense here rather than `?: return`, don't you think? Because if the visitor is not interested in one annotation instance in the array, we shouldn't disregard the whole array, but rather try to visit the rest too.

At this point it makes no difference, I think, because only the implementation from `BinaryClassAnnotationAndConstantLoaderImpl.kt` can arrive here, and it always returns a visitor. But if this code is refactored/reused somewhere else, it might behave unexpectedly...

Code after:
            }
            clazz.isEnumClassOrSpecializedEnumEntryClass() -> {
                // isEnum returns false for specialized enum constants (enum entries which are anonymous enum subclasses)
                val classId = (if (clazz.isEnum) clazz else clazz.enclosingClass).classId
                visitor.visitEnum(name, classId, Name.identifier((value as Enum<*>).name))
            }
            Annotation::class.java.isAssignableFrom(clazz) -> {
                val annotationClass = clazz.interfaces.single()
                val v = visitor.visitAnnotation(name, annotationClass.classId) ?: return
                processAnnotationArguments(v, value as Annotation, annotationClass)
            }
            clazz.isArray -> {
                val v = visitor.visitArray(name) ?: return
                val componentType = clazz.componentType
                when {
                    componentType.isEnum -> {
                        val enumClassId = componentType.classId
                        for (element in value as Array<*>) {
                            v.visitEnum(enumClassId, Name.identifier((element as Enum<*>).name))
                        }
                    }
                    componentType == Class::class.java -> for (element in value as Array<*>) {
                        v.visitClassLiteral((element as Class<*>).classLiteralValue())
                    }
                    Annotation::class.java.isAssignableFrom(componentType) -> for (element in value as Array<*>) {
                        val vv = v.visitAnnotation(componentType.classId) ?: continue
                        processAnnotationArguments(vv, element as Annotation, componentType)
                    }
                    else -> for (element in value as Array<*>) {
                        v.visit(element)
                    }
                }
                v.visitEnd()
            }
            else -> {
                throw UnsupportedOperationException("Unsupported annotation argument value ($clazz): $value")
            }
        }
    }
}

private object SignatureSerializer {
    fun methodDesc(method: Method): String {
        val sb = StringBuilder()
        sb.append("(")
        for (parameterType in method.parameterTypes) {
            sb.append(parameterType.desc)
        }
        sb.append(")")
        sb.append(method.returnType.desc)
        return sb.toString()