Skip to content

Commit

Permalink
default objects -> companion objects
Browse files Browse the repository at this point in the history
  • Loading branch information
yole committed Mar 17, 2015
1 parent 0406a6b commit c7916f7
Show file tree
Hide file tree
Showing 20 changed files with 51 additions and 51 deletions.
Binary file modified lib/markdown.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion src/Formats/HtmlTemplateService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public trait HtmlTemplateService {
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) {
Expand Down
12 changes: 6 additions & 6 deletions src/Formats/StructuredFormatService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,8 @@ public abstract class StructuredFormatService(locationService: LocationService,
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(
Expand All @@ -300,16 +300,16 @@ public abstract class StructuredFormatService(locationService: LocationService,
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)
Expand Down
4 changes: 2 additions & 2 deletions src/Java/JavaDocumentationBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions,

private fun PsiField.nodeKind(): Kind = when {
this is PsiEnumConstant -> Kind.EnumItem
hasModifierProperty(PsiModifier.STATIC) -> Kind.DefaultObjectProperty
hasModifierProperty(PsiModifier.STATIC) -> Kind.CompanionObjectProperty
else -> Kind.Property
}

Expand All @@ -311,7 +311,7 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions,

private fun PsiMethod.nodeKind(): Kind = when {
isConstructor() -> Kind.Constructor
hasModifierProperty(PsiModifier.STATIC) -> Kind.DefaultObjectFunction
hasModifierProperty(PsiModifier.STATIC) -> Kind.CompanionObjectFunction
else -> Kind.Function
}

Expand Down
18 changes: 9 additions & 9 deletions src/Kotlin/DocumentationBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ class DocumentationBuilder(val session: ResolveSession,
val classifierDescriptor = jetType.getConstructor().getDeclarationDescriptor()
val name = when (classifierDescriptor) {
is ClassDescriptor -> {
if (classifierDescriptor.isDefaultObject()) {
if (classifierDescriptor.isCompanionObject()) {
classifierDescriptor.getContainingDeclaration().getName().asString() +
"." + classifierDescriptor.getName().asString()
}
Expand Down Expand Up @@ -436,9 +436,9 @@ class DocumentationBuilder(val session: ResolveSession,
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)
Expand All @@ -456,13 +456,13 @@ class DocumentationBuilder(val session: ResolveSession,
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? {
Expand All @@ -475,7 +475,7 @@ class DocumentationBuilder(val session: ResolveSession,
}

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) }
Expand Down Expand Up @@ -557,7 +557,7 @@ class DocumentationBuilder(val session: ResolveSession,
}

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())
Expand Down Expand Up @@ -649,7 +649,7 @@ class DocumentationBuilder(val session: ResolveSession,

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,
Expand Down
8 changes: 4 additions & 4 deletions src/Kotlin/KotlinLanguageService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ class KotlinLanguageService : LanguageService {
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)
}
}
Expand Down Expand Up @@ -248,7 +248,7 @@ class KotlinLanguageService : LanguageService {
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)
Expand Down Expand Up @@ -285,7 +285,7 @@ class KotlinLanguageService : LanguageService {
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)
Expand Down
4 changes: 2 additions & 2 deletions src/Model/Content.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org.jetbrains.dokka
import kotlin.properties.Delegates

public abstract class ContentNode {
default object {
companion object {
val empty = ContentEmpty
}
}
Expand Down Expand Up @@ -126,7 +126,7 @@ public open class Content(): ContentBlock() {
fun findSectionByTag(tag: String): ContentSection? =
sections.firstOrNull { tag.equalsIgnoreCase(it.tag) }

default object {
companion object {
val Empty = Content()
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Model/DocumentationNode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ public open class DocumentationNode(val name: String,
Function
Property

DefaultObjectProperty
DefaultObjectFunction
CompanionObjectProperty
CompanionObjectFunction

Parameter
Receiver
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Klass() {
default object {
companion object {
val x = 1

fun foo() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Foo {
default object Default {
companion object Default {
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ <h3>Constructors</h3>
</tr>
</tbody>
</table>
<h3>Default Object Properties</h3>
<h3>Companion Object Properties</h3>
<table>
<tbody>
<tr>
Expand All @@ -31,7 +31,7 @@ <h3>Default Object Properties</h3>
</tr>
</tbody>
</table>
<h3>Default Object Functions</h3>
<h3>Companion Object Functions</h3>
<table>
<tbody>
<tr>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Klass() {
default object {
companion object {
val x = 1

fun foo() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
| [&lt;init&gt;](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` |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Foo {
default object Default {
companion object Default {
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
| [&lt;init&gt;](test/-foo/-init-) | `Foo()` |


### Default Object Extension Properties
### Companion Object Extension Properties


| [x](test/x) | `val Foo.Default.x: Int`
Expand Down
4 changes: 2 additions & 2 deletions test/src/format/HtmlFormatTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import org.jetbrains.dokka.HtmlFormatService
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)
}
}
Expand Down
8 changes: 4 additions & 4 deletions test/src/format/MarkdownFormatTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public class MarkdownFormatTest {
}
}

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)
}
}
Expand Down Expand Up @@ -161,8 +161,8 @@ public class MarkdownFormatTest {
}
}

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" })
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/src/markdown/MarkdownTestRunner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import kotlin.properties.Delegates
import org.junit.ComparisonFailure

data class MarkdownTestUniqueId(val id: Int) : Serializable {
default object {
companion object {
var id = 0
fun next() = MarkdownTestUniqueId(id++)
}
Expand Down
14 changes: 7 additions & 7 deletions test/src/model/ClassTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ public class ClassTest {
}
}

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)
Expand All @@ -140,13 +140,13 @@ public class ClassTest {
}
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())
}
Expand Down Expand Up @@ -245,11 +245,11 @@ public class ClassTest {
}
}

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())
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/src/model/JavaTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,15 @@ public class JavaTest {
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 })
}
}

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 })
}
}
Expand Down

0 comments on commit c7916f7

Please sign in to comment.