private static void addTokenLinesToSet(Set<Integer> set, Token token) { int currentLine = token.getLine(); for (String line : token.getOriginalValue().split("\r\n?+|\n", -1)) { set.add(currentLine); currentLine++; } }
public int startOffset(Token token) { int lineStartOffset = lineStartOffsets.get(token.getLine() - 1); int column = token.getColumn(); return lineStartOffset + column; }
@Override public void leaveNode(Tree tree) { expectedLevel -= indentationLevel; isBlockAlreadyReported = false; lastCheckedLine = ((JavaTree) tree).getLastToken().getLine(); if (isClassTree(tree)) { isInAnonymousClass.pop(); } }
private void checkBranch(List<AstNode> branches, int index) { for (int j = 0; j < index; j++) { if (CheckUtils.equalNodes(branches.get(j), branches.get(index))) { String message = String.format(MESSAGE, branches.get(j).getToken().getLine() + 1); getContext().createLineViolation(this, message, branches.get(index).getToken().getLine() + 1); return; } } }
private void checkName(Token token) { String name = token.getValue(); if (!pattern.matcher(name).matches()) { getContext().createLineViolation(this, String.format(MESSAGE, name, format), token.getLine()); } }
private void checkName(Token token, String type) { String name = token.getValue(); if (!pattern.matcher(name).matches()) { getContext().createLineViolation(this, String.format(MESSAGE, type, name, format), token.getLine()); } }
private static Pos getTokenStart(Token token) { Pos pos = new Pos(); pos.line = token.getLine(); pos.column = token.getColumn(); return pos; }
@Override public void visitToken(Token token) { if (lastTokenIsRightCurlyBrace && lastTokenLine != token.getLine() && NEXT_BLOCKS.contains(token.getValue())) { getContext().createLineViolation(this, "Move this \"" + token.getValue() + "\" on the same line that the previous closing curly brace.", token); } lastTokenIsRightCurlyBrace = "}".equals(token.getValue()); lastTokenLine = token.getLine(); }
public int getEndOffset(Token token) { String[] tokenLines = token.getOriginalValue().split("(\r)?\n", -1); int tokenLastLine = token.getLine() + tokenLines.length - 1; int tokenLastLineColumn = (tokenLines.length > 1 ? 0 : token.getColumn()) + tokenLines[tokenLines.length - 1].length(); return getOffset(tokenLastLine, tokenLastLineColumn); }
public int getEndOffset(Token token) { String[] tokenLines = token.getOriginalValue().split(NEWLINE_REGEX, -1); int tokenLastLine = token.getLine() + tokenLines.length - 1; int tokenLastLineColumn = (tokenLines.length > 1 ? 0 : token.getColumn()) + tokenLines[tokenLines.length - 1].length(); return getOffset(tokenLastLine, tokenLastLineColumn); }
private static List<SyntaxTrivia> createTrivias(List<Trivia> trivias, boolean hasByteOrderMark) { List<SyntaxTrivia> result = Lists.newArrayList(); for (Trivia trivia : trivias) { Token trivialToken = trivia.getToken(); int column = column(hasByteOrderMark, trivialToken.getLine(), trivialToken.getColumn()); result.add(InternalSyntaxTrivia.create(trivialToken.getValue(), trivialToken.getLine(), column)); } return result; }
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; }
@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 void checkParameters(AstNode functionDef) { for (AstNode paramIdentifier : Function.getParametersIdentifiers(functionDef)) { String paramName = paramIdentifier.getTokenValue(); AstNode field = classStack.peek().getFieldNamed(paramName); if (field != null) { addIssue(MessageFormat.format(MESSAGE, paramName, field.getToken().getLine()), paramIdentifier); } } }
private void checkIndentation(List<? extends Tree> trees) { for (Tree tree : trees) { int column = getColumn(tree); if (column != expectedLevel && !isExcluded(tree)) { addIssue(tree, "Make this line start at column " + (expectedLevel + 1) + "."); isBlockAlreadyReported = true; } lastCheckedLine = ((JavaTree) tree).getLastToken().getLine(); } }
@Override public void visitToken(Token token) { for (Trivia trivia : token.getTrivia()) { if (trivia.isComment() && trivia.getToken().getLine() < token.getLine()) { String comment = trivia.getToken().getOriginalValue(); if (!comment.startsWith(getSingleLineCommentSyntaxPrefix()) && !StringUtils.containsAny(comment, "\r\n")) { getContext().createLineViolation(this, "This single line comment should use the single line comment syntax \"{0}\"", trivia.getToken(), getSingleLineCommentSyntaxPrefix()); } } } }
@Override public void visitToken(Token token) { for (Trivia trivia : token.getTrivia()) { if (trivia.isComment()) { Token triviaToken = trivia.getToken(); int offset = getOffset(triviaToken.getLine(), triviaToken.getColumn()); highlighting.highlight(offset, offset + triviaToken.getValue().length(), "cppd"); } } }
@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; } } } }
public void tokenize(SourceCode source, Tokens cpdTokens) throws IOException { Lexer lexer = ObjectiveCLexer.create(new ObjectiveCConfiguration(charset)); String fileName = source.getFileName(); List<Token> tokens = lexer.lex(new File(fileName)); for (Token token : tokens) { TokenEntry cpdToken = new TokenEntry(getTokenImage(token), fileName, token.getLine()); cpdTokens.add(cpdToken); } cpdTokens.add(TokenEntry.getEOF()); }
@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));