use of com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGMethod in project android by JetBrains.
the class CFGUtil method outputCallGraphDotFile.
public static void outputCallGraphDotFile(Callgraph cg) {
String path = PathManager.getLogPath();
String fileName = "CallGraph.dot";
BufferedWriter bw = null;
try {
File dotFile = new File(path, fileName);
if (dotFile.exists()) {
dotFile.delete();
}
dotFile.createNewFile();
PsiCFGDebugUtil.LOG.info("Log Callgraph to file: " + dotFile.getAbsolutePath());
FileWriter fw = new FileWriter(dotFile);
bw = new BufferedWriter(fw);
Map<PsiCFGMethod, Integer> allNodes = getAllMethodNodesFromCallGraph(cg);
bw.write("digraph G{\n");
for (PsiCFGMethod method : allNodes.keySet()) {
String label = method.getName();
String line = String.format("n%d[label=\"%s\"];\n", allNodes.get(method), label);
bw.write(line);
}
bw.write("\n");
for (PsiCFGMethod curMethod : cg.callerMethodToCalleeMethodMap.keySet()) {
Integer sId = allNodes.get(curMethod);
for (PsiCFGMethod tgtMethod : cg.callerMethodToCalleeMethodMap.get(curMethod)) {
Integer tId = allNodes.get(tgtMethod);
String line = String.format("n%d -> n%d;\n", sId, tId);
bw.write(line);
}
}
bw.write("\n");
bw.write("}");
//Output digraphG
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
try {
if (bw != null) {
bw.close();
}
} catch (Exception ex) {
}
}
}
use of com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGMethod 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);
}
}
}
}
Aggregations