use of com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGPartialMethodSignature 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.PsiCFGPartialMethodSignature 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.PsiCFGPartialMethodSignature 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);
}
}
}
Aggregations