Skip to content

Commit c1d08bc

Browse files
authored
Merge pull request #2160 from guwirth/td-2
clean-up
2 parents eb5cf4c + 13131ae commit c1d08bc

File tree

84 files changed

+204
-1132
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+204
-1132
lines changed

cxx-checks/src/main/java/org/sonar/cxx/checks/metrics/TooManyLinesOfCodeInFileCheck.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
import org.sonar.check.Rule;
2626
import org.sonar.check.RuleProperty;
2727
import org.sonar.cxx.api.CxxMetric;
28-
import org.sonar.cxx.tag.Tag;
2928
import org.sonar.cxx.squidbridge.annotations.ActivatedByDefault;
3029
import org.sonar.cxx.squidbridge.annotations.SqaleConstantRemediation;
3130
import org.sonar.cxx.squidbridge.checks.ChecksHelper;
3231
import org.sonar.cxx.squidbridge.checks.SquidCheck;
32+
import org.sonar.cxx.tag.Tag;
3333

3434
@Rule(
3535
key = "TooManyLinesOfCodeInFile",
@@ -55,10 +55,10 @@ public void setMax(int max) {
5555

5656
@Override
5757
public void leaveFile(AstNode astNode) {
58-
int linesOfCode = ChecksHelper.getRecursiveMeasureInt(getContext().peekSourceCode(), CxxMetric.LINES_OF_CODE);
58+
var linesOfCode = ChecksHelper.getRecursiveMeasureInt(getContext().peekSourceCode(), CxxMetric.LINES_OF_CODE);
5959
if (linesOfCode > max) {
6060
getContext().createFileViolation(this, "This file has {0} lines of code, which is greater than {1} authorized. "
61-
+ "Split it into smaller files.", linesOfCode, max);
61+
+ "Split it into smaller files.", linesOfCode, max);
6262
}
6363
}
6464

cxx-sensors/src/main/java/org/sonar/cxx/sensors/clangsa/CxxClangSASensor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,21 +103,21 @@ protected void processReport(File report) {
103103
try {
104104
var f = new File(report.getPath());
105105

106-
NSDictionary rootDict = (NSDictionary) PropertyListParser.parse(f);
106+
var rootDict = (NSDictionary) PropertyListParser.parse(f);
107107

108108
NSObject[] diagnostics = ((NSArray) require(rootDict.objectForKey("diagnostics"),
109109
"Missing mandatory entry 'diagnostics'")).getArray();
110110
NSObject[] sourceFiles = ((NSArray) require(rootDict.objectForKey("files"),
111111
"Missing mandatory entry 'files'")).getArray();
112112

113113
for (var diagnostic : diagnostics) {
114-
NSDictionary diag = (NSDictionary) diagnostic;
114+
var diag = (NSDictionary) diagnostic;
115115

116116
String description = ((NSString) require(diag.get("description"),
117117
"Missing mandatory entry 'diagnostics/description'")).getContent();
118118
String checkerName = ((NSString) require(diag.get("check_name"),
119119
"Missing mandatory entry 'diagnostics/check_name'")).getContent();
120-
NSDictionary location = (NSDictionary) require(diag.get("location"),
120+
var location = (NSDictionary) require(diag.get("location"),
121121
"Missing mandatory entry 'diagnostics/location'");
122122
var line = ((NSNumber) require(location.get("line"),
123123
"Missing mandatory entry 'diagnostics/location/line'")).intValue();

cxx-sensors/src/main/java/org/sonar/cxx/sensors/coverage/cobertura/CoberturaParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public static String join(Path path1, Path path2) {
7676
path2 = Paths.get(".", path2.toString());
7777
}
7878

79-
Path result = path1.resolve(path2).normalize();
79+
var result = path1.resolve(path2).normalize();
8080
if (!result.isAbsolute()) {
8181
result = Paths.get(".", result.toString());
8282
}
@@ -89,7 +89,7 @@ private static void collectFileData(SMInputCursor clazz, CoverageMeasures builde
8989

9090
while (line.getNext() != null) {
9191
var lineId = Integer.parseInt(line.getAttrValue("number"));
92-
long noHits = Long.parseLong(line.getAttrValue("hits"));
92+
var noHits = Long.parseLong(line.getAttrValue("hits"));
9393
if (noHits > Integer.MAX_VALUE) {
9494
LOG.warn("Truncating the actual number of hits ({}) to the maximum number supported by SonarQube ({})",
9595
noHits, Integer.MAX_VALUE);

cxx-sensors/src/main/java/org/sonar/cxx/sensors/cppcheck/CppcheckParser.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.sonar.cxx.sensors.utils.EmptyReportException;
3131
import org.sonar.cxx.sensors.utils.StaxParser;
3232
import org.sonar.cxx.utils.CxxReportIssue;
33-
import org.sonar.cxx.utils.CxxReportLocation;
3433

3534
public class CppcheckParser {
3635

@@ -145,7 +144,7 @@ private void processErrorTag(SMInputCursor errorCursor) throws XMLStreamExceptio
145144
if (isLocationInProject) {
146145
issue.addLocation(file, line, null, info);
147146
} else {
148-
CxxReportLocation primaryLocation = issue.getLocations().get(0);
147+
var primaryLocation = issue.getLocations().get(0);
149148
String primaryFile = primaryLocation.getFile();
150149
String primaryLine = primaryLocation.getLine();
151150

cxx-sensors/src/main/java/org/sonar/cxx/sensors/pclint/CxxPCLintSensor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import org.sonar.cxx.sensors.utils.InvalidReportException;
4141
import org.sonar.cxx.sensors.utils.StaxParser;
4242
import org.sonar.cxx.utils.CxxReportIssue;
43-
import org.sonar.cxx.utils.CxxReportLocation;
4443

4544
/**
4645
* PC-lint is an equivalent to pmd but for C++ The first version of the tool was release 1985 and the tool analyzes
@@ -182,7 +181,7 @@ private void addSecondaryLocationsToCurrentIssue(@Nonnull CxxReportIssue current
182181

183182
// Due to SONAR-9929, even the API supports the extra/flow in different file,
184183
// the UI is not ready. For this case, use the parent issue's file and line for now.
185-
CxxReportLocation primaryLocation = currentIssue.getLocations().get(0);
184+
var primaryLocation = currentIssue.getLocations().get(0);
186185
if (!primaryLocation.getFile().equals(file)) {
187186
if (msg != null && !msg.startsWith(PREFIX_DURING_SPECIFIC_WALK_MSG)) {
188187
msg = String.format("%s %s:%s %s", PREFIX_DURING_SPECIFIC_WALK_MSG, file, line, msg);

cxx-sensors/src/main/java/org/sonar/cxx/sensors/rats/CxxRatsSensor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ protected void processReport(File report) {
8787
var builder = new SAXBuilder(XMLReaders.NONVALIDATING);
8888
builder.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "");
8989
builder.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
90-
Element root = builder.build(report).getRootElement();
90+
var root = builder.build(report).getRootElement();
9191

9292
List<Element> vulnerabilities = root.getChildren("vulnerability");
9393
for (var vulnerability : vulnerabilities) {

cxx-sensors/src/main/java/org/sonar/cxx/sensors/tests/dotnet/CxxUnitTestResultsImportSensor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ public void execute(SensorContext context) {
9292
}
9393

9494
public void analyze(UnitTestResults unitTestResults, UnitTestConfiguration unitTestConf) {
95-
UnitTestResults aggregatedResults = unitTestResultsAggregator.aggregate(wildcardPatternFileProvider,
96-
unitTestResults, unitTestConf);
95+
var aggregatedResults = unitTestResultsAggregator.aggregate(wildcardPatternFileProvider,
96+
unitTestResults, unitTestConf);
9797
if (aggregatedResults != null) {
9898
saveMetric(CoreMetrics.TESTS, aggregatedResults.tests());
9999
saveMetric(CoreMetrics.TEST_ERRORS, aggregatedResults.errors());

cxx-sensors/src/main/java/org/sonar/cxx/sensors/tests/dotnet/NUnitTestResultsFileParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private static Double readExecutionTimeFromDirectlyNestedTestSuiteTags(XmlParser
6868
while ((tag = xmlParserHelper.nextStartOrEndTag()) != null) {
6969
if ("<test-suite>".equals(tag)) {
7070
level++;
71-
Double time = xmlParserHelper.getDoubleAttribute("time");
71+
var time = xmlParserHelper.getDoubleAttribute("time");
7272

7373
if (level == 1 && time != null) {
7474
if (executionTime == null) {

cxx-sensors/src/main/java/org/sonar/cxx/sensors/tests/xunit/XunitReportParser.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,19 @@ private void parseTestCaseTag(SMInputCursor testCaseCursor, String tsName, Strin
9090
var status = "ok";
9191
var stack = "";
9292
var msg = "";
93-
final String SKIPPED_STATUS = "skipped";
9493

9594
// Googletest-reports mark the skipped tests with status="notrun"
9695
String statusattr = testCaseCursor.getAttrValue("status");
9796
if ("notrun".equals(statusattr)) {
98-
status = SKIPPED_STATUS;
97+
status = "skipped";
9998
} else {
10099
SMInputCursor childCursor = testCaseCursor.childElementCursor();
101100
if (childCursor.getNext() != null) {
102101
String elementName = childCursor.getLocalName();
103102
if (null != elementName) {
104103
switch (elementName) {
105-
case SKIPPED_STATUS:
106-
status = SKIPPED_STATUS;
104+
case "skipped":
105+
status = "skipped";
107106
break;
108107
case "failure":
109108
status = "failure";
@@ -123,7 +122,7 @@ private void parseTestCaseTag(SMInputCursor testCaseCursor, String tsName, Strin
123122
}
124123

125124
String filename = tcFilename != null ? tcFilename : tsFilename;
126-
TestFile file = getTestFile(filename);
125+
var file = getTestFile(filename);
127126
file.add(new TestCase(name, time.intValue(), status, stack, msg, classname, filename, tsName));
128127
}
129128

@@ -132,7 +131,7 @@ private TestFile getTestFile(String filename) {
132131
if (absolute != null) {
133132
absolute = absolute.toLowerCase();
134133
}
135-
TestFile file = testFiles.get(absolute);
134+
var file = testFiles.get(absolute);
136135
if (file == null) {
137136
file = new TestFile(absolute);
138137
testFiles.put(absolute, file);
@@ -151,7 +150,7 @@ private String parseTestCaseName(SMInputCursor testCaseCursor) throws XMLStreamE
151150

152151
private double parseTime(SMInputCursor testCaseCursor)
153152
throws XMLStreamException {
154-
double time = 0.0;
153+
var time = 0.0;
155154
try {
156155
String sTime = testCaseCursor.getAttrValue("time");
157156
if (sTime != null && !sTime.isEmpty()) {

cxx-sensors/src/main/java/org/sonar/cxx/sensors/utils/CxxIssuesReportSensor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void executeImpl() {
7575
public void saveUniqueViolation(CxxReportIssue issue) {
7676
if (uniqueIssues.add(issue)) {
7777
try {
78-
NewIssue newIssue = context.newIssue();
78+
var newIssue = context.newIssue();
7979
if (addLocations(newIssue, issue)) {
8080
addFlow(newIssue, issue);
8181
newIssue.save();
@@ -169,7 +169,7 @@ private boolean addLocations(NewIssue newIssue, CxxReportIssue issue) {
169169
private void addFlow(NewIssue newIssue, CxxReportIssue issue) {
170170
var newIssueFlow = new ArrayList<NewIssueLocation>();
171171
for (var location : issue.getFlow()) {
172-
NewIssueLocation newIssueLocation = createNewIssueLocation(newIssue, location);
172+
var newIssueLocation = createNewIssueLocation(newIssue, location);
173173
if (newIssueLocation != null) {
174174
newIssueFlow.add(newIssueLocation);
175175
} else {

0 commit comments

Comments
 (0)