Issue #2661: Enforce LogicConditionNeedOptimizationCheck of sevntu-checkstyle over Checkstyle source code
This commit is contained in:
parent
6c04cd63af
commit
6ee4a0f805
|
|
@ -137,5 +137,6 @@
|
|||
### InnerInterface(.*)
|
||||
### InnerClass(.*)"/>
|
||||
</module>
|
||||
<module name="LogicConditionNeedOptimizationCheck"/>
|
||||
</module>
|
||||
</module>
|
||||
|
|
|
|||
|
|
@ -156,8 +156,7 @@ public class SuppressWarningsHolder
|
|||
final boolean afterStart =
|
||||
entry.getFirstLine() < line
|
||||
|| entry.getFirstLine() == line
|
||||
&& (entry.getFirstColumn() <= column
|
||||
|| column == 0);
|
||||
&& (column == 0 || entry.getFirstColumn() <= column);
|
||||
final boolean beforeEnd =
|
||||
entry.getLastLine() > line
|
||||
|| entry.getLastLine() == line && entry
|
||||
|
|
|
|||
|
|
@ -253,9 +253,9 @@ public class AnnotationLocationCheck extends Check {
|
|||
else {
|
||||
allowingCondition = allowSamelineSingleParameterlessAnnotation;
|
||||
}
|
||||
return allowingCondition && !hasNodeBefore(annotation)
|
||||
|| !allowingCondition && !hasNodeBeside(annotation)
|
||||
|| allowSamelineMultipleAnnotations;
|
||||
return allowSamelineMultipleAnnotations
|
||||
|| allowingCondition && !hasNodeBefore(annotation)
|
||||
|| !allowingCondition && !hasNodeBeside(annotation);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -501,10 +501,10 @@ public final class AnnotationUseStyleCheck extends Check {
|
|||
log(ast.getLineNo(), MSG_KEY_ANNOTATION_PARENS_MISSING);
|
||||
}
|
||||
else if (closingParens == ClosingParens.NEVER
|
||||
&& !ast.branchContains(TokenTypes.EXPR)
|
||||
&& !ast.branchContains(TokenTypes.ANNOTATION_MEMBER_VALUE_PAIR)
|
||||
&& !ast.branchContains(TokenTypes.ANNOTATION_ARRAY_INIT)
|
||||
&& parenExists) {
|
||||
&& parenExists
|
||||
&& !ast.branchContains(TokenTypes.EXPR)
|
||||
&& !ast.branchContains(TokenTypes.ANNOTATION_MEMBER_VALUE_PAIR)
|
||||
&& !ast.branchContains(TokenTypes.ANNOTATION_ARRAY_INIT)) {
|
||||
log(ast.getLineNo(), MSG_KEY_ANNOTATION_PARENS_PRESENT);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -385,8 +385,8 @@ public class LeftCurlyCheck
|
|||
nextToken = leftCurly.getFirstChild();
|
||||
}
|
||||
else {
|
||||
if (leftCurly.getParent().getParent().getType() == TokenTypes.ENUM_DEF
|
||||
&& !ignoreEnums) {
|
||||
if (!ignoreEnums
|
||||
&& leftCurly.getParent().getParent().getType() == TokenTypes.ENUM_DEF) {
|
||||
nextToken = leftCurly.getNextSibling();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -401,7 +401,7 @@ public class HiddenFieldCheck
|
|||
* ignoreSetter is true and ast is the parameter of a setter method.
|
||||
*/
|
||||
private boolean isIgnoredSetterParam(DetailAST ast, String name) {
|
||||
if (ast.getType() == TokenTypes.PARAMETER_DEF && ignoreSetter) {
|
||||
if (ignoreSetter && ast.getType() == TokenTypes.PARAMETER_DEF) {
|
||||
final DetailAST parametersAST = ast.getParent();
|
||||
final DetailAST methodAST = parametersAST.getParent();
|
||||
if (parametersAST.getChildCount() == 1
|
||||
|
|
@ -479,8 +479,8 @@ public class HiddenFieldCheck
|
|||
*/
|
||||
private boolean isIgnoredConstructorParam(DetailAST ast) {
|
||||
boolean result = false;
|
||||
if (ast.getType() == TokenTypes.PARAMETER_DEF
|
||||
&& ignoreConstructorParameter) {
|
||||
if (ignoreConstructorParameter
|
||||
&& ast.getType() == TokenTypes.PARAMETER_DEF) {
|
||||
final DetailAST parametersAST = ast.getParent();
|
||||
final DetailAST constructorAST = parametersAST.getParent();
|
||||
result = constructorAST.getType() == TokenTypes.CTOR_DEF;
|
||||
|
|
@ -497,8 +497,8 @@ public class HiddenFieldCheck
|
|||
*/
|
||||
private boolean isIgnoredParamOfAbstractMethod(DetailAST ast) {
|
||||
boolean result = false;
|
||||
if (ast.getType() == TokenTypes.PARAMETER_DEF
|
||||
&& ignoreAbstractMethods) {
|
||||
if (ignoreAbstractMethods
|
||||
&& ast.getType() == TokenTypes.PARAMETER_DEF) {
|
||||
final DetailAST method = ast.getParent().getParent();
|
||||
if (method.getType() == TokenTypes.METHOD_DEF) {
|
||||
final DetailAST mods = method.findFirstToken(TokenTypes.MODIFIERS);
|
||||
|
|
|
|||
|
|
@ -123,8 +123,8 @@ public final class OneStatementPerLineCheck extends Check {
|
|||
if (!hasResourcesPrevSibling && isMultilineStatement(currentStatement)) {
|
||||
currentStatement = ast.getPreviousSibling();
|
||||
}
|
||||
if (isOnTheSameLine(currentStatement, lastStatementEnd,
|
||||
forStatementEnd) && !inForHeader) {
|
||||
if (!inForHeader
|
||||
&& isOnTheSameLine(currentStatement, lastStatementEnd, forStatementEnd)) {
|
||||
log(ast, MSG_KEY);
|
||||
}
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -262,8 +262,8 @@ public class VariableDeclarationUsageDistanceCheck extends Check {
|
|||
final int parentType = ast.getParent().getType();
|
||||
final DetailAST modifiers = ast.getFirstChild();
|
||||
|
||||
if (!(ignoreFinal && modifiers.branchContains(TokenTypes.FINAL)
|
||||
|| parentType == TokenTypes.OBJBLOCK)) {
|
||||
if (!(parentType == TokenTypes.OBJBLOCK
|
||||
|| ignoreFinal && modifiers.branchContains(TokenTypes.FINAL))) {
|
||||
final DetailAST variable = ast.findFirstToken(TokenTypes.IDENT);
|
||||
|
||||
if (!isVariableMatchesIgnorePattern(variable.getText())) {
|
||||
|
|
|
|||
|
|
@ -785,7 +785,7 @@ public class CustomImportOrderCheck extends Check {
|
|||
final StringTokenizer tokens = new StringTokenizer(packageFullPath, ".");
|
||||
int count = firstPackageDomainsCount;
|
||||
|
||||
while (tokens.hasMoreTokens() && count > 0) {
|
||||
while (count > 0 && tokens.hasMoreTokens()) {
|
||||
builder.append(tokens.nextToken()).append('.');
|
||||
count--;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -417,8 +417,8 @@ public class ImportOrderCheck
|
|||
final int groupIdx = getGroupNumber(name);
|
||||
final int line = ident.getLineNo();
|
||||
|
||||
if (!beforeFirstImport && isAlphabeticallySortableStaticImport(isStatic)
|
||||
|| groupIdx == lastGroup) {
|
||||
if (groupIdx == lastGroup
|
||||
|| !beforeFirstImport && isAlphabeticallySortableStaticImport(isStatic)) {
|
||||
doVisitTokenInSameGroup(isStatic, previous, name, line);
|
||||
}
|
||||
else if (groupIdx > lastGroup) {
|
||||
|
|
@ -469,17 +469,17 @@ public class ImportOrderCheck
|
|||
}
|
||||
else {
|
||||
final boolean shouldFireError =
|
||||
// current and previous static or current and
|
||||
// previous non-static
|
||||
lastImportStatic == isStatic
|
||||
&&
|
||||
// and out of lexicographic order
|
||||
compare(lastImport, name, caseSensitive) > 0
|
||||
||
|
||||
// previous non-static but current is static (above)
|
||||
// or
|
||||
// previous static but current is non-static (under)
|
||||
previous;
|
||||
previous
|
||||
||
|
||||
// current and previous static or current and
|
||||
// previous non-static
|
||||
lastImportStatic == isStatic
|
||||
&&
|
||||
// and out of lexicographic order
|
||||
compare(lastImport, name, caseSensitive) > 0;
|
||||
|
||||
if (shouldFireError) {
|
||||
log(line, MSG_ORDERING, name);
|
||||
|
|
|
|||
|
|
@ -577,8 +577,9 @@ public abstract class AbstractExpressionHandler {
|
|||
// or has <lparen level> + 1 indentation
|
||||
final int lparenLevel = expandedTabsColumnNo(lparen);
|
||||
|
||||
if (!getIndent().isAcceptable(rparenLevel) && isOnStartOfLine(rparen)
|
||||
&& rparenLevel != lparenLevel + 1) {
|
||||
if (rparenLevel != lparenLevel + 1
|
||||
&& !getIndent().isAcceptable(rparenLevel)
|
||||
&& isOnStartOfLine(rparen)) {
|
||||
logError(rparen, "rparen", rparenLevel);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -315,8 +315,8 @@ public class CommentsIndentationCheck extends Check {
|
|||
*/
|
||||
private static boolean isFallThroughSingleLineComment(DetailAST prevStmt, DetailAST nextStmt) {
|
||||
return prevStmt != null
|
||||
&& prevStmt.getType() != TokenTypes.LITERAL_CASE
|
||||
&& nextStmt != null
|
||||
&& prevStmt.getType() != TokenTypes.LITERAL_CASE
|
||||
&& (nextStmt.getType() == TokenTypes.LITERAL_CASE
|
||||
|| nextStmt.getType() == TokenTypes.LITERAL_DEFAULT);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,8 +81,8 @@ public class SlistHandler extends BlockParentHandler {
|
|||
// if our parent is a block handler we want to be transparent
|
||||
if (getParent() instanceof BlockParentHandler
|
||||
&& !(getParent() instanceof SlistHandler)
|
||||
|| getParent() instanceof CaseHandler
|
||||
&& child instanceof SlistHandler) {
|
||||
|| child instanceof SlistHandler
|
||||
&& getParent() instanceof CaseHandler) {
|
||||
return getParent().getSuggestedChildIndent(child);
|
||||
}
|
||||
return super.getSuggestedChildIndent(child);
|
||||
|
|
|
|||
|
|
@ -462,10 +462,11 @@ public class JavadocMethodCheck extends AbstractTypeAwareCheck {
|
|||
private boolean shouldCheck(final DetailAST ast, final Scope nodeScope) {
|
||||
final Scope surroundingScope = ScopeUtils.getSurroundingScope(ast);
|
||||
|
||||
return nodeScope.isIn(scope)
|
||||
&& surroundingScope.isIn(scope)
|
||||
&& (excludeScope == null || nodeScope != excludeScope
|
||||
&& surroundingScope != excludeScope);
|
||||
return (excludeScope == null
|
||||
|| nodeScope != excludeScope
|
||||
&& surroundingScope != excludeScope)
|
||||
&& nodeScope.isIn(scope)
|
||||
&& surroundingScope.isIn(scope);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -488,7 +489,7 @@ public class JavadocMethodCheck extends AbstractTypeAwareCheck {
|
|||
else {
|
||||
// Check for inheritDoc
|
||||
boolean hasInheritDocTag = false;
|
||||
while (it.hasNext() && !hasInheritDocTag) {
|
||||
while (!hasInheritDocTag && it.hasNext()) {
|
||||
hasInheritDocTag = it.next().isInheritDocTag();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -334,7 +334,7 @@ public class RedundantModifierCheck
|
|||
else {
|
||||
final DetailAST parentClassAst = ast.getParent().getParent();
|
||||
|
||||
if (parentClassAst.getType() == TokenTypes.INTERFACE_DEF || hasPublicModifier) {
|
||||
if (hasPublicModifier || parentClassAst.getType() == TokenTypes.INTERFACE_DEF) {
|
||||
isAccessibleFromPublic = isClassPublic(parentClassAst);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -307,10 +307,10 @@ public class GenericWhitespaceCheck extends Check {
|
|||
* @return checks if given character is valid
|
||||
*/
|
||||
private static boolean isCharacterValidAfterGenericEnd(char charAfter) {
|
||||
return Character.isWhitespace(charAfter)
|
||||
|| charAfter == '(' || charAfter == ')'
|
||||
|| charAfter == ',' || charAfter == '['
|
||||
|| charAfter == '.' || charAfter == ':'
|
||||
|| charAfter == ';';
|
||||
return charAfter == '(' || charAfter == ')'
|
||||
|| charAfter == ',' || charAfter == '['
|
||||
|| charAfter == '.' || charAfter == ':'
|
||||
|| charAfter == ';'
|
||||
|| Character.isWhitespace(charAfter);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -123,9 +123,9 @@ public class WhitespaceAfterCheck
|
|||
|
||||
if (after < line.length()) {
|
||||
final char charAfter = line.charAt(after);
|
||||
followedByWhitespace = Character.isWhitespace(charAfter)
|
||||
|| targetAST.getType() == TokenTypes.SEMI
|
||||
&& (charAfter == ';' || charAfter == ')');
|
||||
followedByWhitespace = charAfter == ';'
|
||||
|| charAfter == ')'
|
||||
|| Character.isWhitespace(charAfter);
|
||||
}
|
||||
return followedByWhitespace;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue