Search in sources :

Example 26 with PsiCFGClass

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

the class PsiCFGAnalysisUtil method setClassHierarchyForApplicationClass.

public void setClassHierarchyForApplicationClass(@NotNull PsiCFGClass clazz) {
    if (clazz.getPsiClass() != null) {
        PsiClass psiClassRef = clazz.getPsiClass();
        PsiClass directSuperClass = psiClassRef.getSuperClass();
        PsiClass[] implementedInterface = psiClassRef.getInterfaces();
        if (directSuperClass == null && mLangOjectClass != null) {
            PsiCFGDebugUtil.LOG.warning("Super class is null for class " + clazz.getQualifiedClassName());
            directSuperClass = mLangOjectClass;
        }
        if (directSuperClass != null) {
            PsiCFGClass directCFGSuperClass = mScene.getOrCreateCFGClass(directSuperClass);
            //Set superClass
            clazz.setSuperClass(directCFGSuperClass);
            directCFGSuperClass.addSubClass(clazz);
        }
        for (PsiClass interfaze : implementedInterface) {
            PsiCFGClass cfgInterfaze = mScene.getOrCreateCFGClass(interfaze);
            clazz.addInterface(cfgInterfaze);
            if (clazz.isInterface()) {
                cfgInterfaze.addSubInterface(clazz);
            } else {
                cfgInterfaze.addSubClass(clazz);
            }
        }
    }
}
Also used : PsiCFGClass(com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGClass)

Example 27 with PsiCFGClass

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

the class PsiCFGAnalysisUtil method setInterfacesIfInLibrary.

public void setInterfacesIfInLibrary(PsiCFGClass curLibraryClass, PsiClass[] interfazes, Set<PsiClass> interfaceSet) {
    for (PsiClass curInterface : interfazes) {
        if (interfaceSet.contains(curInterface)) {
            PsiCFGClass curCFGInterface = mScene.getOrCreateCFGClass(curInterface);
            curLibraryClass.setSuperClass(curCFGInterface);
            curCFGInterface.addSubClass(curLibraryClass);
        }
    }
}
Also used : PsiCFGClass(com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGClass)

Example 28 with PsiCFGClass

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

PsiCFGClass (com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGClass)28 PsiCFGMethod (com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGMethod)8 PsiCFGPartialMethodSignature (com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGPartialMethodSignature)3 PsiCFGField (com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGField)2 PsiClassType (com.intellij.psi.PsiClassType)2 MethodGraph (com.android.tools.idea.experimental.codeanalysis.datastructs.graph.MethodGraph)1 PsiCFGAnalysisUtil (com.android.tools.idea.experimental.codeanalysis.utils.PsiCFGAnalysisUtil)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