Skip to content

Handle non-physical PsiFile in utbot inspections #1598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.intellij.openapi.util.TextRange
import com.intellij.psi.JavaPsiFacade
import com.intellij.psi.PsiDocumentManager
import com.intellij.psi.PsiFile
import org.jetbrains.kotlin.idea.core.util.toPsiFile
import org.jetbrains.kotlin.idea.search.allScope
import org.utbot.sarif.*
import java.nio.file.Path
Expand Down Expand Up @@ -59,7 +60,14 @@ class UnitTestBotInspectionTool : GlobalSimpleInspectionTool() {
val errorPsiFile = srcFileLogicalLocation?.fullyQualifiedName?.let { errorClassFqn ->
val psiFacade = JavaPsiFacade.getInstance(srcPsiFile.project)
val psiClass = psiFacade.findClass(errorClassFqn, srcPsiFile.project.allScope())
psiClass?.containingFile
val psiFile = psiClass?.containingFile ?: return@let null

// We can't just return psiFile because it may be non-physical
if (psiFile.isPhysical) {
psiFile
} else {
psiFile.virtualFile.toPsiFile(srcPsiFile.project)
}
} ?: srcPsiFile
val errorRegion = srcFilePhysicalLocation.region
val errorTextRange = getTextRange(problemsHolder.project, errorPsiFile, errorRegion)
Expand Down