diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Generation/JavaSignatureGenerator.kt | 15 | ||||
-rw-r--r-- | src/Generation/KotlinSignatureGenerator.kt | 19 | ||||
-rw-r--r-- | src/Generation/SignatureGenerator.kt | 2 | ||||
-rw-r--r-- | src/Model/Diagnostics.kt | 1 |
4 files changed, 37 insertions, 0 deletions
diff --git a/src/Generation/JavaSignatureGenerator.kt b/src/Generation/JavaSignatureGenerator.kt index bc9b9a46..6ba9ac88 100644 --- a/src/Generation/JavaSignatureGenerator.kt +++ b/src/Generation/JavaSignatureGenerator.kt @@ -25,6 +25,14 @@ class JavaSignatureGenerator : SignatureGenerator { return "package ${node.name}" } + override fun renderModifier(node: DocumentationNode): String { + return when (node.name) { + "open" -> "" + "internal" -> "" + else -> node.name + } + } + override fun renderType(node: DocumentationNode): String { return when (node.name) { "Unit" -> "void" @@ -63,6 +71,13 @@ class JavaSignatureGenerator : SignatureGenerator { }.toString() } + override fun renderModifiersForNode(node: DocumentationNode): String { + val modifiers = node.details(Kind.Modifier).map { renderModifier(it) }.filter { it != ""} + if (modifiers.none()) + return "" + return modifiers.join(" ", postfix = " ") + } + override fun renderClass(node: DocumentationNode): String { return StringBuilder { when (node.kind) { diff --git a/src/Generation/KotlinSignatureGenerator.kt b/src/Generation/KotlinSignatureGenerator.kt index f42b34eb..481e5133 100644 --- a/src/Generation/KotlinSignatureGenerator.kt +++ b/src/Generation/KotlinSignatureGenerator.kt @@ -14,6 +14,7 @@ class KotlinSignatureGenerator : SignatureGenerator { Kind.Type, Kind.UpperBound -> renderType(node) + Kind.Modifier -> renderModifier(node) Kind.Constructor, Kind.Function -> renderFunction(node) Kind.Property -> renderProperty(node) @@ -29,6 +30,14 @@ class KotlinSignatureGenerator : SignatureGenerator { return node.name } + override fun renderModifier(node: DocumentationNode): String { + return when (node.name) { + "final" -> "" + "internal" -> "" + else -> node.name + } + } + override fun renderTypeParameter(node: DocumentationNode): String { val constraints = node.details(Kind.UpperBound) return if (constraints.none()) @@ -53,8 +62,16 @@ class KotlinSignatureGenerator : SignatureGenerator { }.toString() } + override fun renderModifiersForNode(node: DocumentationNode): String { + val modifiers = node.details(Kind.Modifier).map { renderModifier(it) }.filter { it != ""} + if (modifiers.none()) + return "" + return modifiers.join(" ", postfix = " ") + } + override fun renderClass(node: DocumentationNode): String { return StringBuilder { + append(renderModifiersForNode(node)) when (node.kind) { Kind.Class -> append("class ") Kind.Interface -> append("trait ") @@ -73,6 +90,7 @@ class KotlinSignatureGenerator : SignatureGenerator { override fun renderFunction(node: DocumentationNode): String { return StringBuilder { + append(renderModifiersForNode(node)) when (node.kind) { Kind.Constructor -> append("init") Kind.Function -> append("fun ") @@ -100,6 +118,7 @@ class KotlinSignatureGenerator : SignatureGenerator { override fun renderProperty(node: DocumentationNode): String { return StringBuilder { + append(renderModifiersForNode(node)) when (node.kind) { Kind.Property -> append("val ") else -> throw IllegalArgumentException("Node $node is not a property") diff --git a/src/Generation/SignatureGenerator.kt b/src/Generation/SignatureGenerator.kt index 8ddeddc8..176f8d40 100644 --- a/src/Generation/SignatureGenerator.kt +++ b/src/Generation/SignatureGenerator.kt @@ -10,5 +10,7 @@ trait SignatureGenerator { fun renderType(node: DocumentationNode): String fun renderPackage(node: DocumentationNode): String fun renderProperty(node: DocumentationNode): String + open fun renderModifier(node: DocumentationNode): String + open fun renderModifiersForNode(node: DocumentationNode): String } diff --git a/src/Model/Diagnostics.kt b/src/Model/Diagnostics.kt index 129f23b6..899ff7de 100644 --- a/src/Model/Diagnostics.kt +++ b/src/Model/Diagnostics.kt @@ -12,6 +12,7 @@ fun BindingContext.checkResolveChildren(node : DocumentationNode) { for (item in node.details + node.members) { val symbolName = item.name val symbol: DeclarationDescriptor? = when (item.kind) { + DocumentationNode.Kind.Modifier -> continue // do not resolve modifiers DocumentationNode.Kind.Receiver -> (parentScope.getContainingDeclaration() as CallableDescriptor).getReceiverParameter() DocumentationNode.Kind.Parameter -> parentScope.getLocalVariable(Name.guess(symbolName)) DocumentationNode.Kind.Function -> parentScope.getFunctions(Name.guess(symbolName)).firstOrNull() |