use of com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGMethod in project android by JetBrains.
the class PermissionUsageInspection method dfsFindCallChain.
private void dfsFindCallChain(Stack<GraphNode> nodeStack, Stack<PsiCFGMethod> methodStack, GraphNode node, PsiCFGMethod target) {
if ((methodStack.size() > 5) || methodStack.contains(target)) {
if (longestMethodStack.size() < methodStack.size()) {
longestNodeStack = Lists.newArrayList(nodeStack);
longestMethodStack = Lists.newArrayList(methodStack);
}
return;
}
methodStack.push(target);
nodeStack.push(node);
if (mCG.calleeMethodToCallerGraphNodeMap.containsKey(target)) {
Collection<GraphNode> invocationSites = mCG.calleeMethodToCallerGraphNodeMap.get(target);
for (GraphNode nextTarget : invocationSites) {
PsiCFGMethod targetMethod = mCG.getNodesParentMethod(nextTarget);
if (targetMethod != null) {
dfsFindCallChain(nodeStack, methodStack, nextTarget, targetMethod);
}
}
} else {
//Top
if (longestMethodStack.size() < methodStack.size()) {
longestNodeStack = Lists.newArrayList(nodeStack);
longestMethodStack = Lists.newArrayList(methodStack);
}
}
}
use of com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGMethod in project android by JetBrains.
the class PermissionUsageInspection method resolveInitialCaller.
private void resolveInitialCaller(PsiCFGMethod method) {
Set<PsiCFGMethod> calledMethods = Sets.newHashSet();
//Stack<PsiCFGMethod> callStack = new Stack<>();
Stack<GraphNode> nodeStack = new Stack<>();
Stack<PsiCFGMethod> methodStack = new Stack<>();
longestMethodStack = Lists.newArrayList();
longestNodeStack = Lists.newArrayList();
if ((!mCG.calleeMethodToCallerMethodReturnMap.containsKey(method)) && (!mCG.callerMethodToCalleeMethodMap.containsKey(method))) {
return;
}
dfsFindCallChain(nodeStack, methodStack, null, method);
for (int i = 0; i < longestMethodStack.size(); i++) {
GraphNode currentNode = longestNodeStack.get(i);
PsiCFGMethod currentMethod = longestMethodStack.get(i);
}
PsiCFGMethod topMethod = longestMethodStack.get(longestMethodStack.size() - 1);
GraphNode topNode = longestNodeStack.get(longestNodeStack.size() - 1);
PsiElement psiRef = extractPsiElement(topNode);
invocationSiteCollection.add(new Pair<>(topMethod, psiRef));
}
use of com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGMethod in project android by JetBrains.
the class PermissionUsageInspection method runAnalysis.
public void runAnalysis() {
getTargetMethodsList();
if (targetMethodList.isEmpty()) {
//System.out.println("No Location API used in this project.");
return;
}
for (PsiCFGMethod currentTarget : targetMethodList) {
resolveInitialCaller(currentTarget);
}
//outputInvocationSiteInfos();
tagTheResult();
}
use of com.android.tools.idea.experimental.codeanalysis.datastructs.PsiCFGMethod 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.PsiCFGMethod in project android by JetBrains.
the class PermissionUsageInspection method outputInvocationSiteInfos.
public void outputInvocationSiteInfos() {
for (Pair<PsiCFGMethod, PsiElement> singleInvoke : invocationSiteCollection) {
PsiCFGMethod currentMethod = singleInvoke.getFirst();
PsiElement currentElement = singleInvoke.getSecond();
if (currentElement != null) {
//System.out.println(String.format("In %s method, Invoke Element %s", currentMethod.getName(), currentElement.getText()));
}
}
}
Aggregations