From 36f4b916bc956d8f5c9f6b55d295ea9a69c9f0bc Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Wed, 28 Oct 2015 15:23:50 +0100 Subject: show inherited members in the list of class members --- src/Formats/StructuredFormatService.kt | 2 ++ src/Kotlin/DocumentationBuilder.kt | 21 ++++++++---- src/Model/DocumentationNode.kt | 3 ++ src/Model/DocumentationReference.kt | 1 + .../crossLanguage/kotlinExtendsJava/Bar.html | 11 +++++++ test/data/format/inheritedMembers.kt | 12 +++++++ test/data/format/inheritedMembers.md | 38 ++++++++++++++++++++++ test/src/format/MarkdownFormatTest.kt | 6 ++++ 8 files changed, 88 insertions(+), 6 deletions(-) create mode 100644 test/data/format/inheritedMembers.kt create mode 100644 test/data/format/inheritedMembers.md diff --git a/src/Formats/StructuredFormatService.kt b/src/Formats/StructuredFormatService.kt index 8473ccd5..8bc60826 100644 --- a/src/Formats/StructuredFormatService.kt +++ b/src/Formats/StructuredFormatService.kt @@ -314,7 +314,9 @@ public abstract class StructuredFormatService(locationService: LocationService, appendSection(location, "Extensions for External Classes", node.members(DocumentationNode.Kind.ExternalClass), node, to) appendSection(location, "Constructors", node.members(DocumentationNode.Kind.Constructor), node, to) appendSection(location, "Properties", node.members(DocumentationNode.Kind.Property), node, to) + appendSection(location, "Inherited Properties", node.inheritedMembers(DocumentationNode.Kind.Property), node, to) appendSection(location, "Functions", node.members(DocumentationNode.Kind.Function), node, to) + appendSection(location, "Inherited Functions", node.inheritedMembers(DocumentationNode.Kind.Function), node, to) appendSection(location, "Companion Object Properties", node.members(DocumentationNode.Kind.CompanionObjectProperty), node, to) appendSection(location, "Companion Object Functions", node.members(DocumentationNode.Kind.CompanionObjectFunction), node, to) appendSection(location, "Enum Values", node.members(DocumentationNode.Kind.EnumItem), node, to) diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt index ea54f4d3..08a74172 100644 --- a/src/Kotlin/DocumentationBuilder.kt +++ b/src/Kotlin/DocumentationBuilder.kt @@ -404,8 +404,18 @@ class DocumentationBuilder(val resolutionFacade: ResolutionFacade, } - fun DocumentationNode.appendChildren(descriptors: Iterable, kind: DocumentationReference.Kind) { - descriptors.forEach { descriptor -> appendChild(descriptor, kind) } + fun DocumentationNode.appendMembers(descriptors: Iterable) { + descriptors.forEach { descriptor -> + if (descriptor is CallableMemberDescriptor && descriptor.kind == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) { + val baseDescriptor = descriptor.overriddenDescriptors.firstOrNull() + if (baseDescriptor != null) { + link(this, baseDescriptor, DocumentationReference.Kind.InheritedMember) + } + } + else { + appendChild(descriptor, DocumentationReference.Kind.Member) + } + } } fun DocumentationNode.appendInPageChildren(descriptors: Iterable, kind: DocumentationReference.Kind) { @@ -483,14 +493,13 @@ class DocumentationBuilder(val resolutionFacade: ResolutionFacade, constructors.filter { it.valueParameters.size > 0 } else constructors - node.appendChildren(constructorsToDocument, DocumentationReference.Kind.Member) + node.appendMembers(constructorsToDocument) } val members = defaultType.memberScope.getAllDescriptors().filter { it != companionObjectDescriptor } - node.appendChildren(members, DocumentationReference.Kind.Member) + node.appendMembers(members) val companionObjectDescriptor = companionObjectDescriptor if (companionObjectDescriptor != null) { - node.appendChildren(companionObjectDescriptor.defaultType.memberScope.getAllDescriptors(), - DocumentationReference.Kind.Member) + node.appendMembers(companionObjectDescriptor.defaultType.memberScope.getAllDescriptors()) } node.appendAnnotations(this) node.appendModifiers(this) diff --git a/src/Model/DocumentationNode.kt b/src/Model/DocumentationNode.kt index c082365f..6f6cee7e 100644 --- a/src/Model/DocumentationNode.kt +++ b/src/Model/DocumentationNode.kt @@ -19,6 +19,8 @@ public open class DocumentationNode(val name: String, get() = references(DocumentationReference.Kind.Detail).map { it.to } public val members: List get() = references(DocumentationReference.Kind.Member).map { it.to } + public val inheritedMembers: List + get() = references(DocumentationReference.Kind.InheritedMember).map { it.to } public val extensions: List get() = references(DocumentationReference.Kind.Extension).map { it.to } public val inheritors: List @@ -52,6 +54,7 @@ public open class DocumentationNode(val name: String, public fun details(kind: DocumentationNode.Kind): List = details.filter { it.kind == kind } public fun members(kind: DocumentationNode.Kind): List = members.filter { it.kind == kind } + public fun inheritedMembers(kind: DocumentationNode.Kind): List = inheritedMembers.filter { it.kind == kind } public fun links(kind: DocumentationNode.Kind): List = links.filter { it.kind == kind } public fun detail(kind: DocumentationNode.Kind): DocumentationNode = details.filter { it.kind == kind }.single() diff --git a/src/Model/DocumentationReference.kt b/src/Model/DocumentationReference.kt index bbdd026d..47b9a265 100644 --- a/src/Model/DocumentationReference.kt +++ b/src/Model/DocumentationReference.kt @@ -4,6 +4,7 @@ public data class DocumentationReference(val from: DocumentationNode, val to: Do public enum class Kind { Owner, Member, + InheritedMember, Detail, Link, HiddenLink, diff --git a/test/data/format/crossLanguage/kotlinExtendsJava/Bar.html b/test/data/format/crossLanguage/kotlinExtendsJava/Bar.html index 5b93d837..e7b139d8 100644 --- a/test/data/format/crossLanguage/kotlinExtendsJava/Bar.html +++ b/test/data/format/crossLanguage/kotlinExtendsJava/Bar.html @@ -22,5 +22,16 @@ +

Inherited Functions

+ + + + + + + +
+xyzzy +open fun xyzzy(): Unit
diff --git a/test/data/format/inheritedMembers.kt b/test/data/format/inheritedMembers.kt new file mode 100644 index 00000000..2d0c4ca1 --- /dev/null +++ b/test/data/format/inheritedMembers.kt @@ -0,0 +1,12 @@ +open class Foo { + fun first() { + } + + val firstProp: Int = 0 +} + +class Bar : Foo() { + fun second() + + val secondProp: Int = 1 +} diff --git a/test/data/format/inheritedMembers.md b/test/data/format/inheritedMembers.md new file mode 100644 index 00000000..d58d3974 --- /dev/null +++ b/test/data/format/inheritedMembers.md @@ -0,0 +1,38 @@ +[test](test/index) / [Bar](test/-bar/index) + + +# Bar + +`class Bar : [Foo](test/-foo/index)` + + + +### Constructors + + +| [<init>](test/-bar/-init-) | `Bar()` | + + +### Properties + + +| [secondProp](test/-bar/second-prop) | `val secondProp: Int` | + + +### Inherited Properties + + +| [firstProp](test/-foo/first-prop) | `val firstProp: Int` | + + +### Functions + + +| [second](test/-bar/second) | `fun second(): Unit` | + + +### Inherited Functions + + +| [first](test/-foo/first) | `fun first(): Unit` | + diff --git a/test/src/format/MarkdownFormatTest.kt b/test/src/format/MarkdownFormatTest.kt index ab905c18..728ce20f 100644 --- a/test/src/format/MarkdownFormatTest.kt +++ b/test/src/format/MarkdownFormatTest.kt @@ -203,4 +203,10 @@ public class MarkdownFormatTest { markdownService.appendNodes(tempLocation, output, model.members.single().members) } } + + @Test fun inheritedMembers() { + verifyOutput("test/data/format/inheritedMembers.kt", ".md") { model, output -> + markdownService.appendNodes(tempLocation, output, model.members.single().members.filter { it.name == "Bar" }) + } + } } -- cgit