use of com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGMethod in project android by JetBrains.
the class CallgraphBuilder method addToCallGraph.
/**
* Add a single target method to the call graph
*
* @param callerNode The node that contains invocation statement
* @param calleeMethod The target method of this invocation
*/
public void addToCallGraph(GraphNode callerNode, PsiCFGMethod calleeMethod) {
mCallGraphInstance.callerNodeToMethodsMap.put(callerNode, calleeMethod);
mCallGraphInstance.calleeMethodToCallerGraphNodeMap.put(calleeMethod, callerNode);
PsiCFGMethod callerMethod = retrieveParentMethod(callerNode);
if (callerMethod != null) {
mCallGraphInstance.callerMethodToCalleeMethodMap.put(callerMethod, calleeMethod);
mCallGraphInstance.calleeMethodToCallerMethodReturnMap.put(calleeMethod, callerMethod);
mCallGraphInstance.allMethodsInGraph.add(callerMethod);
mCallGraphInstance.allMethodsInGraph.add(calleeMethod);
}
if (calleeMethod.getControlFlowGraph() != null) {
GraphNode entryNode = calleeMethod.getControlFlowGraph().getEntryNode();
GraphNode exitNode = calleeMethod.getControlFlowGraph().getExitNode();
mCallGraphInstance.callerNodeToCalleeNodeMap.put(callerNode, entryNode);
mCallGraphInstance.calleeNodeToCallerNodeMap.put(exitNode, callerNode);
}
}
use of com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGMethod 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.PsiCFGMethod in project android by JetBrains.
the class PsiCFGScene method createLambdaAnonymousClass.
public PsiCFGClass createLambdaAnonymousClass(PsiLambdaExpression lambdaExpress, PsiClass parentInterface, PsiCFGClass declearingClass) {
PsiCFGClass parentInterfaceCFGClass = getOrCreateCFGClass(parentInterface);
//PsiCFGMethod[] methodsArray = parentInterfaceCFGClass.getAllMethods();
PsiMethod overridedMethod = extractLambdaMethod(parentInterface);
//Create the wrapper anonymous class
PsiCFGClass wrapperClass = new PsiCFGClass(null, declearingClass.getDeclearingFile());
wrapperClass.setAnonlymous();
wrapperClass.setLambdaRef(lambdaExpress);
//parentInterfaceCFGClass.addLambda(wrapperClass);
declearingClass.addLambda(wrapperClass);
wrapperClass.setDirectOverride(parentInterfaceCFGClass);
PsiCFGMethod wrapperMethod = new PsiCFGMethod(lambdaExpress, overridedMethod, wrapperClass);
wrapperClass.addMethod(wrapperMethod);
mLambdaPsiCFGClassMap.put(lambdaExpress, wrapperClass);
CFGUtil.constructMethodGraphForLambda(this, wrapperMethod);
return wrapperClass;
}
use of com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGMethod in project android by JetBrains.
the class CallgraphBuilder method performCHAForInvocationSite.
public void performCHAForInvocationSite(GraphNode node, PsiType receiverType, PsiCFGMethod targetMethod) {
//Only Object can perform instance invoke
if (!(receiverType instanceof PsiClassType)) {
//The reciever type is not an object
PsiCFGDebugUtil.LOG.warning("The Receiver's type is not PsiClassType " + receiverType.getCanonicalText() + " " + targetMethod.getName());
} else {
PsiClassType receiverClassType = (PsiClassType) receiverType;
PsiClass psiClassRef = receiverClassType.resolve();
PsiCFGClass receiverClass = mScene.getPsiCFGClass(psiClassRef);
if (receiverClass == null) {
PsiCFGDebugUtil.LOG.warning("The Receiver's CFGClass is not resolved during " + "the CFG construction " + psiClassRef.getQualifiedName());
return;
}
//Find first concrete method to the top
//It may not exist
PsiCFGPartialMethodSignature methodSignature = targetMethod.getSignature();
PsiCFGMethod nearestConcreteMethodFromTop = getNearestConcreteMethod(receiverClass, methodSignature);
if (nearestConcreteMethodFromTop != null) {
addToCallGraph(node, nearestConcreteMethodFromTop);
}
//Find concrete method to the leaf
ArrayList<PsiCFGMethod> methodList = Lists.newArrayList();
recursivelyQueryConcreteMethodFromChildrenWithCache(methodList, receiverClass, methodSignature);
for (PsiCFGMethod concreteMethodFromSubClass : methodList) {
addToCallGraph(node, concreteMethodFromSubClass);
}
}
}
use of com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGMethod in project android by JetBrains.
the class PsiCFGAnalysisUtil method parseMethods.
public void parseMethods(@NotNull PsiCFGClass clazz) {
PsiMethod[] methods = clazz.getPsiClass().getMethods();
for (PsiMethod curMethod : methods) {
PsiCFGMethod curCFGMethod = new PsiCFGMethod(curMethod, clazz);
clazz.addMethod(curCFGMethod);
}
}
Aggregations