From abfc952fd0ed88f6246b1d969a8a980ea63f0bd6 Mon Sep 17 00:00:00 2001 From: Michal Kordas Date: Sat, 22 Aug 2015 00:13:53 +0200 Subject: [PATCH] Fix suspicious getters and setters. #1555 Fixes `SuspiciousGetterSetter` inspection violations. Description: >Reports suspicious getter or setter methods. A getter or setter is suspicious if it accesses a different field than would be expected by its name. --- .../checkstyle/ant/CheckstyleAntTask.java | 10 ++--- .../tools/checkstyle/api/AuditEvent.java | 24 +++++------ .../tools/checkstyle/api/Comment.java | 40 +++++++++---------- .../tools/checkstyle/api/FullIdent.java | 10 ++--- .../tools/checkstyle/api/LineColumn.java | 14 +++---- .../checkstyle/api/LocalizedMessage.java | 20 +++++----- 6 files changed, 59 insertions(+), 59 deletions(-) diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/ant/CheckstyleAntTask.java b/src/main/java/com/puppycrawl/tools/checkstyle/ant/CheckstyleAntTask.java index 67d88b857..868def572 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/ant/CheckstyleAntTask.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/ant/CheckstyleAntTask.java @@ -90,7 +90,7 @@ public class CheckstyleAntTask extends Task { private final List overrideProps = Lists.newArrayList(); /** The name of the properties file */ - private File propertiesFile; + private File properties; /** The maximum number of errors that are tolerated. */ private int maxErrors; @@ -236,7 +236,7 @@ public class CheckstyleAntTask extends Task { * @param props the properties File to use */ public void setProperties(File props) { - propertiesFile = props; + properties = props; } //////////////////////////////////////////////////////////////////////////// @@ -384,15 +384,15 @@ public class CheckstyleAntTask extends Task { final Properties retVal = new Properties(); // Load the properties file if specified - if (propertiesFile != null) { + if (properties != null) { FileInputStream inStream = null; try { - inStream = new FileInputStream(propertiesFile); + inStream = new FileInputStream(properties); retVal.load(inStream); } catch (final IOException e) { throw new BuildException("Error loading Properties file '" - + propertiesFile + "'", e, getLocation()); + + properties + "'", e, getLocation()); } finally { Closeables.closeQuietly(inStream); diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/api/AuditEvent.java b/src/main/java/com/puppycrawl/tools/checkstyle/api/AuditEvent.java index 308d259b4..b967be5e8 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/api/AuditEvent.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/api/AuditEvent.java @@ -45,7 +45,7 @@ public final class AuditEvent /** Filename event associated with **/ private final String fileName; /** Message associated with the event **/ - private final LocalizedMessage message; + private final LocalizedMessage localizedMessage; /** * Creates a new instance. @@ -69,12 +69,12 @@ public final class AuditEvent * * @param src source of the event * @param fileName file associated with the event - * @param message the actual message + * @param localizedMessage the actual message */ - public AuditEvent(Object src, String fileName, LocalizedMessage message) { + public AuditEvent(Object src, String fileName, LocalizedMessage localizedMessage) { super(src); this.fileName = fileName; - this.message = message; + this.localizedMessage = localizedMessage; } /** @@ -91,7 +91,7 @@ public final class AuditEvent * @return an integer representing the line number in the file source code. */ public int getLine() { - return message.getLineNo(); + return localizedMessage.getLineNo(); } /** @@ -99,21 +99,21 @@ public final class AuditEvent * @return the event message */ public String getMessage() { - return message.getMessage(); + return localizedMessage.getMessage(); } /** @return the column associated with the message **/ public int getColumn() { - return message.getColumnNo(); + return localizedMessage.getColumnNo(); } /** @return the audit event severity level **/ public SeverityLevel getSeverityLevel() { - if (message == null) { + if (localizedMessage == null) { return SeverityLevel.INFO; } else { - return message.getSeverityLevel(); + return localizedMessage.getSeverityLevel(); } } @@ -122,16 +122,16 @@ public final class AuditEvent * null. */ public String getModuleId() { - return message.getModuleId(); + return localizedMessage.getModuleId(); } /** @return the name of the source for the message **/ public String getSourceName() { - return message.getSourceName(); + return localizedMessage.getSourceName(); } /** @return the localized message **/ public LocalizedMessage getLocalizedMessage() { - return message; + return localizedMessage; } } diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/api/Comment.java b/src/main/java/com/puppycrawl/tools/checkstyle/api/Comment.java index 25b75f617..87e4678c5 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/api/Comment.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/api/Comment.java @@ -29,16 +29,16 @@ public class Comment implements TextBlock { private final String[] text; /** Number of first line of the comment. */ - private final int firstLine; + private final int startLineNo; /** Number of last line of the comment. */ - private final int lastLine; + private final int endLineNo; /** Number of first column of the comment. */ - private final int firstCol; + private final int startColNo; /** Number of last column of the comment. */ - private final int lastCol; + private final int endColNo; /** * Creates new instance. @@ -51,10 +51,10 @@ public class Comment implements TextBlock { final int lastLine, final int lastCol) { this.text = new String[text.length]; System.arraycopy(text, 0, this.text, 0, this.text.length); - firstLine = lastLine - this.text.length + 1; - this.lastLine = lastLine; - this.firstCol = firstCol; - this.lastCol = lastCol; + startLineNo = lastLine - this.text.length + 1; + this.endLineNo = lastLine; + this.startColNo = firstCol; + this.endColNo = lastCol; } @Override @@ -64,41 +64,41 @@ public class Comment implements TextBlock { @Override public final int getStartLineNo() { - return firstLine; + return startLineNo; } @Override public final int getEndLineNo() { - return lastLine; + return endLineNo; } @Override public int getStartColNo() { - return firstCol; + return startColNo; } @Override public int getEndColNo() { - return lastCol; + return endColNo; } @Override - public boolean intersects(int startLineNo, int startColNo, - int endLineNo, int endColNo) { + public boolean intersects(int startLine, int startCol, + int endLine, int endCol) { // compute a single number for start and end // to simplify conditional logic final long multiplier = Integer.MAX_VALUE; - final long thisStart = firstLine * multiplier + firstCol; - final long thisEnd = lastLine * multiplier + lastCol; - final long inStart = startLineNo * multiplier + startColNo; - final long inEnd = endLineNo * multiplier + endColNo; + final long thisStart = startLineNo * multiplier + startColNo; + final long thisEnd = endLineNo * multiplier + endColNo; + final long inStart = startLine * multiplier + startCol; + final long inEnd = endLine * multiplier + endCol; return !(thisEnd < inStart || inEnd < thisStart); } @Override public String toString() { - return "Comment[" + firstLine + ":" + firstCol + "-" - + lastLine + ":" + lastCol + "]"; + return "Comment[" + startLineNo + ":" + startColNo + "-" + + endLineNo + ":" + endColNo + "]"; } } diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/api/FullIdent.java b/src/main/java/com/puppycrawl/tools/checkstyle/api/FullIdent.java index 0f5fff96f..64f17cff8 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/api/FullIdent.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/api/FullIdent.java @@ -45,7 +45,7 @@ public final class FullIdent { /** The line number **/ private int lineNo; /** The column number **/ - private int colNo; + private int columnNo; /** Hide default constructor */ private FullIdent() { @@ -63,7 +63,7 @@ public final class FullIdent { /** @return the column number **/ public int getColumnNo() { - return colNo; + return columnNo; } /** @@ -87,11 +87,11 @@ public final class FullIdent { else if (ast.getLineNo() > 0) { lineNo = Math.min(lineNo, ast.getLineNo()); } - if (colNo == 0) { - colNo = ast.getColumnNo(); + if (columnNo == 0) { + columnNo = ast.getColumnNo(); } else if (ast.getColumnNo() > 0) { - colNo = Math.min(colNo, ast.getColumnNo()); + columnNo = Math.min(columnNo, ast.getColumnNo()); } } 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 603b7b349..fc905e6e8 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/api/LineColumn.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/api/LineColumn.java @@ -32,16 +32,16 @@ public class LineColumn implements Comparable { private final int line; /** The zero-based column number */ - private final int col; + private final int column; /** * Constructs a new pair of line and column numbers. * @param line the one-based line number - * @param col the zero-based column number + * @param column the zero-based column number */ - public LineColumn(int line, int col) { + public LineColumn(int line, int column) { this.line = line; - this.col = col; + this.column = column; } /** @return the one-based line number */ @@ -51,7 +51,7 @@ public class LineColumn implements Comparable { /** @return the zero-based column number */ public int getColumn() { - return col; + return column; } @Override @@ -74,11 +74,11 @@ public class LineColumn implements Comparable { } final LineColumn lineColumn = (LineColumn) o; return Objects.equals(line, lineColumn.line) - && Objects.equals(col, lineColumn.col); + && Objects.equals(column, lineColumn.column); } @Override public int hashCode() { - return Objects.hash(line, col); + return Objects.hash(line, column); } } diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/api/LocalizedMessage.java b/src/main/java/com/puppycrawl/tools/checkstyle/api/LocalizedMessage.java index 22455383c..205652113 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/api/LocalizedMessage.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/api/LocalizedMessage.java @@ -67,7 +67,7 @@ public final class LocalizedMessage /** The line number **/ private final int lineNo; /** The column number **/ - private final int colNo; + private final int columnNo; /** The severity level **/ private final SeverityLevel severityLevel; @@ -94,7 +94,7 @@ public final class LocalizedMessage * Creates a new {@code LocalizedMessage} instance. * * @param lineNo line number associated with the message - * @param colNo column number associated with the message + * @param columnNo column number associated with the message * @param bundle resource bundle name * @param key the key to locate the translation * @param args arguments for the translation @@ -104,7 +104,7 @@ public final class LocalizedMessage * @param customMessage optional custom message overriding the default */ public LocalizedMessage(int lineNo, - int colNo, + int columnNo, String bundle, String key, Object[] args, @@ -113,7 +113,7 @@ public final class LocalizedMessage Class sourceClass, String customMessage) { this.lineNo = lineNo; - this.colNo = colNo; + this.columnNo = columnNo; this.key = key; if (args == null) { @@ -133,7 +133,7 @@ public final class LocalizedMessage * Creates a new {@code LocalizedMessage} instance. * * @param lineNo line number associated with the message - * @param colNo column number associated with the message + * @param columnNo column number associated with the message * @param bundle resource bundle name * @param key the key to locate the translation * @param args arguments for the translation @@ -142,7 +142,7 @@ public final class LocalizedMessage * @param customMessage optional custom message overriding the default */ public LocalizedMessage(int lineNo, - int colNo, + int columnNo, String bundle, String key, Object[] args, @@ -150,7 +150,7 @@ public final class LocalizedMessage Class sourceClass, String customMessage) { this(lineNo, - colNo, + columnNo, bundle, key, args, @@ -218,7 +218,7 @@ public final class LocalizedMessage } final LocalizedMessage localizedMessage = (LocalizedMessage) object; return Objects.equals(lineNo, localizedMessage.lineNo) - && Objects.equals(colNo, localizedMessage.colNo) + && Objects.equals(columnNo, localizedMessage.columnNo) && Objects.equals(severityLevel, localizedMessage.severityLevel) && Objects.equals(moduleId, localizedMessage.moduleId) && Objects.equals(key, localizedMessage.key) @@ -230,7 +230,7 @@ public final class LocalizedMessage @Override public int hashCode() { - return Objects.hash(lineNo, colNo, severityLevel, moduleId, key, bundle, sourceClass, + return Objects.hash(lineNo, columnNo, severityLevel, moduleId, key, bundle, sourceClass, customMessage, Arrays.hashCode(args)); } @@ -306,7 +306,7 @@ public final class LocalizedMessage /** @return the column number **/ public int getColumnNo() { - return colNo; + return columnNo; } /** @return the severity level **/