Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simply JinjavaConfig construction #528

Merged
merged 1 commit into from
Nov 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 29 additions & 107 deletions src/main/java/com/hubspot/jinjava/JinjavaConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,32 +63,11 @@ public static Builder newBuilder() {
}

public JinjavaConfig() {
this(new JinjavaInterpreterFactory());
this(newBuilder());
}

public JinjavaConfig(InterpreterFactory interpreterFactory) {
this(
StandardCharsets.UTF_8,
Locale.ENGLISH,
ZoneOffset.UTC,
10,
new HashMap<>(),
false,
false,
false,
0,
false,
0,
true,
RandomNumberGeneratorStrategy.THREAD_LOCAL,
false,
0,
interpreterFactory,
new DefaultTokenScannerSymbols(),
JinjavaInterpreterResolver.DEFAULT_RESOLVER_READ_ONLY,
false,
false
);
this(newBuilder().withInterperterFactory(interpreterFactory));
}

public JinjavaConfig(
Expand All @@ -98,71 +77,35 @@ public JinjavaConfig(
int maxRenderDepth
) {
this(
charset,
locale,
timeZone,
maxRenderDepth,
new HashMap<>(),
false,
false,
false,
0,
false,
0,
true,
RandomNumberGeneratorStrategy.THREAD_LOCAL,
false,
0,
new JinjavaInterpreterFactory(),
new DefaultTokenScannerSymbols(),
JinjavaInterpreterResolver.DEFAULT_RESOLVER_READ_ONLY,
false,
false
newBuilder()
.withCharset(charset)
.withLocale(locale)
.withTimeZone(timeZone)
.withMaxRenderDepth(maxRenderDepth)
);
}

private JinjavaConfig(
Charset charset,
Locale locale,
ZoneId timeZone,
int maxRenderDepth,
Map<Context.Library, Set<String>> disabled,
boolean trimBlocks,
boolean lstripBlocks,
boolean enableRecursiveMacroCalls,
int maxMacroRecursionDepth,
boolean failOnUnknownTokens,
long maxOutputSize,
boolean nestedInterpretationEnabled,
RandomNumberGeneratorStrategy randomNumberGenerator,
boolean validationMode,
long maxStringLength,
InterpreterFactory interpreterFactory,
TokenScannerSymbols tokenScannerSymbols,
ELResolver elResolver,
boolean iterateOverMapKeys,
boolean preserveForFinalPass
) {
this.charset = charset;
this.locale = locale;
this.timeZone = timeZone;
this.maxRenderDepth = maxRenderDepth;
this.disabled = disabled;
this.trimBlocks = trimBlocks;
this.lstripBlocks = lstripBlocks;
this.enableRecursiveMacroCalls = enableRecursiveMacroCalls;
this.maxMacroRecursionDepth = maxMacroRecursionDepth;
this.failOnUnknownTokens = failOnUnknownTokens;
this.maxOutputSize = maxOutputSize;
this.nestedInterpretationEnabled = nestedInterpretationEnabled;
this.randomNumberGenerator = randomNumberGenerator;
this.validationMode = validationMode;
this.maxStringLength = maxStringLength;
this.interpreterFactory = interpreterFactory;
this.tokenScannerSymbols = tokenScannerSymbols;
this.elResolver = elResolver;
this.iterateOverMapKeys = iterateOverMapKeys;
this.preserveForFinalPass = preserveForFinalPass;
private JinjavaConfig(Builder builder) {
charset = builder.charset;
locale = builder.locale;
timeZone = builder.timeZone;
maxRenderDepth = builder.maxRenderDepth;
disabled = builder.disabled;
trimBlocks = builder.trimBlocks;
lstripBlocks = builder.lstripBlocks;
enableRecursiveMacroCalls = builder.enableRecursiveMacroCalls;
maxMacroRecursionDepth = builder.maxMacroRecursionDepth;
failOnUnknownTokens = builder.failOnUnknownTokens;
maxOutputSize = builder.maxOutputSize;
nestedInterpretationEnabled = builder.nestedInterpretationEnabled;
randomNumberGenerator = builder.randomNumberGeneratorStrategy;
validationMode = builder.validationMode;
maxStringLength = builder.maxStringLength;
interpreterFactory = builder.interpreterFactory;
tokenScannerSymbols = builder.tokenScannerSymbols;
elResolver = builder.elResolver;
iterateOverMapKeys = builder.iterateOverMapKeys;
preserveForFinalPass = builder.preserveForFinalPass;
}

public Charset getCharset() {
Expand Down Expand Up @@ -387,28 +330,7 @@ public Builder withPreserveForFinalPass(boolean preserveForFinalPass) {
}

public JinjavaConfig build() {
return new JinjavaConfig(
charset,
locale,
timeZone,
maxRenderDepth,
disabled,
trimBlocks,
lstripBlocks,
enableRecursiveMacroCalls,
maxMacroRecursionDepth,
failOnUnknownTokens,
maxOutputSize,
nestedInterpretationEnabled,
randomNumberGeneratorStrategy,
validationMode,
maxStringLength,
interpreterFactory,
tokenScannerSymbols,
elResolver,
iterateOverMapKeys,
preserveForFinalPass
);
return new JinjavaConfig(this);
}
}
}