Skip to content

Commit

Permalink
Filter out files without child nodes in the results view (#644)
Browse files Browse the repository at this point in the history
Note that the child count is currently hard coded and hence incorrect at present, that will take a little more tweaking to fix
  • Loading branch information
jshiell committed Aug 8, 2024
1 parent aacce0d commit 18019dd
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

# CheckStyle-IDEA Changelog

* **5.93.0** New: Files in results are now hidden when all of their children aren't visible in the current filtering state (#644).
* **5.92.0** New: Added CheckStyle 10.17.0.
* **5.91.0** New: Added CheckStyle 10.16.0.
* **5.90.0** New: Added CheckStyle 10.15.0.
Expand Down
7 changes: 6 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ plugins {
id("org.infernus.idea.checkstyle.build")
}

version = "5.92.0"
version = "5.93.0"

repositories {
mavenCentral()
Expand Down Expand Up @@ -48,6 +48,11 @@ java {
}

tasks {
// doesn't work, maybe waiting on https://github.com/JetBrains/intellij-platform-gradle-plugin/issues/1723
// prepareSandbox {
// sandboxDirectory = intellijPlatform.sandboxContainer.dir("current")
// }

withType<VerifyPluginTask> {
dependsOn(copyClassesToSandbox, copyCheckstyleArtifactsToSandbox)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ private void createCopyClassesToSandboxTask(final Project pProject, final boolea
});
}

// TODO this will break when we change the base IDEA version; it should use SandboxAware or similar: https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-task-awares.html#SandboxAware
private @NotNull String pluginSandboxDir(final boolean test, final String subDirectory) {
// must remain in sync with task configuration in Gradle file
return "idea-sandbox/IC-2023.1.5/plugins"
+ (test ? "-test" : "")
+ "/CheckStyle-IDEA/" + subDirectory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.*;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.MutableTreeNode;
import javax.swing.tree.TreeNode;

import com.intellij.psi.PsiFile;
Expand All @@ -20,12 +21,12 @@ public class ResultTreeModel extends DefaultTreeModel {
@Serial
private static final long serialVersionUID = 2161855162879365203L;

private final DefaultMutableTreeNode visibleRootNode;
private final ToggleableTreeNode visibleRootNode;

public ResultTreeModel() {
super(new DefaultMutableTreeNode());

visibleRootNode = new DefaultMutableTreeNode();
visibleRootNode = new ToggleableTreeNode();
((DefaultMutableTreeNode) getRoot()).add(visibleRootNode);

setRootMessage(null);
Expand Down Expand Up @@ -83,26 +84,31 @@ public void filter(final SeverityLevel... levels) {
}

private void filter(final boolean sendEvents, final SeverityLevel... levels) {
final Set<ToggleableTreeNode> changedNodes = new HashSet<>();

for (int fileIndex = 0; fileIndex < visibleRootNode.getChildCount(); ++fileIndex) {
final ToggleableTreeNode fileNode = (ToggleableTreeNode) visibleRootNode.getChildAt(fileIndex);
final Set<MutableTreeNode> changedNodes = new HashSet<>();

for (final ToggleableTreeNode fileNode : visibleRootNode.getAllChildren()) {
boolean childChanged = false;
for (final ToggleableTreeNode problemNode : fileNode.getAllChildren()) {
final ResultTreeNode result = (ResultTreeNode) problemNode.getUserObject();

final boolean currentVisible = problemNode.isVisible();
final boolean desiredVisible = contains(levels, result.getSeverity());
if (currentVisible != desiredVisible) {
problemNode.setVisible(desiredVisible);

changedNodes.add(fileNode);
final boolean resultShouldBeVisible = contains(levels, result.getSeverity());
if (problemNode.isVisible() != resultShouldBeVisible) {
problemNode.setVisible(resultShouldBeVisible);
childChanged = true;
}
}

final boolean fileNodeShouldBeVisible = fileNode.getChildCount() > 0;
if (fileNode.isVisible() != fileNodeShouldBeVisible) {
fileNode.setVisible(fileNodeShouldBeVisible);
changedNodes.add(visibleRootNode);
} else if (childChanged) {
changedNodes.add(fileNode);
}
}

if (sendEvents) {
for (final ToggleableTreeNode node : changedNodes) {
for (final MutableTreeNode node : changedNodes) {
nodeStructureChanged(node);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<change-notes>
<![CDATA[
<ul>
<li>5.93.0: New: Files in results are now hidden when all of their children aren't visible in the current filtering state (#644).</li>
<li>5.92.0: New: Added CheckStyle 10.17.0.</li>
<li>5.91.0: New: Added CheckStyle 10.16.0.</li>
<li>5.90.0: New: Added CheckStyle 10.15.0.</li>
Expand Down

0 comments on commit 18019dd

Please sign in to comment.