Skip to content

Commit

Permalink
enh(api-gen): generate kdoc from api json
Browse files Browse the repository at this point in the history
  • Loading branch information
piiertho committed Nov 10, 2023
1 parent 644dc04 commit 2950ba7
Show file tree
Hide file tree
Showing 900 changed files with 70,821 additions and 46,658 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ val jvmReservedMethods = listOf(
hashCompatibility = listOf(),
returnValue = null,
returnType = null,
arguments = null
arguments = null,
documentation = null
),
""
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,16 @@ import godot.codegen.repositories.*
import godot.codegen.repositories.impl.*
import godot.codegen.services.*
import godot.codegen.services.impl.*
import godot.docgen.DocGen
import godot.tools.common.constants.GENERATED_COMMENT
import java.io.File

fun File.generateApiFrom(jsonSource: File, docsDir: File? = null) {
val classDocs = docsDir?.let { DocGen.deserializeDoc(it) } ?: mapOf()
val apiDescription = ObjectMapper().readValue(jsonSource, object : TypeReference<ApiDescription>() {})

val classRepository: ClassRepository = JsonClassRepository(apiDescription.classes.toEnriched())
val singletonRepository: SingletonRepository = JsonSingletonRepository(apiDescription.singletons.toEnriched())
val globalEnumRepository: GlobalEnumRepository = JsonGlobalEnumRepository(apiDescription.globalEnums.toEnriched())
val coreTypeEnumRepository: CoreTypeEnumRepository = KnownCoreTypeEnumRepository()
val docRepository: IDocRepository = DocRepository(classDocs)
val nativeStructureRepository = NativeStructureRepository(apiDescription.nativeStructures.toEnriched())

val classGraphService: IClassGraphService = ClassGraphService(classRepository)
Expand All @@ -33,7 +30,7 @@ fun File.generateApiFrom(jsonSource: File, docsDir: File? = null) {
classGraphService
)
val enumService: IEnumService = EnumService(globalEnumRepository, coreTypeEnumRepository, classService)
val generationService: IGenerationService = GenerationService(docRepository, classGraphService, enumService, nativeStructureRepository)
val generationService: IGenerationService = GenerationService(classGraphService, enumService, nativeStructureRepository)

classService.findGetSetMethodsAndUpdateProperties()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ data class BuiltinClass @JsonCreator constructor (
@JsonProperty("members") val members: List<Member>?,
@JsonProperty("constants") val constants: List<Constant>?,
@JsonProperty("enums") val enums: List<Enum>?,
@JsonProperty("indexing_return_type") val indexingReturnType: String?
@JsonProperty("indexing_return_type") val indexingReturnType: String?,
@JsonProperty("documentation") val documentation: String?
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ data class Class @JsonCreator constructor (
@JsonProperty("methods") val methods : List<Method>?,
@JsonProperty("properties") val properties: List<Property>?,
@JsonProperty("constants") val constants: List<Constant>?,
@JsonProperty("signals") val signals : List<Signal>?
@JsonProperty("signals") val signals : List<Signal>?,
@JsonProperty("documentation") val documentation: String?
) {
fun copy(newName: String) = Class(
newName,
Expand All @@ -25,6 +26,7 @@ data class Class @JsonCreator constructor (
methods,
properties,
constants,
signals
signals,
documentation
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ import godot.codegen.traits.TypedTrait
data class Constant @JsonCreator constructor(
@JsonProperty("name") val name: String,
@JsonProperty("type") val type: String?,
@JsonProperty("value") val value: String
@JsonProperty("value") val value: String,
@JsonProperty("documentation") val documentation: String?
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ import com.fasterxml.jackson.annotation.JsonProperty

data class Constructor @JsonCreator constructor (
@JsonProperty("index") val index : Int,
@JsonProperty("arguments") val arguments: List<Argument>?
@JsonProperty("arguments") val arguments: List<Argument>?,
@JsonProperty("documentation") val documentation: String?
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package godot.codegen.models

import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonProperty
import godot.codegen.traits.IDocumented

data class EnumValue @JsonCreator constructor(
@JsonProperty("name") val name : String,
@JsonProperty("value") val value : Long
)
@JsonProperty("value") val value : Long,
@JsonProperty("documentation") override val documentation: String? = null
) : IDocumented
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ import godot.codegen.traits.TypedTrait

data class Member @JsonCreator constructor(
@JsonProperty("name") val name: String,
@JsonProperty("type") override val type: String
@JsonProperty("type") override val type: String,
@JsonProperty("documentation") val documentation: String?
) : TypedTrait
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ data class Method @JsonCreator constructor(
@JsonProperty("hash_compatibility") val hashCompatibility: List<Long>?,
@JsonProperty("return_value") val returnValue : ReturnValue?,
@JsonProperty("return_type") val returnType: String?,
@JsonProperty("arguments") val arguments : List<Argument>?
@JsonProperty("arguments") val arguments : List<Argument>?,
@JsonProperty("documentation") val documentation: String?
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package godot.codegen.models

import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonProperty
import godot.codegen.traits.IDocumented

data class Operator @JsonCreator constructor(
@JsonProperty("name") val name : String,
@JsonProperty("right_type") val rightType : String?,
@JsonProperty("return_type") val returnType : String
@JsonProperty("return_type") val returnType : String,
@JsonProperty("documentation") val documentation: String?
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ data class Property @JsonCreator constructor(
@JsonProperty("name") val name: String,
@JsonProperty("setter") val setter: String?,
@JsonProperty("getter") val getter: String,
@JsonProperty("index") val index: Int?
@JsonProperty("index") val index: Int?,
@JsonProperty("documentation") val documentation: String?
) : TypedTrait
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ import com.fasterxml.jackson.annotation.JsonProperty

data class Signal @JsonCreator constructor(
@JsonProperty("name") val name: String,
@JsonProperty("arguments") val arguments: List<Argument>?
@JsonProperty("arguments") val arguments: List<Argument>?,
@JsonProperty("documentation") val documentation: String?
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package godot.codegen.models

import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonProperty
import godot.codegen.traits.IDocumented

data class UtilityFunction @JsonCreator constructor (
@JsonProperty("name") val name : String,
@JsonProperty("return_type") val returnType : String?,
@JsonProperty("category") val category : String,
@JsonProperty("is_vararg") val isVararg : Boolean,
@JsonProperty("hash") val hash : Long,
@JsonProperty("arguments") val arguments : List<Argument>?
@JsonProperty("arguments") val arguments : List<Argument>?,
@JsonProperty("documentation") val documentation: String?
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@ package godot.codegen.models.enriched

import godot.codegen.models.Class
import godot.codegen.models.custom.AdditionalImport
import godot.codegen.traits.IDocumented
import godot.codegen.traits.TypedTrait
import godot.tools.common.extensions.escapeUnderscore
import java.util.*

class EnrichedClass(val internal: Class) : TypedTrait {
class EnrichedClass(val internal: Class) : TypedTrait, IDocumented {
val constants= internal.constants?.toEnriched() ?: listOf()
val signals = internal.signals?.toEnriched() ?: listOf()
val name = internal.name.escapeUnderscore()
val inherits = internal.inherits?.escapeUnderscore()
val engineClassDBIndexName = "ENGINECLASS_${internal.name.uppercase(Locale.US)}"
val properties= internal.properties?.toEnriched() ?: listOf()
val methods = internal.methods?.toEnriched(engineClassDBIndexName) ?: listOf()
override val documentation = internal.documentation

override val type = name

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package godot.codegen.models.enriched

import godot.codegen.workarounds.sanitizeApiType
import godot.codegen.models.Constant
import godot.codegen.traits.IDocumented
import godot.codegen.traits.TypedTrait

class EnrichedConstant(val internal: Constant) : TypedTrait {
class EnrichedConstant(val internal: Constant) : TypedTrait, IDocumented {
override val type = internal.type?.sanitizeApiType() ?: "int"
override val documentation = internal.documentation
}

fun List<Constant>.toEnriched() = map { EnrichedConstant(it) }
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import godot.codegen.extensions.isObjectSubClass
import godot.codegen.models.Argument
import godot.codegen.models.Method
import godot.codegen.traits.CallableTrait
import godot.codegen.traits.IDocumented
import godot.codegen.workarounds.sanitizeApiType
import godot.tools.common.constants.Constraints
import godot.tools.common.constants.GodotTypes
import godot.tools.common.extensions.convertToCamelCase
import java.util.*

class EnrichedMethod(val internal: Method, engineClassIndexName: String) : CallableTrait {
class EnrichedMethod(val internal: Method, engineClassIndexName: String) : CallableTrait, IDocumented {
override val arguments = internal.arguments?.toEnriched() ?: listOf()
override val isVararg = internal.isVararg
val name: String
Expand All @@ -34,6 +35,7 @@ class EnrichedMethod(val internal: Method, engineClassIndexName: String) : Calla
override val type = internal.returnValue?.type?.sanitizeApiType()
override val meta: String? = internal.returnValue?.meta
override val nullable = isObjectSubClass() || type == GodotTypes.variant
override val documentation = internal.documentation
}

fun List<Method>.toEnriched(engineClassIndexName: String) = map { EnrichedMethod(it, engineClassIndexName) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import godot.codegen.models.Argument
import godot.codegen.models.Property
import godot.codegen.traits.CallableTrait
import godot.codegen.traits.CastableTrait
import godot.codegen.traits.IDocumented
import godot.codegen.traits.NullableTrait

class EnrichedProperty(val internal: Property) : CastableTrait, NullableTrait {
class EnrichedProperty(val internal: Property) : CastableTrait, NullableTrait, IDocumented {
val name = internal.name.replace("/", "_").convertToCamelCase()
val getter = internal.getter.convertToCamelCase()
val setter = internal.setter?.convertToCamelCase()
Expand Down Expand Up @@ -48,6 +49,7 @@ class EnrichedProperty(val internal: Property) : CastableTrait, NullableTrait {
override val nullable = isObjectSubClass() || type == GodotTypes.variant
override val meta: String?
get() = getterMethod?.meta
override val documentation = internal.documentation
}

fun List<Property>.toEnriched() = map {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import godot.codegen.exceptions.TooManySignalArgument
import godot.tools.common.extensions.convertToCamelCase
import godot.tools.common.extensions.escapeKotlinReservedNames
import godot.codegen.models.Signal
import godot.codegen.traits.IDocumented
import godot.codegen.traits.TypedTrait
import godot.tools.common.constants.Constraints

class EnrichedSignal(val internal: Signal) : TypedTrait {
class EnrichedSignal(val internal: Signal) : TypedTrait, IDocumented {
val name = internal.name.convertToCamelCase().escapeKotlinReservedNames()
val arguments = internal.arguments?.toEnriched() ?: listOf()
override val type = "Signal${arguments.size}"
override val documentation = internal.documentation

init{
if (arguments.size > Constraints.MAX_SIGNAL_ARG_COUNT) {
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ class ClassService(
hashCompatibility = listOf(),
returnValue = ReturnValue(returnType, null),
returnType = null,
arguments = arguments
arguments = arguments,
documentation = null
),
clazz.engineClassDBIndexName
)
Expand Down
Loading

0 comments on commit 2950ba7

Please sign in to comment.