Search in sources :

Example 1 with CALL_EXPR

use of org.sonar.plugins.python.api.tree.Tree.Kind.CALL_EXPR in project sonar-python by SonarSource.

the class UnsafeHttpMethodsCheck method checkDjangoView.

private static void checkDjangoView(FunctionDef functionDef, SubscriptionContext ctx) {
    for (Decorator decorator : functionDef.decorators()) {
        if (getSymbolFromTree(decorator.expression()).filter(symbol -> symbol.fullyQualifiedName() == null || COMPLIANT_DECORATORS.contains(symbol.fullyQualifiedName())).isPresent()) {
            return;
        }
        if (decorator.expression().is(CALL_EXPR)) {
            CallExpression callExpression = (CallExpression) decorator.expression();
            Symbol symbol = callExpression.calleeSymbol();
            if (symbol != null && "django.views.decorators.http.require_http_methods".equals(symbol.fullyQualifiedName())) {
                checkRequireHttpMethodsDecorator(ctx, callExpression);
                return;
            }
        }
    }
    ctx.addIssue(functionDef.name(), MESSAGE);
}
Also used : Decorator(org.sonar.plugins.python.api.tree.Decorator) LIST_LITERAL(org.sonar.plugins.python.api.tree.Tree.Kind.LIST_LITERAL) Arrays(java.util.Arrays) RegularArgument(org.sonar.plugins.python.api.tree.RegularArgument) REGULAR_ARGUMENT(org.sonar.plugins.python.api.tree.Tree.Kind.REGULAR_ARGUMENT) TreeUtils.argumentByKeyword(org.sonar.python.tree.TreeUtils.argumentByKeyword) PythonSubscriptionCheck(org.sonar.plugins.python.api.PythonSubscriptionCheck) FunctionDefImpl(org.sonar.python.tree.FunctionDefImpl) FunctionDef(org.sonar.plugins.python.api.tree.FunctionDef) TreeUtils(org.sonar.python.tree.TreeUtils) HashSet(java.util.HashSet) Decorator(org.sonar.plugins.python.api.tree.Decorator) FUNCDEF(org.sonar.plugins.python.api.tree.Tree.Kind.FUNCDEF) CALL_EXPR(org.sonar.plugins.python.api.tree.Tree.Kind.CALL_EXPR) STRING_LITERAL(org.sonar.plugins.python.api.tree.Tree.Kind.STRING_LITERAL) Expression(org.sonar.plugins.python.api.tree.Expression) TreeUtils.getSymbolFromTree(org.sonar.python.tree.TreeUtils.getSymbolFromTree) FILE_INPUT(org.sonar.plugins.python.api.tree.Tree.Kind.FILE_INPUT) Set(java.util.Set) StringLiteral(org.sonar.plugins.python.api.tree.StringLiteral) SubscriptionContext(org.sonar.plugins.python.api.SubscriptionContext) ListLiteral(org.sonar.plugins.python.api.tree.ListLiteral) Objects(java.util.Objects) FunctionSymbolImpl(org.sonar.python.semantic.FunctionSymbolImpl) List(java.util.List) CallExpression(org.sonar.plugins.python.api.tree.CallExpression) FileInput(org.sonar.plugins.python.api.tree.FileInput) Argument(org.sonar.plugins.python.api.tree.Argument) Optional(java.util.Optional) Rule(org.sonar.check.Rule) FunctionSymbol(org.sonar.plugins.python.api.symbols.FunctionSymbol) Symbol(org.sonar.plugins.python.api.symbols.Symbol) FunctionSymbol(org.sonar.plugins.python.api.symbols.FunctionSymbol) Symbol(org.sonar.plugins.python.api.symbols.Symbol) CallExpression(org.sonar.plugins.python.api.tree.CallExpression)

Aggregations

Arrays (java.util.Arrays)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Rule (org.sonar.check.Rule)1 PythonSubscriptionCheck (org.sonar.plugins.python.api.PythonSubscriptionCheck)1 SubscriptionContext (org.sonar.plugins.python.api.SubscriptionContext)1 FunctionSymbol (org.sonar.plugins.python.api.symbols.FunctionSymbol)1 Symbol (org.sonar.plugins.python.api.symbols.Symbol)1 Argument (org.sonar.plugins.python.api.tree.Argument)1 CallExpression (org.sonar.plugins.python.api.tree.CallExpression)1 Decorator (org.sonar.plugins.python.api.tree.Decorator)1 Expression (org.sonar.plugins.python.api.tree.Expression)1 FileInput (org.sonar.plugins.python.api.tree.FileInput)1 FunctionDef (org.sonar.plugins.python.api.tree.FunctionDef)1 ListLiteral (org.sonar.plugins.python.api.tree.ListLiteral)1 RegularArgument (org.sonar.plugins.python.api.tree.RegularArgument)1 StringLiteral (org.sonar.plugins.python.api.tree.StringLiteral)1