Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enh(api-gen): generate kdoc from api json #534

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ val jvmReservedMethods = listOf(
hashCompatibility = listOf(),
returnValue = null,
returnType = null,
arguments = null
arguments = null,
description = null,
briefDescription = 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,7 @@ 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("description") val description: String?,
@JsonProperty("brief_description") val briefDescription: String?
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ 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("description") val description: String?,
@JsonProperty("brief_description") val briefDescription: String?
) {
fun copy(newName: String) = Class(
newName,
Expand All @@ -25,6 +27,8 @@ data class Class @JsonCreator constructor (
methods,
properties,
constants,
signals
signals,
description,
briefDescription
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ 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("description") val description: String?,
@JsonProperty("brief_description") val briefDescription: String?
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ 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("description") val description: String?,
@JsonProperty("brief_description") val briefDescription: 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("description") override val description: String? = null
) : IDocumented
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ 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("description") val description: String?,
@JsonProperty("brief_description") val briefDescription: String?
) : TypedTrait
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ 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("description") val description: String?,
@JsonProperty("brief_description") val briefDescription: String?
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ 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("description") val description: String?,
@JsonProperty("brief_description") val briefDescription: String?
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ 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("description") val description: String?,
@JsonProperty("brief_description") val briefDescription: String?
) : TypedTrait
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ 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("description") val description: String?,
@JsonProperty("brief_description") val briefDescription: String?
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ 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("description") val description: String?,
@JsonProperty("brief_description") val briefDescription: String?
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package godot.codegen.models.enriched
import godot.codegen.models.ApiType
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()
Expand All @@ -16,6 +17,7 @@ class EnrichedClass(val internal: Class) : TypedTrait {
val properties= internal.properties?.toEnriched() ?: listOf()
val methods = internal.methods?.toEnriched(engineClassDBIndexName) ?: listOf()
val apiType = ApiType.from(internal.apiType)
override val description = internal.description

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 description = internal.description
}

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 @@ -35,6 +36,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 description = internal.description
}

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 description = internal.description
}

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 description = internal.description

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 @@ -64,7 +64,9 @@ class ClassService(
hashCompatibility = listOf(),
returnValue = ReturnValue(returnType, null),
returnType = null,
arguments = arguments
arguments = arguments,
description = null,
briefDescription = null
),
clazz.engineClassDBIndexName
)
Expand Down
Loading
Loading