From 3a5da915e906c81b9f151a796a7bbdeb4c81ade5 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Wed, 27 Mar 2013 10:37:41 -0700 Subject: [PATCH] These days I always cuddle method braces. --- .../com/samskivert/mustache/Mustache.java | 17 +++----- .../mustache/MustacheParseException.java | 6 +-- .../com/samskivert/mustache/Template.java | 42 +++++++------------ 3 files changed, 22 insertions(+), 43 deletions(-) diff --git a/src/main/java/com/samskivert/mustache/Mustache.java b/src/main/java/com/samskivert/mustache/Mustache.java index 4365f41..c758282 100644 --- a/src/main/java/com/samskivert/mustache/Mustache.java +++ b/src/main/java/com/samskivert/mustache/Mustache.java @@ -133,7 +133,7 @@ public class Mustache } /** Returns a compiler configured to use the supplied delims as default delimiters. - * @param delims a string of the form {@code {AB CD} or {@code {A D} where A and B are + * @param delims a string of the form {@code AB CD} or {@code A D} where A and B are * opening delims and C and D are closing delims. */ public Compiler withDelims (String delims) { return new Compiler(this.escapeHTML, this.standardsMode, this.nullValue, @@ -209,8 +209,7 @@ public class Mustache /** * Returns a compiler that escapes HTML by default and does not use standards mode. */ - public static Compiler compiler () - { + public static Compiler compiler () { return new Compiler(true, false, null, true, false, FAILING_LOADER, new DefaultCollector(), new Delims()); } @@ -218,32 +217,28 @@ public class Mustache /** * Compiles the supplied template into a repeatedly executable intermediate form. */ - protected static Template compile (Reader source, Compiler compiler) - { + protected static Template compile (Reader source, Compiler compiler) { Accumulator accum = new Parser(compiler).parse(source); return new Template(accum.finish(), compiler); } private Mustache () {} // no instantiateski - protected static void restoreStartTag (StringBuilder text, Delims starts) - { + protected static void restoreStartTag (StringBuilder text, Delims starts) { text.insert(0, starts.start1); if (starts.start2 != NO_CHAR) { text.insert(1, starts.start2); } } - protected static String escapeHTML (String text) - { + protected static String escapeHTML (String text) { for (String[] escape : ATTR_ESCAPES) { text = text.replace(escape[0], escape[1]); } return text; } - protected static boolean allowsWhitespace (char typeChar) - { + protected static boolean allowsWhitespace (char typeChar) { return (typeChar == '=') || // change delimiters (typeChar == '!'); // comment } diff --git a/src/main/java/com/samskivert/mustache/MustacheParseException.java b/src/main/java/com/samskivert/mustache/MustacheParseException.java index 163c997..a0a4446 100644 --- a/src/main/java/com/samskivert/mustache/MustacheParseException.java +++ b/src/main/java/com/samskivert/mustache/MustacheParseException.java @@ -8,13 +8,11 @@ package com.samskivert.mustache; */ public class MustacheParseException extends MustacheException { - public MustacheParseException (String message) - { + public MustacheParseException (String message) { super(message); } - public MustacheParseException (String message, int lineNo) - { + public MustacheParseException (String message, int lineNo) { super(message + " @ line " + lineNo); } } diff --git a/src/main/java/com/samskivert/mustache/Template.java b/src/main/java/com/samskivert/mustache/Template.java index d09a36c..c5c4186 100644 --- a/src/main/java/com/samskivert/mustache/Template.java +++ b/src/main/java/com/samskivert/mustache/Template.java @@ -56,8 +56,7 @@ public class Template * Executes this template with the given context, returning the results as a string. * @throws MustacheException if an error occurs while executing or writing the template. */ - public String execute (Object context) throws MustacheException - { + public String execute (Object context) throws MustacheException { StringWriter out = new StringWriter(); execute(context, out); return out.toString(); @@ -67,8 +66,7 @@ public class Template * Executes this template with the given context, writing the results to the supplied writer. * @throws MustacheException if an error occurs while executing or writing the template. */ - public void execute (Object context, Writer out) throws MustacheException - { + public void execute (Object context, Writer out) throws MustacheException { executeSegs(new Context(context, null, 0, false, false), out); } @@ -79,28 +77,24 @@ public class Template * a block. * @throws MustacheException if an error occurs while executing or writing the template. */ - public void execute (Object context, Object parentContext, Writer out) throws MustacheException - { + public void execute (Object context, Object parentContext, Writer out) throws MustacheException { Context pctx = new Context(parentContext, null, 0, false, false); executeSegs(new Context(context, pctx, 0, false, false), out); } - protected Template (Segment[] segs, Mustache.Compiler compiler) - { + protected Template (Segment[] segs, Mustache.Compiler compiler) { _segs = segs; _compiler = compiler; _fcache = compiler.collector.createFetcherCache(); } - protected void executeSegs (Context ctx, Writer out) throws MustacheException - { + protected void executeSegs (Context ctx, Writer out) throws MustacheException { for (Segment seg : _segs) { seg.execute(this, ctx, out); } } - protected Fragment createFragment (final Segment[] segs, final Context ctx) - { + protected Fragment createFragment (final Segment[] segs, final Context ctx) { return new Fragment() { @Override public void execute (Writer out) { for (Segment seg : segs) { @@ -121,8 +115,7 @@ public class Template * * @return the value associated with the supplied name or null if no value could be resolved. */ - protected Object getValue (Context ctx, String name, int line, boolean missingIsNull) - { + protected Object getValue (Context ctx, String name, int line, boolean missingIsNull) { if (!_compiler.standardsMode) { // if we're dealing with a compound key, resolve each component and use the result to // resolve the subsequent component and so forth @@ -179,8 +172,7 @@ public class Template * will be the means by which we enact configured behavior for sections that reference null or * missing variables. Right now, all such variables result in a length 0 section. */ - protected Object getSectionValue (Context ctx, String name, int line) - { + protected Object getSectionValue (Context ctx, String name, int line) { // TODO: configurable behavior on missing values Object value = getValue(ctx, name, line, _compiler.missingIsNull); // TODO: configurable behavior on null values @@ -191,8 +183,7 @@ public class Template * Returns the value for the specified variable, or the configured default value if the * variable resolves to null. See {@link #getValue}. */ - protected Object getValueOrDefault (Context ctx, String name, int line) - { + protected Object getValueOrDefault (Context ctx, String name, int line) { Object value = getValue(ctx, name, line, _compiler.missingIsNull); // getValue will raise MustacheException if a variable cannot be resolved and missingIsNull // is not configured; so we're safe to assume that any null that makes it up to this point @@ -200,8 +191,7 @@ public class Template return (value == null) ? _compiler.computeNullValue(name) : value; } - protected Object getValueIn (Object data, String name, int line) - { + protected Object getValueIn (Object data, String name, int line) { if (data == null) { throw new NullPointerException( "Null context for variable '" + name + "' on line " + line); @@ -236,8 +226,7 @@ public class Template } } - protected Object checkForMissing (String name, int line, boolean missingIsNull, Object value) - { + protected Object checkForMissing (String name, int line, boolean missingIsNull, Object value) { if (value == NO_FETCHER_FOUND) { if (missingIsNull) return null; throw new MustacheException.Context( @@ -251,8 +240,7 @@ public class Template protected final Mustache.Compiler _compiler; protected final Map _fcache; - protected static class Context - { + protected static class Context { public final Object data; public final Context parent; public final int index; @@ -273,8 +261,7 @@ public class Template } /** A template is broken into segments. */ - protected static abstract class Segment - { + protected static abstract class Segment { abstract void execute (Template tmpl, Context ctx, Writer out); protected static void write (Writer out, String data) { @@ -287,8 +274,7 @@ public class Template } /** Used to cache variable fetchers for a given context class, name combination. */ - protected static class Key - { + protected static class Key { public final Class cclass; public final String name;