aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Java/JavaDocumentationBuilder.kt19
-rw-r--r--test/data/java/annotatedAnnotation.java7
-rw-r--r--test/src/model/JavaTest.kt17
3 files changed, 43 insertions, 0 deletions
diff --git a/src/Java/JavaDocumentationBuilder.kt b/src/Java/JavaDocumentationBuilder.kt
index 5f0798dd..f1a9c520 100644
--- a/src/Java/JavaDocumentationBuilder.kt
+++ b/src/Java/JavaDocumentationBuilder.kt
@@ -19,6 +19,7 @@ import com.intellij.psi.javadoc.PsiDocTag
import com.intellij.psi.javadoc.PsiDocTagValue
import com.intellij.psi.PsiEllipsisType
import com.intellij.psi.PsiField
+import com.intellij.psi.PsiAnnotation
public class JavaDocumentationBuilder(private val options: DocumentationOptions) {
fun appendFile(file: PsiJavaFile, module: DocumentationModule) {
@@ -59,6 +60,10 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions)
val node = DocumentationNode(name, docComment, kind)
if (element is PsiModifierListOwner) {
node.appendModifiers(element)
+ val modifierList = element.getModifierList()
+ if (modifierList != null) {
+ node.appendChildren(modifierList.getAnnotations(), DocumentationReference.Kind.Annotation) { build() }
+ }
}
return node
}
@@ -186,4 +191,18 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions)
is PsiArrayType -> "Array"
else -> psiType.getCanonicalText()
}
+
+ fun PsiAnnotation.build(): DocumentationNode {
+ val node = DocumentationNode(getNameReferenceElement()?.getText() ?: "<?>", Content.Empty, DocumentationNode.Kind.Annotation)
+ getParameterList().getAttributes().forEach {
+ val parameter = DocumentationNode(it.getName() ?: "value", Content.Empty, DocumentationNode.Kind.Parameter)
+ val value = it.getValue()
+ if (value != null) {
+ val valueNode = DocumentationNode(value.getText(), Content.Empty, DocumentationNode.Kind.Value)
+ parameter.append(valueNode, DocumentationReference.Kind.Detail)
+ }
+ node.append(parameter, DocumentationReference.Kind.Detail)
+ }
+ return node
+ }
}
diff --git a/test/data/java/annotatedAnnotation.java b/test/data/java/annotatedAnnotation.java
new file mode 100644
index 00000000..d9fae956
--- /dev/null
+++ b/test/data/java/annotatedAnnotation.java
@@ -0,0 +1,7 @@
+package test;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.FIELD, ElementType.TYPE, ElementType.METHOD})
+public @interface Attribute {
+ String value() default "";
+}
diff --git a/test/src/model/JavaTest.kt b/test/src/model/JavaTest.kt
index df8d8eae..ff04c90c 100644
--- a/test/src/model/JavaTest.kt
+++ b/test/src/model/JavaTest.kt
@@ -143,4 +143,21 @@ public class JavaTest {
assertFalse("static" in m.details(DocumentationNode.Kind.Modifier).map { it.name })
}
}
+
+ Test fun annotatedAnnotation() {
+ verifyPackageMember("test/data/java/annotatedAnnotation.java") { cls ->
+ assertEquals(2, cls.annotations.size())
+ with(cls.annotations[0]) {
+ assertEquals(1, details.count())
+ with(details[0]) {
+ assertEquals(DocumentationNode.Kind.Parameter, kind)
+ assertEquals(1, details.count())
+ with(details[0]) {
+ assertEquals(DocumentationNode.Kind.Value, kind)
+ assertEquals("RetentionPolicy.RUNTIME", name)
+ }
+ }
+ }
+ }
+ }
}