From 8b7ffd64f86bd4929e00f18faae928dc4dd6bfcb Mon Sep 17 00:00:00 2001 From: JesseBrault0709 <62299747+JesseBrault0709@users.noreply.github.com> Date: Sat, 1 Jun 2024 17:24:25 +0200 Subject: [PATCH] Better internal logic for DefaultComponentTemplateCompilerConfiguration. --- ...omponentTemplateCompilerConfiguration.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/view-components/src/main/java/groowt/view/component/compiler/DefaultComponentTemplateCompilerConfiguration.java b/view-components/src/main/java/groowt/view/component/compiler/DefaultComponentTemplateCompilerConfiguration.java index 2a02ed9..2066262 100644 --- a/view-components/src/main/java/groowt/view/component/compiler/DefaultComponentTemplateCompilerConfiguration.java +++ b/view-components/src/main/java/groowt/view/component/compiler/DefaultComponentTemplateCompilerConfiguration.java @@ -4,41 +4,45 @@ import groovy.lang.GroovyClassLoader; import org.codehaus.groovy.control.CompilePhase; import org.codehaus.groovy.control.CompilerConfiguration; +import static java.util.Objects.requireNonNull; + public class DefaultComponentTemplateCompilerConfiguration implements ComponentTemplateCompilerConfiguration { private GroovyClassLoader groovyClassLoader; private CompilerConfiguration groovyCompilerConfiguration; private CompilePhase toCompilePhase; + public DefaultComponentTemplateCompilerConfiguration() { + this.groovyClassLoader = new GroovyClassLoader(Thread.currentThread().getContextClassLoader()); + this.groovyCompilerConfiguration = new CompilerConfiguration(); + this.toCompilePhase = CompilePhase.CLASS_GENERATION; + } + @Override public GroovyClassLoader getGroovyClassLoader() { - return this.groovyClassLoader != null - ? this.groovyClassLoader - : new GroovyClassLoader(this.getClass().getClassLoader()); + return this.groovyClassLoader; } public void setGroovyClassLoader(GroovyClassLoader groovyClassLoader) { - this.groovyClassLoader = groovyClassLoader; + this.groovyClassLoader = requireNonNull(groovyClassLoader); } @Override public CompilerConfiguration getGroovyCompilerConfiguration() { - return this.groovyCompilerConfiguration != null - ? this.groovyCompilerConfiguration - : CompilerConfiguration.DEFAULT; + return this.groovyCompilerConfiguration; } public void setGroovyCompilerConfiguration(CompilerConfiguration groovyCompilerConfiguration) { - this.groovyCompilerConfiguration = groovyCompilerConfiguration; + this.groovyCompilerConfiguration = requireNonNull(groovyCompilerConfiguration); } @Override public CompilePhase getToCompilePhase() { - return this.toCompilePhase != null ? this.toCompilePhase : CompilePhase.CLASS_GENERATION; + return this.toCompilePhase; } public void setToCompilePhase(CompilePhase toCompilePhase) { - this.toCompilePhase = toCompilePhase; + this.toCompilePhase = requireNonNull(toCompilePhase); } }