diff options
author | Andrea Falcone <1848683+asfalcone@users.noreply.github.com> | 2019-12-13 16:33:28 -0500 |
---|---|---|
committer | Kamil Doległo <kamilok1965@users.noreply.github.com> | 2019-12-18 12:47:30 +0100 |
commit | 41ac08a63a3813b1d6b2ede0c50e8269c9aeb3aa (patch) | |
tree | 92b9d3f1d0120a5e1451634d0599a8ef3bda273e /core | |
parent | 59c3f5fb48ce65e85d72deddebf57b9775317b79 (diff) | |
download | dokka-41ac08a63a3813b1d6b2ede0c50e8269c9aeb3aa.tar.gz dokka-41ac08a63a3813b1d6b2ede0c50e8269c9aeb3aa.tar.bz2 dokka-41ac08a63a3813b1d6b2ede0c50e8269c9aeb3aa.zip |
Implement display of Java default constructors
PsiClass does not include methods which are not present in the text
of the code. So when there are no constructors in a java class this
represents a class that only has a default constructor. The fix is
to create one for documentation.
Diffstat (limited to 'core')
-rw-r--r-- | core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt | 14 | ||||
-rw-r--r-- | core/src/test/kotlin/model/KotlinAsJavaTest.kt | 3 |
2 files changed, 12 insertions, 5 deletions
diff --git a/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt b/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt index 3b368329..d6743e60 100644 --- a/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt +++ b/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt @@ -29,7 +29,7 @@ fun getSignature(element: PsiElement?) = when(element) { } private fun methodSignature(method: PsiMethod): String { - return method.containingClass!!.qualifiedName + "$" + method.name + "(" + + return method.containingClass?.qualifiedName + "$" + method.name + "(" + method.parameterList.parameters.map { it.type.typeSignature() }.joinToString(",") + ")" } @@ -167,7 +167,7 @@ class JavaPsiDocumentationBuilder : JavaDocumentationBuilder { element.isInternal()) private fun skipElementBySuppressedFiles(element: Any): Boolean = - element is PsiElement && element.containingFile.virtualFile.path in passConfiguration.suppressedFiles + element is PsiElement && element.containingFile.virtualFile?.path in passConfiguration.suppressedFiles private fun PsiElement.isInternal(): Boolean { val ktElement = (this as? KtLightElement<*, *>)?.kotlinOrigin ?: return false @@ -196,8 +196,16 @@ class JavaPsiDocumentationBuilder : JavaDocumentationBuilder { link(superClass, node, RefKind.Inheritor) } } + + var methodsAndConstructors = methods + if (constructors.isEmpty()) { + // Having no constructor represents a class that only has an implicit/default constructor + // so we create one synthetically for documentation + val factory = JavaPsiFacade.getElementFactory(this.project) + methodsAndConstructors += factory.createMethodFromText("public $name() {}", this) + } node.appendDetails(typeParameters) { build() } - node.appendMembers(methods) { build() } + node.appendMembers(methodsAndConstructors) { build() } node.appendMembers(fields) { build() } node.appendMembers(innerClasses) { build() } register(this, node) diff --git a/core/src/test/kotlin/model/KotlinAsJavaTest.kt b/core/src/test/kotlin/model/KotlinAsJavaTest.kt index 8249dd0f..c29776be 100644 --- a/core/src/test/kotlin/model/KotlinAsJavaTest.kt +++ b/core/src/test/kotlin/model/KotlinAsJavaTest.kt @@ -16,9 +16,8 @@ class KotlinAsJavaTest { val facadeClass = pkg.members.single { it.name == "FunctionKt" } assertEquals(NodeKind.Class, facadeClass.kind) - val fn = facadeClass.members.single() + val fn = facadeClass.members.single { it.kind == NodeKind.Function} assertEquals("fn", fn.name) - assertEquals(NodeKind.Function, fn.kind) } } |