Skip to content
Permalink
Browse files
minor refactor: reduce style warnings
  • Loading branch information
paulk-asert committed Apr 15, 2022
1 parent e50398f commit 66b79c821d0cf995ebc20a62c4d407836dbf1e5c
Showing 3 changed files with 18 additions and 19 deletions.
@@ -97,7 +97,7 @@
public class GStringTemplateEngine extends TemplateEngine {
private final ClassLoader parentLoader;
private static AtomicInteger counter = new AtomicInteger();
private static final boolean reuseClassLoader = SystemUtil.getBooleanSafe("groovy.GStringTemplateEngine.reuseClassLoader");
private static final boolean REUSE_CLASS_LOADER = SystemUtil.getBooleanSafe("groovy.GStringTemplateEngine.reuseClassLoader");

public GStringTemplateEngine() {
this(GStringTemplate.class.getClassLoader());
@@ -191,10 +191,10 @@ private static class GStringTemplate implements Template {

// Use a new class loader by default for each class so each class can be independently garbage collected
final GroovyClassLoader loader =
reuseClassLoader && parentLoader instanceof GroovyClassLoader
REUSE_CLASS_LOADER && parentLoader instanceof GroovyClassLoader
? (GroovyClassLoader) parentLoader
: VMPluginFactory.getPlugin().doPrivileged((PrivilegedAction<GroovyClassLoader>) () -> new GroovyClassLoader(parentLoader));
final Class groovyClass;
final Class<?> groovyClass;
try {
groovyClass = loader.parseClass(new GroovyCodeSource(templateExpressions.toString(), "GStringTemplateScript" + counter.incrementAndGet() + ".groovy", "x"));
} catch (Exception e) {
@@ -306,10 +306,10 @@ public Writable make() {

@Override
public Writable make(final Map map) {
final Closure template = ((Closure) this.template.clone()).asWritable();
final Closure templateClosure = ((Closure) this.template.clone()).asWritable();
Binding binding = new Binding(map);
template.setDelegate(binding);
return (Writable) template;
templateClosure.setDelegate(binding);
return (Writable) templateClosure;
}
}
}
@@ -439,7 +439,7 @@ private String padLeft(String s, int len) {
*/
StreamingTemplate(final Reader source, final ClassLoader parentLoader) throws CompilationFailedException, ClassNotFoundException, IOException {
final StringBuilder target = new StringBuilder();
List<StringSection> sections = new ArrayList<StringSection>();
List<StringSection> sections = new ArrayList<>();
Position sourcePosition = new Position(1, 1);
Position targetPosition = new Position(1, 1);
Position lastSourcePosition = new Position(1, 1);
@@ -597,7 +597,7 @@ private void handleEscaping(final Reader source,

private Closure createTemplateClosure(List<StringSection> sections, final ClassLoader parentLoader, StringBuilder target) throws ClassNotFoundException {
final GroovyClassLoader loader = VMPluginFactory.getPlugin().doPrivileged((PrivilegedAction<GroovyClassLoader>) () -> new GroovyClassLoader(parentLoader));
final Class groovyClass;
final Class<?> groovyClass;
try {
groovyClass = loader.parseClass(new GroovyCodeSource(target.toString(), TEMPLATE_SCRIPT_PREFIX + COUNTER.incrementAndGet() + ".groovy", "x"));
} catch (MultipleCompilationErrorsException e) {
@@ -772,8 +772,7 @@ public Writable make() {
@Override
public Writable make(final Map map) {
//we don't need a template.clone here as curry calls clone under the hood
final Closure template = this.template.curry(new Object[]{map});
return (Writable) template;
return (Writable) this.template.curry(new Object[]{map});
}

/*
@@ -825,22 +824,22 @@ private RuntimeException mangleMultipleCompilationErrorsException(MultipleCompil

private String mangleExceptionMessage(String original, Position p) {
String result = original;
int index = result.indexOf("@ line ");
if (index != -1) {
result = result.substring(0, index);
int idx = result.indexOf("@ line ");
if (idx != -1) {
result = result.substring(0, idx);
}

int count = 0;
index = 0;
idx = 0;
for (char c : result.toCharArray()) {
if (c == ':') {
count++;
if (count == 3) {
result = result.substring(index + 2);
result = result.substring(idx + 2);
break;
}
}
index++;
idx++;
}

String msg = "Template parse error '" + result + "' at line " + p.row + ", column " + p.column;
@@ -26,7 +26,7 @@
public class XmlTemplateEngineTest extends TestCase {

public void testBinding() throws Exception {
Map<String, String> binding = new HashMap();
Map<String, String> binding = new HashMap<>();
binding.put("Christian", "Stein");

XmlTemplateEngine xmlTemplateEngine = new XmlTemplateEngine();
@@ -46,7 +46,7 @@ public void testBinding() throws Exception {
}

public void testQuotes() throws Exception {
Map<String, String> binding = new HashMap();
Map<String, String> binding = new HashMap<>();
binding.put("Christian", "Stein");

XmlTemplateEngine xmlTemplateEngine = new XmlTemplateEngine();
@@ -66,7 +66,7 @@ public void testQuotes() throws Exception {
}

public void testNamespaces() throws Exception {
Map<String, String> binding = new HashMap();
Map<String, String> binding = new HashMap<>();
binding.put("Christian", "Stein");

XmlTemplateEngine xmlTemplateEngine = new XmlTemplateEngine();

0 comments on commit 66b79c8

Please sign in to comment.