use of org.sonar.plugins.java.api.tree.StatementTree in project sonar-java by SonarSource.
the class MethodInvocationTreeImplTest method symbol_should_be_set.
@Test
public void symbol_should_be_set() {
CompilationUnitTree cut = createTree("class A { void foo(){} void bar(){foo();} }");
ClassTree classTree = (ClassTree) cut.types().get(0);
Symbol.MethodSymbol declaration = ((MethodTree) classTree.members().get(0)).symbol();
StatementTree statementTree = ((MethodTree) classTree.members().get(1)).block().body().get(0);
MethodInvocationTree mit = (MethodInvocationTree) ((ExpressionStatementTree) statementTree).expression();
assertThat(mit.symbol()).isSameAs(declaration);
assertThat(mit.arguments()).isNotNull();
assertThat(mit.arguments().openParenToken()).isNotNull();
assertThat(mit.arguments().closeParenToken()).isNotNull();
}
use of org.sonar.plugins.java.api.tree.StatementTree in project sonar-java by SonarSource.
the class NestedIfStatementsCheck method visit.
private void visit(IfStatementTree tree) {
scan(tree.condition());
scan(tree.thenStatement());
StatementTree elseStatementTree = tree.elseStatement();
if (elseStatementTree != null && elseStatementTree.is(Tree.Kind.IF_STATEMENT)) {
visit((IfStatementTree) elseStatementTree);
} else {
scan(elseStatementTree);
}
}
use of org.sonar.plugins.java.api.tree.StatementTree in project sonar-java by SonarSource.
the class OverwrittenKeyCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (!hasSemantic()) {
return;
}
ListMultimap<CollectionAndKey, Tree> usedKeys = ArrayListMultimap.create();
for (StatementTree statementTree : ((BlockTree) tree).body()) {
CollectionAndKey mapPut = isMapPut(statementTree);
if (mapPut != null) {
usedKeys.put(mapPut, mapPut.keyTree);
} else {
CollectionAndKey arrayAssignment = isArrayAssignment(statementTree);
if (arrayAssignment != null) {
if (arrayAssignment.collectionOnRHS()) {
usedKeys.clear();
}
usedKeys.put(arrayAssignment, arrayAssignment.keyTree);
} else {
// sequence of setting collection values is interrupted
reportOverwrittenKeys(usedKeys);
usedKeys.clear();
}
}
}
reportOverwrittenKeys(usedKeys);
}
use of org.sonar.plugins.java.api.tree.StatementTree in project sonar-java by SonarSource.
the class MultilineBlocksCurlyBracesCheck method visitBlock.
@Override
public void visitBlock(BlockTree tree) {
super.visitBlock(tree);
StatementTree previous = null;
for (StatementTree current : tree.body()) {
if (previous != null) {
check(current, previous);
}
previous = current;
}
}
use of org.sonar.plugins.java.api.tree.StatementTree in project sonar-java by SonarSource.
the class TreeFactory method newStatementExpressions.
public StatementExpressionListTreeImpl newStatementExpressions(ExpressionTree expression, Optional<List<Tuple<InternalSyntaxToken, ExpressionTree>>> rests) {
ImmutableList.Builder<StatementTree> statements = ImmutableList.builder();
statements.add(new ExpressionStatementTreeImpl(expression, null));
ImmutableList.Builder<SyntaxToken> separators = ImmutableList.builder();
if (rests.isPresent()) {
for (Tuple<InternalSyntaxToken, ExpressionTree> rest : rests.get()) {
separators.add(rest.first());
statements.add(new ExpressionStatementTreeImpl(rest.second(), null));
}
}
return new StatementExpressionListTreeImpl(statements.build(), separators.build());
}
Aggregations