use of org.sonar.plugins.java.api.tree.VariableTree in project sonar-java by SonarSource.
the class MethodOnlyCallsSuperCheck method callsWithSameParameters.
private static boolean callsWithSameParameters(List<ExpressionTree> arguments, List<VariableTree> parameters) {
if (arguments.size() != parameters.size()) {
return false;
}
for (int i = 0; i < arguments.size(); i++) {
ExpressionTree arg = arguments.get(i);
VariableTree param = parameters.get(i);
if (!(arg.is(Tree.Kind.IDENTIFIER) && ((IdentifierTree) arg).name().equals(param.simpleName().name()))) {
return false;
}
}
return true;
}
use of org.sonar.plugins.java.api.tree.VariableTree in project sonar-java by SonarSource.
the class PrivateFieldUsedLocallyCheck method checkPrivateField.
private void checkPrivateField(Symbol privateFieldSymbol, TypeSymbol classSymbol) {
MethodTree methodWhereUsed = usedInOneMethodOnly(privateFieldSymbol, classSymbol);
if (methodWhereUsed != null && !isLiveInMethodEntry(privateFieldSymbol, methodWhereUsed)) {
IdentifierTree declarationIdentifier = ((VariableTree) privateFieldSymbol.declaration()).simpleName();
String message = String.format(MESSAGE, privateFieldSymbol.name());
reportIssue(declarationIdentifier, message);
}
}
use of org.sonar.plugins.java.api.tree.VariableTree in project sonar-java by SonarSource.
the class OptionalAsParameterCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (!hasSemantic()) {
return;
}
for (VariableTree parameter : ((MethodTree) tree).parameters()) {
TypeTree typeTree = parameter.type();
Optional<String> msg = expectedTypeInsteadOfOptional(typeTree.symbolType());
if (msg.isPresent()) {
reportIssue(typeTree, msg.get());
}
}
}
use of org.sonar.plugins.java.api.tree.VariableTree in project sonar-java by SonarSource.
the class MutableMembersUsageCheck method visitMethod.
@Override
public void visitMethod(MethodTree tree) {
ArrayList<Symbol> parameters = new ArrayList<>();
for (VariableTree variableTree : tree.parameters()) {
parameters.add(variableTree.symbol());
}
parametersStack.push(parameters);
super.visitMethod(tree);
parametersStack.pop();
}
use of org.sonar.plugins.java.api.tree.VariableTree in project sonar-java by SonarSource.
the class MutableMembersUsageCheck method isImmutableConstant.
private static boolean isImmutableConstant(Symbol.VariableSymbol symbol) {
if (symbol.isStatic() && symbol.isFinal()) {
VariableTree declaration = symbol.declaration();
// symbol is private, so declaration can only be null if assignment is done in static block
ExpressionTree initializer = declaration.initializer();
if (initializer != null) {
return !isMutableType(initializer) || isEmptyArray(initializer);
}
return !assignementsOfMutableType(symbol.usages());
}
return false;
}
Aggregations