mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
capitalization inspection: report problem in constructor calls
This commit is contained in:
@@ -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>);
|
||||
}
|
||||
}
|
||||
@@ -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>);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+10
-7
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+8
@@ -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"));
|
||||
|
||||
Reference in New Issue
Block a user