22
33import java .io .Serial ;
44import java .util .*;
5+ import java .util .function .Function ;
56import javax .swing .tree .DefaultMutableTreeNode ;
67import javax .swing .tree .DefaultTreeModel ;
78import javax .swing .tree .TreeNode ;
@@ -87,7 +88,8 @@ private void rebuildTree() {
8788 switch (grouping ) {
8889 case BY_PACKAGE -> groupResultsByPackage ();
8990 case BY_SEVERITY -> groupResultsBySeverity ();
90- case BY_CONFIGURATION_LOCATION -> groupResultsByConfigurationLocation ();
91+ case BY_CONFIGURATION_LOCATION -> groupResultsBy (ResultProblem ::locationDescription );
92+ case BY_SOURCE_CHECK -> groupResultsBy (ResultProblem ::sourceCheck );
9193 default -> groupResultsByFile ();
9294 }
9395
@@ -295,14 +297,14 @@ private SortedMap<SeverityLevel, Map<PsiFile, List<ResultProblem>>> groupBySever
295297 return groupedBySeverity ;
296298 }
297299
298- private void groupResultsByConfigurationLocation ( ) {
300+ private void groupResultsBy ( final Function < ResultProblem , String > groupingKeyFunction ) {
299301 int problemCount = 0 ;
300302
301- var groupedByConfigurationLocation = groupByConfigurationLocation (lastResults );
302- for (String locationDescription : groupedByConfigurationLocation .keySet ()) {
303+ var groupsResults = groupBy (lastResults , groupingKeyFunction );
304+ for (String locationDescription : groupsResults .keySet ()) {
303305 final var locationNode = new ToggleableTreeNode ();
304306
305- final var fileToProblems = groupedByConfigurationLocation .get (locationDescription );
307+ final var fileToProblems = groupsResults .get (locationDescription );
306308 final var childProblemCount = createFileNodes (sortByFileName (fileToProblems ), fileToProblems , locationNode );
307309 if (childProblemCount > 0 ) {
308310 final var packageInfo = new ConfigurationLocationGroupTreeInfo (locationDescription , childProblemCount );
@@ -316,19 +318,20 @@ private void groupResultsByConfigurationLocation() {
316318 setRootMessage (problemCount );
317319 }
318320
319- private SortedMap <String , Map <PsiFile , List <ResultProblem >>> groupByConfigurationLocation (final Map <PsiFile , List <ResultProblem >> results ) {
321+ private SortedMap <String , Map <PsiFile , List <ResultProblem >>> groupBy (final Map <PsiFile , List <ResultProblem >> results ,
322+ final Function <ResultProblem , String > groupingKeyFunction ) {
320323 if (results == null || results .isEmpty ()) {
321324 return Collections .emptySortedMap ();
322325 }
323- final var groupedByConfigurationLocation = new TreeMap <String , Map <PsiFile , List <ResultProblem >>>();
326+ final var groupedProblems = new TreeMap <String , Map <PsiFile , List <ResultProblem >>>();
324327 results .forEach ((file , problems ) -> {
325328 for (ResultProblem problem : problems ) {
326- groupedByConfigurationLocation
327- .computeIfAbsent (problem . locationDescription ( ), locationKey -> new HashMap <>())
329+ groupedProblems
330+ .computeIfAbsent (groupingKeyFunction . apply ( problem ), key -> new HashMap <>())
328331 .computeIfAbsent (file , keyFile -> new ArrayList <>()).add (problem );
329332 }
330333 });
331- return groupedByConfigurationLocation ;
334+ return groupedProblems ;
332335 }
333336
334337 private void setRootMessage (final int problemCount ) {
0 commit comments