[path-annotations] Don't register warnings on empty PSI expressions

#IJPL-234474 Fixed

GitOrigin-RevId: 9c1bb588b861577ec31a43b8dd7c6f015e44c560
This commit is contained in:
Bart van Helvert
2026-02-11 16:06:30 +00:00
committed by intellij-monorepo-bot
parent 7cf55257b6
commit 513fce5bd9
3 changed files with 32 additions and 1 deletions
@@ -62,6 +62,12 @@ internal sealed interface PathAnnotationInfo {
object Unspecified : PathAnnotationInfo
/**
* Impossible to determine the path annotation type for the given expression.
* This happens when, for example, the source PSI is a [com.intellij.psi.impl.source.tree.java.PsiEmptyExpressionImpl].
*/
object Invalid : PathAnnotationInfo
companion object {
/**
* Checks if the given string is a valid filename (no forward or backward slashes).
@@ -271,6 +277,8 @@ internal sealed interface PathAnnotationInfo {
}
}
if (sourcePsi?.textLength == 0) return Invalid
// We don't check if the expression is a string literal or constant that denotes a filename here
// because we want to handle that in the visitCallExpression method
@@ -122,6 +122,7 @@ class PathAnnotationInspection : DevKitUastInspectionBase() {
*PathAnnotationInfo.MultiRouting.quickFixesFor(arg.sourcePsi).toTypedArray()
)
}
is PathAnnotationInfo.Invalid -> { }
}
}
}
@@ -191,6 +192,7 @@ class PathAnnotationInspection : DevKitUastInspectionBase() {
*PathAnnotationInfo.MultiRouting.quickFixesFor(arg.sourcePsi).toTypedArray()
)
}
is PathAnnotationInfo.Invalid -> { }
}
}
}
@@ -232,6 +234,7 @@ class PathAnnotationInspection : DevKitUastInspectionBase() {
*PathAnnotationInfo.Native.quickFixesFor(firstArg.sourcePsi).toTypedArray()
)
}
is PathAnnotationInfo.Invalid -> { }
}
// Check remaining arguments (should be annotated with either @NativePath or @Filename)
@@ -289,6 +292,7 @@ class PathAnnotationInspection : DevKitUastInspectionBase() {
*PathAnnotationInfo.Native.quickFixesFor(arg.sourcePsi).toTypedArray()
)
}
is PathAnnotationInfo.Invalid -> { }
}
}
}
@@ -311,6 +315,7 @@ class PathAnnotationInspection : DevKitUastInspectionBase() {
when (expectedInfo) {
is PathAnnotationInfo.Specified -> Unit
is PathAnnotationInfo.Unspecified -> continue
is PathAnnotationInfo.Invalid -> continue
}
val actualInfo = PathAnnotationInfo.forExpression(arg)
@@ -358,6 +363,7 @@ class PathAnnotationInspection : DevKitUastInspectionBase() {
)
}
}
is PathAnnotationInfo.Invalid -> { }
}
}
@@ -406,6 +412,7 @@ class PathAnnotationInspection : DevKitUastInspectionBase() {
// If the method doesn't have a path annotation, don't register any problems
return true
}
is PathAnnotationInfo.Invalid -> { return true }
}
// Check if the return value has a path annotation
@@ -430,6 +437,7 @@ class PathAnnotationInspection : DevKitUastInspectionBase() {
)
}
}
is PathAnnotationInfo.Invalid -> { }
}
return true
@@ -300,4 +300,19 @@ class PathAnnotationInspectionJavaTest : PathAnnotationInspectionTestBase() {
}
""".trimIndent())
}
}
fun testEmptyExpression() {
doTest("""
import com.intellij.platform.eel.annotations.LocalPath;
import java.nio.file.Paths;
class LocalPathTest {
public void testMethod() {
@LocalPath String localPath = "/local/path";
Paths.get(localPath, "a", "b",<error descr="Expression expected"> </error>);
}
}
""".trimIndent())
}
}