Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Apr 27, 2018
2 parents c1da438 + d3c17e4 commit 89e522f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@
<module name="AvoidInlineConditionals"/>
<module name="CovariantEquals"/>
<module name="EmptyStatement"/>
<module name="EqualsAvoidNull"/>
<module name="EqualsHashCode"/>
<module name="FinalLocalVariable"/>
<module name="HiddenField">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,18 @@ public void allowsDiamondOperatorUsage() throws Exception {
this.runValidation("ValidDiamondsUsage.java", true);
}

/**
* CheckstyleValidator can allow usage of string literals on either sides.
* E.g. both {@code txt.equals("contents")}
* and {@code "contents".equals(txt)} are valid.
* @throws Exception If error
*/
@Test
public void allowsStringLiteralsOnBothSideInComparisons()
throws Exception {
this.runValidation("ValidLiteralComparisonCheck.java", true);
}

/**
* Convert file name to URL.
* @param file The file
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Hello.
*/
package foo;

/**
* Simple.
* @author John Smith (john@example.com)
* @version $Id$
* @since 1.0
*/
public final class ValidLiteralComparisonCheck {
/**
* Some text.
*/
private final String text;

/**
* Constructor.
* @param txt Some text.
*/
public ValidLiteralCheck(final String txt) {
this.text = txt;
}

/**
* Method using input.equals("contents")
* instead of "contents".equals(input).
*/
public void validStringComparison() {
System.out.println(this.text.equals("contents"));
System.out.println("contents".equals(this.text));
}
}

0 comments on commit 89e522f

Please sign in to comment.