@@ -26,12 +26,12 @@ import org.jetbrains.kotlin.idea.base.psi.KotlinPsiHeuristics
26
26
import org.jetbrains.kotlin.idea.base.utils.fqname.fqName
27
27
import org.jetbrains.kotlin.nj2k.postProcessing.type
28
28
import org.jetbrains.kotlin.psi.KtClass
29
+ import org.jetbrains.kotlin.psi.KtFile
29
30
import org.jetbrains.kotlin.psi.KtFunction
30
31
import org.jetbrains.kotlin.psi.KtNamedFunction
31
32
import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType
32
- import spp.jetbrains.artifact.service.ArtifactScopeService
33
- import spp.jetbrains.artifact.service.ArtifactTypeService
34
- import spp.jetbrains.artifact.service.isKotlin
33
+ import org.jetbrains.plugins.groovy.lang.psi.GroovyFile
34
+ import spp.jetbrains.artifact.service.*
35
35
import spp.jetbrains.marker.SourceMarkerUtils
36
36
import spp.jetbrains.marker.source.mark.api.SourceMark
37
37
import spp.protocol.artifact.ArtifactQualifiedName
@@ -90,23 +90,42 @@ object JVMMarkerUtils {
90
90
}
91
91
92
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
93
+ if (psiElement.isJava() && psiElement.containingFile is PsiJavaFile ) {
94
+ val javaFile = psiElement.containingFile as PsiJavaFile
95
+ for (importStatement in javaFile.importList?.importStatements ? : emptyArray()) {
96
+ val qName = importStatement.qualifiedName
97
+ if (qName?.endsWith(" .$simpleName " ) == true || qName == simpleName) {
98
+ return qName
99
+ }
100
+ }
98
101
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
102
+ val packageName = javaFile.packageStatement?.packageName
103
+ return if (packageName != null ) " $packageName .$simpleName " else simpleName
104
+ } else if (psiElement.isKotlin() && psiElement.containingFile is KtFile ) {
105
+ val ktFile = psiElement.containingFile as KtFile
106
+ for (importDirective in ktFile.importDirectives) {
107
+ val qName = importDirective.importedFqName?.asString()
108
+ if (qName?.endsWith(" .$simpleName " ) == true || qName == simpleName) {
109
+ return qName
110
+ }
104
111
}
105
- }
106
112
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
113
+ val packageName = ktFile.packageFqName.asString()
114
+ return " $packageName .$simpleName "
115
+ } else if (psiElement.isGroovy() && psiElement.containingFile is GroovyFile ) {
116
+ val groovyFile = psiElement.containingFile as GroovyFile
117
+ for (importStatement in groovyFile.importStatements) {
118
+ val qName = importStatement.importFqn.toString()
119
+ if (qName.endsWith(" .$simpleName " ) || qName == simpleName) {
120
+ return qName
121
+ }
122
+ }
123
+
124
+ val packageName = groovyFile.packageDefinition?.packageName
125
+ return if (packageName != null ) " $packageName .$simpleName " else simpleName
126
+ } else {
127
+ return simpleName
128
+ }
110
129
}
111
130
112
131
private fun getFullyQualifiedName (clazz : PsiClass ): ArtifactQualifiedName {
0 commit comments