Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/keenwrite.git

Eliminate null reference from ProcessorFactory

AuthorDaveJarvis <email>
Date2020-10-03 21:54:45 GMT-0700
Commitb13461836fa4d6d20a7835fcad16590eda963f85
Parent32941e1
Delta26 lines added, 41 lines removed, 15-line decrease
src/main/java/com/keenwrite/processors/IdentityProcessor.java
/**
- * Responsible for transforming a string into itself. This is typically used
- * at the end of a processing chain when no more processing is required, such
- * as when exporting files.
+ * Responsible for transforming a string into itself. This is used at the
+ * end of a processing chain when no more processing is required.
*/
public class IdentityProcessor extends AbstractProcessor<String> {
/**
- * Passes the link to the super constructor.
- *
- * @param successor The next processor in the chain to use for text
- * processing.
+ * Constructs a new instance having no successor.
*/
- public IdentityProcessor( final Processor<String> successor ) {
- super( successor );
+ public IdentityProcessor() {
+ super( null );
}
src/main/java/com/keenwrite/processors/ProcessorFactory.java
private Processor<String> createProcessor() {
final ProcessorContext context = getProcessorContext();
- final Processor<String> successor;
- if( context.isExportFormat( NONE ) ) {
- // If the content is not to be exported, then the successor processor
- // is one that parses Markdown into HTML and passes the string to the
- // HTML preview pane.
- successor = getCommonProcessor();
- }
- else {
- // Otherwise, bolt on a processor that--after the interpolation and
- // substitution phase, which includes text strings or R code---will
- // generate HTML or plain Markdown. HTML has a few output formats:
- // with embedded SVG representing formulas, or without any conversion
- // to SVG. Without conversion would require client-side rendering of
- // math (such as using the JavaScript-based KaTeX engine).
- successor = switch( context.getExportFormat() ) {
- case HTML_TEX_SVG -> createHtmlSvgProcessor();
- case HTML_TEX_DELIMITED -> createHtmlTexProcessor();
- case MARKDOWN_PLAIN -> createMarkdownPlainProcessor();
- case NONE -> null;
- };
- }
+ // If the content is not to be exported, then the successor processor
+ // is one that parses Markdown into HTML and passes the string to the
+ // HTML preview pane.
+ //
+ // Otherwise, bolt on a processor that--after the interpolation and
+ // substitution phase, which includes text strings or R code---will
+ // generate HTML or plain Markdown. HTML has a few output formats:
+ // with embedded SVG representing formulas, or without any conversion
+ // to SVG. Without conversion would require client-side rendering of
+ // math (such as using the JavaScript-based KaTeX engine).
+ final Processor<String> successor = context.isExportFormat( NONE )
+ ? getCommonProcessor()
+ :
+ switch( context.getExportFormat() ) {
+ case HTML_TEX_SVG, HTML_TEX_DELIMITED -> createHtmlProcessor();
+ case MARKDOWN_PLAIN, NONE -> createIdentityProcessor();
+ };
return switch( context.getFileType() ) {
*/
private Processor<String> createIdentityProcessor() {
- return new IdentityProcessor( null );
+ return new IdentityProcessor();
}
final var xmlp = new XmlProcessor( successor, getPath() );
return createDefinitionProcessor( xmlp );
- }
-
- private Processor<String> createHtmlSvgProcessor() {
- return MarkdownProcessor.create( null, getProcessorContext() );
- }
-
- private Processor<String> createHtmlTexProcessor() {
- return MarkdownProcessor.create( null, getProcessorContext() );
}
- private Processor<String> createMarkdownPlainProcessor() {
- return createIdentityProcessor();
+ private Processor<String> createHtmlProcessor() {
+ final Processor<String> successor = createIdentityProcessor();
+ return MarkdownProcessor.create( successor, getProcessorContext() );
}