@@ -52,6 +52,7 @@ object JVMMarkerUtils {
52
52
when {
53
53
element.isKotlin() && element is KtClass -> return getFullyQualifiedName(element)
54
54
element.isKotlin() && element is KtNamedFunction -> return getFullyQualifiedName(element)
55
+ element is PsiAnnotation -> return getFullyQualifiedName(element)
55
56
element is PsiClass -> return getFullyQualifiedName(element)
56
57
element is PsiMethod -> return getFullyQualifiedName(element)
57
58
else -> Unit
@@ -79,6 +80,35 @@ object JVMMarkerUtils {
79
80
)
80
81
}
81
82
83
+ private fun getFullyQualifiedName (annotation : PsiAnnotation ): ArtifactQualifiedName {
84
+ val qualifiedName = getFullyQualifiedName(annotation, annotation.qualifiedName.toString())
85
+ return ArtifactQualifiedName (
86
+ qualifiedName,
87
+ type = ArtifactType .ANNOTATION ,
88
+ lineNumber = annotation.nameReferenceElement?.let { SourceMarkerUtils .getLineNumber(it) }
89
+ )
90
+ }
91
+
92
+ private fun getFullyQualifiedName (psiElement : PsiElement , simpleName : String ): String {
93
+ var parent = psiElement
94
+ while (parent !is PsiJavaFile && parent.parent != null ) {
95
+ parent = parent.parent
96
+ }
97
+ val javaFile = parent as ? PsiJavaFile ? : TODO () // todo: others
98
+
99
+ // Loop through imports to find fully qualified name
100
+ for (importStatement in javaFile.importList?.importStatements ? : emptyArray()) {
101
+ val qName = importStatement.qualifiedName
102
+ if (qName?.endsWith(" .$simpleName " ) == true || qName == simpleName) {
103
+ return qName
104
+ }
105
+ }
106
+
107
+ // If the simple name wasn't found in the imports, it might be in the same package.
108
+ val packageName = javaFile.packageStatement?.packageName
109
+ return if (packageName != null ) " $packageName .$simpleName " else simpleName
110
+ }
111
+
82
112
private fun getFullyQualifiedName (clazz : PsiClass ): ArtifactQualifiedName {
83
113
return ArtifactQualifiedName (
84
114
" ${JvmClassUtil .getJvmClassName(clazz)} " ,
0 commit comments