Skip to content

Commit 87eae72

Browse files
committed
refactoring of CommentTextProcessor api
1 parent b70bfea commit 87eae72

File tree

4 files changed

+32
-35
lines changed

4 files changed

+32
-35
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,9 +456,9 @@ private void flushTextBufferForRemovedComments(
456456
try {
457457
final FilePositionInfo filePositionInfo =
458458
new FilePositionInfo(this.sourceFile, stringIndex);
459-
final String result = x.onUncommentText(
459+
final String result = x.processUncommentedText(
460460
firstUncommentLine == null ? 0 : firstUncommentLine.getKey().length(), origText,
461-
filePositionInfo, this, context, state);
461+
this, filePositionInfo, context, state);
462462
textBuffer.append(result);
463463
} catch (Exception ex) {
464464
throw new PreprocessorException(

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

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.igormaznitsa.jcp.containers.FileInfoContainer;
44
import com.igormaznitsa.jcp.exceptions.FilePositionInfo;
5-
import java.io.IOException;
65

76
/**
87
* Custom processor to detect and process uncommenting text line or text block
@@ -16,23 +15,21 @@
1615
public interface CommentTextProcessor extends PreprocessorContextListener {
1716

1817
/**
19-
* Process text value.
18+
* Process uncommented text detected in //$ or //$$ sections. If processing not needed then the provided text must be returned.
2019
*
21-
* @param firstLineIndent detected indent for the first line during accumulation
22-
* @param text the source text
23-
* @param filePositionInfo position of the uncommented line or the first line of the uncommented text block
24-
* @param fileInfoContainer the source file info container, must not be null
25-
* @param context the source preprocessor context, must not be null
20+
* @param recommendedIndent indent to be recommended for the processed text if it will be processed
21+
* @param uncommentedText the text which was uncommented and needs processing, must not be null
22+
* @param fileContainer the source file info container calling the processor, must not be null
23+
* @param positionInfo position of the uncommented line or the first line of the uncommented text block, must not be null
24+
* @param context the current preprocessor context, must not be null
2625
* @param state the current preprocess state, must not be null
2726
* @return must return value as the same text or as the changed one.
28-
* @throws IOException if any IO error during operation
2927
* @since 7.2.1
3028
*/
31-
String onUncommentText(
32-
int firstLineIndent,
33-
String text,
34-
FilePositionInfo filePositionInfo,
35-
FileInfoContainer fileInfoContainer,
29+
String processUncommentedText(
30+
int recommendedIndent,
31+
String uncommentedText,
32+
FileInfoContainer fileContainer, FilePositionInfo positionInfo,
3633
PreprocessorContext context,
37-
PreprocessingState state) throws IOException;
34+
PreprocessingState state);
3835
}

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,21 @@ public void onContextStopped(PreprocessorContext context, Throwable error) {
6262
}
6363

6464
@Override
65-
public String onUncommentText(int firstLineIndent, String text,
66-
FilePositionInfo filePositionInfo,
67-
FileInfoContainer fileInfoContainer,
68-
PreprocessorContext context, PreprocessingState state) {
69-
assertTrue(filePositionInfo.getLineNumber() >= 0);
70-
assertNotNull(text);
71-
assertNotNull(fileInfoContainer);
65+
public String processUncommentedText(int recommendedIndent, String uncommentedText,
66+
FileInfoContainer fileContainer,
67+
FilePositionInfo positionInfo,
68+
PreprocessorContext context, PreprocessingState state) {
69+
assertTrue(positionInfo.getLineNumber() >= 0);
70+
assertNotNull(uncommentedText);
71+
assertNotNull(fileContainer);
7272
assertNotNull(context);
7373
assertNotNull(state);
7474

75-
calledForText.append("...\n").append(text);
75+
calledForText.append("...\n").append(uncommentedText);
7676

77-
final String indent = context.isPreserveIndents() ? " ".repeat(firstLineIndent) : "";
77+
final String indent = context.isPreserveIndents() ? " ".repeat(recommendedIndent) : "";
7878

79-
return Arrays.stream(text.split("\\R"))
79+
return Arrays.stream(uncommentedText.split("\\R"))
8080
.map(x -> indent + x)
8181
.collect(Collectors.joining(context.getEol(), "", context.getEol()));
8282
}

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,19 @@ public void onContextStopped(PreprocessorContext context, Throwable error) {
6060
}
6161

6262
@Override
63-
public String onUncommentText(int firstLineIndent, String text,
64-
FilePositionInfo filePositionInfo,
65-
FileInfoContainer fileInfoContainer,
66-
PreprocessorContext context, PreprocessingState state) {
67-
assertTrue(filePositionInfo.getLineNumber() >= 0);
68-
assertNotNull(text);
69-
assertNotNull(fileInfoContainer);
63+
public String processUncommentedText(int recommendedIndent, String uncommentedText,
64+
FileInfoContainer fileContainer,
65+
FilePositionInfo positionInfo,
66+
PreprocessorContext context, PreprocessingState state) {
67+
assertTrue(positionInfo.getLineNumber() >= 0);
68+
assertNotNull(uncommentedText);
69+
assertNotNull(fileContainer);
7070
assertNotNull(context);
7171
assertNotNull(state);
7272

73-
calledForText.append("...\n").append(text);
73+
calledForText.append("...\n").append(uncommentedText);
7474

75-
return text;
75+
return uncommentedText;
7676
}
7777
};
7878

0 commit comments

Comments
 (0)