Skip to content

Commit 054e27d

Browse files
authored
Merge pull request #1388 from Bertk/bugfix
Bugfix
2 parents 8c27b74 + 79f31a8 commit 054e27d

File tree

11 files changed

+32
-28
lines changed

11 files changed

+32
-28
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public void visitFile(AstNode fileNode) {
138138
if (compare(invertRegularExpression, matcher.find())) {
139139
getContext().createFileViolation(this, message);
140140
}
141-
} catch (Exception e) {
141+
} catch (IOException e) {
142142
throw new IllegalStateException(e);
143143
}
144144
}

cxx-checks/src/test/java/org/sonar/cxx/checks/UndocumentedApiCheckTest.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class UndocumentedApiCheckTest {
3535
@Rule
3636
public CheckMessagesVerifierRule checkMessagesVerifier = new CheckMessagesVerifierRule();
3737

38-
@SuppressWarnings({"unchecked", "squid:S2699"})
38+
@SuppressWarnings("squid:S2699")
3939
@Test
4040
public void detected() throws UnsupportedEncodingException, IOException {
4141
CxxFileTester tester = CxxFileTesterHelper.CreateCxxFileTester("src/test/resources/checks/UndocumentedApiCheck/no_doc.h", ".");
@@ -96,7 +96,6 @@ public void detected() throws UnsupportedEncodingException, IOException {
9696
}
9797
}
9898

99-
@SuppressWarnings("unchecked")
10099
@Test
101100
public void docStyle1() throws UnsupportedEncodingException, IOException {
102101
CxxFileTester tester = CxxFileTesterHelper.CreateCxxFileTester("src/test/resources/checks/UndocumentedApiCheck/doc_style1.h", ".");
@@ -110,11 +109,9 @@ public void docStyle1() throws UnsupportedEncodingException, IOException {
110109
errors.append(msg.formatDefaultMessage());
111110
errors.append("\r\n");
112111
}
113-
114-
assert errors.length() == 0 : errors;
112+
assertThat(errors.length()).isEqualTo(0);
115113
}
116114

117-
@SuppressWarnings("unchecked")
118115
@Test
119116
public void docStyle2() throws UnsupportedEncodingException, IOException {
120117
CxxFileTester tester = CxxFileTesterHelper.CreateCxxFileTester("src/test/resources/checks/UndocumentedApiCheck/doc_style2.h", ".");
@@ -128,7 +125,7 @@ public void docStyle2() throws UnsupportedEncodingException, IOException {
128125
errors.append(msg.formatDefaultMessage());
129126
errors.append("\r\n");
130127
}
131-
assert errors.length() == 0 : errors;
128+
assertThat(errors.length()).isEqualTo(0);
132129
}
133130

134131
}

cxx-checks/src/test/java/org/sonar/cxx/checks/naming/ClassNameCheckTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
public class ClassNameCheckTest {
3131

3232
@Test
33+
@SuppressWarnings("squid:S2699") // ... verify contains the assertion
3334
public void test() throws Exception {
3435
ClassNameCheck check = new ClassNameCheck();
3536

cxx-checks/src/test/java/org/sonar/cxx/checks/naming/FileNameCheckTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class FileNameCheckTest {
3737
public CheckMessagesVerifierRule checkMessagesVerifier = new CheckMessagesVerifierRule();
3838

3939
@Test
40+
@SuppressWarnings("squid:S2699") // ... verify contains the assertion
4041
public void bad_name() throws UnsupportedEncodingException, IOException {
4142
CxxFileTester tester = CxxFileTesterHelper.CreateCxxFileTester("src/test/resources/checks/badFile_name.cc", ".");
4243
SourceFile file = CxxAstScanner.scanSingleFile(tester.cxxFile, tester.sensorContext, CxxFileTesterHelper.mockCxxLanguage(), check);
@@ -48,6 +49,7 @@ public void bad_name() throws UnsupportedEncodingException, IOException {
4849
}
4950

5051
@Test
52+
@SuppressWarnings("squid:S2699") // ... verify contains the assertion
5153
public void good_name_camel_case() throws UnsupportedEncodingException, IOException {
5254
CxxFileTester tester = CxxFileTesterHelper.CreateCxxFileTester("src/test/resources/checks/FileName.cc", ".");
5355
SourceFile file = CxxAstScanner.scanSingleFile(tester.cxxFile, tester.sensorContext, CxxFileTesterHelper.mockCxxLanguage(), check);
@@ -56,6 +58,7 @@ public void good_name_camel_case() throws UnsupportedEncodingException, IOExcept
5658
}
5759

5860
@Test
61+
@SuppressWarnings("squid:S2699") // ... verify contains the assertion
5962
public void good_name_snake_case() throws UnsupportedEncodingException, IOException {
6063
CxxFileTester tester = CxxFileTesterHelper.CreateCxxFileTester("src/test/resources/checks/file_name.cc", ".");
6164
SourceFile file = CxxAstScanner.scanSingleFile(tester.cxxFile, tester.sensorContext, CxxFileTesterHelper.mockCxxLanguage(), check);

cxx-checks/src/test/java/org/sonar/cxx/checks/naming/FunctionNameCheckTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
public class FunctionNameCheckTest {
3131

3232
@Test
33+
@SuppressWarnings("squid:S2699") // ... verify contains the assertion
3334
public void test() throws Exception {
3435
FunctionNameCheck check = new FunctionNameCheck();
3536

cxx-sensors/src/main/java/org/sonar/cxx/sensors/visitors/CxxFileLinesVisitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ public void leaveFile(AstNode astNode) {
215215
this.allLinesOfCode.put(inputFile, Sets.newHashSet(linesOfCode));
216216

217217
if (LOG.isDebugEnabled()) {
218-
LOG.debug("CxxFileLinesVisitor: '{}'", inputFile.absolutePath()); //@todo: deprecated absolutePath
218+
LOG.debug("CxxFileLinesVisitor: '{}'", inputFile.uri().getPath());
219219
LOG.debug(" lines: '{}'", inputFile.lines());
220220
LOG.debug(" executableLines: '{}'", executableLines);
221221
LOG.debug(" linesOfCode: '{}'", linesOfCode);

cxx-sensors/src/test/java/org/sonar/cxx/sensors/visitors/CxxHighlighterTest.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ public class CxxHighlighterTest {
4141
private File target;
4242

4343
@Before
44-
@SuppressWarnings("unchecked")
4544
public void scanFile() throws IOException {
4645
File baseDir = TestUtils.loadResource("/org/sonar/cxx/sensors");
4746
target = new File(baseDir, "highlighter.cc");
@@ -58,7 +57,8 @@ public void scanFile() throws IOException {
5857
}
5958

6059
@Test
61-
public void keyword() throws Exception {
60+
@SuppressWarnings("squid:S2699") // ... checkOnRange contains the assertion
61+
public void keyword() {
6262

6363
checkOnRange(55, 0, 4, TypeOfText.KEYWORD); // void
6464
checkOnRange(57, 3, 4, TypeOfText.KEYWORD); // auto
@@ -70,7 +70,8 @@ public void keyword() throws Exception {
7070
}
7171

7272
@Test
73-
public void stringLiteral() throws Exception {
73+
@SuppressWarnings("squid:S2699") // ... checkOnRange contains the assertion
74+
public void stringLiteral() {
7475

7576
checkOnRange(49, 19, 7, TypeOfText.STRING); // "hello"
7677
checkOnRange(50, 19, 18, TypeOfText.STRING); // "hello\tworld\r\n"
@@ -87,14 +88,16 @@ public void stringLiteral() throws Exception {
8788
}
8889

8990
@Test
90-
public void character() throws Exception {
91+
@SuppressWarnings("squid:S2699") // ... checkOnRange contains the assertion
92+
public void character() {
9193

9294
checkOnRange(46, 10, 3, TypeOfText.STRING); // 'x'
9395
checkOnRange(47, 10, 4, TypeOfText.STRING); // '\t'
9496
}
9597

9698
@Test
97-
public void comment() throws Exception {
99+
@SuppressWarnings("squid:S2699") // ... checkOnRange contains the assertion
100+
public void comment() {
98101

99102
check(1, 0, TypeOfText.COMMENT);
100103
/*\r\n comment\r\n*/
@@ -113,7 +116,8 @@ public void comment() throws Exception {
113116
}
114117

115118
@Test
116-
public void number() throws Exception {
119+
@SuppressWarnings("squid:S2699") // ... checkOnRange contains the assertion
120+
public void number() {
117121

118122
checkOnRange(27, 10, 1, TypeOfText.CONSTANT); // 0
119123
checkOnRange(28, 10, 1, TypeOfText.CONSTANT); // -1 (without minus)
@@ -133,7 +137,8 @@ public void number() throws Exception {
133137
}
134138

135139
@Test
136-
public void preprocessDirective() throws Exception {
140+
@SuppressWarnings("squid:S2699") // ... checkOnRange contains the assertion
141+
public void preprocessDirective() {
137142

138143
checkOnRange(12, 0, 8, TypeOfText.PREPROCESS_DIRECTIVE); // #include
139144

cxx-squid/src/main/java/org/sonar/cxx/CxxAstScanner.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ private CxxAstScanner() {
7070
* @param language CxxLanguage to use
7171
* @return file checked with measures and issues
7272
*/
73+
@SafeVarargs
7374
public static SourceFile scanSingleFile(InputFile file, SensorContext sensorContext, CxxLanguage language,
7475
SquidAstVisitor<Grammar>... visitors) {
7576
return scanSingleFileConfig(language, file, new CxxConfiguration(sensorContext.fileSystem().encoding()),
@@ -109,6 +110,7 @@ public static SourceFile scanSingleFileConfig(CxxLanguage language, InputFile fi
109110
* @param visitors visitors AST checks and visitors to use
110111
* @return scanner for the given parameters
111112
*/
113+
@SafeVarargs
112114
public static AstScanner<Grammar> create(CxxLanguage language, CxxConfiguration conf,
113115
SquidAstVisitor<Grammar>... visitors) {
114116
final SquidAstVisitorContextImpl<Grammar> context

cxx-squid/src/main/java/org/sonar/cxx/preprocessor/CxxPreprocessor.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@
8282

8383
public class CxxPreprocessor extends Preprocessor {
8484

85+
private static final String CPLUSPLUS = "__cplusplus";
86+
private static final String EVALUATED_TO_FALSE = "[{}:{}]: '{}' evaluated to false, skipping tokens that follow";
8587
private final CxxLanguage language;
8688
private File currentContextFile;
8789
private String rootFilePath;
@@ -393,7 +395,7 @@ public PreprocessorAction process(List<Token> tokens) { //TODO: deprecated Prepr
393395
getMacros().setHighPrio(false);
394396
}
395397

396-
if (getMacro("__cplusplus") == null) {
398+
if (getMacro(CPLUSPLUS) == null) {
397399
//Create macros to replace C++ keywords when parsing C files
398400
registerMacros(StandardDefinitions.compatibilityMacros());
399401
}
@@ -403,9 +405,9 @@ public PreprocessorAction process(List<Token> tokens) { //TODO: deprecated Prepr
403405
if (isCFile(currentContextFile.getAbsolutePath())) {
404406
//Create macros to replace C++ keywords when parsing C files
405407
registerMacros(StandardDefinitions.compatibilityMacros());
406-
fixedMacros.disable("__cplusplus");
408+
fixedMacros.disable(CPLUSPLUS);
407409
} else {
408-
fixedMacros.enable("__cplusplus");
410+
fixedMacros.enable(CPLUSPLUS);
409411
}
410412
}
411413
}
@@ -527,8 +529,7 @@ PreprocessorAction handleIfLine(AstNode ast, Token token, String filename) { //T
527529

528530
if (currentFileState.skipPreprocessorDirectives) {
529531
if (LOG.isTraceEnabled()) {
530-
LOG.trace("[{}:{}]: '{}' evaluated to false, skipping tokens that follow",
531-
filename, token.getLine(), token.getValue());
532+
LOG.trace(EVALUATED_TO_FALSE, filename, token.getLine(), token.getValue());
532533
}
533534
} else {
534535
currentFileState.conditionWasTrue = true;
@@ -563,8 +564,7 @@ PreprocessorAction handleElIfLine(AstNode ast, Token token, String filename) { /
563564

564565
if (currentFileState.skipPreprocessorDirectives) {
565566
if (LOG.isTraceEnabled()) {
566-
LOG.trace("[{}:{}]: '{}' evaluated to false, skipping tokens that follow",
567-
filename, token.getLine(), token.getValue());
567+
LOG.trace(EVALUATED_TO_FALSE, filename, token.getLine(), token.getValue());
568568
}
569569
} else {
570570
currentFileState.conditionWasTrue = true;
@@ -587,8 +587,7 @@ private PreprocessorAction handleIfdefLine(AstNode ast, Token token, String file
587587
TokenType tokType = ast.getToken().getType();
588588
if ((tokType.equals(IFDEF) && macro == null) || (tokType.equals(IFNDEF) && macro != null)) {
589589
if (LOG.isTraceEnabled()) {
590-
LOG.trace("[{}:{}]: '{}' evaluated to false, skipping tokens that follow",
591-
filename, token.getLine(), token.getValue());
590+
LOG.trace(EVALUATED_TO_FALSE, filename, token.getLine(), token.getValue());
592591
}
593592
currentFileState.skipPreprocessorDirectives = true;
594593
}

cxx-squid/src/test/java/org/sonar/cxx/visitors/CxxParseErrorLoggerVisitorTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ public class CxxParseErrorLoggerVisitorTest {
3939
private SensorContextTester context;
4040

4141
@Before
42-
@SuppressWarnings("unchecked")
4342
public void scanFile() {
4443
String dir = "src/test/resources/visitors";
4544

0 commit comments

Comments
 (0)