use of com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGClass in project android by JetBrains.
the class CFGUtil method outputCFGDotFile.
public static void outputCFGDotFile(MethodGraph graph) {
String path = PathManager.getLogPath();
//PsiMethod psiMethod = (PsiMethod) graph.getPsiCFGMethod().getPsiRef();
String methodName = graph.getPsiCFGMethod().getName();
String className = "dummyClass";
//PsiElement parentElement = psiMethod.getParent();
PsiCFGClass cfgClass = graph.getPsiCFGMethod().getDeclaringClass();
//if (parentElement instanceof PsiClass) {
// PsiClass mClass = graph.getPsiCFGMethod().getDeclaringClass().getPsiClass();
// className = mClass.getQualifiedName().replace("." , "-");
//}
className = cfgClass.getQualifiedClassName().replace(".", "-");
String fileName = className + "-" + methodName + ".dot";
BufferedWriter bw = null;
try {
File dotFile = new File(path, fileName);
if (dotFile.exists()) {
dotFile.delete();
}
dotFile.createNewFile();
PsiCFGDebugUtil.LOG.info("Log CFG to file: " + dotFile.getAbsolutePath());
FileWriter fw = new FileWriter(dotFile);
bw = new BufferedWriter(fw);
Map<GraphNode, Integer> allNodes = getAllNodeFromGraph(graph);
//Output digraph G
bw.write("digraph G {\n");
for (GraphNode node : allNodes.keySet()) {
String label = getLabelFromGraphNode(node);
String line = String.format("n%d[label=\"%s\"];\n", allNodes.get(node), label);
bw.write(line);
}
bw.write("\n");
bfsOutputEdges(bw, graph.getEntryNode(), allNodes);
bw.write("}");
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
try {
if (bw != null) {
bw.close();
}
} catch (Exception ex) {
}
}
}
use of com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGClass in project android by JetBrains.
the class CHAUtil method dfsSetConeBits.
private void dfsSetConeBits(BitSet bitSet, PsiCFGClass clazz) {
if (!mClassIndexMap.containsKey(clazz)) {
throw new RuntimeException("class is not found in IndexMap: " + clazz.getQualifiedClassName());
}
int index = mClassIndexMap.get(clazz);
bitSet.set(index);
Set<PsiCFGClass> subClassSet = clazz.getSubClassSet();
for (PsiCFGClass subClazz : subClassSet) {
dfsSetConeBits(bitSet, subClazz);
}
}
use of com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGClass in project android by JetBrains.
the class CallgraphBuilder method addInvokeExprWithThisRef.
public void addInvokeExprWithThisRef(GraphNode node, PsiType thisBaseType, PsiCFGMethod method) {
if (!method.isAbstract()) {
addToCallGraph(node, method);
} else {
PsiClassType classType = null;
PsiCFGClass cfgClass = null;
if (thisBaseType instanceof PsiClassType) {
classType = (PsiClassType) thisBaseType;
cfgClass = mScene.getPsiCFGClass(classType.resolve());
} else {
PsiCFGDebugUtil.LOG.warning("PsiType of ThisRef is not a PsiClassType :" + thisBaseType.getClass().getSimpleName());
return;
}
if (cfgClass == null) {
PsiCFGDebugUtil.LOG.warning("PsiType of ThisRef cannot be resolved to cfgClass :" + thisBaseType.getClass().getSimpleName());
}
ArrayList<PsiCFGMethod> methodsList = Lists.newArrayList();
recursivelyQueryConcreteMethodFromChildrenWithCache(methodsList, cfgClass, method.getSignature());
}
}
use of com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGClass 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);
}
}
}
use of com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGClass in project android by JetBrains.
the class PsiCFGAnalysisUtil method performStage1.
/**
* The purpose of the Stage1 is scan the project java files and
* create wrapper objects for the Fields and Methods.
*/
public void performStage1() {
PsiCFGClass[] appClasses = mScene.getAllApplicationClasses();
for (PsiCFGClass curClass : appClasses) {
parseFields(curClass);
parseMethods(curClass);
}
}
Aggregations