capitalization inspection: report problem in constructor calls
authornik <Nikolay.Chashnikov@jetbrains.com>
Thu, 6 Aug 2015 11:44:33 +0000 (14:44 +0300)
committernik <Nikolay.Chashnikov@jetbrains.com>
Thu, 6 Aug 2015 11:45:04 +0000 (14:45 +0300)
plugins/devkit/testData/inspections/capitalization/ConstructorArgument.java [new file with mode: 0644]
plugins/devkit/testData/inspections/capitalization/SuperConstructorArgument.java [new file with mode: 0644]
plugins/java-i18n/src/com/intellij/codeInspection/capitalization/TitleCapitalizationInspection.java
plugins/java-i18n/testSrc/com/intellij/codeInspection/CapitalizationInspectionTest.java

diff --git a/plugins/devkit/testData/inspections/capitalization/ConstructorArgument.java b/plugins/devkit/testData/inspections/capitalization/ConstructorArgument.java
new file mode 100644 (file)
index 0000000..09a38a8
--- /dev/null
@@ -0,0 +1,10 @@
+import org.jetbrains.annotations.Nls;
+
+class ConstructorArgument  {
+    ConstructorArgument(@Nls(capitalization = Nls.Capitalization.Title) String foo) {
+    }
+
+    public static void create() {
+        new ConstructorArgument(<warning descr="String 'Foo bar' is not properly capitalized. It should have title capitalization">"Foo bar"</warning>);
+    }
+}
\ No newline at end of file
diff --git a/plugins/devkit/testData/inspections/capitalization/SuperConstructorArgument.java b/plugins/devkit/testData/inspections/capitalization/SuperConstructorArgument.java
new file mode 100644 (file)
index 0000000..ef9c2e0
--- /dev/null
@@ -0,0 +1,13 @@
+import org.jetbrains.annotations.Nls;
+
+class SuperConstructorArgument  {
+    SuperConstructorArgument(@Nls(capitalization = Nls.Capitalization.Title) String foo) {
+    }
+
+    public static class SubClass extends SuperConstructorArgument {
+        public SubClass() {
+            super(<warning descr="String 'Foo bar' is not properly capitalized. It should have title capitalization">"Foo bar"</warning>);
+        }
+    }
+
+}
\ No newline at end of file
index a0b9c8203ff749daee316665d19573d29d97ce34..2cb3fb71919cfa4a8e38e6150df52803f2ababc9 100644 (file)
@@ -84,15 +84,18 @@ public class TitleCapitalizationInspection extends BaseJavaLocalInspectionTool {
       }
 
       @Override
-      public void visitMethodCallExpression(PsiMethodCallExpression expression) {
+      public void visitCallExpression(PsiCallExpression expression) {
         PsiMethod psiMethod = expression.resolveMethod();
         if (psiMethod != null) {
-          PsiExpression[] args = expression.getArgumentList().getExpressions();
-          PsiParameter[] parameters = psiMethod.getParameterList().getParameters();
-          for (int i = 0; i < Math.min(parameters.length, args.length); i++) {
-            PsiParameter parameter = parameters[i];
-            Nls.Capitalization capitalization = getCapitalizationFromAnno(parameter);
-            checkCapitalization(args[i], holder, capitalization);
+          PsiExpressionList argumentList = expression.getArgumentList();
+          if (argumentList != null) {
+            PsiExpression[] args = argumentList.getExpressions();
+            PsiParameter[] parameters = psiMethod.getParameterList().getParameters();
+            for (int i = 0; i < Math.min(parameters.length, args.length); i++) {
+              PsiParameter parameter = parameters[i];
+              Nls.Capitalization capitalization = getCapitalizationFromAnno(parameter);
+              checkCapitalization(args[i], holder, capitalization);
+            }
           }
         }
       }
index c25e5e72e7cfb00d5276f92b60f6a9b46097ded0..e18557c6fb94fcde704ee3cad1d381e36aae03ec 100644 (file)
@@ -47,6 +47,14 @@ public class CapitalizationInspectionTest extends LightCodeInsightFixtureTestCas
     doTest(false);
   }
 
+  public void testConstructorArgument() {
+    doTest(false);
+  }
+
+  public void testSuperConstructorArgument() {
+    doTest(false);
+  }
+
   public void testRecursiveMethod() {
     myFixture.testHighlighting(getTestName(false) + ".java");
     assertEmpty(myFixture.filterAvailableIntentions("Properly capitalize"));