@Override public void visitToken(SyntaxToken syntaxToken) { executableLines.add(syntaxToken.line()); } }
@Override public void visitToken(SyntaxToken syntaxToken) { if (!((InternalSyntaxToken) syntaxToken).isEOF()) { lines.add(syntaxToken.line()); } } }
private void leaveNode(Tree tree) { expectedLevel -= indentationLevel; isBlockAlreadyReported = false; excludeIssueAtLine = tree.lastToken().line(); }
private static int getLine(ImportClauseTree importClauseTree, boolean fromStart) { if (importClauseTree.is(Tree.Kind.IMPORT)) { if (fromStart) { return ((ImportTree) importClauseTree).importKeyword().line(); } else { return ((ImportTree) importClauseTree).semicolonToken().line(); } } return ((EmptyStatementTree) importClauseTree).semicolonToken().line(); }
private static AnalyzerMessage.TextSpan textSpanBetween(SyntaxToken firstSyntaxToken, SyntaxToken lastSyntaxToken) { AnalyzerMessage.TextSpan location = new AnalyzerMessage.TextSpan( firstSyntaxToken.line(), firstSyntaxToken.column(), lastSyntaxToken.line(), lastSyntaxToken.column() + lastSyntaxToken.text().length() ); Preconditions.checkState(!location.isEmpty(), "Invalid issue location: Text span is empty when trying reporting on (l:%s, c:%s).", firstSyntaxToken.line(), firstSyntaxToken.column()); return location; }
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 boolean isAlignedWith(SyntaxToken operatorToken, Tree other) { SyntaxToken otherOperator = operatorToken(other); return otherOperator.text().equals(operatorToken.text()) && operatorToken.column() == otherOperator.column() // less than 2 lines distance && Math.abs(operatorToken.line() - otherOperator.line()) < 2; }
private static int startLineIncludingTrivia(Tree tree) { SyntaxToken firstToken = tree.firstToken(); // first token can't be null, because tree has @SuppressWarnings annotation if (!firstToken.trivias().isEmpty()) { return firstToken.trivias().get(0).startLine(); } return firstToken.line(); }
private void checkConditionalOperand(ExpressionTree tree) { if(!(tree.is(CONDITIONAL_EXCLUSIONS) || tree instanceof LiteralTree || tree instanceof UnaryExpressionTree)) { raiseIssue(tree.firstToken().line(), tree); } }
private void checkForEachExpression(Tree forEachIterable, ExpressionTree expressionTree) { if (SyntacticEquivalence.areEquivalent(expressionTree, forEachIterable)) { addIssue(expressionTree, forEachIterable.firstToken().line()); } }
private static int getDeclarationLine(Symbol symbol) { if (symbol.declaration() == null) { return -1; } if (symbol.isVariableSymbol()) { return ((Symbol.VariableSymbol) symbol).declaration().simpleName().identifierToken().line(); } return ((Symbol.MethodSymbol) symbol).declaration().simpleName().identifierToken().line(); }
private void reportIssue(CatchTree catchTree, CatchTree catchTreeToBeCompared) { String message = "Combine this catch with the one at line " + catchTreeToBeCompared.catchKeyword().line() + ", which has the same body." + context.getJavaVersion().java7CompatibilityMessage(); List<JavaFileScannerContext.Location> flow = Lists.newArrayList(new JavaFileScannerContext.Location("Combine with this catch", catchTreeToBeCompared)); reportIssue(catchTree.parameter(), message, flow, null); }
private void checkVariable(VariableTree varTree) { int line = varTree.simpleName().identifierToken().line(); if (varSameDeclaration || lastVarLine == line) { reportIssue(varTree.simpleName(), String.format("Declare \"%s\" on a separate line.", varTree.simpleName().name())); } varSameDeclaration = ",".equals(varTree.endToken().text()); lastVarLine = line; } }
@Override public void visitIfStatement(IfStatementTree tree) { super.visitIfStatement(tree); ExpressionTree condition = tree.condition(); if (condition.is(Tree.Kind.ASSIGNMENT) && EQUALITY_RELATIONAL_OPERATORS.contains(((AssignmentExpressionTree) condition).expression().kind())) { raiseIssue(((AssignmentExpressionTree) condition).operatorToken().line(), tree); } }
private void throwMaxSteps(MethodTree tree) { String message = String.format("reached limit of %d steps for method %s#%d in class %s", maxSteps(), tree.simpleName().name(), tree.simpleName().firstToken().line(), tree.symbol().owner().name()); MaximumStepsReachedException cause = new MaximumStepsReachedException(message); interrupted(cause); throw cause; }