From 3eaf8e868047bd7728f7c5d5d5561a3aabdf3d72 Mon Sep 17 00:00:00 2001 From: Mitchell Bosecke Date: Sat, 25 Jan 2014 11:41:46 -0700 Subject: [PATCH] Misc code cleanup --- .../mitchellbosecke/pebble/PebbleEngine.java | 18 ++++++++---------- .../cache/DefaultTemplateLoadingCache.java | 6 +++--- .../pebble/cache/TemplateLoadingCache.java | 5 +++-- .../pebble/extension/CoreExtension.java | 10 +++++----- .../mitchellbosecke/pebble/extension/Test.java | 2 +- ...leDefaultLoader.java => DefaultLoader.java} | 6 +++--- .../mitchellbosecke/pebble/AbstractTest.java | 4 ++-- .../com/mitchellbosecke/pebble/CacheTest.java | 6 +++--- 8 files changed, 28 insertions(+), 29 deletions(-) rename src/main/java/com/mitchellbosecke/pebble/loader/{PebbleDefaultLoader.java => DefaultLoader.java} (93%) diff --git a/src/main/java/com/mitchellbosecke/pebble/PebbleEngine.java b/src/main/java/com/mitchellbosecke/pebble/PebbleEngine.java index d502d44ed..1ec922ce4 100644 --- a/src/main/java/com/mitchellbosecke/pebble/PebbleEngine.java +++ b/src/main/java/com/mitchellbosecke/pebble/PebbleEngine.java @@ -38,7 +38,7 @@ import com.mitchellbosecke.pebble.lexer.LexerImpl; import com.mitchellbosecke.pebble.lexer.TokenStream; import com.mitchellbosecke.pebble.loader.Loader; -import com.mitchellbosecke.pebble.loader.PebbleDefaultLoader; +import com.mitchellbosecke.pebble.loader.DefaultLoader; import com.mitchellbosecke.pebble.node.NodeRoot; import com.mitchellbosecke.pebble.operator.BinaryOperator; import com.mitchellbosecke.pebble.operator.UnaryOperator; @@ -77,7 +77,7 @@ public class PebbleEngine { /** * Template cache */ - private TemplateLoadingCache loadingTemplateCache; + private TemplateLoadingCache loadingTemplateCache; /* * Extensions @@ -103,7 +103,7 @@ public class PebbleEngine { private final Semaphore compilationMutex = new Semaphore(1); public PebbleEngine() { - this(new PebbleDefaultLoader()); + this(new DefaultLoader()); } /** @@ -170,19 +170,17 @@ public PebbleTemplate call() throws PebbleException, InterruptedException { TokenStream tokenStream = getLexer().tokenize(templateSource, templateName); NodeRoot root = getParser().parse(tokenStream); String javaSource = getCompiler().compile(root).getSource(); - + // we are now done with the non-thread-safe objects, so release // the compilation mutex compilationMutex.release(); - + PebbleTemplate parent = null; - if(root.hasParent()){ + if (root.hasParent()) { parent = self.compile(root.getParentFileName()); } instance = getCompiler().instantiateTemplate(javaSource, className, parent); - - // init blocks and macros instance.initBlocks(); instance.initMacros(); @@ -387,11 +385,11 @@ public Class getTemplateParentClass() { return templateParentClass; } - public TemplateLoadingCache getTemplateCache() { + public TemplateLoadingCache getTemplateCache() { return loadingTemplateCache; } - public void setTemplateCache(TemplateLoadingCache cache) { + public void setTemplateCache(TemplateLoadingCache cache) { this.loadingTemplateCache = cache; } diff --git a/src/main/java/com/mitchellbosecke/pebble/cache/DefaultTemplateLoadingCache.java b/src/main/java/com/mitchellbosecke/pebble/cache/DefaultTemplateLoadingCache.java index 0eb5b85d9..ce4842f5b 100644 --- a/src/main/java/com/mitchellbosecke/pebble/cache/DefaultTemplateLoadingCache.java +++ b/src/main/java/com/mitchellbosecke/pebble/cache/DefaultTemplateLoadingCache.java @@ -10,7 +10,7 @@ import com.mitchellbosecke.pebble.error.PebbleException; import com.mitchellbosecke.pebble.template.PebbleTemplate; -public class DefaultTemplateLoadingCache implements TemplateLoadingCache { +public class DefaultTemplateLoadingCache implements TemplateLoadingCache { private final ConcurrentMap> cache = new ConcurrentHashMap<>(); @@ -31,8 +31,8 @@ public PebbleTemplate get(String key, Callable loadingFunction) try { return future.get(); } catch (ExecutionException | InterruptedException e) { - if(e.getCause() instanceof PebbleException){ - throw (PebbleException)e.getCause(); + if (e.getCause() instanceof PebbleException) { + throw (PebbleException) e.getCause(); } throw new RuntimeException("An error occurred while retrieving from cache"); } diff --git a/src/main/java/com/mitchellbosecke/pebble/cache/TemplateLoadingCache.java b/src/main/java/com/mitchellbosecke/pebble/cache/TemplateLoadingCache.java index e178e4091..4a60740b5 100644 --- a/src/main/java/com/mitchellbosecke/pebble/cache/TemplateLoadingCache.java +++ b/src/main/java/com/mitchellbosecke/pebble/cache/TemplateLoadingCache.java @@ -3,8 +3,9 @@ import java.util.concurrent.Callable; import com.mitchellbosecke.pebble.error.PebbleException; +import com.mitchellbosecke.pebble.template.PebbleTemplate; -public interface TemplateLoadingCache { +public interface TemplateLoadingCache { - public V get(K key, Callable loadingFunction) throws PebbleException; + public PebbleTemplate get(String key, Callable loadingFunction) throws PebbleException; } diff --git a/src/main/java/com/mitchellbosecke/pebble/extension/CoreExtension.java b/src/main/java/com/mitchellbosecke/pebble/extension/CoreExtension.java index 6084990f7..ea1e5bb94 100644 --- a/src/main/java/com/mitchellbosecke/pebble/extension/CoreExtension.java +++ b/src/main/java/com/mitchellbosecke/pebble/extension/CoreExtension.java @@ -356,7 +356,7 @@ public String getName() { return "even"; } - public Boolean apply(Object input, List args) { + public boolean apply(Object input, List args) { Integer obj = (Integer) input; return (obj % 2 == 0); @@ -368,7 +368,7 @@ public String getName() { return "odd"; } - public Boolean apply(Object input, List args) { + public boolean apply(Object input, List args) { return evenTest.apply(input, args) == false; } @@ -379,7 +379,7 @@ public String getName() { return "null"; } - public Boolean apply(Object input, List args) { + public boolean apply(Object input, List args) { return input == null; } @@ -390,7 +390,7 @@ public String getName() { return "empty"; } - public Boolean apply(Object input, List args) { + public boolean apply(Object input, List args) { boolean isEmpty = input == null; if (!isEmpty && input instanceof String) { @@ -414,7 +414,7 @@ public String getName() { return "iterable"; } - public Boolean apply(Object input, List args) { + public boolean apply(Object input, List args) { return input instanceof Iterable; } diff --git a/src/main/java/com/mitchellbosecke/pebble/extension/Test.java b/src/main/java/com/mitchellbosecke/pebble/extension/Test.java index d1beac0f7..ed5f4ad6b 100644 --- a/src/main/java/com/mitchellbosecke/pebble/extension/Test.java +++ b/src/main/java/com/mitchellbosecke/pebble/extension/Test.java @@ -15,5 +15,5 @@ public interface Test { public String getName(); - public Boolean apply(Object input, List args); + public boolean apply(Object input, List args); } diff --git a/src/main/java/com/mitchellbosecke/pebble/loader/PebbleDefaultLoader.java b/src/main/java/com/mitchellbosecke/pebble/loader/DefaultLoader.java similarity index 93% rename from src/main/java/com/mitchellbosecke/pebble/loader/PebbleDefaultLoader.java rename to src/main/java/com/mitchellbosecke/pebble/loader/DefaultLoader.java index 579e5e777..290e036ae 100644 --- a/src/main/java/com/mitchellbosecke/pebble/loader/PebbleDefaultLoader.java +++ b/src/main/java/com/mitchellbosecke/pebble/loader/DefaultLoader.java @@ -23,9 +23,9 @@ import com.mitchellbosecke.pebble.error.LoaderException; -public class PebbleDefaultLoader implements Loader { +public class DefaultLoader implements Loader { - private static final Logger logger = LoggerFactory.getLogger(PebbleDefaultLoader.class); + private static final Logger logger = LoggerFactory.getLogger(DefaultLoader.class); private String prefix; @@ -59,7 +59,7 @@ public Reader getReader(String templateName) throws LoaderException { is = ccl.getResourceAsStream(location); // try ResourceLoader's class loader - ClassLoader rcl = PebbleDefaultLoader.class.getClassLoader(); + ClassLoader rcl = DefaultLoader.class.getClassLoader(); if (is == null) { is = rcl.getResourceAsStream(location); } diff --git a/src/test/java/com/mitchellbosecke/pebble/AbstractTest.java b/src/test/java/com/mitchellbosecke/pebble/AbstractTest.java index ba3ed3eca..d560c4c35 100644 --- a/src/test/java/com/mitchellbosecke/pebble/AbstractTest.java +++ b/src/test/java/com/mitchellbosecke/pebble/AbstractTest.java @@ -9,7 +9,7 @@ import com.mitchellbosecke.pebble.compiler.Compiler; import com.mitchellbosecke.pebble.lexer.Lexer; import com.mitchellbosecke.pebble.loader.Loader; -import com.mitchellbosecke.pebble.loader.PebbleDefaultLoader; +import com.mitchellbosecke.pebble.loader.DefaultLoader; import com.mitchellbosecke.pebble.parser.Parser; public abstract class AbstractTest { @@ -22,7 +22,7 @@ public abstract class AbstractTest { public AbstractTest() { - Loader templateLoader = new PebbleDefaultLoader(); + Loader templateLoader = new DefaultLoader(); templateLoader.setPrefix("templates"); // main testing engine uses all default settings diff --git a/src/test/java/com/mitchellbosecke/pebble/CacheTest.java b/src/test/java/com/mitchellbosecke/pebble/CacheTest.java index 86a2b6147..570afefb6 100644 --- a/src/test/java/com/mitchellbosecke/pebble/CacheTest.java +++ b/src/test/java/com/mitchellbosecke/pebble/CacheTest.java @@ -19,7 +19,7 @@ import com.mitchellbosecke.pebble.error.PebbleException; import com.mitchellbosecke.pebble.loader.Loader; -import com.mitchellbosecke.pebble.loader.PebbleDefaultLoader; +import com.mitchellbosecke.pebble.loader.DefaultLoader; import com.mitchellbosecke.pebble.template.PebbleTemplate; public class CacheTest extends AbstractTest { @@ -32,7 +32,7 @@ public class CacheTest extends AbstractTest { */ @Test public void templatesWithSameNameOverridingCache() throws PebbleException, IOException { - Loader loader = new PebbleDefaultLoader(); + Loader loader = new DefaultLoader(); PebbleEngine engine = new PebbleEngine(loader); PebbleTemplate cache1 = engine.compile("templates/cache/cache1/template.cache.peb"); @@ -60,7 +60,7 @@ public void templatesWithSameNameOverridingCache() throws PebbleException, IOExc */ @Test public void ensureChildTemplateNotCached() throws PebbleException, IOException { - Loader loader = new PebbleDefaultLoader(); + Loader loader = new DefaultLoader(); PebbleEngine engine = new PebbleEngine(loader); PebbleTemplate cache1 = engine.compile("templates/cache/template.cacheChild.peb");