diff --git a/plugins/java-i18n/src/com/intellij/codeInspection/capitalization/TitleCapitalizationInspection.java b/plugins/java-i18n/src/com/intellij/codeInspection/capitalization/TitleCapitalizationInspection.java
index 0b343a2ce6fb..68bd02e63815 100644
--- a/plugins/java-i18n/src/com/intellij/codeInspection/capitalization/TitleCapitalizationInspection.java
+++ b/plugins/java-i18n/src/com/intellij/codeInspection/capitalization/TitleCapitalizationInspection.java
@@ -95,7 +95,8 @@ public class TitleCapitalizationInspection extends AbstractBaseJavaLocalInspecti
return Value.of((PsiLiteralExpression)arg);
}
if (arg instanceof PsiMethodCallExpression) {
- PsiMethod psiMethod = ((PsiMethodCallExpression)arg).resolveMethod();
+ PsiMethodCallExpression call = (PsiMethodCallExpression)arg;
+ PsiMethod psiMethod = call.resolveMethod();
PsiExpression returnValue = PropertyUtilBase.getGetterReturnExpression(psiMethod);
if (arg == returnValue) {
return null;
@@ -103,7 +104,7 @@ public class TitleCapitalizationInspection extends AbstractBaseJavaLocalInspecti
if (returnValue != null && processed.add(returnValue)) {
return getTitleValue(returnValue, processed);
}
- return Value.of(getPropertyArgument((PsiMethodCallExpression)arg));
+ return Value.of(getPropertyArgument(call), call.getArgumentList().getExpressionCount() > 1);
}
if (arg instanceof PsiReferenceExpression) {
PsiElement result = ((PsiReferenceExpression)arg).resolve();
@@ -169,14 +170,14 @@ public class TitleCapitalizationInspection extends AbstractBaseJavaLocalInspecti
element.replace(newExpression);
}
else if (element instanceof PsiMethodCallExpression) {
- final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)element;
- final PsiMethod method = methodCallExpression.resolveMethod();
+ final PsiMethodCallExpression call = (PsiMethodCallExpression)element;
+ final PsiMethod method = call.resolveMethod();
final PsiExpression returnValue = PropertyUtilBase.getGetterReturnExpression(method);
if (returnValue != null) {
doFix(project, returnValue);
}
- final Property property = getPropertyArgument(methodCallExpression);
- Value value = Value.of(property);
+ final Property property = getPropertyArgument(call);
+ Value value = Value.of(property, call.getArgumentList().getExpressionCount() > 1);
if (value == null) return;
property.setValue(value.fixCapitalization(myCapitalization));
}
@@ -211,19 +212,20 @@ public class TitleCapitalizationInspection extends AbstractBaseJavaLocalInspecti
default boolean canFix() { return true; }
- @Contract("null -> null")
+ @Contract("null, _ -> null")
@Nullable
- static Value of(@Nullable Property property) {
+ static Value of(@Nullable Property property, boolean useFormat) {
if (property == null) return null;
String value = property.getUnescapedValue();
if (value == null) return null;
- try {
- MessageFormat format = new MessageFormat(value);
- return new PropertyValue(value, format);
- }
- catch (IllegalArgumentException e) {
- return new TextValue(value);
+ if (useFormat) {
+ try {
+ MessageFormat format = new MessageFormat(value);
+ return new PropertyValue(value, format);
+ }
+ catch (IllegalArgumentException ignore) {}
}
+ return new TextValue(value);
}
@Nullable
diff --git a/plugins/java-i18n/testData/inspections/capitalization/PropertyTest.java b/plugins/java-i18n/testData/inspections/capitalization/PropertyTest.java
index 6715686e4317..ef4207195a89 100644
--- a/plugins/java-i18n/testData/inspections/capitalization/PropertyTest.java
+++ b/plugins/java-i18n/testData/inspections/capitalization/PropertyTest.java
@@ -29,5 +29,7 @@ class X {
test2(message("property.choice.title", x));
test2(message("property.choice.mixed", x));
test2(message("property.choice.lower", x));
+
+ test2(message("property.sentence.with.quote"));
}
}
\ No newline at end of file
diff --git a/plugins/java-i18n/testSrc/com/intellij/codeInspection/CapitalizationInspectionTest.java b/plugins/java-i18n/testSrc/com/intellij/codeInspection/CapitalizationInspectionTest.java
index fa77004c78d8..0b4f5248187e 100644
--- a/plugins/java-i18n/testSrc/com/intellij/codeInspection/CapitalizationInspectionTest.java
+++ b/plugins/java-i18n/testSrc/com/intellij/codeInspection/CapitalizationInspectionTest.java
@@ -67,7 +67,8 @@ public class CapitalizationInspectionTest extends LightJavaCodeInsightFixtureTes
"property.parameterized=Hello {0}\n" +
"property.choice.title=Hello {0,choice,0#World|1#Universe}\n" +
"property.choice.mixed=Hello {0,choice,0#World|1#universe}\n" +
- "property.choice.lower=Hello {0,choice,0#world|1#universe}\n";
+ "property.choice.lower=Hello {0,choice,0#world|1#universe}\n" +
+ "property.sentence.with.quote='return' is not allowed here";
myFixture.addFileToProject("MyBundle.properties", props);
doTest(false);
}