use of org.sonar.plugins.java.api.tree.LiteralTree in project sonar-java by SonarSource.
the class DeprecatedHashAlgorithmCheck method algorithm.
private static Optional<InsecureAlgorithm> algorithm(ExpressionTree invocationArgument) {
ExpressionTree expectedAlgorithm = invocationArgument;
ExpressionTree defaultPropertyValue = JavaPropertiesHelper.retrievedPropertyDefaultValue(invocationArgument);
if (defaultPropertyValue != null) {
expectedAlgorithm = defaultPropertyValue;
}
if (expectedAlgorithm.is(Tree.Kind.STRING_LITERAL)) {
String algorithmName = LiteralUtils.trimQuotes(((LiteralTree) expectedAlgorithm).value());
return Arrays.stream(InsecureAlgorithm.values()).filter(alg -> alg.match(algorithmName)).findFirst();
}
return Optional.empty();
}
use of org.sonar.plugins.java.api.tree.LiteralTree in project sonar-java by SonarSource.
the class StringBufferAndBuilderWithCharCheck method visitNewClass.
@Override
public void visitNewClass(NewClassTree tree) {
if (TARGETED_CLASS.contains(getclassName(tree)) && tree.arguments().size() == 1) {
ExpressionTree argument = tree.arguments().get(0);
if (argument.is(Tree.Kind.CHAR_LITERAL)) {
String character = ((LiteralTree) argument).value();
context.reportIssue(this, argument, "Replace the constructor character parameter " + character + " with string parameter " + character.replace("'", "\"") + ".");
}
}
}
use of org.sonar.plugins.java.api.tree.LiteralTree in project sonar-java by SonarSource.
the class SwitchInsteadOfIfSequenceCheck method getEqualMethodInvocationOperands.
private static Optional<EqualsOperands> getEqualMethodInvocationOperands(ExpressionTree expressionTree) {
ExpressionTree arg = null;
ExpressionTree expression = null;
if (expressionTree.is(Tree.Kind.METHOD_INVOCATION)) {
MethodInvocationTree mit = (MethodInvocationTree) expressionTree;
Symbol symbol = mit.symbol();
ExpressionTree methodSelect = mit.methodSelect();
if (mit.arguments().size() == 1) {
arg = mit.arguments().get(0);
if ("equals".equals(symbol.name()) && arg.symbolType().is("java.lang.String") && methodSelect.is(Tree.Kind.MEMBER_SELECT)) {
expression = ((MemberSelectExpressionTree) methodSelect).expression();
}
}
} else if (expressionTree.is(Tree.Kind.EQUAL_TO)) {
BinaryExpressionTree equalTo = (BinaryExpressionTree) expressionTree;
arg = equalTo.leftOperand();
expression = equalTo.rightOperand();
}
if (arg != null && expression != null) {
if (arg.is(Tree.Kind.STRING_LITERAL) && expression.is(Tree.Kind.IDENTIFIER)) {
return Optional.of(new EqualsOperands((LiteralTree) arg, (IdentifierTree) expression));
} else if (arg.is(Tree.Kind.IDENTIFIER) && expression.is(Tree.Kind.STRING_LITERAL)) {
return Optional.of(new EqualsOperands((LiteralTree) expression, (IdentifierTree) arg));
}
}
return Optional.empty();
}
use of org.sonar.plugins.java.api.tree.LiteralTree in project sonar-java by SonarSource.
the class SecureCookieCheck method isSetSecureCall.
private static boolean isSetSecureCall(MethodInvocationTree mit) {
Symbol methodSymbol = mit.symbol();
boolean hasArityOne = mit.arguments().size() == 1;
if (hasArityOne && isCallSiteCookie(methodSymbol)) {
ExpressionTree expressionTree = mit.arguments().get(0);
if (expressionTree.is(Tree.Kind.BOOLEAN_LITERAL) && "false".equals(((LiteralTree) expressionTree).value())) {
return false;
}
return "setSecure".equals(getIdentifier(mit).name());
}
return false;
}
use of org.sonar.plugins.java.api.tree.LiteralTree in project sonar-java by SonarSource.
the class StringLiteralInsideEqualsCheck method check.
private void check(MethodInvocationTree tree) {
if (isEquals(tree.methodSelect()) && tree.arguments().size() == 1 && tree.arguments().get(0).is(Kind.STRING_LITERAL)) {
LiteralTree stringLiteral = (LiteralTree) tree.arguments().get(0);
reportIssue(stringLiteral, "Move the " + stringLiteral.value() + " string literal on the left side of this string comparison.");
}
}
Aggregations