Search in sources :

Example 1 with PsiCFGClass

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

the class CodeAnalysisMain method analyze.

public void analyze(@NotNull AnalysisScope scope) {
    //    PsiDocumentManager.getInstance(mProject).commitAllDocuments();
    //Create a mScene for this project.
    //Each project has its own mScene.
    mScene = PsiCFGScene.createFreshInstance(mProject);
    PsiCFGAnalysisUtil AnalysisUtil = mScene.analysisUtil;
    //Get list of java files available in this project
    int fileCount = scope.getFileCount();
    //LOG.info("File count in scope " + fileCount);
    PsiFile[] allFilesInScope = findAllJavaFiles(mProject, scope);
    //LOG.info("File count in visitor " + allFilesInScope.length);
    //outputFileNames(allFilesInScope);
    //Extract all java classes from java files.
    //Consider these classes are application classes.
    //As they are written by developer
    initiateProjectClassesFromPsiFile(allFilesInScope);
    PsiCFGClass[] allClasses = mScene.getAllApplicationClasses();
    //Perform the analysis
    AnalysisUtil.performStage0();
    AnalysisUtil.performStage1();
    AnalysisUtil.performStage2();
    AnalysisUtil.performStage3();
    AnalysisUtil.performStage4();
    //AnalysisUtil.summarizeStage();
    AnalysisUtil.performStage5();
    AnalysisUtil.performStage6();
}
Also used : PsiCFGAnalysisUtil(com.android.tools.idea.experimental.codeanalysis.utils.PsiCFGAnalysisUtil) PsiCFGClass(com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGClass)

Example 2 with PsiCFGClass

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

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

the class PsiCFGScene method getAllLambdaClass.

/**
   * Get all PsiCFGClass instances constructed from the lambda expression.
   * @return A new array of PsiCFGClass instances which are lambda anonymous classes will be
   * returned.
   */
public PsiCFGClass[] getAllLambdaClass() {
    PsiCFGClass[] retArray = new PsiCFGClass[mLambdaPsiCFGClassMap.size()];
    int i = 0;
    for (PsiLambdaExpression lbdExpr : mLambdaPsiCFGClassMap.keySet()) {
        PsiCFGClass mLbdClass = mLambdaPsiCFGClassMap.get(lbdExpr);
        retArray[i++] = mLbdClass;
    }
    return retArray;
}
Also used : PsiCFGClass(com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGClass)

Example 4 with PsiCFGClass

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

the class PsiCFGScene method createLibraryCFGClassesWInnerClasses.

/**
   * @param clazz
   * @return
   */
public PsiCFGClass createLibraryCFGClassesWInnerClasses(PsiClass clazz) {
    ArrayList<PsiClass> classList = Lists.newArrayList();
    retriveClassAndInnerClass(classList, clazz);
    classList.remove(clazz);
    PsiCFGClass retVal = createPsiCFGClass(clazz, null, false);
    analysisUtil.parseFields(retVal);
    analysisUtil.parseMethods(retVal);
    for (PsiClass curClassRef : classList) {
        PsiCFGClass curCFGClass = createPsiCFGClass(curClassRef, null, false);
        analysisUtil.parseFields(curCFGClass);
        analysisUtil.parseMethods(curCFGClass);
    }
    retVal.setLibraryClass();
    return retVal;
}
Also used : PsiCFGClass(com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGClass)

Example 5 with PsiCFGClass

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

the class PsiCFGScene method createPsiCFGClass.

public PsiCFGClass createPsiCFGClass(PsiClass psiClass, PsiFile declaringFile, boolean bAppClass) {
    String fullClassName = psiClass.getQualifiedName();
    if (fullClassName == null) {
        //TODO: Local or anonymous class
        PsiCFGDebugUtil.LOG.warning("The class has no name: ");
        PsiCFGDebugUtil.debugOutputPsiElement(psiClass);
        throw new RuntimeException(String.format("Class %s does not have a full name", psiClass.getText()));
    }
    if (!psiClass.isInterface()) {
        PsiCFGClass newClass = new PsiCFGClass(psiClass, declaringFile);
        if (bAppClass) {
            mAppClassNamePsiMap.put(fullClassName, newClass);
            mAppPsiClassPsiCFGClassMap.put(psiClass, newClass);
        } else {
            mLibraryClassNamePsiMap.put(fullClassName, newClass);
            mLibraryPsiClassPsiCFGClassMap.put(psiClass, newClass);
            newClass.setLibraryClass();
        }
        return newClass;
    } else {
        PsiCFGClass newInterface = new PsiCFGClass(psiClass, declaringFile);
        newInterface.setIsInterface(true);
        if (bAppClass) {
            mAppClassNamePsiMap.put(fullClassName, newInterface);
            mAppPsiClassPsiCFGClassMap.put(psiClass, newInterface);
        } else {
            mLibraryClassNamePsiMap.put(fullClassName, newInterface);
            mLibraryPsiClassPsiCFGClassMap.put(psiClass, newInterface);
            newInterface.setLibraryClass();
        }
        return newInterface;
    }
}
Also used : 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