Skip to content

Commit d4c4cee

Browse files
committed
added flag into context to activate support for block comments
1 parent 253b9b4 commit d4c4cee

4 files changed

Lines changed: 20 additions & 5 deletions

File tree

jcp/src/main/java/com/igormaznitsa/jcp/containers/FileInfoContainer.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,8 @@ public PreprocessingState preprocessFile(final PreprocessingState state,
532532
// Output the tail of the string to the output stream without comments and macroses
533533
final String text =
534534
extractDoubleDollarPrefixedDirective(leftTrimmedString, false, context);
535-
if (isDoubleDollarBlockPrefixed(leftTrimmedString, context.isAllowWhitespaces())) {
535+
if (context.isAllowsBlocks() &&
536+
isDoubleDollarBlockPrefixed(leftTrimmedString, context.isAllowWhitespaces())) {
536537
textBlockBuffer.append(
537538
extractDoubleDollarPrefixedDirective(leftTrimmedString, true, context));
538539
if (doPrintLn) {
@@ -551,7 +552,8 @@ public PreprocessingState preprocessFile(final PreprocessingState state,
551552
final String text =
552553
extractSingleDollarPrefixedDirective(stringToBeProcessed, false, context);
553554

554-
if (isDollarBlockPrefixed(stringToBeProcessed, context.isAllowWhitespaces())) {
555+
if (context.isAllowsBlocks() &&
556+
isDollarBlockPrefixed(stringToBeProcessed, context.isAllowWhitespaces())) {
555557
textBlockBuffer.append(
556558
extractSingleDollarPrefixedDirective(stringToBeProcessed, true, context));
557559
if (doPrintLn) {

jcp/src/main/java/com/igormaznitsa/jcp/context/PreprocessorContext.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ public class PreprocessorContext {
106106
private boolean preserveIndents = false;
107107
private boolean keepAttributes = false;
108108
private boolean unknownVariableAsFalse = false;
109+
private boolean allowsBlocks = false;
109110
private File target;
110111
private Set<String> extensions = new HashSet<>(DEFAULT_PROCESSING_EXTENSIONS);
111112
private Set<String> excludeExtensions = new HashSet<>(DEFAULT_EXCLUDED_EXTENSIONS);
@@ -166,6 +167,7 @@ public PreprocessorContext(final PreprocessorContext context) {
166167
this.excludeExtensions.addAll(context.excludeExtensions);
167168

168169
this.unknownVariableAsFalse = context.unknownVariableAsFalse;
170+
this.allowsBlocks = context.allowsBlocks;
169171

170172
this.preprocessorExtension = context.getPreprocessorExtension();
171173
this.sourceEncoding = context.getSourceEncoding();

jcp/src/test/java/com/igormaznitsa/jcp/directives/AbstractDirectiveHandlerAcceptanceTest.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import static org.junit.Assert.assertNotNull;
2828
import static org.junit.Assert.fail;
2929

30-
3130
import com.igormaznitsa.jcp.containers.FileInfoContainer;
3231
import com.igormaznitsa.jcp.containers.TextFileDataContainer;
3332
import com.igormaznitsa.jcp.context.PreprocessingState;
@@ -187,6 +186,7 @@ private PreprocessorContext internalPreprocessAndMatch(final File srcfile,
187186
final PreprocessorExtension extension,
188187
final PreprocessorLogger logger,
189188
final boolean keepLines,
189+
final boolean allowBlocks,
190190
final VariablePair... globalVariables)
191191
throws Exception {
192192
assertNotNull("Preprocessing text is null", preprocessingText);
@@ -200,6 +200,7 @@ private PreprocessorContext internalPreprocessAndMatch(final File srcfile,
200200
context.setDryRun(true);
201201
context.setSources(Collections.singletonList(srcfile.getParent()));
202202
context.setKeepLines(keepLines);
203+
context.setAllowsBlocks(allowBlocks);
203204
context.setPreprocessorExtension(extension);
204205

205206
setGlobalVars(context, globalVariables);
@@ -283,10 +284,20 @@ private PreprocessorContext preprocessString(final String text, final List<Strin
283284
final List<String> preprocessingPart = parseStringForLines(text);
284285
return internalPreprocessAndMatch(THIS_CLASS_FILE, preprocessingPart,
285286
preprocessedText == null ? new ArrayList<>() : preprocessedText, null, ext, null, false,
287+
false,
286288
globalVars);
287289
}
288290

289291
public PreprocessorContext assertFilePreprocessing(final String testFileName, boolean keepLines, final PreprocessorExtension ext, final PreprocessorLogger logger, final VariablePair... globalVars) throws Exception {
292+
return this.assertFilePreprocessing(testFileName, keepLines, false, ext, logger, globalVars);
293+
}
294+
295+
public PreprocessorContext assertFilePreprocessing(final String testFileName, boolean keepLines,
296+
boolean allowsBlocks,
297+
final PreprocessorExtension ext,
298+
final PreprocessorLogger logger,
299+
final VariablePair... globalVars)
300+
throws Exception {
290301
final File file = new File(getClass().getResource(testFileName).toURI());
291302

292303
if (!file.exists() || !file.isFile()) {
@@ -324,6 +335,6 @@ public PreprocessorContext assertFilePreprocessing(final String testFileName, bo
324335
}
325336

326337
return internalPreprocessAndMatch(file, preprocessingPart, new ArrayList<>(), etalonPart, ext,
327-
logger, keepLines, globalVars);
338+
logger, keepLines, allowsBlocks, globalVars);
328339
}
329340
}

jcp/src/test/java/com/igormaznitsa/jcp/directives/SpecialDirectivesBlockTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class SpecialDirectivesBlockTest extends AbstractDirectiveHandlerAcceptan
2727

2828
@Override
2929
public void testExecution() throws Exception {
30-
assertFilePreprocessing("directive_special_block.txt", false, null, null);
30+
assertFilePreprocessing("directive_special_block.txt", false, true, null, null);
3131
}
3232

3333
@Override

0 commit comments

Comments
 (0)