diff options
-rw-r--r-- | src/Java/JavaDocumentationBuilder.kt | 13 | ||||
-rw-r--r-- | test/data/java/field.java | 6 | ||||
-rw-r--r-- | test/src/model/JavaTest.kt | 11 |
3 files changed, 29 insertions, 1 deletions
diff --git a/src/Java/JavaDocumentationBuilder.kt b/src/Java/JavaDocumentationBuilder.kt index 0a9632bf..d57ffb0c 100644 --- a/src/Java/JavaDocumentationBuilder.kt +++ b/src/Java/JavaDocumentationBuilder.kt @@ -18,7 +18,7 @@ import com.intellij.psi.PsiTypeParameter import com.intellij.psi.javadoc.PsiDocTag import com.intellij.psi.javadoc.PsiDocTagValue import com.intellij.psi.PsiEllipsisType -import com.intellij.psi.PsiElement +import com.intellij.psi.PsiField public class JavaDocumentationBuilder(private val options: DocumentationOptions) { fun appendFile(file: PsiJavaFile, module: DocumentationModule) { @@ -94,10 +94,21 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions) getImplementsListTypes().forEach { node.appendType(it, Kind.Supertype) } node.appendDetails(getTypeParameters()) { build() } node.appendMembers(getMethods()) { build() } + node.appendMembers(getFields()) { build() } node.appendMembers(getInnerClasses()) { build() } return node } + fun PsiField.build(): DocumentationNode { + val node = DocumentationNode(this, + if (hasModifierProperty(PsiModifier.STATIC)) DocumentationNode.Kind.ClassObjectProperty else DocumentationNode.Kind.Property) + if (!hasModifierProperty(PsiModifier.FINAL)) { + node.append(DocumentationNode("var", Content.Empty, Kind.Modifier), DocumentationReference.Kind.Detail) + } + node.appendType(getType()) + return node + } + fun PsiMethod.build(): DocumentationNode { val node = DocumentationNode(this, if (isConstructor()) Kind.Constructor else Kind.Function, diff --git a/test/data/java/field.java b/test/data/java/field.java new file mode 100644 index 00000000..47dac0a4 --- /dev/null +++ b/test/data/java/field.java @@ -0,0 +1,6 @@ +package test; + +class Test { + public int i; + public static final String s; +} diff --git a/test/src/model/JavaTest.kt b/test/src/model/JavaTest.kt index 3ff04b14..15efa90b 100644 --- a/test/src/model/JavaTest.kt +++ b/test/src/model/JavaTest.kt @@ -122,4 +122,15 @@ public class JavaTest { assertTrue(psiType.details(DocumentationNode.Kind.Type).isEmpty()) } } + + Test fun fields() { + verifyPackageMember("test/data/java/field.java") { cls -> + val i = cls.members(DocumentationNode.Kind.Property).single { it.name == "i" } + assertEquals("Int", i.detail(DocumentationNode.Kind.Type).name) + assertTrue("var" in i.details(DocumentationNode.Kind.Modifier).map { it.name }) + val s = cls.members(DocumentationNode.Kind.ClassObjectProperty).single { it.name == "s" } + assertEquals("String", s.detail(DocumentationNode.Kind.Type).name) + assertFalse("var" in s.details(DocumentationNode.Kind.Modifier).map { it.name }) + } + } } |