@Override public void visitNode(AstNode astNode) { Token lastToken = astNode.getLastToken(); if (lastToken == null || !FlexPunctuator.SEMICOLON.getValue().equals(lastToken.getValue())) { addIssue("Add a semicolon at the end of this statement", astNode.getParent().getLastToken()); } }
public static boolean isOnASingleLine(AstNode parent) { List<AstNode> statements = parent.getChildren(PythonGrammar.STATEMENT); if (statements.isEmpty()) { return true; } return statements.get(0).getTokenLine() == statements.get(statements.size() - 1).getLastToken().getLine(); } }
public PreciseIssueLocation(AstNode node, @Nullable String message) { super(message); this.firstToken = node.getToken(); this.lastTokenLocation = new TokenLocation(node.getLastToken()); }
public static boolean isOnASingleLine(AstNode parent) { List<AstNode> statements = parent.getChildren(PythonGrammar.STATEMENT); if (statements.isEmpty()) { return true; } return statements.get(0).getTokenLine() == statements.get(statements.size() - 1).getLastToken().getLine(); } }
public PreciseIssueLocation(AstNode startNode, AstNode endNode, String message) { super(message); this.firstToken = startNode.getToken(); this.lastTokenLocation = TokenLocation.from(endNode.getLastToken()); }
public PreciseIssueLocation(AstNode startNode, AstNode endNode, String message) { super(message); this.firstToken = startNode.getToken(); this.lastTokenLocation = new TokenLocation(endNode.getLastToken()); }
private static boolean containsComment(BlockTree tree) { AstNode blockAstNode = ((JavaTree) tree).getAstNode(); return blockAstNode.getLastToken().hasTrivia(); }
public PreciseIssueLocation(AstNode startNode, AstNode endNode, String message) { super(message); this.firstToken = startNode.getToken(); this.lastTokenLocation = new TokenLocation(endNode.getLastToken()); }
@Override public void visitNode(AstNode astNode) { Token lastToken = astNode.getLastToken(); if (lastToken == null || !FlexPunctuator.SEMICOLON.getValue().equals(lastToken.getValue())) { getContext().createLineViolation(this, "Add a semicolon at the end of this statement", astNode.getParent().getLastToken()); } }
private boolean isOnlyBooleanLiteral(AstNode expression) { AstNode exprChild = expression.getFirstChild(); if (!exprChild.getToken().equals(exprChild.getLastToken())) { return false; } String tokenValue = exprChild.getTokenValue(); return CSharpKeyword.TRUE.getValue().equals(tokenValue) || CSharpKeyword.FALSE.getValue().equals(tokenValue); }
private boolean isFirstOnline(AstNode curlyBrace) { Token previousToken = curlyBrace.getPreviousAstNode().getLastToken(); // In one case, clonsing parenthesis can be on the same line as the opening curly brace if (previousToken.getType().equals(PHPPunctuator.RPARENTHESIS)) { previousToken = curlyBrace.getPreviousAstNode().getPreviousAstNode().getLastToken(); } return previousToken.getLine() != curlyBrace.getTokenLine(); }
private boolean isBooleanLiteral(AstNode equalityExpr) { AstNode exprChild = equalityExpr.getFirstChild(); if (!exprChild.getToken().equals(exprChild.getLastToken())) { return false; } String tokenValue = exprChild.getTokenValue(); return CSharpKeyword.TRUE.getValue().equals(tokenValue) || CSharpKeyword.FALSE.getValue().equals(tokenValue); }
private String extractPropertySignature(AstNode astNode) { StringBuilder signature = new StringBuilder(astNode.getPreviousSibling().getLastToken().getValue()); signature.append("_"); AstNode delcarationNode = astNode.getParent().getParent().getParent(); if (delcarationNode.is(CSharpGrammar.INDEXER_DECLARATION)) { signature.append("Item"); } else { signature.append(delcarationNode.getFirstChild(CSharpGrammar.MEMBER_NAME).getTokenValue()); } signature.append(":"); signature.append(astNode.getTokenLine()); return signature.toString(); }
@Override public void visitNode(AstNode node) { if (!isExcluded(node) && node.getPreviousAstNode().getLastToken() != null && node.getPreviousAstNode().getLastToken().getLine() != node.getTokenLine()) { getContext().createLineViolation(this, "Move this left curly brace to the end of previous line of code.", node); } }
public static InternalSyntaxToken create(AstNode astNode) { Preconditions.checkArgument(astNode.hasToken(), "has no token"); Preconditions.checkArgument(astNode.getToken() == astNode.getLastToken(), "has several tokens"); return new InternalSyntaxToken(astNode.getType(), astNode.getToken(), astNode.getFromIndex(), astNode.getToIndex()); }
public static InternalSyntaxToken create(AstNode astNode) { Preconditions.checkArgument(astNode.hasToken(), "has no token"); Preconditions.checkArgument(astNode.getToken() == astNode.getLastToken(), "has several tokens"); return new InternalSyntaxToken(astNode.getType(), astNode.getToken(), astNode.getFromIndex(), astNode.getToIndex()); }
/** * Check that else, catch or finally keywords are on the same line as the previous closing curly brace. */ private void checkRCurlyBraceOnSameLine(FormattingStandardCheck formattingCheck, AstNode node) { Token previsouToken = node.getPreviousAstNode().getLastToken(); String keyword = node.getFirstChild(PHPKeyword.ELSE, PHPKeyword.CATCH, PHPKeyword.FINALLY).getTokenOriginalValue(); if (previsouToken.getType().equals(PHPPunctuator.RCURLYBRACE) && previsouToken.getLine() != node.getTokenLine()) { formattingCheck.reportIssue("Move this \"" + keyword + "\" to the same line as the previous closing curly brace.", node); } }
@Override public void visitNode(AstNode node) { if (!isExcluded(node) && node.getPreviousAstNode().getLastToken().getLine() == node.getTokenLine()) { getContext().createLineViolation(this, "Move this left curly brace to the beginning of next line of code.", node); } }
/** * Check the number of space before and after the given node. */ protected boolean isSpaceAround(AstNode node, int before, int after) { int spaceBefore = getNbSpaceBetween(node.getPreviousAstNode().getLastToken(), node.getToken()); int spaceAfter = getNbSpaceBetween(node.getToken(), node.getNextAstNode().getToken()); return spaceBefore == before && spaceAfter == after; }
/** * Check there is not space between a function's name and the opening parenthesis. */ private void checkSpaceAfterFunctionName(FormattingStandardCheck formattingCheck, AstNode node) { Token lParenToken = node.getFirstChild(PHPPunctuator.LPARENTHESIS).getToken(); Token funcNameToken = node.is(PHPGrammar.FUNCTION_CALL_PARAMETER_LIST) ? node.getPreviousAstNode().getLastToken() : node.getFirstChild(PHPGrammar.IDENTIFIER).getToken(); if (getNbSpaceBetween(funcNameToken, lParenToken) != 0) { formattingCheck.reportIssue("Remove all space between the method name \"" + funcNameToken.getOriginalValue() + "\" and the opening parenthesis.", node); } }