From a244f057057913003dd17e952ee76a844f0fb76b Mon Sep 17 00:00:00 2001 From: Michal Kordas Date: Sat, 22 Aug 2015 23:03:45 +0200 Subject: [PATCH] Remove calls to simple getters withing classes. #1555 Fixes `CallToSimpleGetterInClass` inspection violations. Description: >Reports any calls to a simple property getter from within the property's class. A simple property getter is defined as one which simply returns the value of a field, and does no other calculation. Such simple getter calls may be safely inlined, at a small performance improvement. Some coding standards also suggest against the use of simple getters for code clarity reasons. --- .../checkstyle/api/AbstractFileSetCheck.java | 28 +++++++++---------- .../tools/checkstyle/api/JavadocTagInfo.java | 4 +-- .../checkstyle/api/LocalizedMessage.java | 8 +++--- .../sizes/ExecutableStatementCountCheck.java | 12 ++------ 4 files changed, 22 insertions(+), 30 deletions(-) diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/api/AbstractFileSetCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/api/AbstractFileSetCheck.java index 084e1c9b8..79dc4368d 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/api/AbstractFileSetCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/api/AbstractFileSetCheck.java @@ -69,12 +69,12 @@ public abstract class AbstractFileSetCheck @Override public final SortedSet process(File file, List lines) { - getMessageCollector().reset(); + messageCollector.reset(); // Process only what interested in if (Utils.fileExtensionMatches(file, fileExtensions)) { processFiltered(file, lines); } - return getMessageCollector().getMessages(); + return messageCollector.getMessages(); } @Override @@ -148,16 +148,16 @@ public abstract class AbstractFileSetCheck @Override public final void log(int lineNo, int colNo, String key, Object... args) { - getMessageCollector().add( - new LocalizedMessage(lineNo, - colNo, - getMessageBundle(), - key, - args, - getSeverityLevel(), - getId(), - getClass(), - getCustomMessages().get(key))); + messageCollector.add( + new LocalizedMessage(lineNo, + colNo, + getMessageBundle(), + key, + args, + getSeverityLevel(), + getId(), + getClass(), + getCustomMessages().get(key))); } /** @@ -167,9 +167,9 @@ public abstract class AbstractFileSetCheck * @param fileName the audited file */ protected final void fireErrors(String fileName) { - final SortedSet errors = getMessageCollector() + final SortedSet errors = messageCollector .getMessages(); - getMessageCollector().reset(); + messageCollector.reset(); getMessageDispatcher().fireErrors(fileName, errors); } } diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/api/JavadocTagInfo.java b/src/main/java/com/puppycrawl/tools/checkstyle/api/JavadocTagInfo.java index 12a45e2d5..7ce11a464 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/api/JavadocTagInfo.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/api/JavadocTagInfo.java @@ -354,8 +354,8 @@ public enum JavadocTagInfo { new ImmutableMap.Builder<>(); for (final JavadocTagInfo tag : JavadocTagInfo.values()) { - textToTagBuilder.put(tag.getText(), tag); - nameToTagBuilder.put(tag.getName(), tag); + textToTagBuilder.put(tag.text, tag); + nameToTagBuilder.put(tag.name, tag); } TEXT_TO_TAG = textToTagBuilder.build(); 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 205652113..1ce67de79 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/api/LocalizedMessage.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/api/LocalizedMessage.java @@ -350,14 +350,14 @@ public final class LocalizedMessage @Override public int compareTo(LocalizedMessage other) { - int result = Integer.compare(getLineNo(), other.getLineNo()); + int result = Integer.compare(lineNo, other.lineNo); - if (getLineNo() == other.getLineNo()) { - if (getColumnNo() == other.getColumnNo()) { + if (lineNo == other.lineNo) { + if (columnNo == other.columnNo) { result = getMessage().compareTo(other.getMessage()); } else { - result = Integer.compare(getColumnNo(), other.getColumnNo()); + result = Integer.compare(columnNo, other.columnNo); } } return result; diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/sizes/ExecutableStatementCountCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/sizes/ExecutableStatementCountCheck.java index 1c3dd8f1f..ec6581937 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/sizes/ExecutableStatementCountCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/sizes/ExecutableStatementCountCheck.java @@ -84,14 +84,6 @@ public final class ExecutableStatementCountCheck }; } - /** - * Gets the maximum threshold. - * @return the maximum threshold. - */ - public int getMax() { - return max; - } - /** * Sets the maximum threshold. * @param max the maximum threshold. @@ -156,9 +148,9 @@ public final class ExecutableStatementCountCheck */ private void leaveMemberDef(DetailAST ast) { final int count = context.getCount(); - if (count > getMax()) { + if (count > max) { log(ast.getLineNo(), ast.getColumnNo(), - MSG_KEY, count, getMax()); + MSG_KEY, count, max); } context = contextStack.pop(); }