[java-i18n] IDEA-247707 @NonNls inspection doesn't propagate to receiver expressions...
authorTagir Valeev <Tagir.Valeev@jetbrains.com>
Tue, 11 Aug 2020 11:34:37 +0000 (18:34 +0700)
committerintellij-monorepo-bot <intellij-monorepo-bot-no-reply@jetbrains.com>
Tue, 11 Aug 2020 12:49:01 +0000 (12:49 +0000)
GitOrigin-RevId: 77b96c095d076825edb0cab3f5629de52b1611b8

plugins/devkit/devkit-kotlin-tests/testSrc/org/jetbrains/idea/devkit/kotlin/inspections/KtI18NInspectionTest.kt
plugins/java-i18n/src/com/intellij/codeInspection/i18n/NlsInfo.java
plugins/java-i18n/testData/inspections/i18n/StringMethods.java

index 124a64a260d36ebff870ff32cb23d584d70d575a..b256ca218a4f9240df1aa124899444bfedafd7ec 100644 (file)
@@ -18,6 +18,19 @@ class KtI18NInspectionTest : LightJavaCodeInsightFixtureTestCase() {
     """.trimIndent())
     myFixture.testHighlighting()
   }
+
+  fun testPropagateToReceiver() {
+    myFixture.enableInspections(com.intellij.codeInspection.i18n.I18nInspection())
+    myFixture.configureByText("Foo.kt", """
+       public fun String.trimIndent(): String = this
+       fun foo(@org.jetbrains.annotations.NonNls <warning descr="[UNUSED_PARAMETER] Parameter 'message' is never used">message</warning>: String) { }
+       fun bar() {
+          foo("foo bar")
+          foo("foo bar".trimIndent())
+       }
+    """.trimIndent())
+    myFixture.testHighlighting()
+  }
   
   fun testPropertyAssignment() {
     val inspection = com.intellij.codeInspection.i18n.I18nInspection()
index cc9e57deb69fbb340bfffd658968253bc0280c29..0aabf04aba9a51c157a409cd63098147541ca45d 100644 (file)
@@ -352,8 +352,13 @@ public abstract class NlsInfo {
     UExpression parent = expression;
     while (true) {
       UExpression next = ObjectUtils.tryCast(parent.getUastParent(), UExpression.class);
-      if (next == null || next instanceof ULambdaExpression || next instanceof UReturnExpression) return parent;
-      if (next instanceof USwitchClauseExpression || next instanceof UNamedExpression) return parent;
+      if (next == null ||
+          next instanceof ULambdaExpression ||
+          next instanceof UReturnExpression ||
+          next instanceof USwitchClauseExpression ||
+          next instanceof UNamedExpression) {
+        return parent;
+      }
       if (next instanceof UPolyadicExpression && ((UPolyadicExpression)next).getOperator() != UastBinaryOperator.PLUS) return parent;
       if (next instanceof UCallExpression) {
         if (!UastExpressionUtils.isArrayInitializer(next) && !UastExpressionUtils.isNewArrayWithInitializer(next)) {
index 6e09cfb751517bf5ec9d39da2dff40111f43dd4e..1009e2ee38607cc2c2ece8552665a5ca98bf0776 100644 (file)
@@ -43,5 +43,9 @@ class StringMethods {
         if (this.getFoo().toLowerCase().equals("bar")) {}
     }
     
+    void test() {
+        test("foo".trim());
+    }
+    
     @NonNls native String getFoo();
 }
\ No newline at end of file