1 package com.github.sevntu.checkstyle.checks.coding;
2
3 public class InputAvoidConstantAsFirstOperandInConditionCheck {
4
5 private Object classField;
6
7 private boolean someFunction() {
8 return false;
9 }
10
11 private Object returnNull() {
12 return null;
13 }
14
15 public void allTypesCheck() {
16
17 Object someVariable = new Object();
18
19 final int constant = 5;
20 int testInt = 10;
21 float testConst = 5.0f;
22 boolean testBool = true;
23
24 if ((null) == someVariable) {}
25 if (5 == testInt) {}
26 if (constant == testInt) {}
27 if (5.0d == (Double) someVariable) {}
28 if (5.0f == (Float) someVariable) {}
29 if (5l == (Long) someVariable) {}
30 if (true == testBool) {}
31 if (false == testBool) {}
32 }
33
34
35
36
37 public void ifCheck() {
38 Object someVariable = new Object();
39 Object nullVariable = null;
40
41 if (null == null) {}
42
43
44 if (someVariable == null) {}
45 if (someVariable != null) {}
46 if (null == someVariable) {}
47 if (null != someVariable) {}
48
49
50 if (returnNull() == null) {}
51 if (returnNull() != null) {}
52 if (null == returnNull()) {}
53 if (null != returnNull()) {}
54
55
56 if (this.classField == null) {}
57 if (classField != null) {}
58 if (null == this.classField) {}
59 if (null != classField) {}
60
61
62 if (someVariable == nullVariable) {}
63 if (nullVariable == someVariable) {}
64
65
66 someVariable = (nullVariable == null) ? true : false;
67 someVariable = (null == nullVariable) ? true : false;
68
69
70 if (someFunction() && (someVariable == null)) {}
71 if (someFunction() && null == someVariable) {}
72 if (someFunction() && (null == someVariable)) {}
73 if ((null == someVariable) && someFunction()) {}
74 if (someFunction() || (null == someVariable) && someFunction()) {}
75
76 if (someVariable == null && null == someVariable) {}
77 if (null == someVariable && someVariable == null) {}
78 if (null == someVariable && null == someVariable) {}
79
80
81
82 if ((
83 null
84 == someVariable)
85 &&null==someVariable
86 || ( null == someVariable)) {}
87 }
88
89
90
91
92
93 public void whileCyclesCheck() {
94 Object someVariable = new Object();
95
96 while (someVariable == null) {}
97 while (null == someVariable) {}
98
99 do {
100
101 } while (null == someVariable);
102 }
103
104
105
106
107
108 public void forCyclesCheck() {
109 Object someVariable = new Object();
110
111 for (;null==someVariable;) {}
112 for (someVariable = null; null == someVariable; someVariable = null) {}
113 }
114
115 }