Findbugs violation: defines compareTo(LineColumn) and uses Object.equals(). #911

This commit is contained in:
Roman Ivanov 2015-05-15 23:52:15 -07:00
parent e6034ec381
commit 6cdcfc135a
5 changed files with 80 additions and 8 deletions

View File

@ -27,11 +27,6 @@
<Class name="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocUtils" />
<Bug pattern="REC_CATCH_EXCEPTION" />
</Match>
<Match>
<!-- till #911 -->
<Package name="~com\.puppycrawl\.tools\.checkstyle.*" />
<Bug pattern="EQ_COMPARETO_USE_OBJECT_EQUALS" />
</Match>
<Match>
<!-- see a reason of suppression at #910 -->
<Class name="com.puppycrawl.tools.checkstyle.checks.UniquePropertiesCheck$UniqueProperties" />

View File

@ -664,7 +664,7 @@
<regex><pattern>.*.api.JavadocTagInfo</pattern><branchRate>25</branchRate><lineRate>77</lineRate></regex>
<regex><pattern>.*.api.JavadocTagInfo\$.*</pattern><branchRate>0</branchRate><lineRate>8</lineRate></regex>
<regex><pattern>.*.api.JavadocTokenTypes</pattern><branchRate>100</branchRate><lineRate>0</lineRate></regex>
<regex><pattern>.*.api.LineColumn</pattern><branchRate>0</branchRate><lineRate>60</lineRate></regex>
<regex><pattern>.*.api.LineColumn</pattern><branchRate>0</branchRate><lineRate>33</lineRate></regex>
<regex><pattern>.*.api.LocalizedMessage</pattern><branchRate>53</branchRate><lineRate>67</lineRate></regex>
<regex><pattern>.*.api.LocalizedMessage\$.*</pattern><branchRate>41</branchRate><lineRate>66</lineRate></regex>
<regex><pattern>.*.api.ScopeUtils</pattern><branchRate>0</branchRate><lineRate>0</lineRate></regex>
@ -889,11 +889,11 @@
<regex><pattern>.*.filters.IntRangeFilter</pattern><branchRate>100</branchRate><lineRate>90</lineRate></regex>
<regex><pattern>.*.filters.SuppressElement</pattern><branchRate>69</branchRate><lineRate>78</lineRate></regex>
<regex><pattern>.*.filters.SuppressionCommentFilter</pattern><branchRate>83</branchRate><lineRate>87</lineRate></regex>
<regex><pattern>.*.filters.SuppressionCommentFilter\$.*</pattern><branchRate>87</branchRate><lineRate>84</lineRate></regex>
<regex><pattern>.*.filters.SuppressionCommentFilter\$.*</pattern><branchRate>41</branchRate><lineRate>69</lineRate></regex>
<regex><pattern>.*.filters.SuppressionFilter</pattern><branchRate>0</branchRate><lineRate>0</lineRate></regex>
<regex><pattern>.*.filters.SuppressionsLoader</pattern><branchRate>68</branchRate><lineRate>77</lineRate></regex>
<regex><pattern>.*.filters.SuppressWithNearbyCommentFilter</pattern><branchRate>76</branchRate><lineRate>89</lineRate></regex>
<regex><pattern>.*.filters.SuppressWithNearbyCommentFilter\$.*</pattern><branchRate>81</branchRate><lineRate>75</lineRate></regex>
<regex><pattern>.*.filters.SuppressWithNearbyCommentFilter\$.*</pattern><branchRate>47</branchRate><lineRate>63</lineRate></regex>
</regexes>
</check>

View File

@ -19,6 +19,8 @@
package com.puppycrawl.tools.checkstyle.api;
import java.util.Objects;
/**
* Immutable line and column numbers.
*
@ -64,4 +66,26 @@ public class LineColumn implements Comparable<LineColumn>
? this.getLine() - lineColumn.getLine()
: this.getColumn() - lineColumn.getColumn();
}
/** {@inheritDoc} */
@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
final LineColumn that = (LineColumn) o;
return Objects.equals(line, that.line)
&& Objects.equals(col, that.col);
}
/** {@inheritDoc} */
@Override
public int hashCode()
{
return Objects.hash(line, col);
}
}

View File

@ -32,6 +32,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
@ -191,6 +192,31 @@ public class SuppressWithNearbyCommentFilter
return firstLine - other.firstLine;
}
/** {@inheritDoc} */
@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
final Tag tag = (Tag) o;
return Objects.equals(firstLine, tag.firstLine)
&& Objects.equals(lastLine, tag.lastLine)
&& Objects.equals(text, tag.text)
&& Objects.equals(tagCheckRegexp, tag.tagCheckRegexp)
&& Objects.equals(tagMessageRegexp, tag.tagMessageRegexp);
}
/** {@inheritDoc} */
@Override
public int hashCode()
{
return Objects.hash(text, firstLine, lastLine, tagCheckRegexp, tagMessageRegexp);
}
/**
* Determines whether the source of an audit event
* matches the text of this tag.

View File

@ -31,6 +31,7 @@ import java.lang.ref.WeakReference;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
@ -195,6 +196,32 @@ public class SuppressionCommentFilter
return line - object.line;
}
/** {@inheritDoc} */
@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
final Tag tag = (Tag) o;
return Objects.equals(line, tag.line)
&& Objects.equals(column, tag.column)
&& Objects.equals(on, tag.on)
&& Objects.equals(text, tag.text)
&& Objects.equals(tagCheckRegexp, tag.tagCheckRegexp)
&& Objects.equals(tagMessageRegexp, tag.tagMessageRegexp);
}
/** {@inheritDoc} */
@Override
public int hashCode()
{
return Objects.hash(text, line, column, on, tagCheckRegexp, tagMessageRegexp);
}
/**
* Determines whether the source of an audit event
* matches the text of this tag.