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();
}
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);
}
}
}
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;
}
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;
}
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;
}
}
Aggregations