diff --git a/plugins/devkit/devkit-core/src/inspections/path/PathAnnotationInfo.kt b/plugins/devkit/devkit-core/src/inspections/path/PathAnnotationInfo.kt index 784f110712d9..0e032dbc0004 100644 --- a/plugins/devkit/devkit-core/src/inspections/path/PathAnnotationInfo.kt +++ b/plugins/devkit/devkit-core/src/inspections/path/PathAnnotationInfo.kt @@ -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 diff --git a/plugins/devkit/devkit-core/src/inspections/path/PathAnnotationInspection.kt b/plugins/devkit/devkit-core/src/inspections/path/PathAnnotationInspection.kt index 3f916beb7356..60229c25cb16 100644 --- a/plugins/devkit/devkit-core/src/inspections/path/PathAnnotationInspection.kt +++ b/plugins/devkit/devkit-core/src/inspections/path/PathAnnotationInspection.kt @@ -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 diff --git a/plugins/devkit/devkit-tests/testSrc/org/jetbrains/idea/devkit/inspections/path/PathAnnotationInspectionJavaTest.kt b/plugins/devkit/devkit-tests/testSrc/org/jetbrains/idea/devkit/inspections/path/PathAnnotationInspectionJavaTest.kt index 17e5cb6314a3..6d8dc927a15b 100644 --- a/plugins/devkit/devkit-tests/testSrc/org/jetbrains/idea/devkit/inspections/path/PathAnnotationInspectionJavaTest.kt +++ b/plugins/devkit/devkit-tests/testSrc/org/jetbrains/idea/devkit/inspections/path/PathAnnotationInspectionJavaTest.kt @@ -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", ); + } + } + """.trimIndent()) + } +} \ No newline at end of file