diff options
-rw-r--r-- | src/DocumentationBuilder.kt | 9 | ||||
-rw-r--r-- | src/DocumentationBuildingVisitor.kt | 9 | ||||
-rw-r--r-- | src/DocumentationModel.kt | 1 | ||||
-rw-r--r-- | src/main.kt | 35 | ||||
-rw-r--r-- | test/data/classes/emptyObject.kt | 3 | ||||
-rw-r--r-- | test/src/ClassTest.kt | 13 |
6 files changed, 35 insertions, 35 deletions
diff --git a/src/DocumentationBuilder.kt b/src/DocumentationBuilder.kt index b82049a5..ec153aa0 100644 --- a/src/DocumentationBuilder.kt +++ b/src/DocumentationBuilder.kt @@ -16,7 +16,7 @@ fun BindingContext.createDocumentation(file: JetFile): DocumentationModel { return model } -class DocumentationBuilderVisitor(val context : BindingContext) : DeclarationDescriptorVisitorEmptyBodies<DocumentationNode, DocumentationNode>() { +class DocumentationBuilderVisitor(val context: BindingContext) : DeclarationDescriptorVisitorEmptyBodies<DocumentationNode, DocumentationNode>() { override fun visitDeclarationDescriptor(descriptor: DeclarationDescriptor?, data: DocumentationNode?): DocumentationNode? { val doc = context.getDocumentation(descriptor!!).extractText() @@ -34,7 +34,12 @@ class DocumentationBuilderVisitor(val context : BindingContext) : DeclarationDes override fun visitClassDescriptor(descriptor: ClassDescriptor?, data: DocumentationNode?): DocumentationNode? { val doc = context.getDocumentation(descriptor!!).extractText() - val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNodeKind.Class) + val node = DocumentationNode(descriptor.getName().asString(), doc, + when (descriptor.getKind()) { + ClassKind.OBJECT -> DocumentationNodeKind.Object + else -> DocumentationNodeKind.Class + } + ) data?.addReferenceTo(node, DocumentationReferenceKind.Member) return node } diff --git a/src/DocumentationBuildingVisitor.kt b/src/DocumentationBuildingVisitor.kt index 4f76ed0e..31c126fc 100644 --- a/src/DocumentationBuildingVisitor.kt +++ b/src/DocumentationBuildingVisitor.kt @@ -66,9 +66,12 @@ class DocumentationBuildingVisitor(private val worker: DeclarationDescriptorVisi public override fun visitClassDescriptor(descriptor: ClassDescriptor?, data: DocumentationNode?): DocumentationNode? { val node = createDocumentation(descriptor!!, data!!) - visitChildren(descriptor.getConstructors(), node) - visitChildren(descriptor.getTypeConstructor().getParameters(), node) - visitChild(descriptor.getClassObjectDescriptor(), node) + if (descriptor.getKind() != ClassKind.OBJECT) { + // do not go inside object for class object and constructors, they are generated + visitChildren(descriptor.getTypeConstructor().getParameters(), node) + visitChildren(descriptor.getConstructors(), node) + visitChild(descriptor.getClassObjectDescriptor(), node) + } val members = descriptor.getDefaultType().getMemberScope().getAllDescriptors().filter { it !is CallableMemberDescriptor || it.isUserCode() } diff --git a/src/DocumentationModel.kt b/src/DocumentationModel.kt index 048f3e4e..0cb4c6cb 100644 --- a/src/DocumentationModel.kt +++ b/src/DocumentationModel.kt @@ -8,6 +8,7 @@ public enum class DocumentationNodeKind { Package Class + Object Constructor Function Property diff --git a/src/main.kt b/src/main.kt index 04415070..f71cfccb 100644 --- a/src/main.kt +++ b/src/main.kt @@ -27,36 +27,11 @@ public fun main(args: Array<String>) { println() - val results = environment.processFiles { context, file -> + val result = environment.processFiles { context, file -> println("Processing: ${file.getName()}") - println() - context.analyseFile(file) - } - - println() - println("Results:") - results.forEach { - println(it) - } + context.createDocumentation(file) + }.fold(DocumentationModel()) {(aggregate, item) -> aggregate.merge(item) } + println(result) Disposer.dispose(environment) -} - - -fun BindingContext.analyseFile(file: JetFile) { - val packageFragment = getPackageFragment(file) - if (packageFragment == null) { - println("PackageFragment is null") - return - } - - println("Package: ${packageFragment}") - for (descriptor in packageFragment.getMemberScope().getAllDescriptors()) { - println("Member: ${descriptor}") - val doc = getDocumentation(descriptor) - if (doc != null) { - println("Comment:\n${doc.getText()}") - } - println() - } -} +}
\ No newline at end of file diff --git a/test/data/classes/emptyObject.kt b/test/data/classes/emptyObject.kt new file mode 100644 index 00000000..4138bf31 --- /dev/null +++ b/test/data/classes/emptyObject.kt @@ -0,0 +1,3 @@ +object Obj { + +}
\ No newline at end of file diff --git a/test/src/ClassTest.kt b/test/src/ClassTest.kt index 328cc358..692a496d 100644 --- a/test/src/ClassTest.kt +++ b/test/src/ClassTest.kt @@ -18,6 +18,19 @@ public class ClassTest { } } + Test fun emptyObject() { + verifyModel("test/data/classes/emptyObject.kt") { model -> + with(model.nodes.single().members.single()) { + assertEquals(DocumentationNodeKind.Object, kind) + assertEquals("Obj", name) + assertEquals("", doc) + assertTrue(details.none()) + assertTrue(members.none()) + assertTrue(links.none()) + } + } + } + Test fun classWithConstructor() { verifyModel("test/data/classes/classWithConstructor.kt") { model -> with (model.nodes.single().members.single()) { |