From 6cdcfc135ab45c2ab0c69080b89b4baa360fed16 Mon Sep 17 00:00:00 2001 From: Roman Ivanov Date: Fri, 15 May 2015 23:52:15 -0700 Subject: [PATCH] Findbugs violation: defines compareTo(LineColumn) and uses Object.equals(). #911 --- config/findbugs-exclude.xml | 5 ---- pom.xml | 6 ++--- .../tools/checkstyle/api/LineColumn.java | 24 +++++++++++++++++ .../SuppressWithNearbyCommentFilter.java | 26 ++++++++++++++++++ .../filters/SuppressionCommentFilter.java | 27 +++++++++++++++++++ 5 files changed, 80 insertions(+), 8 deletions(-) diff --git a/config/findbugs-exclude.xml b/config/findbugs-exclude.xml index ed130d7b6..fdda9e04d 100644 --- a/config/findbugs-exclude.xml +++ b/config/findbugs-exclude.xml @@ -27,11 +27,6 @@ - - - - - diff --git a/pom.xml b/pom.xml index 95ea05d74..a1e2103b3 100644 --- a/pom.xml +++ b/pom.xml @@ -664,7 +664,7 @@ .*.api.JavadocTagInfo2577 .*.api.JavadocTagInfo\$.*08 .*.api.JavadocTokenTypes1000 - .*.api.LineColumn060 + .*.api.LineColumn033 .*.api.LocalizedMessage5367 .*.api.LocalizedMessage\$.*4166 .*.api.ScopeUtils00 @@ -889,11 +889,11 @@ .*.filters.IntRangeFilter10090 .*.filters.SuppressElement6978 .*.filters.SuppressionCommentFilter8387 - .*.filters.SuppressionCommentFilter\$.*8784 + .*.filters.SuppressionCommentFilter\$.*4169 .*.filters.SuppressionFilter00 .*.filters.SuppressionsLoader6877 .*.filters.SuppressWithNearbyCommentFilter7689 - .*.filters.SuppressWithNearbyCommentFilter\$.*8175 + .*.filters.SuppressWithNearbyCommentFilter\$.*4763 diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/api/LineColumn.java b/src/main/java/com/puppycrawl/tools/checkstyle/api/LineColumn.java index 8a57f977b..429d3da13 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/api/LineColumn.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/api/LineColumn.java @@ -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 ? 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); + } } diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/filters/SuppressWithNearbyCommentFilter.java b/src/main/java/com/puppycrawl/tools/checkstyle/filters/SuppressWithNearbyCommentFilter.java index 0c1c33313..f3502b5a7 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/filters/SuppressWithNearbyCommentFilter.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/filters/SuppressWithNearbyCommentFilter.java @@ -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. diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/filters/SuppressionCommentFilter.java b/src/main/java/com/puppycrawl/tools/checkstyle/filters/SuppressionCommentFilter.java index 0e6ba2525..da9fdf783 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/filters/SuppressionCommentFilter.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/filters/SuppressionCommentFilter.java @@ -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.