Skip to content

Commit 1d614c3

Browse files
committed
poartial fix for #46 - Sonarqube found problems in Checkstyle
1 parent 5ce771a commit 1d614c3

17 files changed

Lines changed: 72 additions & 83 deletions

src/checkstyle/com/puppycrawl/tools/checkstyle/CheckStyleTask.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ private void realExecute()
284284
log("compiled on " + compileTimestamp, Project.MSG_VERBOSE);
285285

286286
// Check for no arguments
287-
if ((mFileName == null) && (mFileSets.size() == 0)) {
287+
if ((mFileName == null) && mFileSets.isEmpty()) {
288288
throw new BuildException(
289289
"Must specify at least one of 'file' or nested 'fileset'.",
290290
getLocation());
@@ -449,7 +449,7 @@ protected AuditListener[] getListeners() throws ClassNotFoundException,
449449
final AuditListener[] listeners = new AuditListener[formatterCount];
450450

451451
// formatters
452-
if (mFormatters.size() == 0) {
452+
if (mFormatters.isEmpty()) {
453453
final OutputStream debug = new LogOutputStream(this,
454454
Project.MSG_DEBUG);
455455
final OutputStream err = new LogOutputStream(this, Project.MSG_ERR);

src/checkstyle/com/puppycrawl/tools/checkstyle/Checker.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import com.puppycrawl.tools.checkstyle.api.SeverityLevel;
3737
import com.puppycrawl.tools.checkstyle.api.SeverityLevelCounter;
3838
import com.puppycrawl.tools.checkstyle.api.Utils;
39+
3940
import java.io.File;
4041
import java.io.FileNotFoundException;
4142
import java.io.IOException;
@@ -44,8 +45,8 @@
4445
import java.util.List;
4546
import java.util.Locale;
4647
import java.util.Set;
48+
import java.util.SortedSet;
4749
import java.util.StringTokenizer;
48-
import java.util.TreeSet;
4950

5051
/**
5152
* This class provides the functionality to check a set of files.
@@ -254,7 +255,7 @@ public int process(List<File> aFiles)
254255
for (final File f : aFiles) {
255256
final String fileName = f.getAbsolutePath();
256257
fireFileStarted(fileName);
257-
final TreeSet<LocalizedMessage> fileMessages = Sets.newTreeSet();
258+
final SortedSet<LocalizedMessage> fileMessages = Sets.newTreeSet();
258259
try {
259260
final FileText theText = new FileText(f.getAbsoluteFile(),
260261
mCharset);
@@ -501,7 +502,8 @@ public void fireFileFinished(String aFileName)
501502
* @param aFileName the audited file
502503
* @param aErrors the audit errors from the file
503504
*/
504-
public void fireErrors(String aFileName, TreeSet<LocalizedMessage> aErrors)
505+
public void fireErrors(String aFileName,
506+
SortedSet<LocalizedMessage> aErrors)
505507
{
506508
final String stripped = getStrippedFileName(aFileName);
507509
for (final LocalizedMessage element : aErrors) {

src/checkstyle/com/puppycrawl/tools/checkstyle/api/MessageDispatcher.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
////////////////////////////////////////////////////////////////////////////////
1919
package com.puppycrawl.tools.checkstyle.api;
2020

21-
import java.util.TreeSet;
21+
import java.util.SortedSet;
2222

2323
/**
2424
* Used by FileSetChecks to distribute AuditEvents to AuditListeners.
@@ -43,5 +43,5 @@ public interface MessageDispatcher
4343
* @param aFileName the audited file
4444
* @param aErrors the audit errors from the file
4545
*/
46-
void fireErrors(String aFileName, TreeSet<LocalizedMessage> aErrors);
46+
void fireErrors(String aFileName, SortedSet<LocalizedMessage> aErrors);
4747
}

src/checkstyle/com/puppycrawl/tools/checkstyle/checks/blocks/EmptyBlockCheck.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,13 @@ public void visitToken(DetailAST aAST)
101101
aAST.getText());
102102
}
103103
}
104-
else if (getAbstractOption() == BlockOption.TEXT) {
105-
if (!hasText(slistAST)) {
106-
log(slistAST.getLineNo(),
107-
slistAST.getColumnNo(),
108-
"block.empty",
109-
aAST.getText());
110-
}
104+
else if (getAbstractOption() == BlockOption.TEXT
105+
&& !hasText(slistAST))
106+
{
107+
log(slistAST.getLineNo(),
108+
slistAST.getColumnNo(),
109+
"block.empty",
110+
aAST.getText());
111111
}
112112
}
113113
}

src/checkstyle/com/puppycrawl/tools/checkstyle/checks/coding/CovariantEqualsCheck.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ public void visitToken(DetailAST aAST)
6969
if (objBlock != null) {
7070
DetailAST child = objBlock.getFirstChild();
7171
while (child != null) {
72-
if (child.getType() == TokenTypes.METHOD_DEF) {
73-
if (CheckUtils.isEqualsMethod(child)) {
74-
if (hasObjectParameter(child)) {
75-
hasEqualsObject = true;
76-
}
77-
else {
78-
mEqualsMethods.add(child);
79-
}
72+
if (child.getType() == TokenTypes.METHOD_DEF
73+
&& CheckUtils.isEqualsMethod(child))
74+
{
75+
if (hasObjectParameter(child)) {
76+
hasEqualsObject = true;
77+
}
78+
else {
79+
mEqualsMethods.add(child);
8080
}
8181
}
8282
child = child.getNextSibling();

src/checkstyle/com/puppycrawl/tools/checkstyle/checks/coding/EqualsAvoidNullCheck.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,18 @@ public void visitToken(final DetailAST aMethodCall)
123123
final DetailAST expr = dot.getNextSibling().getFirstChild();
124124

125125
if ("equals".equals(method.getText())
126-
|| (!mIgnoreEqualsIgnoreCase && "equalsIgnoreCase"
127-
.equals(method.getText())))
126+
&& containsOneArg(expr) && containsAllSafeTokens(expr))
128127
{
129-
if (containsOneArg(expr) && containsAllSafeTokens(expr)) {
130-
log(aMethodCall.getLineNo(), aMethodCall.getColumnNo(),
131-
"equals".equals(method.getText())
132-
? "equals.avoid.null"
133-
: "equalsIgnoreCase.avoid.null");
134-
}
128+
log(aMethodCall.getLineNo(), aMethodCall.getColumnNo(),
129+
"equals.avoid.null");
130+
}
131+
132+
if (!mIgnoreEqualsIgnoreCase
133+
&& "equalsIgnoreCase".equals(method.getText())
134+
&& containsOneArg(expr) && containsAllSafeTokens(expr))
135+
{
136+
log(aMethodCall.getLineNo(), aMethodCall.getColumnNo(),
137+
"equalsIgnoreCase.avoid.null");
135138
}
136139
}
137140

src/checkstyle/com/puppycrawl/tools/checkstyle/checks/coding/FallThroughCheck.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,14 @@ public void visitToken(DetailAST aAST)
133133

134134
final DetailAST slist = aAST.findFirstToken(TokenTypes.SLIST);
135135

136-
if (!isTerminated(slist, true, true)) {
137-
if (!hasFallTruComment(aAST, nextGroup)) {
138-
if (!isLastGroup) {
139-
log(nextGroup, "fall.through");
140-
}
141-
else {
142-
log(aAST, "fall.through.last");
143-
}
136+
if (!isTerminated(slist, true, true)
137+
&& !hasFallTruComment(aAST, nextGroup))
138+
{
139+
if (!isLastGroup) {
140+
log(nextGroup, "fall.through");
141+
}
142+
else {
143+
log(aAST, "fall.through.last");
144144
}
145145
}
146146
}

src/checkstyle/com/puppycrawl/tools/checkstyle/checks/coding/OneStatementPerLineCheck.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,11 @@ public void leaveToken(DetailAST aAst)
9999
private void visitExpr(DetailAST aAst)
100100
{
101101
mExprDepth++;
102-
if (mExprDepth == 1) {
103-
if (!mInForHeader && (mLastStatementEnd == aAst.getLineNo())) {
104-
log(aAst, "multiple.statements.line");
105-
}
102+
if (mExprDepth == 1
103+
&& !mInForHeader
104+
&& (mLastStatementEnd == aAst.getLineNo()))
105+
{
106+
log(aAst, "multiple.statements.line");
106107
}
107108
}
108109

src/checkstyle/com/puppycrawl/tools/checkstyle/checks/coding/RedundantThrowsCheck.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,9 @@ private void checkException(FullIdent aExc, List<ClassInfo> aKnownExcs)
134134
final ClassInfo newClassInfo =
135135
createClassInfo(new Token(aExc), getCurrentClassName());
136136

137-
if (!mAllowUnchecked) {
138-
if (isUnchecked(newClassInfo.getClazz())) {
139-
log(aExc.getLineNo(), aExc.getColumnNo(),
140-
"redundant.throws.unchecked", aExc.getText());
141-
}
137+
if (!mAllowUnchecked && isUnchecked(newClassInfo.getClazz())) {
138+
log(aExc.getLineNo(), aExc.getColumnNo(),
139+
"redundant.throws.unchecked", aExc.getText());
142140
}
143141

144142
boolean shouldAdd = true;

src/checkstyle/com/puppycrawl/tools/checkstyle/checks/duplicates/StrictDuplicateCodeCheck.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -430,11 +430,8 @@ private void findDuplicateFromLine(
430430
}
431431

432432
final Collection<Integer> ignoreEntries = aIgnore.get(aILine);
433-
// avoid Integer constructor whenever we can
434-
if (ignoreEntries != null) {
435-
if (ignoreEntries.contains(jLine)) {
436-
continue;
437-
}
433+
if (ignoreEntries != null && ignoreEntries.contains(jLine)) {
434+
continue;
438435
}
439436

440437
final int duplicateLines =

0 commit comments

Comments
 (0)