@Override public void visitToken(Token token) { String[] tokenLines = token.getValue().split("\n", -1); for (int line = token.getLine(); line < token.getLine() + tokenLines.length; line++) { linesOfCode.add(line); } for (Trivia trivia : token.getTrivia()) { if (trivia.isComment()) { visitComment(trivia); } } }
private static List<SyntaxTrivia> createTrivias(List<Trivia> trivias) { List<SyntaxTrivia> result = Lists.newArrayList(); for (Trivia trivia : trivias) { Token trivialToken = trivia.getToken(); result.add(InternalSyntaxTrivia.create(trivialToken.getValue(), trivialToken.getLine(), trivialToken.getColumn())); } return result; }
private void addSimpleField(AstNode test) { Token token = test.getToken(); if (test.getNumberOfChildren() == 1 && test.getFirstChild().is(PythonGrammar.ATOM) && token.getType().equals(GenericTokenType.IDENTIFIER) && !CheckUtils.containsValue(symbols, token.getValue())) { symbols.add(token); } }
public TokenLocation(Token token) { this.startLine = token.getLine(); this.startCharacter = token.getColumn(); final String[] lines = token.getOriginalValue().split("\r\n|\n|\r", -1); if (lines.length > 1) { this.endLine = token.getLine() + lines.length - 1; this.endCharacter = lines[lines.length - 1].length(); } else { this.endLine = startLine; this.endCharacter = startCharacter + token.getOriginalValue().length(); } }
@Override public void visitToken(Token token) { for (Trivia trivia : token.getTrivia()) { String[] lines = regexpToDivideStringByLine.split(FlexCommentAnalyser.getContents(trivia.getToken().getOriginalValue())); for (int lineOffset = 0; lineOffset < lines.length; lineOffset++) { if (codeRecognizer.isLineOfCode(lines[lineOffset])) { addIssueAtLine("Sections of code should not be \"commented out\".", trivia.getToken().getLine() + lineOffset); break; } } } }
private int getLineStartingColumn(AstNode node) { int line = node.getTokenLine(); AstNode previousNode = node.getPreviousAstNode(); int column = node.getToken().getColumn(); while (previousNode != null && previousNode.getToken().getLine() == line) { column = previousNode.getToken().getColumn(); previousNode = previousNode.getParent(); } return column; }
@Override public SourceCode createSourceCode(SourceCode parentSourceCode, AstNode astNode) { AstNode identifier = astNode.getFirstChild(EcmaScriptTokenType.IDENTIFIER, EcmaScriptGrammar.PROPERTY_NAME, Kind.IDENTIFIER); final String functionName = identifier == null ? "anonymous" : identifier.getTokenValue(); final String fileKey = parentSourceCode.isType(SourceFile.class) ? parentSourceCode.getKey() : parentSourceCode.getParent(SourceFile.class).getKey(); SourceFunction function = new SourceFunction(fileKey + ":" + functionName + ":" + astNode.getToken().getLine() + ":" + astNode.getToken().getColumn()); function.setStartAtLine(astNode.getTokenLine()); return function; } }, FUNCTION_NODES));
/** * 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 SourceCode createSourceCode(SourceCode parentSourceCode, AstNode astNode) { String className = astNode.getFirstDescendant(ErlangGrammarImpl.moduleAttr).getFirstChild(ErlangGrammarImpl.atom).getTokenValue(); SourceClass cls = new SourceClass(className + ":" + astNode.getToken().getLine()); cls.setStartAtLine(astNode.getTokenLine()); return cls; } }, ErlangGrammarImpl.module));
private void retrieveTypeFromDoc(AstNode varDeclaration) { Token varDecToken = varDeclaration.getToken(); for (Trivia comment : varDecToken.getTrivia()) { for (String line : comment.getToken().getValue().split("[" + LexicalConstant.LINE_TERMINATOR + "]++")) { retrieveTypeFromCommentLine(line); } } }
private void appendNodecontent(AstNode node) throws IOException { writer.append(node.getName()); if (node.getTokenValue() != null) { writer.append(" tokenValue=\"" + node.getTokenValue() + "\""); } if (node.hasToken()) { writer.append(" tokenLine=\"" + node.getTokenLine() + "\" tokenColumn=\"" + node.getToken().getColumn() + "\""); } }
@Override public void visitNode(AstNode astNode) { Token token = astNode.getToken(); if (token.getColumn() != 0 || token.getLine() != 1 || !OPENING_TAG.matcher(token.getOriginalValue()).matches()) { getContext().createLineViolation(this, "Remove the extra characters before the open tag.", astNode); } }
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(); }
@Override public String toString() { StringBuilder result = new StringBuilder(); result.append(name); if (token != null) { result.append(" tokenValue='").append(token.getValue()).append("'"); result.append(" tokenLine=").append(token.getLine()); result.append(" tokenColumn=").append(token.getColumn()); } return result.toString(); }
private void visitComment(Trivia trivia) { String comment = trivia.getToken().getValue(); Matcher matcher = patternTodoFixme.matcher(comment); if (matcher.find()) { String tail = comment.substring(matcher.end()); if (!patternPersonReference.matcher(tail).find()) { getContext().createLineViolation(this, MESSAGE, trivia.getToken().getLine()); } } } }
private boolean isReturningBoolean(AstNode methodDec) { Token functionToken = methodDec.getToken(); for (Trivia comment : functionToken.getTrivia()) { for (String line : comment.getToken().getOriginalValue().split(LexicalConstant.LINE_TERMINATOR)) { if (StringUtils.containsIgnoreCase(line, RETURN_TAG)) { return returnsBoolean(line); } } } return false; }
/** * 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); } }