diff options
-rw-r--r-- | src/Java/JavaDocumentationBuilder.kt | 15 | ||||
-rw-r--r-- | test/data/java/constructors.java | 7 | ||||
-rw-r--r-- | test/src/model/JavaTest.kt | 10 |
3 files changed, 28 insertions, 4 deletions
diff --git a/src/Java/JavaDocumentationBuilder.kt b/src/Java/JavaDocumentationBuilder.kt index 879c0b2c..fdf5c665 100644 --- a/src/Java/JavaDocumentationBuilder.kt +++ b/src/Java/JavaDocumentationBuilder.kt @@ -32,9 +32,11 @@ public class JavaDocumentationBuilder() { return result } - fun DocumentationNode(element: PsiNamedElement, kind: Kind): DocumentationNode { + fun DocumentationNode(element: PsiNamedElement, + kind: Kind, + name: String = element.getName() ?: "<anonymous>"): DocumentationNode { val docComment = if (element is PsiDocCommentOwner) parseDocumentation(element.getDocComment()) else Content.Empty - val node = DocumentationNode(element.getName() ?: "<anonymous>", docComment, kind) + val node = DocumentationNode(name, docComment, kind) if (element is PsiModifierListOwner) { node.appendModifiers(element) } @@ -71,8 +73,13 @@ public class JavaDocumentationBuilder() { } fun PsiMethod.build(): DocumentationNode { - val node = DocumentationNode(this, Kind.Function) - node.appendType(getReturnType()) + val node = DocumentationNode(this, + if (isConstructor()) Kind.Constructor else Kind.Function, + if (isConstructor()) "<init>" else getName()) + + if (!isConstructor()) { + node.appendType(getReturnType()) + } node.appendDetails(getParameterList().getParameters()) { build() } node.appendDetails(getTypeParameters()) { build() } return node diff --git a/test/data/java/constructors.java b/test/data/java/constructors.java new file mode 100644 index 00000000..3b1838dd --- /dev/null +++ b/test/data/java/constructors.java @@ -0,0 +1,7 @@ +package test; + +class Test { + public Test() {} + + public Test(String s) {} +} diff --git a/test/src/model/JavaTest.kt b/test/src/model/JavaTest.kt index 5c8163a3..ab417036 100644 --- a/test/src/model/JavaTest.kt +++ b/test/src/model/JavaTest.kt @@ -75,4 +75,14 @@ public class JavaTest { } } } + + Test fun constructors() { + verifyPackageMember("test/data/java/constructors.java") { cls -> + val constructors = cls.members(DocumentationNode.Kind.Constructor) + assertEquals(2, constructors.size()) + with(constructors[0]) { + assertEquals("<init>", name) + } + } + } } |