aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.idea/runConfigurations/All_tests.xml2
-rw-r--r--src/Kotlin/DocumentationBuilder.kt10
-rw-r--r--src/Kotlin/KotlinLanguageService.kt23
-rw-r--r--test/data/format/extensionFunctionParameter.kt1
-rw-r--r--test/data/format/extensionFunctionParameter.md8
-rw-r--r--test/src/format/MarkdownFormatTest.kt6
6 files changed, 32 insertions, 18 deletions
diff --git a/.idea/runConfigurations/All_tests.xml b/.idea/runConfigurations/All_tests.xml
index 57e4134d..5976ed25 100644
--- a/.idea/runConfigurations/All_tests.xml
+++ b/.idea/runConfigurations/All_tests.xml
@@ -8,7 +8,7 @@
<option name="MAIN_CLASS_NAME" value="" />
<option name="METHOD_NAME" value="" />
<option name="TEST_OBJECT" value="package" />
- <option name="VM_PARAMETERS" value="-Xmx256m" />
+ <option name="VM_PARAMETERS" value="-ea -Xmx256m" />
<option name="PARAMETERS" value="" />
<option name="WORKING_DIRECTORY" value="" />
<option name="ENV_VARIABLES" />
diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt
index 9321e5ca..b526e0ed 100644
--- a/src/Kotlin/DocumentationBuilder.kt
+++ b/src/Kotlin/DocumentationBuilder.kt
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant
import org.jetbrains.kotlin.resolve.constants.ConstantValue
import org.jetbrains.kotlin.resolve.constants.TypedCompileTimeConstant
+import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
import org.jetbrains.kotlin.resolve.descriptorUtil.isDocumentedAnnotation
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
import org.jetbrains.kotlin.resolve.source.PsiSourceElement
@@ -327,6 +328,7 @@ class DocumentationBuilder(val resolutionFacade: ResolutionFacade,
}
append(node, DocumentationReference.Kind.Detail)
+ node.appendAnnotations(jetType)
for (typeArgument in jetType.arguments)
node.appendProjection(typeArgument)
}
@@ -335,7 +337,7 @@ class DocumentationBuilder(val resolutionFacade: ResolutionFacade,
DescriptorUtils.getFqName(this).asString() in boringBuiltinClasses
fun DocumentationNode.appendAnnotations(annotated: Annotated) {
- annotated.annotations.filter { it.source.getPsi() != null && it.mustBeDocumented() }.forEach {
+ annotated.annotations.filter { it.isDocumented() }.forEach {
val annotationNode = it.build()
if (annotationNode != null) {
append(annotationNode,
@@ -344,6 +346,12 @@ class DocumentationBuilder(val resolutionFacade: ResolutionFacade,
}
}
+ private fun AnnotationDescriptor.isDocumented(): Boolean {
+ if (source.getPsi() != null && mustBeDocumented()) return true
+ val annotationClassName = type.constructor.declarationDescriptor?.fqNameSafe?.asString()
+ return annotationClassName == "kotlin.Extension"
+ }
+
fun AnnotationDescriptor.mustBeDocumented(): Boolean {
val annotationClass = type.constructor.declarationDescriptor as? Annotated ?: return false
return annotationClass.isDocumentedAnnotation()
diff --git a/src/Kotlin/KotlinLanguageService.kt b/src/Kotlin/KotlinLanguageService.kt
index bd98579a..6541e46c 100644
--- a/src/Kotlin/KotlinLanguageService.kt
+++ b/src/Kotlin/KotlinLanguageService.kt
@@ -76,26 +76,17 @@ class KotlinLanguageService : LanguageService {
}
private fun ContentBlock.renderType(node: DocumentationNode) {
- val typeArguments = node.details(DocumentationNode.Kind.Type)
+ var typeArguments = node.details(DocumentationNode.Kind.Type)
if (node.name == "Function${typeArguments.count() - 1}") {
// lambda
- symbol("(")
- renderList(typeArguments.take(typeArguments.size() - 1), noWrap = true) {
- renderType(it)
+ val isExtension = node.annotations.any { it.name == "Extension" }
+ if (isExtension) {
+ renderType(typeArguments.first())
+ symbol(".")
+ typeArguments = typeArguments.drop(1)
}
- symbol(")")
- nbsp()
- symbol("->")
- nbsp()
- renderType(typeArguments.last())
- return
- }
- if (node.name == "ExtensionFunction${typeArguments.count() - 2}") {
- // extension lambda
- renderType(typeArguments.first())
- symbol(".")
symbol("(")
- renderList(typeArguments.drop(1).take(typeArguments.size() - 2), noWrap = true) {
+ renderList(typeArguments.take(typeArguments.size() - 1), noWrap = true) {
renderType(it)
}
symbol(")")
diff --git a/test/data/format/extensionFunctionParameter.kt b/test/data/format/extensionFunctionParameter.kt
new file mode 100644
index 00000000..bfb344b9
--- /dev/null
+++ b/test/data/format/extensionFunctionParameter.kt
@@ -0,0 +1 @@
+public inline fun <T> T.apply(f: T.() -> Unit): T { f(); return this }
diff --git a/test/data/format/extensionFunctionParameter.md b/test/data/format/extensionFunctionParameter.md
new file mode 100644
index 00000000..6980912d
--- /dev/null
+++ b/test/data/format/extensionFunctionParameter.md
@@ -0,0 +1,8 @@
+[test](test/index) / [apply](test/apply)
+
+
+# apply
+
+`inline fun &lt;T&gt; T.apply(f:&nbsp;T.()&nbsp;-&gt;&nbsp;Unit): T`
+
+
diff --git a/test/src/format/MarkdownFormatTest.kt b/test/src/format/MarkdownFormatTest.kt
index 0df25fd5..32a641ff 100644
--- a/test/src/format/MarkdownFormatTest.kt
+++ b/test/src/format/MarkdownFormatTest.kt
@@ -167,4 +167,10 @@ public class MarkdownFormatTest {
markdownService.appendNodes(tempLocation, output, model.members.single().members.filter { it.name == "Foo" })
}
}
+
+ @Test fun extensionFunctionParameter() {
+ verifyOutput("test/data/format/extensionFunctionParameter.kt", ".md") { model, output ->
+ markdownService.appendNodes(tempLocation, output, model.members.single().members)
+ }
+ }
}