Search in sources :

Example 1 with MethodGraph

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

the class CFGBuilder method resolveParam.

/**
   * Resolve the parameter at the current context.
   * @param param The parameter
   * @return The PsiCFG wrapper for the parameter
   */
@Nullable
private Param resolveParam(@NotNull PsiParameter param) {
    Graph graph = this.mGraph;
    if (graph instanceof BlockGraph) {
        Param p = ((BlockGraph) graph).getParamFromPsiParameter(param);
        if (p == null) {
            if (graph instanceof MethodGraph) {
                MethodGraph methodGraph = (MethodGraph) graph;
                PsiCFGDebugUtil.LOG.warning("Parameter " + param.getName() + " does not exist in method " + methodGraph.getPsiCFGMethod().getName() + " in class " + this.containerClass.getQualifiedClassName());
            } else {
                PsiStatement psiStmt = ((BlockGraph) graph).getParentStmt();
                PsiCFGDebugUtil.LOG.warning("Parameter " + param.getName() + " does not exist in context " + psiStmt.getText() + " in class " + this.containerClass.getQualifiedClassName());
            }
        }
        return p;
    }
    PsiCFGDebugUtil.LOG.warning("Parameter " + param.getName() + " does not exist, the graph is not" + " a block graph");
    return null;
}
Also used : SwitchCaseGraph(com.android.tools.idea.experimental.codeanalysis.datastructs.graph.SwitchCaseGraph) MethodGraph(com.android.tools.idea.experimental.codeanalysis.datastructs.graph.MethodGraph) BlockGraph(com.android.tools.idea.experimental.codeanalysis.datastructs.graph.BlockGraph) Graph(com.android.tools.idea.experimental.codeanalysis.datastructs.graph.Graph) MethodGraph(com.android.tools.idea.experimental.codeanalysis.datastructs.graph.MethodGraph) BlockGraph(com.android.tools.idea.experimental.codeanalysis.datastructs.graph.BlockGraph) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with MethodGraph

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

the class PsiCFGAnalysisUtil method performStage3.

/**
   * The purpose of the Stage3 is create IntraProcedural
   * CFG for the methods and lambdas inside the app
   * class, including the constructor and the init code
   */
public void performStage3() {
    PsiCFGClass[] appClasses = mScene.getAllApplicationClasses();
    mScene.workingList.clear();
    mScene.workingList.addAll(Arrays.asList(appClasses));
    while (!mScene.workingList.isEmpty()) {
        //While the working list is not empty
        //Process the working list
        PsiCFGClass currentClass = mScene.workingList.removeFirst();
        PsiCFGMethod[] allMethods = currentClass.getAllMethods();
        for (PsiCFGMethod currentMethod : allMethods) {
            //Lambda methods' CFG is created by the time it is decleared
            if (currentMethod.isAbstract() || currentMethod.isLambda()) {
                continue;
            }
            PsiMethod methodRef = currentMethod.getMethodRef();
            if (methodRef != null) {
                PsiCodeBlock codeBlock = methodRef.getBody();
                if (codeBlock == null) {
                    PsiCFGDebugUtil.LOG.info("In " + currentClass.getQualifiedClassName() + "." + currentMethod.getName() + "Code block is null");
                    continue;
                }
                MethodGraph cfg = CFGUtil.constructMethodGraph(mScene, codeBlock, currentMethod);
                currentMethod.setControlFlowGraph(cfg);
            }
        }
    }
}
Also used : PsiCFGMethod(com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGMethod) MethodGraph(com.android.tools.idea.experimental.codeanalysis.datastructs.graph.MethodGraph) PsiCFGClass(com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGClass)

Aggregations

MethodGraph (com.android.tools.idea.experimental.codeanalysis.datastructs.graph.MethodGraph)2 PsiCFGClass (com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGClass)1 PsiCFGMethod (com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGMethod)1 BlockGraph (com.android.tools.idea.experimental.codeanalysis.datastructs.graph.BlockGraph)1 Graph (com.android.tools.idea.experimental.codeanalysis.datastructs.graph.Graph)1 SwitchCaseGraph (com.android.tools.idea.experimental.codeanalysis.datastructs.graph.SwitchCaseGraph)1 Nullable (org.jetbrains.annotations.Nullable)1