From 41ac08a63a3813b1d6b2ede0c50e8269c9aeb3aa Mon Sep 17 00:00:00 2001 From: Andrea Falcone <1848683+asfalcone@users.noreply.github.com> Date: Fri, 13 Dec 2019 16:33:28 -0500 Subject: 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. --- core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'core/src/main/kotlin') 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) -- cgit