diff options
author | Matteo Mara <matteo.mara@sonarsource.com> | 2023-07-19 15:32:14 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-08-02 20:03:03 +0000 |
commit | 30abc015459aecb07ea2e3fba2b4bba52a652f74 (patch) | |
tree | dce4c7f9a0a899d27bf77a56e1f5d43ca9307c84 /sonar-core/src/main/java | |
parent | ed50d0636f78948fdc36cdc086cabe5eafe54c2d (diff) | |
download | sonarqube-30abc015459aecb07ea2e3fba2b4bba52a652f74.tar.gz sonarqube-30abc015459aecb07ea2e3fba2b4bba52a652f74.zip |
SONAR-19372 Add a new issue visitor in order to apply anticipated transitions to issues
Diffstat (limited to 'sonar-core/src/main/java')
-rw-r--r-- | sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java | 11 | ||||
-rw-r--r-- | sonar-core/src/main/java/org/sonar/core/issue/tracking/AnticipatedTransitionTracker.java | 51 |
2 files changed, 62 insertions, 0 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java index abfa4154554..32b5154b0b9 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java @@ -131,6 +131,8 @@ public class DefaultIssue implements Issue, Trackable, org.sonar.api.ce.measure. private String ruleDescriptionContextKey = null; + private boolean anticipatedTransitions = false; + @Override public String key() { return key; @@ -689,6 +691,15 @@ public class DefaultIssue implements Issue, Trackable, org.sonar.api.ce.measure. return this; } + public boolean hasAnticipatedTransitions() { + return anticipatedTransitions; + } + + public DefaultIssue setAnticipatedTransitions(boolean anticipatedTransitions) { + this.anticipatedTransitions = anticipatedTransitions; + return this; + } + @Override public Integer getLine() { return line; diff --git a/sonar-core/src/main/java/org/sonar/core/issue/tracking/AnticipatedTransitionTracker.java b/sonar-core/src/main/java/org/sonar/core/issue/tracking/AnticipatedTransitionTracker.java new file mode 100644 index 00000000000..d46d3921a85 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/issue/tracking/AnticipatedTransitionTracker.java @@ -0,0 +1,51 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.core.issue.tracking; + +import java.util.Collection; + +/** + * A simplified version of {@link Tracker}, which doesn't use line hash sequences nor block hash sequences and + * only has two steps instead of 5 steps. + */ +public class AnticipatedTransitionTracker<RAW extends Trackable, BASE extends Trackable> extends AbstractTracker<RAW, BASE> { + + public Tracking<RAW, BASE> track(Collection<RAW> rawInput, Collection<BASE> baseInput) { + Tracking<RAW, BASE> tracking = new Tracking<>(rawInput, baseInput); + + // 1. match by rule, line, line hash and message + match(tracking, LineAndLineHashAndMessage::new); + + // 2. match issues with same rule, same line and same line hash, but not necessarily with same message + match(tracking, LineAndLineHashKey::new); + + // 3. match issues with same rule, same message and same line hash + match(tracking, LineHashAndMessageKey::new); + + // 4. match issues with same rule, same line and same message + match(tracking, LineAndMessageKey::new); + + // 5. match issues with same rule and same line hash but different line and different message. + // See SONAR-2812 + match(tracking, LineHashKey::new); + + return tracking; + } +} |