aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Formats/StructuredFormatService.kt6
-rw-r--r--src/Kotlin/DocumentationBuilder.kt15
-rw-r--r--src/Model/DocumentationNode.kt3
-rw-r--r--test/data/classes/classWithClassObject.kt7
-rw-r--r--test/src/model/ClassTest.kt32
5 files changed, 56 insertions, 7 deletions
diff --git a/src/Formats/StructuredFormatService.kt b/src/Formats/StructuredFormatService.kt
index adfac99c..60d5b7f1 100644
--- a/src/Formats/StructuredFormatService.kt
+++ b/src/Formats/StructuredFormatService.kt
@@ -187,6 +187,8 @@ public abstract class StructuredFormatService(val locationService: LocationServi
appendSection(location, "Constructors", node.members(DocumentationNode.Kind.Constructor), node, to)
appendSection(location, "Properties", node.members(DocumentationNode.Kind.Property), node, to)
appendSection(location, "Functions", node.members(DocumentationNode.Kind.Function), node, to)
+ appendSection(location, "Class Object Properties", node.members(DocumentationNode.Kind.ClassObjectProperty), node, to)
+ appendSection(location, "Class Object Functions", node.members(DocumentationNode.Kind.ClassObjectFunction), node, to)
appendSection(location, "Accessors", node.members(DocumentationNode.Kind.PropertyAccessor), node, to)
appendSection(location, "Other members", node.members.filter {
it.kind !in setOf(
@@ -197,7 +199,9 @@ public abstract class StructuredFormatService(val locationService: LocationServi
DocumentationNode.Kind.Property,
DocumentationNode.Kind.Package,
DocumentationNode.Kind.Function,
- DocumentationNode.Kind.PropertyAccessor
+ DocumentationNode.Kind.PropertyAccessor,
+ DocumentationNode.Kind.ClassObjectProperty,
+ DocumentationNode.Kind.ClassObjectFunction
)
}, node, to)
appendSection(location, "Extensions", node.extensions, node, to)
diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt
index d2c07200..aeea4a55 100644
--- a/src/Kotlin/DocumentationBuilder.kt
+++ b/src/Kotlin/DocumentationBuilder.kt
@@ -161,11 +161,13 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati
if (getKind() != ClassKind.OBJECT) {
node.appendChildren(getTypeConstructor().getParameters(), DocumentationReference.Kind.Detail)
node.appendChildren(getConstructors(), DocumentationReference.Kind.Member)
- val classObjectDescriptor = getClassObjectDescriptor()
- if (classObjectDescriptor != null)
- node.appendChild(classObjectDescriptor, DocumentationReference.Kind.Member)
}
node.appendChildren(getDefaultType().getMemberScope().getAllDescriptors(), DocumentationReference.Kind.Member)
+ val classObjectDescriptor = getClassObjectDescriptor()
+ if (classObjectDescriptor != null) {
+ node.appendChildren(classObjectDescriptor.getDefaultType().getMemberScope().getAllDescriptors(),
+ DocumentationReference.Kind.Member)
+ }
register(this, node)
return node
}
@@ -177,8 +179,11 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati
return node
}
+ private fun DeclarationDescriptor.inClassObject() =
+ getContainingDeclaration().let { it is ClassDescriptor && it.getKind() == ClassKind.CLASS_OBJECT }
+
fun FunctionDescriptor.build(): DocumentationNode {
- val node = DocumentationNode(this, Kind.Function)
+ val node = DocumentationNode(this, if (inClassObject()) Kind.ClassObjectFunction else Kind.Function)
node.appendChildren(getTypeParameters(), DocumentationReference.Kind.Detail)
getExtensionReceiverParameter()?.let { node.appendChild(it, DocumentationReference.Kind.Detail) }
@@ -201,7 +206,7 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati
}
fun PropertyDescriptor.build(): DocumentationNode {
- val node = DocumentationNode(this, Kind.Property)
+ val node = DocumentationNode(this, if (inClassObject()) Kind.ClassObjectProperty else Kind.Property)
node.appendChildren(getTypeParameters(), DocumentationReference.Kind.Detail)
getExtensionReceiverParameter()?.let { node.appendChild(it, DocumentationReference.Kind.Detail) }
node.appendType(getReturnType())
diff --git a/src/Model/DocumentationNode.kt b/src/Model/DocumentationNode.kt
index c2d7e3fb..86d2ee04 100644
--- a/src/Model/DocumentationNode.kt
+++ b/src/Model/DocumentationNode.kt
@@ -70,6 +70,9 @@ public open class DocumentationNode(val name: String,
Property
PropertyAccessor
+ ClassObjectProperty
+ ClassObjectFunction
+
Parameter
Receiver
TypeParameter
diff --git a/test/data/classes/classWithClassObject.kt b/test/data/classes/classWithClassObject.kt
new file mode 100644
index 00000000..459efad6
--- /dev/null
+++ b/test/data/classes/classWithClassObject.kt
@@ -0,0 +1,7 @@
+class Klass() {
+ class object {
+ val x = 1
+
+ fun foo() {}
+ }
+}
diff --git a/test/src/model/ClassTest.kt b/test/src/model/ClassTest.kt
index 65363c92..b95a31dc 100644
--- a/test/src/model/ClassTest.kt
+++ b/test/src/model/ClassTest.kt
@@ -136,4 +136,34 @@ public class ClassTest {
}
}
}
-} \ No newline at end of file
+
+ Test fun classWithClassObject() {
+ verifyModel("test/data/classes/classWithClassObject.kt") { model ->
+ with(model.members.single().members.single()) {
+ assertEquals(DocumentationNode.Kind.Class, kind)
+ assertEquals("Klass", name)
+ assertEquals(Content.Empty, content)
+ assertEquals(2, details.count())
+ assertTrue(links.none())
+
+ assertEquals(3, members.count())
+ with(members.elementAt(0)) {
+ assertEquals("<init>", name)
+ assertEquals(Content.Empty, content)
+ }
+ with(members.elementAt(1)) {
+ assertEquals("x", name)
+ assertEquals(DocumentationNode.Kind.ClassObjectProperty, kind)
+ assertTrue(members.none())
+ assertTrue(links.none())
+ }
+ with(members.elementAt(2)) {
+ assertEquals("foo", name)
+ assertEquals(DocumentationNode.Kind.ClassObjectFunction, kind)
+ assertTrue(members.none())
+ assertTrue(links.none())
+ }
+ }
+ }
+ }
+}