Skip to content

Commit dc83764

Browse files
authored
Merge pull request #1660 from ivangalkin/CxxPreprocessor_init
CxxPreprocessor: unitilize com.sonar.sslr.api.Preprocessor::init()
2 parents 92ae26a + 8dfd12f commit dc83764

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -442,14 +442,10 @@ public Collection<Include> getMissingIncludeFiles(File file) {
442442
}
443443

444444
@Override
445-
public PreprocessorAction process(List<Token> tokens) { //TODO: deprecated PreprocessorAction
446-
Token token = tokens.get(0);
447-
TokenType ttype = token.getType();
448-
449-
final String rootFilePath = getFileUnderAnalysis().getAbsolutePath();
450-
451-
// CxxPreprocessor::process() can be called a) while construction,
452-
// b) for a new "physical" file or c) for #include directive.
445+
public void init() {
446+
// CxxPreprocessor::init() can be called a) while construction,
447+
// b) for a new "physical" file or c) while processing of
448+
// #include directive.
453449
// Make sure, that the following code is executed for a new "physical" file
454450
// only.
455451
final boolean processingNewSourceFile = !ctorInProgress && (context.getFile() != currentContextFile);
@@ -462,12 +458,12 @@ public PreprocessorAction process(List<Token> tokens) { //TODO: deprecated Prepr
462458
compilationUnitSettings = conf.getCompilationUnitSettings(currentContextFile.getAbsolutePath());
463459

464460
if (compilationUnitSettings != null) {
465-
LOG.debug("compilation unit settings for: '{}'", rootFilePath);
461+
LOG.debug("compilation unit settings for: '{}'", currentContextFile);
466462
} else {
467463
compilationUnitSettings = conf.getGlobalCompilationUnitSettings();
468464

469465
if (compilationUnitSettings != null) {
470-
LOG.debug("global compilation unit settings for: '{}'", rootFilePath);
466+
LOG.debug("global compilation unit settings for: '{}'", currentContextFile);
471467
}
472468
}
473469

@@ -523,7 +519,7 @@ public PreprocessorAction process(List<Token> tokens) { //TODO: deprecated Prepr
523519
}
524520
} else {
525521
// Use global settings
526-
LOG.debug("global settings for: '{}'", rootFilePath);
522+
LOG.debug("global settings for: '{}'", currentContextFile);
527523
if (isCFile(currentContextFile.getAbsolutePath())) {
528524
//Create macros to replace C++ keywords when parsing C files
529525
getMacros().putAll(Macro.COMPATIBILITY_MACROS);
@@ -533,6 +529,13 @@ public PreprocessorAction process(List<Token> tokens) { //TODO: deprecated Prepr
533529
}
534530
}
535531
}
532+
}
533+
534+
@Override
535+
public PreprocessorAction process(List<Token> tokens) { //TODO: deprecated PreprocessorAction
536+
final Token token = tokens.get(0);
537+
final TokenType ttype = token.getType();
538+
final String rootFilePath = getFileUnderAnalysis().getAbsolutePath();
536539

537540
if (ttype.equals(PREPROCESSOR)) {
538541

0 commit comments

Comments
 (0)