Skip to content

Commit

Permalink
Issue checkstyle#3496: Enforce ReturnCount max=1 in com.puppycrawl.to…
Browse files Browse the repository at this point in the history
…ols.checkstyle.gui, com.puppycrawl.tools.checkstyle.whitespace, com.puppycrawl.tools.checkstyle.doclets
  • Loading branch information
Vladlis committed Apr 22, 2017
1 parent 2ad6932 commit aed090b
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 29 deletions.
3 changes: 1 addition & 2 deletions config/suppressions.xml
Expand Up @@ -93,6 +93,5 @@
<!-- Until https://github.com/checkstyle/checkstyle/issues/3496 -->
<suppress id="returnCountMaxOne" files=".*[\\/]ant[\\/]|.*[\\/]filters[\\/]|.*[\\/]api[\\/]|.*[\\/]annotation[\\/]|
|.*[\\/]coding[\\/]|.*[\\/]design[\\/]|.*[\\/]imports[\\/]|.*[\\/]indentation[\\/]|.*[\\/]javadoc[\\/]|
|.*[\\/]naming[\\/]|.*[\\/]regexp[\\/]|.*[\\/]sizes[\\/]|.*[\\/]whitespace[\\/]|.*[\\/]doclets[\\/]|.*[\\/]gui[\\/]|
|.*[\\/]doclets[\\/]"/>
|.*[\\/]naming[\\/]|.*[\\/]regexp[\\/]|.*[\\/]sizes[\\/]"/>
</suppressions>
Expand Up @@ -544,13 +544,14 @@ private boolean hasEmptyLine(int startLine, int endLine) {
* @return true, if token have empty line before.
*/
private boolean hasEmptyLineBefore(DetailAST token) {
boolean result = false;
final int lineNo = token.getLineNo();
if (lineNo == 1) {
return false;
if (lineNo != 1) {
// [lineNo - 2] is the number of the previous line as the numbering starts from zero.
final String lineBefore = getLines()[lineNo - 2];
result = lineBefore.trim().isEmpty();
}
// [lineNo - 2] is the number of the previous line because the numbering starts from zero.
final String lineBefore = getLines()[lineNo - 2];
return lineBefore.trim().isEmpty();
return result;
}

/**
Expand Down
Expand Up @@ -291,14 +291,15 @@ else if (Character.isWhitespace(line.charAt(before))
* @param line the line to check
* @return whether there are only whitespaces (or nothing)
*/
private static boolean containsWhitespaceBetween(
int fromIndex, int toIndex, String line) {
private static boolean containsWhitespaceBetween(int fromIndex, int toIndex, String line) {
boolean result = true;
for (int i = fromIndex; i < toIndex; i++) {
if (!Character.isWhitespace(line.charAt(i))) {
return false;
result = false;
break;
}
}
return true;
return result;
}

/**
Expand Down
Expand Up @@ -508,18 +508,21 @@ private boolean isEmptyBlock(DetailAST ast, int parentType) {
* node.
*/
private static boolean isEmptyBlock(DetailAST ast, int parentType, int match) {
final boolean result;
final int type = ast.getType();
if (type == TokenTypes.RCURLY) {
final DetailAST parent = ast.getParent();
final DetailAST grandParent = ast.getParent().getParent();
return parentType == TokenTypes.SLIST
result = parentType == TokenTypes.SLIST
&& parent.getFirstChild().getType() == TokenTypes.RCURLY
&& grandParent.getType() == match;
}

return type == TokenTypes.SLIST
else {
result = type == TokenTypes.SLIST
&& parentType == match
&& ast.getFirstChild().getType() == TokenTypes.RCURLY;
}
return result;
}

/**
Expand Down
Expand Up @@ -90,10 +90,11 @@ public static boolean start(RootDoc root)
* @return option length (how many parts are in option).
*/
public static int optionLength(String option) {
int length = 0;
if (DEST_FILE_OPT.equals(option)) {
return 2;
length = 2;
}
return 0;
return length;
}

/**
Expand All @@ -104,21 +105,21 @@ public static int optionLength(String option) {
*/
public static boolean checkOptions(String[][] options, DocErrorReporter reporter) {
boolean foundDestFileOption = false;
boolean onlyOneDestFileOption = true;
for (final String[] opt : options) {
if (DEST_FILE_OPT.equals(opt[0])) {
if (foundDestFileOption) {
reporter.printError("Only one -destfile option allowed.");
return false;
onlyOneDestFileOption = false;
break;
}
foundDestFileOption = true;
}
}
if (!foundDestFileOption) {
final String message =
"Usage: javadoc -destfile file -doclet TokenTypesDoclet ...";
reporter.printError(message);
reporter.printError("Usage: javadoc -destfile file -doclet TokenTypesDoclet ...");
}
return foundDestFileOption;
return onlyOneDestFileOption && foundDestFileOption;
}

/**
Expand Down
Expand Up @@ -122,13 +122,15 @@ private void findSelectionPositions(DetailNode detailNode) {
* @return Last position of node without children.
*/
private int findLastPosition(final DetailAST astNode) {
final int lastPosition;
if (astNode.getChildCount() == 0) {
return lines2position.get(astNode.getLineNo()) + astNode.getColumnNo()
lastPosition = lines2position.get(astNode.getLineNo()) + astNode.getColumnNo()
+ astNode.getText().length();
}
else {
return findLastPosition(astNode.getLastChild());
lastPosition = findLastPosition(astNode.getLastChild());
}
return lastPosition;
}

/**
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/com/puppycrawl/tools/checkstyle/gui/TreeTable.java
Expand Up @@ -194,14 +194,12 @@ public void updateUI() {
*/
@Override
public int getEditingRow() {
int rowIndex = -1;
final Class<?> editingClass = getColumnClass(editingColumn);

if (editingClass == ParseTreeTableModel.class) {
return -1;
}
else {
return editingRow;
if (editingClass != ParseTreeTableModel.class) {
rowIndex = editingRow;
}
return rowIndex;
}

/**
Expand Down

0 comments on commit aed090b

Please sign in to comment.