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
30 changes: 22 additions & 8 deletions src/main/kotlin/me/ntrrgc/tsGenerator/TypeScriptGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,8 @@ class TypeScriptGenerator(

private fun functionsOf(klass: KClass<*>): String = try {
klass.declaredMemberFunctions
.filter { it.visibility == KVisibility.PUBLIC }
.let { functionsList ->
pipeline.transformFunctionList(functionsList, klass)
pipeline.transformFunctionList(functionsList.toList(), klass)
}.joinToString("") { function ->
val functionName = pipeline.transformFunctionName(function.name, function, klass)
val returnType = pipeline.transformFunctionReturnType(function.returnType, function, klass)
Expand All @@ -318,8 +317,16 @@ class TypeScriptGenerator(
"${param.name}: ${formatKType(paramType).formatWithoutParenthesis()}"

}
val visibility = when (function.visibility) {
KVisibility.PRIVATE -> "private "
KVisibility.PROTECTED -> "protected "
KVisibility.PUBLIC -> ""
KVisibility.INTERNAL -> ""
else -> ""
}

val formattedReturnType = formatKType(returnType).formatWithoutParenthesis()
" $functionName($parameters): $formattedReturnType;\n"
" $visibility$functionName($parameters): $formattedReturnType;\n"
}
} catch (exception: kotlin.reflect.jvm.internal.KotlinReflectionInternalError) {
print(exception.toString())
Expand All @@ -329,11 +336,8 @@ class TypeScriptGenerator(

private fun propertiesOf(klass: KClass<*>): String = try {
klass.declaredMemberProperties
.filter {
it.visibility == KVisibility.PUBLIC || isJavaBeanProperty(it, klass)
}
.let { propertyList ->
pipeline.transformPropertyList(propertyList, klass)
pipeline.transformPropertyList(propertyList.toList(), klass)
}.joinToString("") { property ->
val propertyName = pipeline.transformPropertyName(property.name, property, klass)
val propertyType = pipeline.transformPropertyType(property.returnType, property, klass)
Expand All @@ -342,7 +346,17 @@ class TypeScriptGenerator(
formatPropertyFunctionType(propertyType)
else
formatKType(propertyType).formatWithoutParenthesis()
" $propertyName: $formattedPropertyType;\n"

val visibility = if (isJavaBeanProperty(property, klass)) "" else
when (property.visibility) {
KVisibility.PRIVATE -> "private "
KVisibility.PROTECTED -> "protected "
KVisibility.PUBLIC -> ""
KVisibility.INTERNAL -> ""
else -> ""
}

" $visibility$propertyName: $formattedPropertyType;\n"
}
} catch (exception: kotlin.reflect.jvm.internal.KotlinReflectionInternalError) {
print(exception.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,10 @@ class ClassWithMethods(
}

@Suppress("unused")
class ClassWithMethodsThatReturnsOrTakesFunctionalType(
open class ClassWithMethodsThatReturnsOrTakesFunctionalType(
val propertyMethodReturnsLambda: () -> (() -> Int),
private val privatePropertyMethodReturnsLambda: () -> (() -> Int),
protected val protectedPropertyMethodReturnsLambda: () -> (() -> Int),
val propertyMethodReturnsLambdaMightNull: () -> (() -> Int)?,
val propertyMethodTakesLambdaMightNull: ((() -> Int)?) -> Unit,
) {
Expand All @@ -203,6 +205,9 @@ class ClassWithMethodsThatReturnsOrTakesFunctionalType(

fun regularMethodThatReturnsLambdaMightNull() = null
fun regularMethodTakesLambdaReturnsMightNull(x: () -> Int?) {}

private fun privateMethod() = null
protected fun protectedMethod() = null
}

@Suppress("unused")
Expand Down