Skip to content

Commit 19901cb

Browse files
committed
feature: Bottom-Up graph generate for single method #2
1 parent 79e9e3a commit 19901cb

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

src/main/kotlin/org/skgroup/securityinspector/ui/service/CallGraphGenerator.kt

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import com.intellij.openapi.progress.ProgressManager
77
import com.intellij.openapi.progress.Task
88
import com.intellij.openapi.project.Project
99
import com.intellij.openapi.ui.ComboBox
10-
import com.intellij.psi.PsiFile
11-
import com.intellij.psi.PsiJavaFile
12-
import com.intellij.psi.PsiMethod
10+
import com.intellij.psi.*
11+
import com.intellij.psi.search.GlobalSearchScope
1312
import com.intellij.psi.search.ProjectScope
13+
import com.intellij.psi.search.searches.ReferencesSearch
14+
import com.intellij.psi.util.PsiTreeUtil
1415
import com.intellij.ui.Gray
1516
import com.intellij.ui.components.JBTextArea
1617
import org.skgroup.securityinspector.analysis.ast.nodes.MethodNode
@@ -151,7 +152,6 @@ object CallGraphGenerator {
151152
string = "Initializing..."
152153
}
153154

154-
// TODO 现在的调用图只有一个方法的上下文,非常残缺,需要拓展
155155
ProgressManager.getInstance().run(object : Task.Backgroundable(project, "Generating CallGraph", true) {
156156
private var tempGraph: CallGraph? = null
157157

@@ -166,6 +166,16 @@ object CallGraphGenerator {
166166
indicator.text = "Analyzing ${method.name}"
167167

168168
val builder = CallGraphBuilder()
169+
ReferencesSearch.search(method, GlobalSearchScope.projectScope(project)).forEach { reference ->
170+
var callerMethod: PsiMethod = method
171+
ApplicationManager.getApplication().runReadAction {
172+
callerMethod = PsiTreeUtil.getParentOfType(reference.element, PsiMethod::class.java)
173+
?: return@runReadAction
174+
}
175+
if (callerMethod != method) {
176+
generate(project, callerMethod, progressBar, infoArea, rootListModel)
177+
}
178+
}
169179
ApplicationManager.getApplication().runReadAction {
170180
method.accept(builder)
171181
}
@@ -194,7 +204,7 @@ object CallGraphGenerator {
194204
currentGraph.merge(delta)
195205
memoryService.setCallGraph(currentGraph)
196206

197-
infoArea.append("Added ${delta.nodes.size} nodes for Call graph")
207+
infoArea.append("Added ${delta.nodes.size} nodes for Call graph\n")
198208
updateRootAndSinkLists(currentGraph, rootListModel)
199209
}
200210
}

0 commit comments

Comments
 (0)