Skip to content

Commit

Permalink
Rename CommentComponent to RichTextComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
cjbrooks12 committed May 5, 2020
1 parent 8fa3b50 commit b3c8552
Show file tree
Hide file tree
Showing 82 changed files with 550 additions and 531 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ apply plugin: "de.fayard.buildSrcVersions"
apply plugin: "de.undercouch.download"

group "com.eden.kodiak"
version "0.5.0"
version "0.5.1"

// Config Values
//----------------------------------------------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions common/common-models/src/main/kotlin/AutoDocument.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ interface TopLevel {
* Classes: the immediate superclass, the implemented interfaces. Do not include the superclass of a superclass, etc.
* Packages: the parent package. For example, the package `com.eden.kodiak.common` has a parent package of `com.eden.kodiak`.
*/
val parents: List<CommentComponent>
val parents: List<RichTextComponent>

/**
* The ID of the nodes which the current node "lives" in. This is most likely _not_ the same node type as the
* current node.
*/
val contexts: List<CommentComponent>
val contexts: List<RichTextComponent>
}

interface AutoDocumentNode {
Expand Down
8 changes: 4 additions & 4 deletions common/common-models/src/main/kotlin/CommentTag.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import kotlinx.serialization.Serializable
/**
* A `CommentTag` represents the metadata for a particular documentation element at a specific property. It should be
* _either_ a single String value _or_ a mapping of keys to values, but not both. The text description of each tag is a
* list of `CommentComponent`, which should be joined together just like the main comment text.
* list of `RichTextComponent`, which should be joined together just like the main comment text.
*
* For example, `@param foo The Foo` describes the parameter of a function call, and has a map of values, one for each
* parameter. In the `DocElement`, there will be a mapping from `param` to a CommentTag object with multiple values:
Expand All @@ -26,10 +26,10 @@ import kotlinx.serialization.Serializable
*/
@Serializable
data class CommentTag(
val value: List<CommentComponent>? = null,
val values: Map<String, List<CommentComponent>>? = null
val value: List<RichTextComponent>? = null,
val values: Map<String, List<RichTextComponent>>? = null
) {
init {
check((value != null) xor (values != null)) { "A CommentTag must have a single value or a map of values, but not both!" }
}
}
}
2 changes: 1 addition & 1 deletion common/common-models/src/main/kotlin/DocComment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ data class DocComment(
/**
* A list of comment components which, when concatenated together, creates the full inline comment description.
*/
val components: List<CommentComponent>,
val components: List<RichTextComponent>,

/**
* A map of comment tags which represent the metadata for this element, either written in the comment text, or
Expand Down
2 changes: 1 addition & 1 deletion common/common-models/src/main/kotlin/DocElement.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ interface DocElement {
* A simple, rich signature for this type which, when concatenated together, creates the full declaration of this
* element.
*/
val signature: List<CommentComponent>
val signature: List<RichTextComponent>
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package com.copperleaf.kodiak.common
import kotlinx.serialization.Serializable

/**
* A `CommentComponent` is a rich chunk of text parsed from a code comment.
* A `RichTextComponent` is a rich chunk of text parsed from a code comment.
*
* The full text for inline comments can be created by joining together a list of CommentComponents on their `text`.
* The full text for inline comments can be created by joining together a list of RichTextComponents on their `text`.
* Normal text should have a kind of `text`, and the `text` of the component is just the text as entered in the
* comment. Sections of text that link to another code element have a kind of `link`, the `value` is an identifier
* pointing to the element being referenced, and `text` is the text that should be displayed.
*/
@Serializable
data class CommentComponent(
data class RichTextComponent(
val kind: String,
val text: String,
val value: String? = null
Expand All @@ -20,5 +20,8 @@ data class CommentComponent(
const val TEXT = "text"
const val TYPE_NAME = "typeName"
const val PUNCTUATION = "punctuation"

const val INHERITED = "inherited"
const val COMPOSED = "composed"
}
}
14 changes: 7 additions & 7 deletions common/common-models/src/test/kotlin/AutoDocumentTest.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.copperleaf.kodiak.common

import com.caseyjbrooks.clog.Clog
import com.copperleaf.kodiak.common.CommentComponent.Companion.TEXT
import com.copperleaf.kodiak.common.RichTextComponent.Companion.TEXT
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test

Expand Down Expand Up @@ -47,20 +47,20 @@ class AutoDocumentTest {
override val modifiers = emptyList<String>()
override val comment: DocComment
get() = DocComment(
components = listOf(CommentComponent(TEXT, commentText)),
components = listOf(RichTextComponent(TEXT, commentText)),
tags =
commentTags.mapValues {
CommentTag(
value = listOf(
CommentComponent(
RichTextComponent(
TEXT,
it.value
)
)
)
}
)
override val signature: List<CommentComponent> = emptyList()
override val signature: List<RichTextComponent> = emptyList()
}
}

Expand All @@ -78,8 +78,8 @@ class AutoDocumentTest {
id,
modifiers,
DocComment(
listOf(CommentComponent(TEXT, commentText)),
commentTags.mapValues { CommentTag(value = listOf(CommentComponent(TEXT, it.value))) }
listOf(RichTextComponent(TEXT, commentText)),
commentTags.mapValues { CommentTag(value = listOf(RichTextComponent(TEXT, it.value))) }
)
)
}
Expand Down Expand Up @@ -115,5 +115,5 @@ internal data class TestTypeElement(

override val typeName: String = name,
override val typeId: String = id,
override val signature: List<CommentComponent> = emptyList()
override val signature: List<RichTextComponent> = emptyList()
) : ElementType
6 changes: 3 additions & 3 deletions common/common-models/src/test/kotlin/CommentTagTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CommentTagTest {
fun testSerializeCommentTag_singleValue() {
val underTest = CommentTag(
value = listOf(
CommentComponent(
RichTextComponent(
kind = "testKind",
text = "testText",
value = "testValue"
Expand Down Expand Up @@ -62,7 +62,7 @@ class CommentTagTest {
val underTest = CommentTag(
values = mapOf(
"testKey" to listOf(
CommentComponent(
RichTextComponent(
kind = "testKind",
text = "testText",
value = "testValue"
Expand Down Expand Up @@ -111,7 +111,7 @@ class CommentTagTest {
@Test
fun testSerializeCommentTag_bothValueAndValues_throws() {
val comment = listOf(
CommentComponent(
RichTextComponent(
kind = "testKind",
text = "testText",
value = "testValue"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import strikt.api.expectThat
import strikt.assertions.isEqualTo
import strikt.assertions.isNull

class CommentComponentTest {
class RichTextComponentTest {

@Test
fun testSerializerFor_CommentComponent() {
val underTest = CommentComponent(
fun testSerializerFor_RichTextComponent() {
val underTest = RichTextComponent(
kind = "testKind",
text = "testText",
value = "testValue"
Expand All @@ -25,10 +25,10 @@ class CommentComponentTest {
|}
""".trimMargin()

val serialized = Json.indented.stringify(CommentComponent.serializer(), underTest)
val serialized = Json.indented.stringify(RichTextComponent.serializer(), underTest)
expectThat(serialized).isEqualTo(json)

val parsed = Json.indented.parse(CommentComponent.serializer(), json)
val parsed = Json.indented.parse(RichTextComponent.serializer(), json)
expectThat(parsed)
.and { get { kind }.isEqualTo("testKind") }
.and { get { text }.isEqualTo("testText") }
Expand All @@ -38,8 +38,8 @@ class CommentComponentTest {
}

@Test
fun testSerializerFor_CommentComponent_WithNullValue() {
val underTest = CommentComponent(
fun testSerializerFor_RichTextComponent_WithNullValue() {
val underTest = RichTextComponent(
kind = "testKind",
text = "testText",
value = null
Expand All @@ -52,10 +52,10 @@ class CommentComponentTest {
|}
""".trimMargin()

val serialized = Json.indented.stringify(CommentComponent.serializer(), underTest)
val serialized = Json.indented.stringify(RichTextComponent.serializer(), underTest)
expectThat(serialized).isEqualTo(json)

val parsed = Json.indented.parse(CommentComponent.serializer(), json)
val parsed = Json.indented.parse(RichTextComponent.serializer(), json)
expectThat(parsed)
.and { get { kind }.isEqualTo("testKind") }
.and { get { text }.isEqualTo("testText") }
Expand Down
2 changes: 1 addition & 1 deletion common/common-runner/src/main/kotlin/utils.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.copperleaf.kodiak.common

// -- VERSION --
const val version = "0.5.0"
const val version = "0.5.1"
// -- ENDVERSION --

internal inline fun <T : Any?, U : Any?> List<T>.firstBy(mapper: (T)->U) : U {
Expand Down
1 change: 1 addition & 0 deletions docs/src/orchid/resources/changelog/0.5.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Rename `CommentComponent` to `RichTextComponent`
33 changes: 16 additions & 17 deletions dokka/dokka-formatter/src/main/kotlin/formatter/formatClass.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.copperleaf.kodiak.kotlin.formatter

import com.copperleaf.kodiak.common.CommentComponent
import com.copperleaf.kodiak.common.CommentComponent.Companion.TYPE_NAME
import com.copperleaf.kodiak.common.CommentComponent.Companion.TEXT
import com.copperleaf.kodiak.common.CommentComponent.Companion.PUNCTUATION
import com.copperleaf.kodiak.common.RichTextComponent
import com.copperleaf.kodiak.common.RichTextComponent.Companion.TEXT
import com.copperleaf.kodiak.common.RichTextComponent.Companion.TYPE_NAME
import com.copperleaf.kodiak.common.RichTextComponent.Companion.PUNCTUATION
import com.copperleaf.kodiak.common.RichTextComponent.Companion.INHERITED
import com.copperleaf.kodiak.common.RichTextComponent.Companion.COMPOSED
import com.copperleaf.kodiak.kotlin.models.KotlinClass
import org.jetbrains.dokka.DocumentationNode
import org.jetbrains.dokka.NodeKind
Expand All @@ -22,14 +24,11 @@ fun DocumentationNode.toClassDoc(deep: Boolean): KotlinClass {
.map { it.qualifiedNameFromType() to it }
.filterNot { it.first in listOf("kotlin.Annotation", "kotlin.Enum") }

val superclass = supertypes.filter { it.second.superclassType != null }.singleOrNull()?.second?.name?.let { CommentComponent(TYPE_NAME, it, it) }
val interfaces = supertypes.filter { it.second.superclassType == null }.toMap().keys.toList()?.map { CommentComponent(TYPE_NAME, it, it) }

return KotlinClass(
this,
this.path.map { it.name }.filterNot { it.isEmpty() }.first(),
superclass,
interfaces,
supertypes.filter { it.second.superclassType != null }.singleOrNull()?.second?.name?.let { RichTextComponent(INHERITED, it, it) },
supertypes.filter { it.second.superclassType == null }.toMap().keys.toList()?.map { RichTextComponent(COMPOSED, it, it) },
this.kind.toString(),
this.simpleName,
this.qualifiedName,
Expand All @@ -49,33 +48,33 @@ fun DocumentationNode.toClassDoc(deep: Boolean): KotlinClass {

fun DocumentationNode.classSignature(
modifiers: List<String>
): List<CommentComponent> {
val list = mutableListOf<CommentComponent>()
): List<RichTextComponent> {
val list = mutableListOf<RichTextComponent>()

when (this.kind) {
NodeKind.Object -> {
list.addAll(modifiers.toModifierListSignature())
list.add(CommentComponent(TEXT, "object "))
list.add(RichTextComponent(TEXT, "object "))
}
NodeKind.Interface -> {
list.addAll((modifiers - "abstract").toModifierListSignature())
list.add(CommentComponent(TEXT, "interface "))
list.add(RichTextComponent(TEXT, "interface "))
}
else -> {
list.addAll(modifiers.toModifierListSignature())
list.add(CommentComponent(TEXT, "class "))
list.add(RichTextComponent(TEXT, "class "))
}
}
list.add(CommentComponent(TYPE_NAME, this.simpleName, this.qualifiedName))
list.add(RichTextComponent(TYPE_NAME, this.simpleName, this.qualifiedName))
list.addAll(this.toTypeParameterDeclarationSignature())
list.addAll(this.toSuperclassDeclarationSignature())

return list
}

fun DocumentationNode.toSuperclassDeclarationSignature(): List<CommentComponent> {
fun DocumentationNode.toSuperclassDeclarationSignature(): List<RichTextComponent> {
return this.details(NodeKind.Supertype).toListSignature(
childMapper = { it.toTypeSignature() },
prefix = listOf(CommentComponent(PUNCTUATION, ": "))
prefix = listOf(RichTextComponent(PUNCTUATION, ": "))
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package com.copperleaf.kodiak.kotlin.formatter

import com.copperleaf.kodiak.kotlin.models.KotlinConstructor
import com.copperleaf.kodiak.kotlin.models.KotlinParameter
import com.copperleaf.kodiak.common.CommentComponent.Companion.TYPE_NAME
import com.copperleaf.kodiak.common.CommentComponent.Companion.TEXT
import com.copperleaf.kodiak.common.CommentComponent.Companion.PUNCTUATION
import com.copperleaf.kodiak.common.CommentComponent
import com.copperleaf.kodiak.common.RichTextComponent
import com.copperleaf.kodiak.common.RichTextComponent.Companion.TEXT
import com.copperleaf.kodiak.common.RichTextComponent.Companion.TYPE_NAME
import com.copperleaf.kodiak.common.RichTextComponent.Companion.PUNCTUATION
import com.copperleaf.kodiak.common.RichTextComponent.Companion.INHERITED
import com.copperleaf.kodiak.common.RichTextComponent.Companion.COMPOSED
import org.jetbrains.dokka.DocumentationNode
import org.jetbrains.dokka.NodeKind

Expand All @@ -32,11 +34,11 @@ fun DocumentationNode.toConstructor(): KotlinConstructor {
fun DocumentationNode.constructorSignature(
modifiers: List<String>,
parameters: List<KotlinParameter>
): List<CommentComponent> {
val list = mutableListOf<CommentComponent>()
): List<RichTextComponent> {
val list = mutableListOf<RichTextComponent>()

list.addAll(modifiers.toModifierListSignature())
list.add(CommentComponent(TEXT, "constructor"))
list.add(RichTextComponent(TEXT, "constructor"))
list.addAll(parameters.toParameterListSignature())

return list
Expand Down
Loading

0 comments on commit b3c8552

Please sign in to comment.