Skip to content

Commit

Permalink
Get PsiClass' package by declaration in containingFile and not by its…
Browse files Browse the repository at this point in the history
… directory
  • Loading branch information
volivan239 committed Oct 7, 2022
1 parent d447c86 commit 99f38a1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ object UtTestsDialogProcessor {
val name = qualifiedName
?.substringAfter("$packageName.")
?.replace(".", "$")
?: ""
?: error("Unable to get canonical name for $this")
"$packageName.$name"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import com.intellij.openapi.projectRoots.JavaSdkVersion
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.openapi.vfs.newvfs.impl.FakeVirtualFile
import com.intellij.psi.PsiClass
import com.intellij.psi.PsiJavaFile
import com.intellij.refactoring.util.classMembers.MemberInfo
import org.jetbrains.kotlin.idea.core.getPackage
import org.jetbrains.kotlin.psi.KtFile
import org.utbot.framework.plugin.api.JavaDocCommentStyle
import org.utbot.framework.util.ConflictTriggers
import org.utbot.intellij.plugin.ui.utils.jdkVersion
Expand Down Expand Up @@ -84,4 +85,11 @@ data class GenerateTestsModel(
}
}

val PsiClass.packageName: String get() = this.containingFile.containingDirectory.getPackage()?.qualifiedName ?: ""
val PsiClass.packageName: String
get() {
return when (val currentFile = containingFile) {
is PsiJavaFile -> currentFile.packageName
is KtFile -> currentFile.packageFqName.asString()
else -> error("Can't find package name for $this: it should be located either in Java or Kt file")
}
}

0 comments on commit 99f38a1

Please sign in to comment.