Search in sources :

Example 1 with GraphNode

use of com.android.tools.idea.experimental.codeanalysis.datastructs.graph.node.GraphNode 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 GraphNode

use of com.android.tools.idea.experimental.codeanalysis.datastructs.graph.node.GraphNode 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 GraphNode

use of com.android.tools.idea.experimental.codeanalysis.datastructs.graph.node.GraphNode in project android by JetBrains.

the class LoopBranchingNodeImpl method processBreaks.

public void processBreaks() {
    if (mLoopType == LoopBranchingNode.FOREACH_LOOP) {
        //In foreach loop. Break connects to the exit node of the body
        GraphNode bodyExit = mLoopBody.getExitNode();
        for (GraphNode breakNode : this.breakNodeList) {
            GraphNodeUtil.connectGraphNode(breakNode, bodyExit);
        }
        this.breakNodeList.clear();
    } else {
        //Null check
        if (mConditionCheckExitNode == null) {
            return;
        }
        GraphNode falseBranch = ((ConditionCheckNode) mConditionCheckExitNode).getFalseBranch();
        for (GraphNode breakNode : this.breakNodeList) {
            GraphNodeUtil.connectGraphNode(breakNode, falseBranch);
        }
        this.breakNodeList.clear();
    }
}
Also used : GraphNode(com.android.tools.idea.experimental.codeanalysis.datastructs.graph.node.GraphNode) ConditionCheckNode(com.android.tools.idea.experimental.codeanalysis.datastructs.graph.node.ConditionCheckNode)

Example 4 with GraphNode

use of com.android.tools.idea.experimental.codeanalysis.datastructs.graph.node.GraphNode in project android by JetBrains.

the class CallgraphBuilder method build.

public void build() {
    //Initiate
    this.mCallGraphInstance = new Callgraph();
    //Retrive all callsites
    GraphNode[] invocationNodes = mScene.getAllInvocationNode();
    for (GraphNode invocationNode : invocationNodes) {
        processSingleInvocation(invocationNode);
    }
}
Also used : GraphNode(com.android.tools.idea.experimental.codeanalysis.datastructs.graph.node.GraphNode)

Example 5 with GraphNode

use of com.android.tools.idea.experimental.codeanalysis.datastructs.graph.node.GraphNode in project android by JetBrains.

the class CallgraphBuilder method addToCallGraph.

/**
   * Add a single target method to the call graph
   *
   * @param callerNode   The node that contains invocation statement
   * @param calleeMethod The target method of this invocation
   */
public void addToCallGraph(GraphNode callerNode, PsiCFGMethod calleeMethod) {
    mCallGraphInstance.callerNodeToMethodsMap.put(callerNode, calleeMethod);
    mCallGraphInstance.calleeMethodToCallerGraphNodeMap.put(calleeMethod, callerNode);
    PsiCFGMethod callerMethod = retrieveParentMethod(callerNode);
    if (callerMethod != null) {
        mCallGraphInstance.callerMethodToCalleeMethodMap.put(callerMethod, calleeMethod);
        mCallGraphInstance.calleeMethodToCallerMethodReturnMap.put(calleeMethod, callerMethod);
        mCallGraphInstance.allMethodsInGraph.add(callerMethod);
        mCallGraphInstance.allMethodsInGraph.add(calleeMethod);
    }
    if (calleeMethod.getControlFlowGraph() != null) {
        GraphNode entryNode = calleeMethod.getControlFlowGraph().getEntryNode();
        GraphNode exitNode = calleeMethod.getControlFlowGraph().getExitNode();
        mCallGraphInstance.callerNodeToCalleeNodeMap.put(callerNode, entryNode);
        mCallGraphInstance.calleeNodeToCallerNodeMap.put(exitNode, callerNode);
    }
}
Also used : PsiCFGMethod(com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGMethod) GraphNode(com.android.tools.idea.experimental.codeanalysis.datastructs.graph.node.GraphNode)

Aggregations

GraphNode (com.android.tools.idea.experimental.codeanalysis.datastructs.graph.node.GraphNode)6 PsiCFGMethod (com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGMethod)3 ConditionCheckNode (com.android.tools.idea.experimental.codeanalysis.datastructs.graph.node.ConditionCheckNode)1 Value (com.android.tools.idea.experimental.codeanalysis.datastructs.value.Value)1