Search in sources :

Example 1 with PsiCFGMethod

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

the class PermissionUsageInspection method dfsFindCallChain.

private void dfsFindCallChain(Stack<GraphNode> nodeStack, Stack<PsiCFGMethod> methodStack, GraphNode node, PsiCFGMethod target) {
    if ((methodStack.size() > 5) || methodStack.contains(target)) {
        if (longestMethodStack.size() < methodStack.size()) {
            longestNodeStack = Lists.newArrayList(nodeStack);
            longestMethodStack = Lists.newArrayList(methodStack);
        }
        return;
    }
    methodStack.push(target);
    nodeStack.push(node);
    if (mCG.calleeMethodToCallerGraphNodeMap.containsKey(target)) {
        Collection<GraphNode> invocationSites = mCG.calleeMethodToCallerGraphNodeMap.get(target);
        for (GraphNode nextTarget : invocationSites) {
            PsiCFGMethod targetMethod = mCG.getNodesParentMethod(nextTarget);
            if (targetMethod != null) {
                dfsFindCallChain(nodeStack, methodStack, nextTarget, targetMethod);
            }
        }
    } else {
        //Top
        if (longestMethodStack.size() < methodStack.size()) {
            longestNodeStack = Lists.newArrayList(nodeStack);
            longestMethodStack = Lists.newArrayList(methodStack);
        }
    }
}
Also used : PsiCFGMethod(com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGMethod) GraphNode(com.android.tools.idea.experimental.codeanalysis.datastructs.graph.node.GraphNode)

Example 2 with PsiCFGMethod

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

the class PermissionUsageInspection method resolveInitialCaller.

private void resolveInitialCaller(PsiCFGMethod method) {
    Set<PsiCFGMethod> calledMethods = Sets.newHashSet();
    //Stack<PsiCFGMethod> callStack = new Stack<>();
    Stack<GraphNode> nodeStack = new Stack<>();
    Stack<PsiCFGMethod> methodStack = new Stack<>();
    longestMethodStack = Lists.newArrayList();
    longestNodeStack = Lists.newArrayList();
    if ((!mCG.calleeMethodToCallerMethodReturnMap.containsKey(method)) && (!mCG.callerMethodToCalleeMethodMap.containsKey(method))) {
        return;
    }
    dfsFindCallChain(nodeStack, methodStack, null, method);
    for (int i = 0; i < longestMethodStack.size(); i++) {
        GraphNode currentNode = longestNodeStack.get(i);
        PsiCFGMethod currentMethod = longestMethodStack.get(i);
    }
    PsiCFGMethod topMethod = longestMethodStack.get(longestMethodStack.size() - 1);
    GraphNode topNode = longestNodeStack.get(longestNodeStack.size() - 1);
    PsiElement psiRef = extractPsiElement(topNode);
    invocationSiteCollection.add(new Pair<>(topMethod, psiRef));
}
Also used : PsiCFGMethod(com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGMethod) GraphNode(com.android.tools.idea.experimental.codeanalysis.datastructs.graph.node.GraphNode)

Example 3 with PsiCFGMethod

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

the class PermissionUsageInspection method runAnalysis.

public void runAnalysis() {
    getTargetMethodsList();
    if (targetMethodList.isEmpty()) {
        //System.out.println("No Location API used in this project.");
        return;
    }
    for (PsiCFGMethod currentTarget : targetMethodList) {
        resolveInitialCaller(currentTarget);
    }
    //outputInvocationSiteInfos();
    tagTheResult();
}
Also used : PsiCFGMethod(com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGMethod)

Example 4 with PsiCFGMethod

use of com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGMethod 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 5 with PsiCFGMethod

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

the class PermissionUsageInspection method outputInvocationSiteInfos.

public void outputInvocationSiteInfos() {
    for (Pair<PsiCFGMethod, PsiElement> singleInvoke : invocationSiteCollection) {
        PsiCFGMethod currentMethod = singleInvoke.getFirst();
        PsiElement currentElement = singleInvoke.getSecond();
        if (currentElement != null) {
        //System.out.println(String.format("In %s method, Invoke Element %s", currentMethod.getName(), currentElement.getText()));
        }
    }
}
Also used : PsiCFGMethod(com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGMethod)

Aggregations

PsiCFGMethod (com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGMethod)17 PsiCFGClass (com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGClass)8 PsiCFGPartialMethodSignature (com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGPartialMethodSignature)3 GraphNode (com.android.tools.idea.experimental.codeanalysis.datastructs.graph.node.GraphNode)3 PsiClassType (com.intellij.psi.PsiClassType)2 MethodGraph (com.android.tools.idea.experimental.codeanalysis.datastructs.graph.MethodGraph)1 Pair (com.intellij.openapi.util.Pair)1 PsiClass (com.intellij.psi.PsiClass)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1