View Javadoc
1   /*
2   StringLiteralEquality
3   
4   
5   */
6   
7   package com.puppycrawl.tools.checkstyle.checks.coding.stringliteralequality;
8   
9   public class InputStringLiteralEqualityConcatenatedString {
10  
11      public void testMethod() {
12          String s = "abc";
13          String p = "asd";
14          if (s == "a" + "bc") { // violation
15          }
16  
17          if ("a" + "bc" == s) { // violation
18          }
19  
20          if ("a" + ("b" + "c") != s) { // violation
21          }
22  
23          if (s == "a" + "b" + "c") { // violation
24          }
25          if ((s += "asd") != p) { // ok, can't be detected as check in not type aware.
26          }
27  
28          if ((s += "asd") == s + (p + "asd")) { // violation
29          }
30  
31          if ((s += "asd") != s + "p" + p) { // violation
32          }
33  
34          if (s != s + "p" + p) { // violation
35          }
36  
37          String a = (s + "asd") == null ? "asd" : s; // violation
38  
39          String b = s + "ab" + p != null ? s : p; // violation
40  
41          String c = ("ab" + s) != null ? // violation
42                  (p + "ab" == null ? p : s) : p; // violation
43  
44      }
45  
46  }