Search in sources :

Example 1 with PsiCFGPartialMethodSignature

use of com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGPartialMethodSignature in project android by JetBrains.

the class PermissionUsageInspection method getTargetMethodsListFromPsiClass.

private void getTargetMethodsListFromPsiClass(@NotNull PsiClass clazz) {
    PsiMethod[] methodsArray = clazz.getMethods();
    methodsArray = removeMethodsRequireNoPermission(methodsArray);
    PsiCFGClass cfgClazz = mScene.getPsiCFGClass(clazz);
    if (cfgClazz == null) {
        return;
    }
    for (PsiMethod currentMethod : methodsArray) {
        PsiCFGPartialMethodSignature signature = PsiCFGPartialMethodSignatureBuilder.buildFromPsiMethod(currentMethod);
        PsiCFGMethod cfgMethod = cfgClazz.getMethod(signature);
        if (cfgMethod != null) {
            targetMethodList.add(cfgMethod);
        }
    }
}
Also used : PsiCFGMethod(com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGMethod) PsiCFGPartialMethodSignature(com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGPartialMethodSignature) PsiCFGClass(com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGClass)

Example 2 with PsiCFGPartialMethodSignature

use of com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGPartialMethodSignature in project android by JetBrains.

the class CallgraphBuilder method recursivelyQueryConcreteMethodFromChildrenWithOutCache.

public void recursivelyQueryConcreteMethodFromChildrenWithOutCache(ArrayList<PsiCFGMethod> methodList, PsiCFGClass receiverClass, PsiCFGPartialMethodSignature signature) {
    Pair<PsiCFGClass, PsiCFGPartialMethodSignature> keyPair = new Pair<>(receiverClass, signature);
    PsiCFGMethod method = receiverClass.getMethod(signature);
    if (method != null && (!method.isAbstract())) {
        methodList.add(method);
    }
    //Go through sub classes and interfaces
    for (PsiCFGClass subClass : receiverClass.getSubClassSet()) {
        if (mMethodOrderTreeMap.containsKey(keyPair)) {
            methodList.addAll(mMethodOrderTreeMap.get(keyPair));
        } else {
            recursivelyQueryConcreteMethodFromChildrenWithOutCache(methodList, subClass, signature);
        }
    }
}
Also used : PsiCFGMethod(com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGMethod) PsiCFGPartialMethodSignature(com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGPartialMethodSignature) PsiCFGClass(com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGClass) Pair(com.intellij.openapi.util.Pair)

Example 3 with PsiCFGPartialMethodSignature

use of com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGPartialMethodSignature in project android by JetBrains.

the class CallgraphBuilder method performCHAForInvocationSite.

public void performCHAForInvocationSite(GraphNode node, PsiType receiverType, PsiCFGMethod targetMethod) {
    //Only Object can perform instance invoke
    if (!(receiverType instanceof PsiClassType)) {
        //The reciever type is not an object
        PsiCFGDebugUtil.LOG.warning("The Receiver's type is not PsiClassType " + receiverType.getCanonicalText() + "  " + targetMethod.getName());
    } else {
        PsiClassType receiverClassType = (PsiClassType) receiverType;
        PsiClass psiClassRef = receiverClassType.resolve();
        PsiCFGClass receiverClass = mScene.getPsiCFGClass(psiClassRef);
        if (receiverClass == null) {
            PsiCFGDebugUtil.LOG.warning("The Receiver's CFGClass is not resolved during " + "the CFG construction " + psiClassRef.getQualifiedName());
            return;
        }
        //Find first concrete method to the top
        //It may not exist
        PsiCFGPartialMethodSignature methodSignature = targetMethod.getSignature();
        PsiCFGMethod nearestConcreteMethodFromTop = getNearestConcreteMethod(receiverClass, methodSignature);
        if (nearestConcreteMethodFromTop != null) {
            addToCallGraph(node, nearestConcreteMethodFromTop);
        }
        //Find concrete method to the leaf
        ArrayList<PsiCFGMethod> methodList = Lists.newArrayList();
        recursivelyQueryConcreteMethodFromChildrenWithCache(methodList, receiverClass, methodSignature);
        for (PsiCFGMethod concreteMethodFromSubClass : methodList) {
            addToCallGraph(node, concreteMethodFromSubClass);
        }
    }
}
Also used : PsiCFGMethod(com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGMethod) PsiClassType(com.intellij.psi.PsiClassType) PsiCFGPartialMethodSignature(com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGPartialMethodSignature) PsiClass(com.intellij.psi.PsiClass) PsiCFGClass(com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGClass)

Aggregations

PsiCFGClass (com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGClass)3 PsiCFGMethod (com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGMethod)3 PsiCFGPartialMethodSignature (com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGPartialMethodSignature)3 Pair (com.intellij.openapi.util.Pair)1 PsiClass (com.intellij.psi.PsiClass)1 PsiClassType (com.intellij.psi.PsiClassType)1