Skip to content

Commit

Permalink
Fix properties not generating as get/set; wip: support func overloads
Browse files Browse the repository at this point in the history
  • Loading branch information
mattco98 committed Nov 28, 2023
1 parent bf4d8f2 commit 4ce3990
Showing 1 changed file with 44 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,41 @@ class Processor(environment: SymbolProcessorEnvironment) : SymbolProcessor {
// Note: We take a name parameter so that we can override the name of clazz. This is done for nested classes

appendLine(buildString {
if (clazz.classKind == ClassKind.INTERFACE || Modifier.ABSTRACT in clazz.modifiers)
append("abstract ")
append("class $name")
if (clazz.classKind == ClassKind.INTERFACE) {
append("interface ")
} else {
if (Modifier.ABSTRACT in clazz.modifiers)
append("abstract ")
append("class ")
}
append(name)

if (clazz.typeParameters.isNotEmpty()) {
append(clazz.typeParameters.joinToString(", ", "<", ">") {
it.name.asString()
})
}

val (superInterfaces, superClasses) = clazz.superTypes
.map {
var decl = it.resolve().declaration
while (decl is KSTypeAlias)
decl = decl.type.resolve().declaration
decl
}
.map { it as KSClassDeclaration }
.partition { it.classKind == ClassKind.INTERFACE }
if (superClasses.isNotEmpty()) {
require(superClasses.size == 1)
append(" extends ${superClasses.single().path}")
}
// if (superInterfaces.isNotEmpty()) {
// if (clazz.classKind == ClassKind.INTERFACE) {
// append(" extends ")
// } else append(" implements ")
// append(superInterfaces.joinToString { it.path })
// }

append(" { ")
})

Expand Down Expand Up @@ -189,17 +214,26 @@ class Processor(environment: SymbolProcessorEnvironment) : SymbolProcessor {
}
}

val properties = clazz.getDeclaredProperties().filter { it.isPublic() || it.isProtected() }.toList()
val functions = clazz.getDeclaredFunctions().filter { it.isPublic() || it.isProtected() }.toList()
val functions = clazz.getDeclaredFunctions().filter {
it.isPublic() || it.isProtected()
}.filterNot {
it.findOverridee() != null || it.simpleName.asString().let { name ->
name in excludedMethods || name in typescriptReservedWords
}
}.toList()

// Unlike Java, JS does not allow properties and functions to have the same name,
// so in the case that a pair does share the same name, we prefer the function
val functionNames = functions.map { it.simpleName.asString() }

for (property in properties) {
if (property.simpleName.asString() in functionNames)
continue
val properties = clazz.getDeclaredProperties().filter {
it.isPublic() || it.isProtected()
}.filterNot {
it.simpleName.asString() in functionNames || it.findOverridee() != null
}.toList()


for (property in properties) {
val isStatic = Modifier.JAVA_STATIC in property.modifiers ||
property.isAnnotationPresent(JvmStatic::class) ||
property.isAnnotationPresent(JvmField::class)
Expand Down Expand Up @@ -265,14 +299,12 @@ class Processor(environment: SymbolProcessorEnvironment) : SymbolProcessor {
}
} else listOf(function.parameters)

val functionName = function.simpleName.asString()

for (parameters in parameterSets) {
if (function.docString != null)
append(formatDocString(function.docString!!))

val functionName = function.simpleName.asString()
if (functionName in excludedMethods || functionName in typescriptReservedWords)
continue

appendLine(buildString {
if (Modifier.JAVA_STATIC in function.modifiers || function.isAnnotationPresent(JvmStatic::class))
append("static ")
Expand Down

0 comments on commit 4ce3990

Please sign in to comment.