use of org.sonar.plugins.java.api.tree.SyntaxToken in project sonar-java by SonarSource.
the class TreeFactory method newArrayInitializer.
public NewArrayTreeImpl newArrayInitializer(InternalSyntaxToken openBraceToken, Optional<InternalSyntaxToken> optionalComma, Optional<List<Tuple<ExpressionTree, Optional<InternalSyntaxToken>>>> rests, InternalSyntaxToken closeBraceToken) {
ImmutableList.Builder<ExpressionTree> initializers = ImmutableList.builder();
ImmutableList.Builder<SyntaxToken> separators = ImmutableList.builder();
if (optionalComma.isPresent()) {
separators.add(optionalComma.get());
}
if (rests.isPresent()) {
for (Tuple<ExpressionTree, Optional<InternalSyntaxToken>> rest : rests.get()) {
initializers.add(rest.first());
if (rest.second().isPresent()) {
separators.add(rest.second().get());
}
}
}
return new NewArrayTreeImpl(ImmutableList.<ArrayDimensionTree>of(), new InitializerListTreeImpl(initializers.build(), separators.build())).completeWithCurlyBraces(openBraceToken, closeBraceToken);
}
use of org.sonar.plugins.java.api.tree.SyntaxToken in project sonar-java by SonarSource.
the class AnalyzerMessage method textSpanBetween.
public static AnalyzerMessage.TextSpan textSpanBetween(Tree startTree, Tree endTree) {
SyntaxToken firstSyntaxToken = startTree.firstToken();
SyntaxToken lastSyntaxToken = endTree.lastToken();
return textSpanBetween(firstSyntaxToken, lastSyntaxToken);
}
use of org.sonar.plugins.java.api.tree.SyntaxToken in project sonar-java by SonarSource.
the class SonarSymbolTableVisitor method createSymbol.
private void createSymbol(IdentifierTree declaration, List<IdentifierTree> usages) {
SyntaxToken syntaxToken = declaration.identifierToken();
NewSymbol newSymbol = newSymbolTable.newSymbol(syntaxToken.line(), syntaxToken.column(), syntaxToken.line(), syntaxToken.text().length() + syntaxToken.column());
for (IdentifierTree usage : usages) {
syntaxToken = usage.identifierToken();
newSymbol.newReference(syntaxToken.line(), syntaxToken.column(), syntaxToken.line(), syntaxToken.text().length() + syntaxToken.column());
}
}
use of org.sonar.plugins.java.api.tree.SyntaxToken in project sonar-java by SonarSource.
the class AnonymousClassesTooBigCheck method visitLambdaExpression.
@Override
public void visitLambdaExpression(LambdaExpressionTree lambdaExpressionTree) {
int lines = getNumberOfLines(lambdaExpressionTree);
if (lines > max) {
SyntaxToken firstToken = lambdaExpressionTree.firstToken();
SyntaxToken lastSyntaxToken = lambdaExpressionTree.lastToken();
JavaFileScannerContext.Location lastTokenLocation = new JavaFileScannerContext.Location(lines + " lines", lastSyntaxToken);
context.reportIssue(this, firstToken, lambdaExpressionTree.arrowToken(), "Reduce this lambda expression number of lines from " + lines + " to at most " + max + ".", Lists.newArrayList(lastTokenLocation), null);
}
super.visitLambdaExpression(lambdaExpressionTree);
}
use of org.sonar.plugins.java.api.tree.SyntaxToken in project sonar-java by SonarSource.
the class DataStoredInSessionCheck method usedBetween.
private boolean usedBetween(Symbol variable, Tree start, Tree end) {
SyntaxToken startToken = start.lastToken();
SyntaxToken endToken = end.firstToken();
for (IdentifierTree identifier : variable.usages()) {
SyntaxToken identifierToken = identifier.identifierToken();
if (isAfterFirstToken(identifierToken, startToken) && isBeforeLastToken(identifierToken, endToken) && !identifiersUsedToSetAttribute.contains(identifier)) {
return true;
}
}
return false;
}
Aggregations