Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
694 changes: 360 additions & 334 deletions core/src/main/kotlin/com/simiacryptus/cognotik/describe/JsonDescriber.kt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -9,57 +9,60 @@ import java.util.*

abstract class TypeDescriber {

abstract val markupLanguage: String
abstract val methodBlacklist: Set<String>
var coverMethods = true
abstract fun describe(
rawType: Class<in Nothing>,
stackMax: Int = 10,
describedTypes: MutableSet<String> = mutableSetOf()
): String
abstract val markupLanguage: String
abstract val methodBlacklist: Set<String>
var coverMethods = true
abstract fun describe(
rawType: Class<in Nothing>,
stackMax: Int = 10,
describedTypes: MutableSet<String> = mutableSetOf()
): String

abstract fun describe(self: Method, clazz: Class<*>? = null, stackMax: Int = 5): String
open fun isAbbreviated(self: Type): Boolean {
abstract fun <T, U:T> registerSubType(parentClass: Class<T>, subClass: Class<U>)
abstract fun <T, U:T> registerSubTypes(parentClass: Class<T>, vararg subClasses: Class<U>)
abstract fun <T, U:T> clearSubTypes(parentClass: Class<T>)
abstract fun describe(self: Method, clazz: Class<*>? = null, stackMax: Int = 5): String
open fun isAbbreviated(self: Type): Boolean {

val name = self.typeName
val typeName = self.typeName.substringAfterLast('.').replace('$', '.').lowercase(Locale.getDefault())
if (typeName in primitives) {
val name = self.typeName
val typeName = self.typeName.substringAfterLast('.').replace('$', '.').lowercase(Locale.getDefault())
if (typeName in primitives) {

return false
} else if (self is ParameterizedType && List::class.java.isAssignableFrom(self.rawType as Class<*>)) {
return false
} else if (self is ParameterizedType && List::class.java.isAssignableFrom(self.rawType as Class<*>)) {

return isAbbreviated(self.actualTypeArguments[0])
} else if (self is ParameterizedType && Map::class.java.isAssignableFrom(self.rawType as Class<*>)) {
return isAbbreviated(self.actualTypeArguments[0])
} else if (self is ParameterizedType && Map::class.java.isAssignableFrom(self.rawType as Class<*>)) {

return isAbbreviated(self.actualTypeArguments[0]) && isAbbreviated(self.actualTypeArguments[1])
} else if (self.isArray) {
return isAbbreviated(self.actualTypeArguments[0]) && isAbbreviated(self.actualTypeArguments[1])
} else if (self.isArray) {

return isAbbreviated(self.componentType!!)
}

if (name.startsWith("java.")) return true
if (name.startsWith("kotlin.")) return true
if (name.startsWith("sun.")) return true
if (name.startsWith("apache.")) return true
if (name.startsWith("org.slf4j.")) return true
if (name.startsWith("com.fasterxml.")) return true
return false
return isAbbreviated(self.componentType!!)
}

companion object {
val primitives = setOf(
"boolean",
"int",
"integer",
"number",
"string",
"double",
"float",
"long",
"short",
"byte",
"char",
"object"
)
}
if (name.startsWith("java.")) return true
if (name.startsWith("kotlin.")) return true
if (name.startsWith("sun.")) return true
if (name.startsWith("apache.")) return true
if (name.startsWith("org.slf4j.")) return true
if (name.startsWith("com.fasterxml.")) return true
return false
}

companion object {
val primitives = setOf(
"boolean",
"int",
"integer",
"number",
"string",
"double",
"float",
"long",
"short",
"byte",
"char",
"object"
)
}
}
Loading
Loading