Search in sources :

Example 1 with PsiCallExpression

use of com.intellij.psi.PsiCallExpression in project PermissionsDispatcher by hotchemi.

the class CallOnRequestPermissionsResultDetector method checkMethodCall.

private static boolean checkMethodCall(PsiMethod method, PsiClass psiClass) {
    PsiCodeBlock codeBlock = method.getBody();
    if (codeBlock == null) {
        return false;
    }
    PsiStatement[] statements = codeBlock.getStatements();
    for (PsiStatement statement : statements) {
        if (!(statement instanceof PsiExpressionStatement)) {
            continue;
        }
        PsiExpression expression = ((PsiExpressionStatement) statement).getExpression();
        if (!(expression instanceof PsiCallExpression)) {
            continue;
        }
        PsiCallExpression callExpression = (PsiCallExpression) expression;
        String targetClassName = psiClass.getName() + "PermissionsDispatcher";
        PsiMethod resolveMethod = callExpression.resolveMethod();
        if (resolveMethod == null) {
            continue;
        }
        PsiClass containingClass = resolveMethod.getContainingClass();
        if (containingClass == null) {
            continue;
        }
        if (targetClassName.equals(containingClass.getName()) && "onRequestPermissionsResult".equals(resolveMethod.getName())) {
            return true;
        }
    }
    return false;
}
Also used : PsiStatement(com.intellij.psi.PsiStatement) PsiCodeBlock(com.intellij.psi.PsiCodeBlock) PsiExpressionStatement(com.intellij.psi.PsiExpressionStatement) PsiExpression(com.intellij.psi.PsiExpression) PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) PsiCallExpression(com.intellij.psi.PsiCallExpression)

Aggregations

PsiCallExpression (com.intellij.psi.PsiCallExpression)1 PsiClass (com.intellij.psi.PsiClass)1 PsiCodeBlock (com.intellij.psi.PsiCodeBlock)1 PsiExpression (com.intellij.psi.PsiExpression)1 PsiExpressionStatement (com.intellij.psi.PsiExpressionStatement)1 PsiMethod (com.intellij.psi.PsiMethod)1 PsiStatement (com.intellij.psi.PsiStatement)1