@Override @Nullable public SyntaxToken lastToken() { List<Tree> trees = getChildren(); for (int index = trees.size() - 1; index >= 0; index--) { SyntaxToken last = trees.get(index).lastToken(); if (last != null) { return last; } } return null; }
@Override @Nullable public SyntaxToken lastToken() { List<Tree> trees = getChildren(); for (int index = trees.size() - 1; index >= 0; index--) { SyntaxToken last = trees.get(index).lastToken(); if (last != null) { return last; } } return null; }
private void leaveNode(Tree tree) { expectedLevel -= indentationLevel; isBlockAlreadyReported = false; excludeIssueAtLine = tree.lastToken().line(); }
private void leaveNode(Tree tree) { expectedLevel -= indentationLevel; isBlockAlreadyReported = false; excludeIssueAtLine = tree.lastToken().line(); }
private void checkBlockBody(SyntaxToken openBraceToken, SyntaxToken closeBraceToken, List<? extends Tree> trees) { if (openBraceToken.line() != closeBraceToken.line() && !trees.isEmpty()) { Tree lastTree = trees.get(trees.size() - 1); if (lastTree.lastToken().line() == closeBraceToken.line()) { reportIssue(closeBraceToken, "Move this closing curly brace to the next line."); } } } }
private void checkBlockBody(SyntaxToken openBraceToken, SyntaxToken closeBraceToken, List<? extends Tree> trees) { if (openBraceToken.line() != closeBraceToken.line() && !trees.isEmpty()) { Tree lastTree = trees.get(trees.size() - 1); if (lastTree.lastToken().line() == closeBraceToken.line()) { reportIssue(closeBraceToken, "Move this closing curly brace to the next line."); } } } }
private void computeFilteredLinesForRule(@Nullable Tree tree, Class<? extends JavaCheck> filteredRule, boolean excludeLine) { if (tree == null) { return; } SyntaxToken firstSyntaxToken = tree.firstToken(); SyntaxToken lastSyntaxToken = tree.lastToken(); if (firstSyntaxToken != null && lastSyntaxToken != null) { Set<Integer> filteredlines = ContiguousSet.create(Range.closed(firstSyntaxToken.line(), lastSyntaxToken.line()), DiscreteDomain.integers()); computeFilteredLinesForRule(filteredlines, rulesKeysByRulesClass.get(filteredRule), excludeLine); } }
private void computeFilteredLinesForRule(@Nullable Tree tree, Class<? extends JavaCheck> filteredRule, boolean excludeLine) { if (tree == null) { return; } SyntaxToken firstSyntaxToken = tree.firstToken(); SyntaxToken lastSyntaxToken = tree.lastToken(); if (firstSyntaxToken != null && lastSyntaxToken != null) { Set<Integer> filteredlines = ContiguousSet.create(Range.closed(firstSyntaxToken.line(), lastSyntaxToken.line()), DiscreteDomain.integers()); computeFilteredLinesForRule(filteredlines, rulesKeysByRulesClass.get(filteredRule), excludeLine); } }
private static Set<Integer> filteredLines(Tree tree) { SyntaxToken firstSyntaxToken = tree.firstToken(); SyntaxToken lastSyntaxToken = tree.lastToken(); if (firstSyntaxToken != null && lastSyntaxToken != null) { int startLine = firstSyntaxToken.line(); int endLine = lastSyntaxToken.line(); // includes trivia on top of first syntax token. List<SyntaxTrivia> trivias = firstSyntaxToken.trivias(); if (!trivias.isEmpty()) { startLine = trivias.get(0).startLine(); } return ContiguousSet.create(Range.closed(startLine, endLine), DiscreteDomain.integers()); } return new HashSet<>(); } }
public static AnalyzerMessage.TextSpan textSpanFor(Tree syntaxNode) { SyntaxToken firstSyntaxToken = getNonEmptyTree(syntaxNode).firstToken(); SyntaxToken lastSyntaxToken = getNonEmptyTree(syntaxNode).lastToken(); return textSpanBetween(firstSyntaxToken, lastSyntaxToken); }
public static AnalyzerMessage.TextSpan textSpanBetween(Tree startTree, Tree endTree) { SyntaxToken firstSyntaxToken = getNonEmptyTree(startTree).firstToken(); SyntaxToken lastSyntaxToken = getNonEmptyTree(endTree).lastToken(); return textSpanBetween(firstSyntaxToken, lastSyntaxToken); }
private static Set<Integer> filteredLines(Tree tree) { SyntaxToken firstSyntaxToken = tree.firstToken(); SyntaxToken lastSyntaxToken = tree.lastToken(); if (firstSyntaxToken != null && lastSyntaxToken != null) { int startLine = firstSyntaxToken.line(); int endLine = lastSyntaxToken.line(); // includes trivia on top of first syntax token. List<SyntaxTrivia> trivias = firstSyntaxToken.trivias(); if (!trivias.isEmpty()) { startLine = trivias.get(0).startLine(); } return ContiguousSet.create(Range.closed(startLine, endLine), DiscreteDomain.integers()); } return new HashSet<>(); } }
public static AnalyzerMessage.TextSpan textSpanBetween(Tree startTree, Tree endTree) { SyntaxToken firstSyntaxToken = getNonEmptyTree(startTree).firstToken(); SyntaxToken lastSyntaxToken = getNonEmptyTree(endTree).lastToken(); return textSpanBetween(firstSyntaxToken, lastSyntaxToken); }
public static AnalyzerMessage.TextSpan textSpanFor(Tree syntaxNode) { SyntaxToken firstSyntaxToken = getNonEmptyTree(syntaxNode).firstToken(); SyntaxToken lastSyntaxToken = getNonEmptyTree(syntaxNode).lastToken(); return textSpanBetween(firstSyntaxToken, lastSyntaxToken); }
private void handleSuppressWarning(List<AnnotationTree> annotationTrees, Tree tree) { int startLine = -1; List<String> rules = Lists.newArrayList(); for (AnnotationTree annotationTree : annotationTrees) { if (isSuppressWarningsAnnotation(annotationTree)) { startLine = startLineIncludingTrivia(tree); rules.addAll(getRules(annotationTree)); break; } } if (startLine != -1) { int endLine = tree.lastToken().line(); Set<Integer> filteredlines = ContiguousSet.create(Range.closed(startLine, endLine), DiscreteDomain.integers()); for (String rule : rules) { excludeLines(filteredlines, rule); } } }
private void handleSuppressWarning(List<AnnotationTree> annotationTrees, Tree tree) { int startLine = -1; List<String> rules = Lists.newArrayList(); for (AnnotationTree annotationTree : annotationTrees) { if (isSuppressWarningsAnnotation(annotationTree)) { startLine = startLineIncludingTrivia(tree); rules.addAll(getRules(annotationTree)); break; } } if (startLine != -1) { int endLine = tree.lastToken().line(); Set<Integer> filteredlines = ContiguousSet.create(Range.closed(startLine, endLine), DiscreteDomain.integers()); for (String rule : rules) { excludeLines(filteredlines, rule); } } }
private void highlight(Tree from, Tree to, TypeOfText typeOfText) { SyntaxToken firstToken = from.firstToken(); SyntaxToken lastToken = to.lastToken(); highlighting.highlight(firstToken.line(), firstToken.column(), lastToken.line(), lastToken.column() + lastToken.text().length(), typeOfText); }
private void highlight(Tree from, Tree to, TypeOfText typeOfText) { SyntaxToken firstToken = from.firstToken(); SyntaxToken lastToken = to.lastToken(); highlighting.highlight(firstToken.line(), firstToken.column(), lastToken.line(), lastToken.column() + lastToken.text().length(), typeOfText); }
private void checkIndentation(Tree tree, int expectedLevel) { SyntaxToken firstSyntaxToken = tree.firstToken(); String line = fileLines.get(firstSyntaxToken.line() - 1); int level = firstSyntaxToken.column(); for (int i = 0; i < firstSyntaxToken.column(); i++) { if (line.charAt(i) == '\t') { level += indentationLevel - 1; } } if (level != expectedLevel && !isExcluded(tree, firstSyntaxToken.line())) { context.addIssue(((JavaTree) tree).getLine(), this, "Make this line start at column " + (expectedLevel + 1) + "."); isBlockAlreadyReported = true; } excludeIssueAtLine = tree.lastToken().line(); }
private void checkIndentation(Tree tree, int expectedLevel) { SyntaxToken firstSyntaxToken = tree.firstToken(); String line = fileLines.get(firstSyntaxToken.line() - 1); int level = firstSyntaxToken.column(); for (int i = 0; i < firstSyntaxToken.column(); i++) { if (line.charAt(i) == '\t') { level += indentationLevel - 1; } } if (level != expectedLevel && !isExcluded(tree, firstSyntaxToken.line())) { context.addIssue(((JavaTree) tree).getLine(), this, "Make this line start at column " + (expectedLevel + 1) + "."); isBlockAlreadyReported = true; } excludeIssueAtLine = tree.lastToken().line(); }