From a67162248bbf56f09d7a1a2921abcc28874abcad Mon Sep 17 00:00:00 2001 From: skirge Date: Wed, 11 Sep 2024 21:10:41 +0200 Subject: [PATCH] Group by Class/Package shows bugs for other class/package #1628 --- .../java/org/jetbrains/plugins/spotbugs/core/Bug.java | 9 +++++++++ .../plugins/spotbugs/gui/tree/RecurseNodeVisitor.java | 2 +- .../spotbugs/gui/tree/model/BugInstanceGroupNode.java | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jetbrains/plugins/spotbugs/core/Bug.java b/src/main/java/org/jetbrains/plugins/spotbugs/core/Bug.java index 3ad7e192..2a8be0cd 100644 --- a/src/main/java/org/jetbrains/plugins/spotbugs/core/Bug.java +++ b/src/main/java/org/jetbrains/plugins/spotbugs/core/Bug.java @@ -89,4 +89,13 @@ public static boolean equalsBugType(@NotNull final Bug bugA, @NotNull final Bug } return true; } + + public static boolean equalsBugClass(@NotNull final Bug bugA, @NotNull final Bug bugB) { + final BugInstance a = bugA.getInstance(); + final BugInstance b = bugB.getInstance(); + if (!StringUtil.equals(a.getPrimaryClass().getClassName(), b.getPrimaryClass().getClassName())) { + return false; + } + return true; + } } diff --git a/src/main/java/org/jetbrains/plugins/spotbugs/gui/tree/RecurseNodeVisitor.java b/src/main/java/org/jetbrains/plugins/spotbugs/gui/tree/RecurseNodeVisitor.java index 2af3318d..f5eb6f2f 100644 --- a/src/main/java/org/jetbrains/plugins/spotbugs/gui/tree/RecurseNodeVisitor.java +++ b/src/main/java/org/jetbrains/plugins/spotbugs/gui/tree/RecurseNodeVisitor.java @@ -57,7 +57,7 @@ public BugInstanceGroupNode findChildNode(final RecurseVisitCriteria recurseVisi @Override public void visitGroupNode(@NotNull final BugInstanceGroupNode node) { - if (Bug.equalsBugType(_recurseVisitCriteria.getBug(), node.getBug()) && _recurseVisitCriteria.getDepth() == node.getDepth() && _recurseVisitCriteria.getGroupName().equals(node.getGroupName())) { + if (Bug.equalsBugType(_recurseVisitCriteria.getBug(), node.getBug()) && Bug.equalsBugClass(_recurseVisitCriteria.getBug(), node.getBug()) && _recurseVisitCriteria.getDepth() == node.getDepth() && _recurseVisitCriteria.getGroupName().equals(node.getGroupName())) { _resultNode = node; } else { _resultNode = node.findChildNode(_recurseVisitCriteria.getBug(), _recurseVisitCriteria.getDepth(), _recurseVisitCriteria.getGroupName()); diff --git a/src/main/java/org/jetbrains/plugins/spotbugs/gui/tree/model/BugInstanceGroupNode.java b/src/main/java/org/jetbrains/plugins/spotbugs/gui/tree/model/BugInstanceGroupNode.java index ab8f315a..6c855038 100644 --- a/src/main/java/org/jetbrains/plugins/spotbugs/gui/tree/model/BugInstanceGroupNode.java +++ b/src/main/java/org/jetbrains/plugins/spotbugs/gui/tree/model/BugInstanceGroupNode.java @@ -97,7 +97,7 @@ public void addChild(final VisitableTreeNode node) { @Nullable public BugInstanceGroupNode findChildNode(final Bug bug, final int depth, final String groupName) { - if (Bug.equalsBugType(this.bug, bug) && depth == _depthFromRoot && groupName.equals(_groupName)) { + if (Bug.equalsBugType(this.bug, bug) && Bug.equalsBugClass(this.bug, bug) && depth == _depthFromRoot && groupName.equals(_groupName)) { return this; } final RecurseVisitCriteria criteria = new RecurseVisitCriteria(bug, depth, groupName);