Skip to content

Commit 2290e14

Browse files
committed
review feedback
1 parent 9055e68 commit 2290e14

File tree

6 files changed

+14
-26
lines changed

6 files changed

+14
-26
lines changed

cxx-checks/src/main/java/org/sonar/cxx/checks/ReservedNamesCheck.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void visitFile(AstNode astNode) {
6868
int nr = 0;
6969

7070
while ((line = br.readLine()) != null) {
71-
nr++;
71+
++nr;
7272
Matcher matcher = DEFINE_DECLARATION_PATTERN.matcher(line);
7373
if (matcher.matches()) {
7474
String name = matcher.group(1);

cxx-checks/src/main/java/org/sonar/cxx/checks/UseCorrectIncludeCheck.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void visitFile(AstNode astNode) {
6464
int nr = 0;
6565

6666
while ((line = br.readLine()) != null) {
67-
nr++;
67+
++nr;
6868
if (PATTERN.matcher(line).find()) {
6969
getContext().createLineViolation(this, "Do not use relative path for #include directive.", nr);
7070
}

cxx-checks/src/main/java/org/sonar/cxx/checks/file/TabCharacterCheck.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void visitFile(AstNode astNode) {
7575
int nr = 0;
7676

7777
while ((line = br.readLine()) != null) {
78-
nr++;
78+
++nr;
7979
if (line.contains("\t")) {
8080
if (createLineViolation) {
8181
getContext().createLineViolation(this,

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,8 @@ public void visitFile(AstNode astNode) {
8686
int nr = 0;
8787

8888
while ((line = br.readLine()) != null) {
89-
int length = 0;
90-
nr++;
91-
for (char c : line.toCharArray()) {
92-
if (c == '\t') {
93-
++length;
94-
}
95-
}
89+
++nr;
90+
long length = line.chars().filter(c -> c == '\t').count();
9691
length = line.length() + length * (tabWidth - 1);
9792
if (length > maximumLineLength) {
9893
getContext().createLineViolation(this,

cxx-checks/src/main/java/org/sonar/cxx/checks/regex/FileHeaderCheck.java

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import org.sonar.cxx.visitors.CxxCharsetAwareVisitor;
3838
import org.sonar.squidbridge.annotations.ActivatedByDefault;
3939
import org.sonar.squidbridge.annotations.SqaleConstantRemediation;
40-
import org.sonar.squidbridge.api.AnalysisException;
4140
import org.sonar.squidbridge.checks.SquidCheck;
4241

4342
/**
@@ -82,7 +81,7 @@ public class FileHeaderCheck extends SquidCheck<Grammar> implements CxxCharsetAw
8281
private static boolean matches(String[] expectedLines, BufferedReader br) throws IOException {
8382
for (String expectedLine : expectedLines) {
8483
String line = br.readLine();
85-
if (line == null || !line.equals(expectedLine)) {
84+
if (!expectedLine.equals(line)) {
8685
return false;
8786
}
8887
}
@@ -105,26 +104,20 @@ public void init() {
105104

106105
@Override
107106
public void visitFile(AstNode astNode) {
108-
if (isRegularExpression) {
107+
try {
108+
// use onMalformedInput(CodingErrorAction.REPLACE) / onUnmappableCharacter(CodingErrorAction.REPLACE)
109+
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(getContext().getFile()), charset));
109110

110-
try {
111-
// use onMalformedInput(CodingErrorAction.REPLACE) / onUnmappableCharacter(CodingErrorAction.REPLACE)
112-
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(getContext().getFile()), charset));
111+
if (isRegularExpression) {
113112
String fileContent = br.lines().collect(Collectors.joining(System.lineSeparator()));
114113
checkRegularExpression(fileContent);
115-
} catch (IOException e) {
116-
throw new AnalysisException(e);
117-
}
118-
} else {
119-
try {
120-
// use onMalformedInput(CodingErrorAction.REPLACE) / onUnmappableCharacter(CodingErrorAction.REPLACE)
121-
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(getContext().getFile()), charset));
114+
} else {
122115
if (!matches(expectedLines, br)) {
123116
getContext().createFileViolation(this, MESSAGE);
124117
}
125-
} catch (IOException e) {
126-
throw new IllegalStateException(e);
127118
}
119+
} catch (IOException e) {
120+
throw new IllegalStateException(e);
128121
}
129122
}
130123

cxx-checks/src/main/java/org/sonar/cxx/checks/regex/LineRegularExpressionCheck.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public void visitFile(AstNode fileNode) {
130130

131131
while ((line = br.readLine()) != null) {
132132
Matcher matcher = pattern.matcher(line);
133-
nr++;
133+
++nr;
134134
if (compare(invertRegularExpression, matcher.find())) {
135135
getContext().createLineViolation(this, message, nr);
136136
}

0 commit comments

Comments
 (0)