aboutsummaryrefslogtreecommitdiff
path: root/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenStringLiteralEquality.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenStringLiteralEquality.java')
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenStringLiteralEquality.java43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenStringLiteralEquality.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenStringLiteralEquality.java
new file mode 100644
index 000000000..db67804b1
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenStringLiteralEquality.java
@@ -0,0 +1,43 @@
+package com.puppycrawl.tools.checkstyle.checks.descendanttoken;
+
+public class InputDescendantTokenStringLiteralEquality
+{
+ void foo(String name)
+ {
+ if (name == "Lars")
+ {
+ // flagged, should use equals
+ }
+
+ if ("Oleg" == name)
+ {
+ // flagged, should use equals
+ }
+
+ if ("Oliver" == "Oliver")
+ {
+ // doesn't make much sense because this can be evaluated
+ // to true at compile time, but is flagged anyway
+ }
+
+ String compare = "Rick";
+ if (name == compare)
+ {
+ // currently not flagged.
+ //
+ // Implementing this is very complicated, we would need
+ // - type info on the == operands
+ // - prevent false alarms where the user explicitly wants
+ // to compare object identities
+ //
+ // My current feeling is that we should leave finding
+ // this one to manual code inspections. After all MCI is
+ // what some of us get paid for :-)
+ }
+
+ if ("Rick".toUpperCase(java.util.Locale.getDefault()) == "Rick".toLowerCase(java.util.Locale.getDefault()))
+ {
+ // completly dynamic, don't flag
+ }
+ }
+}