[java-inspections] MismatchedStringCase: make message more technically correct (IDEA-342568)

GitOrigin-RevId: 6cf795e29b18e043d7a08a3263c26badd45dbdc7
This commit is contained in:
Tagir Valeev
2024-01-22 10:54:22 +00:00
committed by intellij-monorepo-bot
parent f5772a224a
commit 0fec0c3bed
2 changed files with 18 additions and 13 deletions
@@ -2269,8 +2269,8 @@ inspection.if.statement.missing.break.in.loop.description=Loop can be terminated
inspection.if.statement.missing.break.in.loop.quickfix=Add 'break'
inspection.case.mismatch.display.name=Mismatched case in 'String' operation
inspection.case.mismatch.message.arg.is.lower=Method ''{0}()'' always returns {1}: the argument contains a lowercase symbol while the qualifier is uppercase-only
inspection.case.mismatch.message.arg.is.upper=Method ''{0}()'' always returns {1}: the argument contains an uppercase symbol while the qualifier is lowercase-only
inspection.case.mismatch.message.arg.is.lower=Method ''{0}()'' always returns {1}: the argument contains a lowercase symbol while the qualifier doesn''t contain lowercase symbols
inspection.case.mismatch.message.arg.is.upper=Method ''{0}()'' always returns {1}: the argument contains an uppercase symbol while the qualifier doesn''t contain uppercase symbols
inspection.case.mismatch.message.label.is.lower=Switch branch is unreachable: the label contains a lowercase symbol while the selector is uppercase-only
inspection.case.mismatch.message.label.is.upper=Switch branch is unreachable: the label contains an uppercase symbol while the selector is lowercase-only
@@ -1,28 +1,33 @@
import java.util.Locale;
class X {
void testEmpty() {
String prevFile = "";
if (prevFile.<warning descr="Method 'endsWith()' always returns false: the argument contains a lowercase symbol while the qualifier doesn't contain lowercase symbols">endsWith</warning>("-cfs")) {}
}
void test(String s1, String s2) {
if(s1.toLowerCase().<warning descr="Method 'startsWith()' always returns false: the argument contains an uppercase symbol while the qualifier is lowercase-only">startsWith</warning>("FOO")) {}
if(s1.toLowerCase().<warning descr="Method 'startsWith()' always returns false: the argument contains an uppercase symbol while the qualifier is lowercase-only">startsWith</warning>("FOO", 1)) {}
if(s1.toLowerCase().<warning descr="Method 'equals()' always returns false: the argument contains an uppercase symbol while the qualifier is lowercase-only">equals</warning>("FOO")) {}
if(s1.toLowerCase().<warning descr="Method 'startsWith()' always returns false: the argument contains an uppercase symbol while the qualifier doesn't contain uppercase symbols">startsWith</warning>("FOO")) {}
if(s1.toLowerCase().<warning descr="Method 'startsWith()' always returns false: the argument contains an uppercase symbol while the qualifier doesn't contain uppercase symbols">startsWith</warning>("FOO", 1)) {}
if(s1.toLowerCase().<warning descr="Method 'equals()' always returns false: the argument contains an uppercase symbol while the qualifier doesn't contain uppercase symbols">equals</warning>("FOO")) {}
if(s1.toLowerCase().equalsIgnoreCase("FOO")) {} // ok
if(s1.toLowerCase().<warning descr="Method 'endsWith()' always returns false: the argument contains an uppercase symbol while the qualifier is lowercase-only">endsWith</warning>("FOO")) {}
if(s1.toLowerCase().<warning descr="Method 'contains()' always returns false: the argument contains an uppercase symbol while the qualifier is lowercase-only">contains</warning>("FOO")) {}
if(s1.toLowerCase().<warning descr="Method 'indexOf()' always returns -1: the argument contains an uppercase symbol while the qualifier is lowercase-only">indexOf</warning>("FOO") == -1) {}
if(s1.toUpperCase(Locale.ENGLISH).<warning descr="Method 'startsWith()' always returns false: the argument contains a lowercase symbol while the qualifier is uppercase-only">startsWith</warning>("AAAAAAaAAA")) {}
if(s1.toLowerCase().<warning descr="Method 'endsWith()' always returns false: the argument contains an uppercase symbol while the qualifier doesn't contain uppercase symbols">endsWith</warning>("FOO")) {}
if(s1.toLowerCase().<warning descr="Method 'contains()' always returns false: the argument contains an uppercase symbol while the qualifier doesn't contain uppercase symbols">contains</warning>("FOO")) {}
if(s1.toLowerCase().<warning descr="Method 'indexOf()' always returns -1: the argument contains an uppercase symbol while the qualifier doesn't contain uppercase symbols">indexOf</warning>("FOO") == -1) {}
if(s1.toUpperCase(Locale.ENGLISH).<warning descr="Method 'startsWith()' always returns false: the argument contains a lowercase symbol while the qualifier doesn't contain lowercase symbols">startsWith</warning>("AAAAAAaAAA")) {}
String s3 = s1.toLowerCase();
if(s3.equals("")) {}
if(s3.<warning descr="Method 'equals()' always returns false: the argument contains an uppercase symbol while the qualifier is lowercase-only">equals</warning>("X")) {}
if(s3.<warning descr="Method 'equals()' always returns false: the argument contains an uppercase symbol while the qualifier is lowercase-only">equals</warning>("Hello " + s2)) {}
if(s3.<warning descr="Method 'equals()' always returns false: the argument contains an uppercase symbol while the qualifier doesn't contain uppercase symbols">equals</warning>("X")) {}
if(s3.<warning descr="Method 'equals()' always returns false: the argument contains an uppercase symbol while the qualifier doesn't contain uppercase symbols">equals</warning>("Hello " + s2)) {}
if(s3.equals(s2.toUpperCase())) {} // strange but possible if both contain no letters
if(s3.equals(s2.toUpperCase()+"!")) {} // also possible
if(s3.<warning descr="Method 'equals()' always returns false: the argument contains an uppercase symbol while the qualifier is lowercase-only">equals</warning>(s2.toUpperCase()+"!"+"X")) {}
if(s3.<warning descr="Method 'equals()' always returns false: the argument contains an uppercase symbol while the qualifier doesn't contain uppercase symbols">equals</warning>(s2.toUpperCase()+"!"+"X")) {}
}
void reassignParameter(String s) {
s = s.toLowerCase();
if (s.<warning descr="Method 'equals()' always returns false: the argument contains an uppercase symbol while the qualifier is lowercase-only">equals</warning>("Yes")) {
if (s.<warning descr="Method 'equals()' always returns false: the argument contains an uppercase symbol while the qualifier doesn't contain uppercase symbols">equals</warning>("Yes")) {
}
}