Search in sources :

Example 11 with PsiCFGMethod

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

Example 12 with PsiCFGMethod

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

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

the class PsiCFGScene method createLambdaAnonymousClass.

public PsiCFGClass createLambdaAnonymousClass(PsiLambdaExpression lambdaExpress, PsiClass parentInterface, PsiCFGClass declearingClass) {
    PsiCFGClass parentInterfaceCFGClass = getOrCreateCFGClass(parentInterface);
    //PsiCFGMethod[] methodsArray = parentInterfaceCFGClass.getAllMethods();
    PsiMethod overridedMethod = extractLambdaMethod(parentInterface);
    //Create the wrapper anonymous class
    PsiCFGClass wrapperClass = new PsiCFGClass(null, declearingClass.getDeclearingFile());
    wrapperClass.setAnonlymous();
    wrapperClass.setLambdaRef(lambdaExpress);
    //parentInterfaceCFGClass.addLambda(wrapperClass);
    declearingClass.addLambda(wrapperClass);
    wrapperClass.setDirectOverride(parentInterfaceCFGClass);
    PsiCFGMethod wrapperMethod = new PsiCFGMethod(lambdaExpress, overridedMethod, wrapperClass);
    wrapperClass.addMethod(wrapperMethod);
    mLambdaPsiCFGClassMap.put(lambdaExpress, wrapperClass);
    CFGUtil.constructMethodGraphForLambda(this, wrapperMethod);
    return wrapperClass;
}
Also used : PsiCFGMethod(com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGMethod) PsiCFGClass(com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGClass)

Example 14 with PsiCFGMethod

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

Example 15 with PsiCFGMethod

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

the class PsiCFGAnalysisUtil method parseMethods.

public void parseMethods(@NotNull PsiCFGClass clazz) {
    PsiMethod[] methods = clazz.getPsiClass().getMethods();
    for (PsiMethod curMethod : methods) {
        PsiCFGMethod curCFGMethod = new PsiCFGMethod(curMethod, clazz);
        clazz.addMethod(curCFGMethod);
    }
}
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