aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Formats/StructuredFormatService.kt3
-rw-r--r--src/Kotlin/DocumentationBuilder.kt57
-rw-r--r--src/Model/Content.kt11
-rw-r--r--src/Model/DocumentationNode.kt6
4 files changed, 76 insertions, 1 deletions
diff --git a/src/Formats/StructuredFormatService.kt b/src/Formats/StructuredFormatService.kt
index 41deeed0..b3d1463e 100644
--- a/src/Formats/StructuredFormatService.kt
+++ b/src/Formats/StructuredFormatService.kt
@@ -114,6 +114,9 @@ public abstract class StructuredFormatService(locationService: LocationService,
}
// All items have exactly the same documentation, so we can use any item to render it
val item = items.first()
+ item.details(DocumentationNode.Kind.OverloadGroupNote).forEach {
+ to.append(formatText(location, it.content))
+ }
to.append(formatText(location, item.content.summary))
appendDescription(location, to, item)
appendLine(to)
diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt
index 14ba94be..2c4c5119 100644
--- a/src/Kotlin/DocumentationBuilder.kt
+++ b/src/Kotlin/DocumentationBuilder.kt
@@ -12,7 +12,9 @@ import org.jetbrains.kotlin.idea.kdoc.KDocFinder
import org.jetbrains.kotlin.idea.kdoc.resolveKDocLink
import org.jetbrains.kotlin.kdoc.psi.impl.KDocSection
import org.jetbrains.kotlin.kdoc.psi.impl.KDocTag
+import org.jetbrains.kotlin.lexer.JetSingleValueToken
import org.jetbrains.kotlin.name.FqName
+import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.JetParameter
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant
@@ -21,7 +23,7 @@ import org.jetbrains.kotlin.resolve.source.getPsi
import org.jetbrains.kotlin.types.ErrorUtils
import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.types.TypeProjection
-import org.jetbrains.kotlin.types.Variance
+import org.jetbrains.kotlin.types.expressions.OperatorConventions
public data class DocumentationOptions(val includeNonPublic: Boolean = false,
val sourceLinks: List<SourceLinkDefinition>)
@@ -394,6 +396,7 @@ class DocumentationBuilder(val session: ResolveSession,
node.appendType(getReturnType())
node.appendAnnotations(this)
node.appendSourceLink(getSource())
+ node.appendOperatorOverloadNote(this)
getOverriddenDescriptors().forEach {
addOverrideLink(it, this)
@@ -414,6 +417,58 @@ class DocumentationBuilder(val session: ResolveSession,
}
}
+ fun DocumentationNode.appendOperatorOverloadNote(descriptor: FunctionDescriptor) {
+ val operatorName = descriptor.getImplementedOperator()
+ if (operatorName != null) {
+ val content = Content()
+ content.append(ContentText("Implements "))
+ content.strong {
+ text("operator ")
+ code {
+ text(operatorName)
+ }
+ }
+ val noteNode = DocumentationNode("", content, DocumentationNode.Kind.OverloadGroupNote)
+ append(noteNode, DocumentationReference.Kind.Detail)
+ }
+ }
+
+ fun FunctionDescriptor.getImplementedOperator(): String? {
+ var arity = getValueParameters().size()
+ if (getContainingDeclaration() is ClassDescriptor) {
+ arity++
+ }
+ if (getExtensionReceiverParameter() != null) {
+ arity++
+ }
+
+ val token = if (arity == 2) {
+ OperatorConventions.BINARY_OPERATION_NAMES.inverse().get(getName()) ?:
+ OperatorConventions.ASSIGNMENT_OPERATIONS.inverse().get(getName()) ?:
+ OperatorConventions.BOOLEAN_OPERATIONS.inverse().get(getName())
+ } else if (arity == 1) {
+ OperatorConventions.UNARY_OPERATION_NAMES.inverse().get(getName())
+ }
+ else null
+
+ if (token is JetSingleValueToken) {
+ return token.getValue()
+ }
+
+ val name = getName().asString()
+ if (arity == 2 && name == "contains") {
+ return "in"
+ }
+ if (arity >= 2 && (name == "get" || name == "set")) {
+ return "[]"
+ }
+ if (arity == 2 && name == "equals" && getValueParameters().size() == 1 &&
+ KotlinBuiltIns.isNullableAny(getValueParameters().first().getType())) {
+ return "=="
+ }
+ return null
+ }
+
fun PropertyDescriptor.build(): DocumentationNode {
val node = DocumentationNode(this, if (inClassObject()) Kind.DefaultObjectProperty else Kind.Property)
node.appendInPageChildren(getTypeParameters(), DocumentationReference.Kind.Detail)
diff --git a/src/Model/Content.kt b/src/Model/Content.kt
index d343c648..91a7da81 100644
--- a/src/Model/Content.kt
+++ b/src/Model/Content.kt
@@ -98,6 +98,17 @@ fun ContentBlock.keyword(value: String) = append(ContentKeyword(value))
fun ContentBlock.symbol(value: String) = append(ContentSymbol(value))
fun ContentBlock.identifier(value: String, kind: IdentifierKind = IdentifierKind.Other) = append(ContentIdentifier(value, kind))
fun ContentBlock.nbsp() = append(ContentNonBreakingSpace)
+fun ContentBlock.strong(body: ContentBlock.() -> Unit) {
+ val strong = ContentStrong()
+ strong.body()
+ append(strong)
+}
+
+fun ContentBlock.code(body: ContentBlock.() -> Unit) {
+ val code = ContentCode()
+ code.body()
+ append(code)
+}
fun ContentBlock.link(to: DocumentationNode, body: ContentBlock.() -> Unit) {
val block = ContentNodeDirectLink(to)
diff --git a/src/Model/DocumentationNode.kt b/src/Model/DocumentationNode.kt
index c9373849..663ca021 100644
--- a/src/Model/DocumentationNode.kt
+++ b/src/Model/DocumentationNode.kt
@@ -101,6 +101,12 @@ public open class DocumentationNode(val name: String,
Value
SourceUrl
+
+ /**
+ * A note which is rendered once on a page documenting a group of overloaded functions.
+ * Needs to be generated equally on all overloads.
+ */
+ OverloadGroupNote
}
}