default objects -> companion objects
diff --git a/lib/markdown.jar b/lib/markdown.jar
index 81cd25c..dc9fa19 100644
--- a/lib/markdown.jar
+++ b/lib/markdown.jar
Binary files differ
diff --git a/src/Formats/HtmlTemplateService.kt b/src/Formats/HtmlTemplateService.kt
index 859c37b..246bd11 100644
--- a/src/Formats/HtmlTemplateService.kt
+++ b/src/Formats/HtmlTemplateService.kt
@@ -4,7 +4,7 @@
fun appendHeader(to: StringBuilder, title: String?)
fun appendFooter(to: StringBuilder)
- default object {
+ companion object {
public fun default(css: String? = null): HtmlTemplateService {
return object : HtmlTemplateService {
override fun appendFooter(to: StringBuilder) {
diff --git a/src/Formats/StructuredFormatService.kt b/src/Formats/StructuredFormatService.kt
index 0e01db4..a380301 100644
--- a/src/Formats/StructuredFormatService.kt
+++ b/src/Formats/StructuredFormatService.kt
@@ -286,8 +286,8 @@
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, "Default Object Properties", node.members(DocumentationNode.Kind.DefaultObjectProperty), node, to)
- appendSection(location, "Default Object Functions", node.members(DocumentationNode.Kind.DefaultObjectFunction), 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)
appendSection(location, "Other members", node.members.filter {
it.kind !in setOf(
@@ -300,16 +300,16 @@
DocumentationNode.Kind.Property,
DocumentationNode.Kind.Package,
DocumentationNode.Kind.Function,
- DocumentationNode.Kind.DefaultObjectProperty,
- DocumentationNode.Kind.DefaultObjectFunction,
+ DocumentationNode.Kind.CompanionObjectProperty,
+ DocumentationNode.Kind.CompanionObjectFunction,
DocumentationNode.Kind.ExternalClass,
DocumentationNode.Kind.EnumItem
)
}, node, to)
appendSection(location, "Extension Properties", node.extensions.filter { it.kind == DocumentationNode.Kind.Property }, node, to)
appendSection(location, "Extension Functions", node.extensions.filter { it.kind == DocumentationNode.Kind.Function }, node, to)
- appendSection(location, "Default Object Extension Properties", node.extensions.filter { it.kind == DocumentationNode.Kind.DefaultObjectProperty }, node, to)
- appendSection(location, "Default Object Extension Functions", node.extensions.filter { it.kind == DocumentationNode.Kind.DefaultObjectFunction }, node, to)
+ appendSection(location, "Companion Object Extension Properties", node.extensions.filter { it.kind == DocumentationNode.Kind.CompanionObjectProperty }, node, to)
+ appendSection(location, "Companion Object Extension Functions", node.extensions.filter { it.kind == DocumentationNode.Kind.CompanionObjectFunction }, node, to)
appendSection(location, "Inheritors",
node.inheritors.filter { it.kind != DocumentationNode.Kind.EnumItem }, node, to)
appendSection(location, "Links", node.links, node, to)
diff --git a/src/Java/JavaDocumentationBuilder.kt b/src/Java/JavaDocumentationBuilder.kt
index 00a7f3a..7987a41 100644
--- a/src/Java/JavaDocumentationBuilder.kt
+++ b/src/Java/JavaDocumentationBuilder.kt
@@ -292,7 +292,7 @@
private fun PsiField.nodeKind(): Kind = when {
this is PsiEnumConstant -> Kind.EnumItem
- hasModifierProperty(PsiModifier.STATIC) -> Kind.DefaultObjectProperty
+ hasModifierProperty(PsiModifier.STATIC) -> Kind.CompanionObjectProperty
else -> Kind.Property
}
@@ -311,7 +311,7 @@
private fun PsiMethod.nodeKind(): Kind = when {
isConstructor() -> Kind.Constructor
- hasModifierProperty(PsiModifier.STATIC) -> Kind.DefaultObjectFunction
+ hasModifierProperty(PsiModifier.STATIC) -> Kind.CompanionObjectFunction
else -> Kind.Function
}
diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt
index fba74b9..0e0767d 100644
--- a/src/Kotlin/DocumentationBuilder.kt
+++ b/src/Kotlin/DocumentationBuilder.kt
@@ -286,7 +286,7 @@
val classifierDescriptor = jetType.getConstructor().getDeclarationDescriptor()
val name = when (classifierDescriptor) {
is ClassDescriptor -> {
- if (classifierDescriptor.isDefaultObject()) {
+ if (classifierDescriptor.isCompanionObject()) {
classifierDescriptor.getContainingDeclaration().getName().asString() +
"." + classifierDescriptor.getName().asString()
}
@@ -436,9 +436,9 @@
getConstructors()
node.appendChildren(constructorsToDocument, DocumentationReference.Kind.Member)
}
- val members = getDefaultType().getMemberScope().getAllDescriptors().filter { it != getDefaultObjectDescriptor() }
+ val members = getDefaultType().getMemberScope().getAllDescriptors().filter { it != getCompanionObjectDescriptor() }
node.appendChildren(members, DocumentationReference.Kind.Member)
- val defaultObjectDescriptor = getDefaultObjectDescriptor()
+ val defaultObjectDescriptor = getCompanionObjectDescriptor()
if (defaultObjectDescriptor != null) {
node.appendChildren(defaultObjectDescriptor.getDefaultType().getMemberScope().getAllDescriptors(),
DocumentationReference.Kind.Member)
@@ -456,13 +456,13 @@
return node
}
- private fun CallableMemberDescriptor.inDefaultObject(): Boolean {
+ private fun CallableMemberDescriptor.inCompanionObject(): Boolean {
val containingDeclaration = getContainingDeclaration()
- if ((containingDeclaration as? ClassDescriptor)?.isDefaultObject() ?: false) {
+ if ((containingDeclaration as? ClassDescriptor)?.isCompanionObject() ?: false) {
return true
}
val receiver = getExtensionReceiverParameter()
- return (receiver?.getType()?.getConstructor()?.getDeclarationDescriptor() as? ClassDescriptor)?.isDefaultObject() ?: false
+ return (receiver?.getType()?.getConstructor()?.getDeclarationDescriptor() as? ClassDescriptor)?.isCompanionObject() ?: false
}
fun CallableMemberDescriptor.getExtensionClassDescriptor(): ClassifierDescriptor? {
@@ -475,7 +475,7 @@
}
fun FunctionDescriptor.build(): DocumentationNode {
- val node = DocumentationNode(this, if (inDefaultObject()) Kind.DefaultObjectFunction else Kind.Function)
+ val node = DocumentationNode(this, if (inCompanionObject()) Kind.CompanionObjectFunction else Kind.Function)
node.appendInPageChildren(getTypeParameters(), DocumentationReference.Kind.Detail)
getExtensionReceiverParameter()?.let { node.appendChild(it, DocumentationReference.Kind.Detail) }
@@ -557,7 +557,7 @@
}
fun PropertyDescriptor.build(): DocumentationNode {
- val node = DocumentationNode(this, if (inDefaultObject()) Kind.DefaultObjectProperty else Kind.Property)
+ val node = DocumentationNode(this, if (inCompanionObject()) Kind.CompanionObjectProperty else Kind.Property)
node.appendInPageChildren(getTypeParameters(), DocumentationReference.Kind.Detail)
getExtensionReceiverParameter()?.let { node.appendChild(it, DocumentationReference.Kind.Detail) }
node.appendType(getReturnType())
@@ -649,7 +649,7 @@
fun ReceiverParameterDescriptor.build(): DocumentationNode {
var receiverClass: DeclarationDescriptor = getType().getConstructor().getDeclarationDescriptor()
- if ((receiverClass as? ClassDescriptor)?.isDefaultObject() ?: false) {
+ if ((receiverClass as? ClassDescriptor)?.isCompanionObject() ?: false) {
receiverClass = receiverClass.getContainingDeclaration()!!
}
link(receiverClass,
diff --git a/src/Kotlin/KotlinLanguageService.kt b/src/Kotlin/KotlinLanguageService.kt
index 855745e..d046b65 100644
--- a/src/Kotlin/KotlinLanguageService.kt
+++ b/src/Kotlin/KotlinLanguageService.kt
@@ -28,9 +28,9 @@
DocumentationNode.Kind.Modifier -> renderModifier(node)
DocumentationNode.Kind.Constructor,
DocumentationNode.Kind.Function,
- DocumentationNode.Kind.DefaultObjectFunction -> renderFunction(node, renderMode)
+ DocumentationNode.Kind.CompanionObjectFunction -> renderFunction(node, renderMode)
DocumentationNode.Kind.Property,
- DocumentationNode.Kind.DefaultObjectProperty -> renderProperty(node, renderMode)
+ DocumentationNode.Kind.CompanionObjectProperty -> renderProperty(node, renderMode)
else -> identifier(node.name)
}
}
@@ -248,7 +248,7 @@
when (node.kind) {
DocumentationNode.Kind.Constructor -> identifier(node.owner!!.name)
DocumentationNode.Kind.Function,
- DocumentationNode.Kind.DefaultObjectFunction -> keyword("fun ")
+ DocumentationNode.Kind.CompanionObjectFunction -> keyword("fun ")
else -> throw IllegalArgumentException("Node $node is not a function-like object")
}
renderTypeParametersForNode(node)
@@ -285,7 +285,7 @@
renderAnnotationsForNode(node)
when (node.kind) {
DocumentationNode.Kind.Property,
- DocumentationNode.Kind.DefaultObjectProperty -> keyword("${node.getPropertyKeyword()} ")
+ DocumentationNode.Kind.CompanionObjectProperty -> keyword("${node.getPropertyKeyword()} ")
else -> throw IllegalArgumentException("Node $node is not a property")
}
renderTypeParametersForNode(node)
diff --git a/src/Model/Content.kt b/src/Model/Content.kt
index 176be8d..0244359 100644
--- a/src/Model/Content.kt
+++ b/src/Model/Content.kt
@@ -3,7 +3,7 @@
import kotlin.properties.Delegates
public abstract class ContentNode {
- default object {
+ companion object {
val empty = ContentEmpty
}
}
@@ -126,7 +126,7 @@
fun findSectionByTag(tag: String): ContentSection? =
sections.firstOrNull { tag.equalsIgnoreCase(it.tag) }
- default object {
+ companion object {
val Empty = Content()
}
}
diff --git a/src/Model/DocumentationNode.kt b/src/Model/DocumentationNode.kt
index 663ca02..9e8a981 100644
--- a/src/Model/DocumentationNode.kt
+++ b/src/Model/DocumentationNode.kt
@@ -78,8 +78,8 @@
Function
Property
- DefaultObjectProperty
- DefaultObjectFunction
+ CompanionObjectProperty
+ CompanionObjectFunction
Parameter
Receiver
diff --git a/test/data/classes/classWithDefaultObject.kt b/test/data/classes/classWithCompanionObject.kt
similarity index 73%
rename from test/data/classes/classWithDefaultObject.kt
rename to test/data/classes/classWithCompanionObject.kt
index 92e1a69..fdbd915 100644
--- a/test/data/classes/classWithDefaultObject.kt
+++ b/test/data/classes/classWithCompanionObject.kt
@@ -1,5 +1,5 @@
class Klass() {
- default object {
+ companion object {
val x = 1
fun foo() {}
diff --git a/test/data/classes/defaultObjectExtension.kt b/test/data/classes/companionObjectExtension.kt
similarity index 70%
rename from test/data/classes/defaultObjectExtension.kt
rename to test/data/classes/companionObjectExtension.kt
index 58d2e86..4b47137 100644
--- a/test/data/classes/defaultObjectExtension.kt
+++ b/test/data/classes/companionObjectExtension.kt
@@ -1,5 +1,5 @@
class Foo {
- default object Default {
+ companion object Default {
}
}
diff --git a/test/data/format/classWithDefaultObject.html b/test/data/format/classWithCompanionObject.html
similarity index 93%
rename from test/data/format/classWithDefaultObject.html
rename to test/data/format/classWithCompanionObject.html
index 663d8f6..be9247e 100644
--- a/test/data/format/classWithDefaultObject.html
+++ b/test/data/format/classWithCompanionObject.html
@@ -20,7 +20,7 @@
</tr>
</tbody>
</table>
-<h3>Default Object Properties</h3>
+<h3>Companion Object Properties</h3>
<table>
<tbody>
<tr>
@@ -31,7 +31,7 @@
</tr>
</tbody>
</table>
-<h3>Default Object Functions</h3>
+<h3>Companion Object Functions</h3>
<table>
<tbody>
<tr>
diff --git a/test/data/classes/classWithDefaultObject.kt b/test/data/format/classWithCompanionObject.kt
similarity index 73%
copy from test/data/classes/classWithDefaultObject.kt
copy to test/data/format/classWithCompanionObject.kt
index 92e1a69..fdbd915 100644
--- a/test/data/classes/classWithDefaultObject.kt
+++ b/test/data/format/classWithCompanionObject.kt
@@ -1,5 +1,5 @@
class Klass() {
- default object {
+ companion object {
val x = 1
fun foo() {}
diff --git a/test/data/format/classWithDefaultObject.md b/test/data/format/classWithCompanionObject.md
similarity index 79%
rename from test/data/format/classWithDefaultObject.md
rename to test/data/format/classWithCompanionObject.md
index 645f475..9398c3d 100644
--- a/test/data/format/classWithDefaultObject.md
+++ b/test/data/format/classWithCompanionObject.md
@@ -13,13 +13,13 @@
| [<init>](test/-klass/-init-) | `Klass()` |
-### Default Object Properties
+### Companion Object Properties
| [x](test/-klass/x) | `val x: Int` |
-### Default Object Functions
+### Companion Object Functions
| [foo](test/-klass/foo) | `fun foo(): Unit` |
diff --git a/test/data/format/classWithDefaultObject.kt b/test/data/format/classWithDefaultObject.kt
deleted file mode 100644
index 92e1a69..0000000
--- a/test/data/format/classWithDefaultObject.kt
+++ /dev/null
@@ -1,7 +0,0 @@
-class Klass() {
- default object {
- val x = 1
-
- fun foo() {}
- }
-}
diff --git a/test/data/format/defaultObjectExtension.kt b/test/data/format/companionObjectExtension.kt
similarity index 75%
rename from test/data/format/defaultObjectExtension.kt
rename to test/data/format/companionObjectExtension.kt
index 78df38c..f452de2 100644
--- a/test/data/format/defaultObjectExtension.kt
+++ b/test/data/format/companionObjectExtension.kt
@@ -1,5 +1,5 @@
class Foo {
- default object Default {
+ companion object Default {
}
}
diff --git a/test/data/format/defaultObjectExtension.md b/test/data/format/companionObjectExtension.md
similarity index 83%
rename from test/data/format/defaultObjectExtension.md
rename to test/data/format/companionObjectExtension.md
index 4ede33e..271da5b 100644
--- a/test/data/format/defaultObjectExtension.md
+++ b/test/data/format/companionObjectExtension.md
@@ -13,7 +13,7 @@
| [<init>](test/-foo/-init-) | `Foo()` |
-### Default Object Extension Properties
+### Companion Object Extension Properties
| [x](test/x) | `val Foo.Default.x: Int`
diff --git a/test/src/format/HtmlFormatTest.kt b/test/src/format/HtmlFormatTest.kt
index fb2df87..98b47f0 100644
--- a/test/src/format/HtmlFormatTest.kt
+++ b/test/src/format/HtmlFormatTest.kt
@@ -7,8 +7,8 @@
public class HtmlFormatTest {
private val htmlService = HtmlFormatService(InMemoryLocationService, KotlinLanguageService())
- Test fun classWithDefaultObject() {
- verifyOutput("test/data/format/classWithDefaultObject.kt", ".html") { model, output ->
+ Test fun classWithCompanionObject() {
+ verifyOutput("test/data/format/classWithCompanionObject.kt", ".html") { model, output ->
htmlService.appendNodes(tempLocation, output, model.members.single().members)
}
}
diff --git a/test/src/format/MarkdownFormatTest.kt b/test/src/format/MarkdownFormatTest.kt
index 1c46e66..059b491 100644
--- a/test/src/format/MarkdownFormatTest.kt
+++ b/test/src/format/MarkdownFormatTest.kt
@@ -12,8 +12,8 @@
}
}
- Test fun classWithDefaultObject() {
- verifyOutput("test/data/format/classWithDefaultObject.kt", ".md") { model, output ->
+ Test fun classWithCompanionObject() {
+ verifyOutput("test/data/format/classWithCompanionObject.kt", ".md") { model, output ->
markdownService.appendNodes(tempLocation, output, model.members.single().members)
}
}
@@ -161,8 +161,8 @@
}
}
- Test fun defaultObjectExtension() {
- verifyOutput("test/data/format/defaultObjectExtension.kt", ".md") { model, output ->
+ Test fun companionObjectExtension() {
+ verifyOutput("test/data/format/companionObjectExtension.kt", ".md") { model, output ->
markdownService.appendNodes(tempLocation, output, model.members.single().members.filter { it.name == "Foo" })
}
}
diff --git a/test/src/markdown/MarkdownTestRunner.kt b/test/src/markdown/MarkdownTestRunner.kt
index 99c3732..4aceb8e 100644
--- a/test/src/markdown/MarkdownTestRunner.kt
+++ b/test/src/markdown/MarkdownTestRunner.kt
@@ -9,7 +9,7 @@
import org.junit.ComparisonFailure
data class MarkdownTestUniqueId(val id: Int) : Serializable {
- default object {
+ companion object {
var id = 0
fun next() = MarkdownTestUniqueId(id++)
}
diff --git a/test/src/model/ClassTest.kt b/test/src/model/ClassTest.kt
index 0a8fc14..6eec91c 100644
--- a/test/src/model/ClassTest.kt
+++ b/test/src/model/ClassTest.kt
@@ -124,8 +124,8 @@
}
}
- Test fun classWithDefaultObject() {
- verifyModel("test/data/classes/classWithDefaultObject.kt") { model ->
+ Test fun classWithCompanionObject() {
+ verifyModel("test/data/classes/classWithCompanionObject.kt") { model ->
with(model.members.single().members.single()) {
assertEquals(DocumentationNode.Kind.Class, kind)
assertEquals("Klass", name)
@@ -140,13 +140,13 @@
}
with(members.elementAt(1)) {
assertEquals("x", name)
- assertEquals(DocumentationNode.Kind.DefaultObjectProperty, kind)
+ assertEquals(DocumentationNode.Kind.CompanionObjectProperty, kind)
assertTrue(members.none())
assertTrue(links.none())
}
with(members.elementAt(2)) {
assertEquals("foo", name)
- assertEquals(DocumentationNode.Kind.DefaultObjectFunction, kind)
+ assertEquals(DocumentationNode.Kind.CompanionObjectFunction, kind)
assertTrue(members.none())
assertTrue(links.none())
}
@@ -245,11 +245,11 @@
}
}
- Test fun defaultObjectExtension() {
- verifyModel("test/data/classes/defaultObjectExtension.kt") { model ->
+ Test fun companionObjectExtension() {
+ verifyModel("test/data/classes/companionObjectExtension.kt") { model ->
val pkg = model.members.single()
val cls = pkg.members.single { it.name == "Foo" }
- val extensions = cls.extensions.filter { it.kind == DocumentationNode.Kind.DefaultObjectProperty }
+ val extensions = cls.extensions.filter { it.kind == DocumentationNode.Kind.CompanionObjectProperty }
assertEquals(1, extensions.size())
}
}
diff --git a/test/src/model/JavaTest.kt b/test/src/model/JavaTest.kt
index 41feb26..cef548c 100644
--- a/test/src/model/JavaTest.kt
+++ b/test/src/model/JavaTest.kt
@@ -131,7 +131,7 @@
val i = cls.members(DocumentationNode.Kind.Property).single { it.name == "i" }
assertEquals("Int", i.detail(DocumentationNode.Kind.Type).name)
assertTrue("var" in i.details(DocumentationNode.Kind.Modifier).map { it.name })
- val s = cls.members(DocumentationNode.Kind.DefaultObjectProperty).single { it.name == "s" }
+ val s = cls.members(DocumentationNode.Kind.CompanionObjectProperty).single { it.name == "s" }
assertEquals("String", s.detail(DocumentationNode.Kind.Type).name)
assertFalse("var" in s.details(DocumentationNode.Kind.Modifier).map { it.name })
}
@@ -139,7 +139,7 @@
Test fun staticMethod() {
verifyPackageMember("test/data/java/staticMethod.java") { cls ->
- val m = cls.members(DocumentationNode.Kind.DefaultObjectFunction).single { it.name == "foo" }
+ val m = cls.members(DocumentationNode.Kind.CompanionObjectFunction).single { it.name == "foo" }
assertFalse("static" in m.details(DocumentationNode.Kind.Modifier).map { it.name })
}
}