37
37
import org .sonarsource .sonarlint .core .tracking .TrackedIssue ;
38
38
39
39
public class MatchingSession {
40
- private final Map <Path , List <KnownFinding >> remainingUnmatchedIssuesPerFile ;
41
- private final Map <Path , List <KnownFinding >> remainingUnmatchedSecurityHotspotsPerFile ;
42
40
private final Map <Path , IssueMatcher <RawIssue , KnownFinding >> issueMatchersByFile = new HashMap <>();
43
41
private final Map <Path , IssueMatcher <RawIssue , KnownFinding >> hotspotMatchersByFile = new HashMap <>();
44
42
@@ -49,12 +47,12 @@ public class MatchingSession {
49
47
private long newIssuesFound = 0 ;
50
48
51
49
public MatchingSession (KnownFindings previousFindings , IntroductionDateProvider introductionDateProvider ) {
52
- this . remainingUnmatchedIssuesPerFile = previousFindings .getIssuesPerFile ().entrySet ().stream ().map (entry -> Map .entry (entry .getKey (), new ArrayList <>(entry .getValue ())))
50
+ var knownIssuesPerFile = previousFindings .getIssuesPerFile ().entrySet ().stream ().map (entry -> Map .entry (entry .getKey (), new ArrayList <>(entry .getValue ())))
53
51
.collect (Collectors .toMap (Map .Entry ::getKey , Map .Entry ::getValue ));
54
- this . remainingUnmatchedSecurityHotspotsPerFile = previousFindings .getSecurityHotspotsPerFile ().entrySet ().stream ()
52
+ var knownSecurityHotspotsPerFile = previousFindings .getSecurityHotspotsPerFile ().entrySet ().stream ()
55
53
.map (entry -> Map .entry (entry .getKey (), new ArrayList <>(entry .getValue ()))).collect (Collectors .toMap (Map .Entry ::getKey , Map .Entry ::getValue ));
56
- remainingUnmatchedIssuesPerFile .forEach ((path , issues ) -> issueMatchersByFile .put (path , new IssueMatcher <>(new KnownIssueMatchingAttributesMapper (), issues )));
57
- remainingUnmatchedSecurityHotspotsPerFile .forEach ((path , hotspots ) -> hotspotMatchersByFile .put (path , new IssueMatcher <>(new KnownIssueMatchingAttributesMapper (), hotspots )));
54
+ knownIssuesPerFile .forEach ((path , issues ) -> issueMatchersByFile .put (path , new IssueMatcher <>(new KnownIssueMatchingAttributesMapper (), issues )));
55
+ knownSecurityHotspotsPerFile .forEach ((path , hotspots ) -> hotspotMatchersByFile .put (path , new IssueMatcher <>(new KnownIssueMatchingAttributesMapper (), hotspots )));
58
56
this .introductionDateProvider = introductionDateProvider ;
59
57
}
60
58
@@ -71,7 +69,7 @@ public TrackedIssue matchWithKnownSecurityHotspot(Path relativePath, RawIssue ne
71
69
if (hotspotMatcher == null ) {
72
70
throw new IllegalStateException ("No hotspot matcher found for " + relativePath );
73
71
}
74
- var trackedSecurityHotspot = matchWithKnownFinding (relativePath , hotspotMatcher , remainingUnmatchedSecurityHotspotsPerFile , newSecurityHotspot );
72
+ var trackedSecurityHotspot = matchWithKnownFinding (relativePath , hotspotMatcher , newSecurityHotspot );
75
73
securityHotspotsPerFile .computeIfAbsent (relativePath , f -> new ArrayList <>()).add (trackedSecurityHotspot );
76
74
relativePathsInvolved .add (relativePath );
77
75
return trackedSecurityHotspot ;
@@ -83,23 +81,16 @@ private TrackedIssue matchWithKnownIssue(Path relativePath, RawIssue rawIssue) {
83
81
throw new IllegalStateException ("No issue matcher found for " + relativePath );
84
82
}
85
83
86
- var trackedIssue = matchWithKnownFinding (relativePath , issueMatcher , remainingUnmatchedIssuesPerFile , rawIssue );
84
+ var trackedIssue = matchWithKnownFinding (relativePath , issueMatcher , rawIssue );
87
85
issuesPerFile .computeIfAbsent (relativePath , f -> new ArrayList <>()).add (trackedIssue );
88
86
relativePathsInvolved .add (relativePath );
89
87
return trackedIssue ;
90
88
}
91
89
92
- private TrackedIssue matchWithKnownFinding (Path relativePath , IssueMatcher <RawIssue , KnownFinding > issueMatcher ,
93
- Map <Path , List <KnownFinding >> remainingUnmatchedKnownFindingsPerFile , RawIssue newFinding ) {
94
- var remainingUnmatchedKnownFindings = remainingUnmatchedKnownFindingsPerFile .get (relativePath );
90
+ private TrackedIssue matchWithKnownFinding (Path relativePath , IssueMatcher <RawIssue , KnownFinding > issueMatcher , RawIssue newFinding ) {
95
91
var localMatchingResult = issueMatcher .matchWith (new RawIssueFindingMatchingAttributeMapper (), List .of (newFinding ));
96
92
return localMatchingResult .getMatchOpt (newFinding )
97
- .map (knownFinding -> {
98
- if (remainingUnmatchedKnownFindings != null ) {
99
- remainingUnmatchedKnownFindings .remove (knownFinding );
100
- }
101
- return updateKnownFindingWithRawIssueData (knownFinding , newFinding );
102
- })
93
+ .map (knownFinding -> updateKnownFindingWithRawIssueData (knownFinding , newFinding ))
103
94
.orElseGet (() -> newlyKnownIssue (relativePath , newFinding ));
104
95
}
105
96
@@ -113,7 +104,7 @@ public static TrackedIssue updateKnownFindingWithRawIssueData(KnownFinding known
113
104
}
114
105
115
106
private TrackedIssue newlyKnownIssue (Path relativePath , RawIssue rawFinding ) {
116
- newIssuesFound ++;
107
+ newIssuesFound ++;
117
108
var introductionDate = introductionDateProvider .determineIntroductionDate (relativePath , rawFinding .getLineNumbers ());
118
109
return IssueMapper .toTrackedIssue (rawFinding , introductionDate );
119
110
}
@@ -135,6 +126,6 @@ public long countNewIssues() {
135
126
}
136
127
137
128
public long countRemainingUnmatchedIssues () {
138
- return remainingUnmatchedIssuesPerFile .values ().stream ().mapToLong (List :: size ).sum ();
129
+ return issueMatchersByFile .values ().stream ().mapToLong (IssueMatcher :: getUnmatchedIssuesCount ).sum ();
139
130
}
140
131
}
0 commit comments