use of org.sonar.plugins.java.api.tree.VariableTree in project sonar-java by SonarSource.
the class ExceptionsShouldBeImmutableCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (!hasSemantic()) {
return;
}
ClassTree classTree = (ClassTree) tree;
if (isException(classTree)) {
for (Tree member : classTree.members()) {
if (member.is(Tree.Kind.VARIABLE) && !isFinal((VariableTree) member)) {
IdentifierTree simpleName = ((VariableTree) member).simpleName();
reportIssue(simpleName, "Make this \"" + simpleName.name() + "\" field final.");
}
}
}
}
use of org.sonar.plugins.java.api.tree.VariableTree in project sonar-java by SonarSource.
the class DefaultEncodingUsageCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (!excluded.contains(tree)) {
super.visitNode(tree);
if (tree.is(Tree.Kind.VARIABLE)) {
VariableTree variableTree = (VariableTree) tree;
boolean foundIssue = checkForbiddenTypes(variableTree.simpleName(), variableTree.type().symbolType());
if (foundIssue) {
excluded.add(variableTree.initializer());
}
} else if (tree.is(Tree.Kind.METHOD_INVOCATION)) {
MethodInvocationTree mit = (MethodInvocationTree) tree;
checkForbiddenTypes(ExpressionUtils.methodName(mit), mit.symbolType());
}
}
}
use of org.sonar.plugins.java.api.tree.VariableTree in project sonar-java by SonarSource.
the class ImmediatelyReturnedVariableCheck method visitBlock.
@Override
public void visitBlock(BlockTree tree) {
super.visitBlock(tree);
List<StatementTree> statements = tree.body();
int size = statements.size();
if (size < 2) {
return;
}
StatementTree butLastStatement = statements.get(size - 2);
if (butLastStatement.is(Kind.VARIABLE)) {
VariableTree variableTree = (VariableTree) butLastStatement;
if (!variableTree.modifiers().annotations().isEmpty()) {
return;
}
StatementTree lastStatement = statements.get(size - 1);
String lastStatementIdentifier = getReturnOrThrowIdentifier(lastStatement);
if (lastStatementIdentifier != null) {
String identifier = variableTree.simpleName().name();
if (StringUtils.equals(lastStatementIdentifier, identifier)) {
context.reportIssue(this, variableTree.initializer(), "Immediately " + lastTypeForMessage + " this expression instead of assigning it to the temporary variable \"" + identifier + "\".");
}
}
}
}
use of org.sonar.plugins.java.api.tree.VariableTree in project sonar-java by SonarSource.
the class MethodTreeImpl method isParameterStringArray.
private boolean isParameterStringArray() {
VariableTree variableTree = parameters.get(0);
boolean result = false;
if (variableTree.type().is(Tree.Kind.ARRAY_TYPE)) {
ArrayTypeTree arrayTypeTree = (ArrayTypeTree) variableTree.type();
result = arrayTypeTree.type().symbolType().isClass() && "String".equals(arrayTypeTree.type().symbolType().name());
}
return result;
}
use of org.sonar.plugins.java.api.tree.VariableTree in project sonar-java by SonarSource.
the class SymbolTableTest method resolve_return_type_after_inference.
@Test
public void resolve_return_type_after_inference() throws Exception {
Result res = Result.createFor("VarInitializerInference");
VariableTree mySet = (VariableTree) res.symbol("mySet").declaration();
assertThat(mySet.initializer().symbolType().is("VarInitializer$ImmutableSet")).isTrue();
}
Aggregations