Skip to content

Commit

Permalink
Filter visibility based on test methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Sherburne committed Jan 15, 2021
1 parent 2aac0f2 commit e589b00
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
23 changes: 21 additions & 2 deletions src/main/kotlin/callgraph/CallGraphToolWindow.form
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@
</component>
</children>
</grid>
<grid id="3fac4" layout-manager="GridLayoutManager" row-count="7" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="3fac4" layout-manager="GridLayoutManager" row-count="8" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="2" row-span="2" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
Expand All @@ -496,7 +496,7 @@
<children>
<vspacer id="c2264">
<constraints>
<grid row="6" column="0" row-span="1" col-span="2" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="7" column="0" row-span="1" col-span="2" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="c207b" class="javax.swing.JLabel">
Expand Down Expand Up @@ -587,6 +587,25 @@
<text value="&amp;External library functions"/>
</properties>
</component>
<component id="4a86a" class="javax.swing.JCheckBox" binding="filterTestCheckbox">
<constraints>
<grid row="6" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<enabled value="false"/>
<selected value="true"/>
<text value="Test functions"/>
</properties>
</component>
<component id="a1c00" class="javax.swing.JLabel">
<constraints>
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<icon value="icons/filter.png"/>
<text value="&lt;html&gt;&lt;b&gt;Tests&lt;/b&gt;&lt;/html&gt;"/>
</properties>
</component>
</children>
</grid>
</children>
Expand Down
6 changes: 5 additions & 1 deletion src/main/kotlin/callgraph/CallGraphToolWindow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class CallGraphToolWindow {
private lateinit var filterAccessProtectedCheckbox: JCheckBox
private lateinit var filterAccessPackageLocalCheckbox: JCheckBox
private lateinit var filterAccessPrivateCheckbox: JCheckBox
private lateinit var filterTestCheckbox: JCheckBox

private val canvasBuilder = CanvasBuilder()
private val canvas: Canvas = Canvas(this)
Expand All @@ -52,7 +53,8 @@ class CallGraphToolWindow {
this.filterAccessPublicCheckbox,
this.filterAccessProtectedCheckbox,
this.filterAccessPackageLocalCheckbox,
this.filterAccessPrivateCheckbox
this.filterAccessPrivateCheckbox,
this.filterTestCheckbox
)

init {
Expand Down Expand Up @@ -194,6 +196,8 @@ class CallGraphToolWindow {

fun isFilterAccessPrivateChecked() = this.filterAccessPrivateCheckbox.isSelected

fun isFilterTestChecked() = this.filterTestCheckbox.isSelected

fun isLegendNeeded() = getSelectedComboBoxOption(this.nodeColorComboBox) != ComboBoxOptions.NODE_COLOR_NONE

fun getCanvasSize(): Dimension = this.canvasPanel.size
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/callgraph/Canvas.kt
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,9 @@ class Canvas(private val callGraphToolWindow: CallGraphToolWindow): JPanel() {
}
val isExternalMethod = Utils.getSourceRoot(method.containingFile.virtualFile) == null
val isVisibleExternal = !isExternalMethod || this.callGraphToolWindow.isFilterExternalChecked()
val isVisibleTest = !Utils.isTest(method) || this.callGraphToolWindow.isFilterTestChecked()

isVisibleAccessLevel && isVisibleExternal
isVisibleAccessLevel && isVisibleExternal && isVisibleTest
})
this.visibleEdges.clear()
this.visibleEdges.addAll(graph.getEdges()
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/callgraph/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ object Utils {

fun isPrivate(method: PsiMethod) = method.modifierList.hasModifierProperty(PsiModifier.PRIVATE)

fun isTest(method: PsiMethod) = getMethodPackageName(method)?.contains("test", ignoreCase = true)

fun getAllSourceCodeFiles(project: Project): Set<PsiFile> {
val sourceCodeRoots = getAllSourceCodeRoots(project)
return getSourceCodeFiles(project, sourceCodeRoots)
Expand Down

0 comments on commit e589b00

Please sign in to comment.