mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
i18n: fix regexp to ignore empty html (IDEA-247437)
GitOrigin-RevId: 7abea9e52ecfef2cf7eb121c54aa4c512737a622
This commit is contained in:
committed by
intellij-monorepo-bot
parent
b0b1c5538b
commit
533a006d5f
@@ -80,7 +80,7 @@ public class I18nInspection extends AbstractBaseUastLocalInspectionTool implemen
|
||||
CallMatcher.instanceCall(CommonClassNames.JAVA_LANG_THROWABLE, "getMessage").parameterCount(0),
|
||||
CallMatcher.instanceCall(CommonClassNames.JAVA_LANG_THROWABLE, "toString").parameterCount(0)
|
||||
);
|
||||
@RegExp private static final String DEFAULT_NON_NLS_LITERAL_PATTERN = "(?i)https?://.+|\\w*[.][\\w.]+|\\w*[$]\\w*|</?(html|b|i|body)>|&\\w+;";
|
||||
@RegExp private static final String DEFAULT_NON_NLS_LITERAL_PATTERN = "((?i)https?://.+|\\w*[.][\\w.]+|\\w*[$]\\w*|</?(html|b|i|body|li|ol|ul)>|&\\w+;)*";
|
||||
private static final CallMatcher STRING_LENGTH =
|
||||
CallMatcher.instanceCall(CommonClassNames.JAVA_LANG_STRING, "length").parameterCount(0);
|
||||
private static final CallMatcher STRING_EQUALS =
|
||||
@@ -807,6 +807,14 @@ public class I18nInspection extends AbstractBaseUastLocalInspectionTool implemen
|
||||
return NlsInfo.nonLocalized();
|
||||
}
|
||||
|
||||
if (isSuppressedByComment(project, expression)) {
|
||||
return NlsInfo.nonLocalized();
|
||||
}
|
||||
|
||||
if (value != null && myCachedLiteralPattern != null && myCachedLiteralPattern.matcher(value).matches()) {
|
||||
return NlsInfo.nonLocalized();
|
||||
}
|
||||
|
||||
List<UExpression> usages = findIndirectUsages(expression);
|
||||
if (usages.isEmpty()) {
|
||||
usages = Collections.singletonList(expression);
|
||||
@@ -816,9 +824,6 @@ public class I18nInspection extends AbstractBaseUastLocalInspectionTool implemen
|
||||
NlsInfo info = NlsInfo.forExpression(usage);
|
||||
switch (info.getNlsStatus()) {
|
||||
case YES: {
|
||||
if (isSuppressedByComment(project, expression)) {
|
||||
return NlsInfo.nonLocalized();
|
||||
}
|
||||
return info;
|
||||
}
|
||||
case UNSURE: {
|
||||
@@ -870,10 +875,6 @@ public class I18nInspection extends AbstractBaseUastLocalInspectionTool implemen
|
||||
@Nullable String value,
|
||||
@NotNull Set<? super PsiModifierListOwner> nonNlsTargets,
|
||||
@NotNull UExpression usage) {
|
||||
if (value != null && myCachedLiteralPattern != null && myCachedLiteralPattern.matcher(value).matches()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isInNonNlsCall(usage, nonNlsTargets)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.intellij.openapi.util;
|
||||
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import java.lang.annotation.*;
|
||||
|
||||
class X {
|
||||
static final @Nls String EMPTY_BODY = "<body></body>";
|
||||
}
|
||||
+24
-66
@@ -19,6 +19,16 @@ public class I18NInspectionTest extends LightJavaCodeInsightFixtureTestCase {
|
||||
myFixture.testHighlighting("i18n/" + getTestName(false) + ".java");
|
||||
}
|
||||
|
||||
private void doTestNlsMode() {
|
||||
boolean old = myTool.setIgnoreForAllButNls(true);
|
||||
try {
|
||||
doTest();
|
||||
}
|
||||
finally {
|
||||
myTool.setIgnoreForAllButNls(old);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_8;
|
||||
@@ -53,36 +63,18 @@ public class I18NInspectionTest extends LightJavaCodeInsightFixtureTestCase {
|
||||
}
|
||||
|
||||
public void testNlsOnly() {
|
||||
boolean old = myTool.setIgnoreForAllButNls(true);
|
||||
try {
|
||||
doTest();
|
||||
}
|
||||
finally {
|
||||
myTool.setIgnoreForAllButNls(old);
|
||||
}
|
||||
doTestNlsMode();
|
||||
}
|
||||
|
||||
public void testNlsOnlyFields() {
|
||||
boolean old = myTool.setIgnoreForAllButNls(true);
|
||||
try {
|
||||
doTest();
|
||||
}
|
||||
finally {
|
||||
myTool.setIgnoreForAllButNls(old);
|
||||
}
|
||||
doTestNlsMode();
|
||||
}
|
||||
|
||||
public void testNlsPackage() {
|
||||
myFixture.addFileToProject("package-info.java", "@Nls\n" +
|
||||
"package foo;\n" +
|
||||
"import org.jetbrains.annotations.Nls;");
|
||||
boolean old = myTool.setIgnoreForAllButNls(true);
|
||||
try {
|
||||
doTest();
|
||||
}
|
||||
finally {
|
||||
myTool.setIgnoreForAllButNls(old);
|
||||
}
|
||||
doTestNlsMode();
|
||||
}
|
||||
|
||||
public void testAnnotationArgument() { doTest(); }
|
||||
@@ -111,56 +103,22 @@ public class I18NInspectionTest extends LightJavaCodeInsightFixtureTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testNlsTypeUse() {
|
||||
boolean old = myTool.setIgnoreForAllButNls(true);
|
||||
try {
|
||||
doTest();
|
||||
}
|
||||
finally {
|
||||
myTool.setIgnoreForAllButNls(old);
|
||||
}
|
||||
}
|
||||
public void testNlsTypeUse() { doTestNlsMode(); }
|
||||
|
||||
public void testNonNlsIndirect() {
|
||||
doTest();
|
||||
}
|
||||
public void testNonNlsIndirect() { doTest(); }
|
||||
|
||||
public void testNlsIndirect() {
|
||||
boolean old = myTool.setIgnoreForAllButNls(true);
|
||||
try {
|
||||
doTest();
|
||||
}
|
||||
finally {
|
||||
myTool.setIgnoreForAllButNls(old);
|
||||
}
|
||||
}
|
||||
|
||||
public void testNonNlsMeta() {
|
||||
doTest();
|
||||
}
|
||||
public void testNlsIndirect() { doTestNlsMode(); }
|
||||
|
||||
public void testNlsMeta() {
|
||||
boolean old = myTool.setIgnoreForAllButNls(true);
|
||||
try {
|
||||
doTest();
|
||||
}
|
||||
finally {
|
||||
myTool.setIgnoreForAllButNls(old);
|
||||
}
|
||||
}
|
||||
public void testNonNlsMeta() { doTest(); }
|
||||
|
||||
public void testUseConstant() {
|
||||
doTest();
|
||||
}
|
||||
public void testNlsMeta() { doTestNlsMode(); }
|
||||
|
||||
public void testUseConstantNls() {
|
||||
boolean old = myTool.setIgnoreForAllButNls(true);
|
||||
try {
|
||||
doTest();
|
||||
}
|
||||
finally {
|
||||
myTool.setIgnoreForAllButNls(old);
|
||||
}
|
||||
public void testUseConstant() { doTest(); }
|
||||
|
||||
public void testUseConstantNls() { doTestNlsMode(); }
|
||||
|
||||
public void testHtmlEntitiesNlsMode() {
|
||||
doTestNlsMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user