/** * @deprecated in 1.17, use {@link #getNextAstNode()} instead */ @Deprecated public AstNode nextAstNode() { return getNextAstNode(); }
/** * @deprecated in 1.17, use {@link #getNextAstNode()} instead */ @Deprecated public AstNode nextAstNode() { return getNextAstNode(); }
/** * @deprecated in 1.17, use {@link #getNextAstNode()} instead */ @Deprecated public AstNode nextAstNode() { return getNextAstNode(); }
private static boolean isCallToDispatchEvent(AstNode primaryExpr) { return "dispatchEvent".equals(primaryExpr.getTokenValue()) && primaryExpr.getNextAstNode().is(FlexGrammar.ARGUMENTS) && primaryExpr.getNextAstNode().getFirstChild(FlexGrammar.LIST_EXPRESSION) != null; }
private static boolean isCallToDispatchEvent(AstNode primaryExpr) { return "dispatchEvent".equals(primaryExpr.getTokenValue()) && primaryExpr.getNextAstNode().is(FlexGrammar.ARGUMENTS) && primaryExpr.getNextAstNode().getFirstChild(FlexGrammar.LIST_EXPRESSION) != null; }
/** * Returns for statement stop condition, null if there is no stop condition. */ @Nullable private static AstNode getStopCondition(AstNode forStatement) { AstNode semicolonNode = forStatement.getFirstChild(FlexPunctuator.SEMICOLON); if (semicolonNode != null) { AstNode stopConditionExpr = semicolonNode.getNextAstNode(); return stopConditionExpr.is(FlexGrammar.LIST_EXPRESSION) ? stopConditionExpr : null; } return null; }
/** * Returns for statement stop condition, null if there is no stop condition. */ @Nullable private AstNode getStopCondition(AstNode forStatement) { AstNode semicolonNode = forStatement.getFirstChild(FlexPunctuator.SEMICOLON); if (semicolonNode != null) { AstNode stopConditionExpr = semicolonNode.getNextAstNode(); return stopConditionExpr.is(FlexGrammar.LIST_EXPRESSION) ? stopConditionExpr : null; } return null; }
public boolean isLastReturnStatement(AstNode astNode) { if (astNode.getNextAstNode().is(FlexPunctuator.RCURLYBRACE)) { AstNode parentNode = astNode.getNextAstNode().getParent().getParent(); return parentNode != null && parentNode.is(FlexGrammar.FUNCTION_COMMON); } return false; }
private void searchEventInNextTag(AstNode metadata) { AstNode nextDirective = metadata.getParent().getParent().getNextAstNode(); while (nextDirective != null && MetadataTag.isMetadataTag(nextDirective)) { checkEventTag(nextDirective); nextDirective = nextDirective.getNextAstNode(); } }
@Override public void visitNode(AstNode astNode) { AstNode lastLabelNode = Iterables.getLast(astNode.getChildren(FlexGrammar.CASE_LABEL)); int lines = Math.max(astNode.getNextAstNode().getTokenLine() - lastLabelNode.getTokenLine(), 1); if (lines > max) { getContext().createLineViolation(this, "Reduce this switch case number of lines from {0} to at most {1}, for example by extracting code into methods.", lastLabelNode, lines, max); } }
@Override public void visitNode(AstNode astNode) { if (hasBooleanLiteralOperand(astNode.getFirstChild(FlexGrammar.EQUALITY_OPERATOR).getNextAstNode())) { addIssue("Remove the unnecessary boolean comparison to simplify this expression.", astNode); } }
private static AstNode getLiteralFromLogicalOrEqualityComparison(AstNode operator) { AstNode leftExpr = operator.getPreviousAstNode(); AstNode rightExpr = operator.getNextAstNode(); if (isBooleanLiteral(leftExpr)) { return leftExpr; } else if (isBooleanLiteral(rightExpr)) { return rightExpr; } else { return null; } }
@Override public void visitNode(AstNode astNode) { int lines = Math.max(astNode.getNextAstNode().getTokenLine() - astNode.getTokenLine(), 1); if (lines > max) { getContext().createLineViolation(this, "Reduce this \"switch/case\" number of lines from {0} to at most {1}, for example by extracting code into function.", astNode, lines, max); } } }
@Override public void visitNode(AstNode astNode) { String varName = StringUtils.repeat(PHPPunctuator.DOLAR.getValue(), astNode.getNumberOfChildren()) + astNode.getNextAstNode().getTokenOriginalValue(); getContext().createLineViolation(this, "Remove the use of this variable variable \"{0}\".", astNode, varName); } }
private static boolean hasBlock(AstNode node) { AstNode statement = node.getFirstChild(CSharpGrammar.EMBEDDED_STATEMENT); return node.is(CSharpKeyword.ELSE) ? isBlock(node.getNextAstNode()) : isBlock(statement); }
@Override public void visitNode(AstNode astNode) { if (hasBooleanLiteralOperand(astNode.getFirstChild(FlexGrammar.EQUALITY_OPERATOR).getNextAstNode())) { getContext().createLineViolation(this, "Remove the unnecessary boolean comparison to simplify this expression.", astNode); } }
private void check(AstNode astNode) { AstNode varNode; if (astNode.is(PHPGrammar.ASSIGNMENT_EXPR)) { varNode = astNode.getFirstChild(); } else { // Increment or decrement varNode = isPostUnaryExpr(astNode) ? astNode.getNextAstNode() : astNode.getPreviousAstNode(); } String varName = CheckUtils.getExpressionAsString(varNode); if (counters.contains(varName)) { reportIssue(astNode, varName); } }
private static boolean isElseIf(AstNode node) { if (node.is(CSharpKeyword.ELSE)) { AstNode statementChild = node.getNextAstNode().getFirstChild(); return statementChild.is(CSharpGrammar.SELECTION_STATEMENT) && statementChild.getFirstChild().is(CSharpGrammar.IF_STATEMENT); } return false; }
@Override public void visitNode(AstNode astNode) { AstNode defaultClause = astNode.getFirstChild(PHPGrammar.DEFAULT_CLAUSE); if (defaultClause == null) { getContext().createLineViolation(this, "Add a \"case default\" clause to this \"switch\" statement.", astNode.getParent()); } else if (defaultClause.getNextAstNode().isNot(PHPPunctuator.RCURLYBRACE)) { getContext().createLineViolation(this, "Move this \"case default\" clause to the end of this \"switch\" statement.", defaultClause); } } }
/** * Check that there is exactly one space between a closing parenthesis and a opening curly brace. */ private void checkSpaceBetweenRParentAndLCurly(FormattingStandardCheck formattingCheck, AstNode rParenthesis) { Token nextToken = rParenthesis.getNextAstNode().getToken(); Token rParenToken = rParenthesis.getToken(); if (isType(nextToken, PHPPunctuator.LCURLYBRACE)) { int nbSpace = getNbSpaceBetween(rParenToken, nextToken); if (nbSpace != 1 && isOnSameLine(rParenToken, nextToken)) { formattingCheck.reportIssue(buildIssueMsg(nbSpace, "between the closing parenthesis and the opening curly brace."), rParenthesis); } } }