@@ -26,12 +26,12 @@ import org.jetbrains.kotlin.idea.base.psi.KotlinPsiHeuristics
2626import org.jetbrains.kotlin.idea.base.utils.fqname.fqName
2727import org.jetbrains.kotlin.nj2k.postProcessing.type
2828import org.jetbrains.kotlin.psi.KtClass
29+ import org.jetbrains.kotlin.psi.KtFile
2930import org.jetbrains.kotlin.psi.KtFunction
3031import org.jetbrains.kotlin.psi.KtNamedFunction
3132import 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.*
3535import spp.jetbrains.marker.SourceMarkerUtils
3636import spp.jetbrains.marker.source.mark.api.SourceMark
3737import spp.protocol.artifact.ArtifactQualifiedName
@@ -90,23 +90,42 @@ object JVMMarkerUtils {
9090 }
9191
9292 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+ }
98101
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+ }
104111 }
105- }
106112
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+ }
110129 }
111130
112131 private fun getFullyQualifiedName (clazz : PsiClass ): ArtifactQualifiedName {
0 commit comments