Skip to content

Commit 7b33dfc

Browse files
committed
major code formatting/cleanup
1 parent 43c7e72 commit 7b33dfc

File tree

135 files changed

+1316
-1366
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+1316
-1366
lines changed

src/main/java/com/hubspot/jinjava/Jinjava.java

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,17 @@
4444
import de.odysseus.el.tree.TreeBuilder;
4545

4646
/**
47-
* The main client API for the Jinjava library, instances of this class can be used to render
48-
* jinja templates with a given map of context values.
47+
* The main client API for the Jinjava library, instances of this class can be used to render jinja templates with a given map of context values.
4948
*
5049
* Example use:
5150
*
5251
* <pre>
53-
* Jinjava jinjava = new Jinjava();
54-
* Map&lt;String, Object&gt; context = new HashMap&lt;&gt;();
55-
* context.put("name", "Jared");
56-
*
57-
* String template = "Hello, {{ name }}";
58-
* String renderedTemplate = jinjava.render(template, context);
52+
* Jinjava jinjava = new Jinjava();
53+
* Map&lt;String, Object&gt; context = new HashMap&lt;&gt;();
54+
* context.put(&quot;name&quot;, &quot;Jared&quot;);
55+
*
56+
* String template = &quot;Hello, {{ name }}&quot;;
57+
* String renderedTemplate = jinjava.render(template, context);
5958
* </pre>
6059
*
6160
* @author jstehler
@@ -69,7 +68,6 @@ public class Jinjava {
6968
private Context globalContext;
7069
private JinjavaConfig globalConfig;
7170

72-
7371
/**
7472
* Create a new Jinjava processor instance with the default global config
7573
*/
@@ -80,7 +78,8 @@ public Jinjava() {
8078
/**
8179
* Create a new jinjava processor instance with the specified global config
8280
*
83-
* @param globalConfig used for all render operations performed by this processor instance
81+
* @param globalConfig
82+
* used for all render operations performed by this processor instance
8483
*/
8584
public Jinjava(JinjavaConfig globalConfig) {
8685
this.globalConfig = globalConfig;
@@ -97,7 +96,9 @@ public Jinjava(JinjavaConfig globalConfig) {
9796

9897
/**
9998
* Set the object responsible for locating templates referenced in other templates
100-
* @param resourceLocator the locator to use for loading all templates
99+
*
100+
* @param resourceLocator
101+
* the locator to use for loading all templates
101102
*/
102103
public void setResourceLocator(ResourceLocator resourceLocator) {
103104
this.resourceLocator = resourceLocator;
@@ -118,8 +119,7 @@ public JinjavaConfig getGlobalConfig() {
118119
}
119120

120121
/**
121-
* The global render context includes such things as the base set of tags, filters, exp tests and functions,
122-
* used as a base by all render operations performed by this instance
122+
* The global render context includes such things as the base set of tags, filters, exp tests and functions, used as a base by all render operations performed by this instance
123123
*
124124
* @return the global render context
125125
*/
@@ -141,10 +141,13 @@ public JinjavaDoc getJinjavaDoc() {
141141
/**
142142
* Render the given template using the given context bindings.
143143
*
144-
* @param template jinja source template
145-
* @param bindings map of objects to put into scope for this rendering action
144+
* @param template
145+
* jinja source template
146+
* @param bindings
147+
* map of objects to put into scope for this rendering action
146148
* @return the rendered template
147-
* @throws InterpretException if any syntax errors were encountered during rendering
149+
* @throws InterpretException
150+
* if any syntax errors were encountered during rendering
148151
*/
149152
public String render(String template, Map<String, ?> bindings) {
150153
RenderResult result = renderForResult(template, bindings);
@@ -156,47 +159,46 @@ public boolean apply(TemplateError input) {
156159
}
157160
});
158161

159-
if(!fatalErrors.isEmpty()) {
162+
if (!fatalErrors.isEmpty()) {
160163
throw new FatalTemplateErrorsException(template, fatalErrors);
161164
}
162165

163166
return result.getOutput();
164167
}
165168

166169
/**
167-
* Render the given template using the given context bindings. This method returns some
168-
* metadata about the render process, including any errors which may have been encountered
169-
* such as unknown variables or syntax errors.
170+
* Render the given template using the given context bindings. This method returns some metadata about the render process, including any errors which may have been encountered such as unknown variables or syntax errors.
170171
*
171-
* This method will not throw any exceptions; it is up to the caller to inspect the renderResult.errors
172-
* collection if necessary / desired.
172+
* This method will not throw any exceptions; it is up to the caller to inspect the renderResult.errors collection if necessary / desired.
173173
*
174-
* @param template jinja source template
175-
* @param bindings map of objects to put into scope for this rendering action
174+
* @param template
175+
* jinja source template
176+
* @param bindings
177+
* map of objects to put into scope for this rendering action
176178
* @return result object containing rendered output, render context, and any encountered errors
177179
*/
178180
public RenderResult renderForResult(String template, Map<String, ?> bindings) {
179181
return renderForResult(template, bindings, globalConfig);
180182
}
181183

182184
/**
183-
* Render the given template using the given context bindings. This method returns some
184-
* metadata about the render process, including any errors which may have been encountered
185-
* such as unknown variables or syntax errors.
185+
* Render the given template using the given context bindings. This method returns some metadata about the render process, including any errors which may have been encountered such as unknown variables or syntax errors.
186186
*
187-
* This method will not throw any exceptions; it is up to the caller to inspect the renderResult.errors
188-
* collection if necessary / desired.
187+
* This method will not throw any exceptions; it is up to the caller to inspect the renderResult.errors collection if necessary / desired.
189188
*
190-
* @param template jinja source template
191-
* @param bindings map of objects to put into scope for this rendering action
192-
* @param renderConfig used to override specific config values for this render operation
189+
* @param template
190+
* jinja source template
191+
* @param bindings
192+
* map of objects to put into scope for this rendering action
193+
* @param renderConfig
194+
* used to override specific config values for this render operation
193195
* @return result object containing rendered output, render context, and any encountered errors
194196
*/
195197
public RenderResult renderForResult(String template, Map<String, ?> bindings, JinjavaConfig renderConfig) {
196198
Context context = new Context(globalContext, bindings);
197199

198200
JinjavaInterpreter parentInterpreter = JinjavaInterpreter.getCurrent();
199-
if(parentInterpreter != null) {
201+
if (parentInterpreter != null) {
200202
renderConfig = parentInterpreter.getConfig();
201203
}
202204

@@ -206,14 +208,11 @@ public RenderResult renderForResult(String template, Map<String, ?> bindings, Ji
206208
try {
207209
String result = interpreter.render(template);
208210
return new RenderResult(result, interpreter.getContext(), interpreter.getErrors());
209-
}
210-
catch(InterpretException e) {
211+
} catch (InterpretException e) {
211212
return new RenderResult(TemplateError.fromSyntaxError(e), interpreter.getContext(), interpreter.getErrors());
212-
}
213-
catch(Exception e) {
213+
} catch (Exception e) {
214214
return new RenderResult(TemplateError.fromException(e), interpreter.getContext(), interpreter.getErrors());
215-
}
216-
finally {
215+
} finally {
217216
JinjavaInterpreter.popCurrent();
218217
}
219218
}

src/main/java/com/hubspot/jinjava/doc/JinjavaDoc.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,34 @@ public class JinjavaDoc {
1010
private final Map<String, JinjavaDocFunction> functions = new TreeMap<>();
1111
private final Map<String, JinjavaDocTag> tags = new TreeMap<>();
1212

13-
1413
public Map<String, JinjavaDocExpTest> getExpTests() {
1514
return expTests;
1615
}
16+
1717
public void addExpTest(JinjavaDocExpTest expTest) {
1818
expTests.put(expTest.getName(), expTest);
1919
}
2020

2121
public Map<String, JinjavaDocFilter> getFilters() {
2222
return filters;
2323
}
24+
2425
public void addFilter(JinjavaDocFilter filter) {
2526
filters.put(filter.getName(), filter);
2627
}
2728

2829
public Map<String, JinjavaDocFunction> getFunctions() {
2930
return functions;
3031
}
32+
3133
public void addFunction(JinjavaDocFunction function) {
3234
functions.put(function.getName(), function);
3335
}
3436

3537
public Map<String, JinjavaDocTag> getTags() {
3638
return tags;
3739
}
40+
3841
public void addTag(JinjavaDocTag tag) {
3942
tags.put(tag.getName(), tag);
4043
}

src/main/java/com/hubspot/jinjava/doc/JinjavaDocFactory.java

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.hubspot.jinjava.doc;
22

3-
43
import java.lang.reflect.Method;
54
import java.util.Collections;
65
import java.util.LinkedHashMap;
@@ -43,40 +42,40 @@ public JinjavaDoc get() {
4342
}
4443

4544
private void addExpTests(JinjavaDoc doc) {
46-
for(ExpTest t : jinjava.getGlobalContext().getAllExpTests()) {
45+
for (ExpTest t : jinjava.getGlobalContext().getAllExpTests()) {
4746
com.hubspot.jinjava.doc.annotations.JinjavaDoc docAnnotation = t.getClass().getAnnotation(com.hubspot.jinjava.doc.annotations.JinjavaDoc.class);
4847

49-
if(docAnnotation == null) {
48+
if (docAnnotation == null) {
5049
LOG.warn("Expression Test {} doesn't have a @{} annotation", t.getName(), com.hubspot.jinjava.doc.annotations.JinjavaDoc.class.getName());
51-
doc.addExpTest(new JinjavaDocExpTest(t.getName(), "", "", false, new JinjavaDocParam[]{}, new JinjavaDocSnippet[]{}, Collections.emptyMap()));
50+
doc.addExpTest(new JinjavaDocExpTest(t.getName(), "", "", false, new JinjavaDocParam[] {}, new JinjavaDocSnippet[] {}, Collections.emptyMap()));
5251
}
53-
else if(!docAnnotation.hidden()) {
52+
else if (!docAnnotation.hidden()) {
5453
doc.addExpTest(new JinjavaDocExpTest(t.getName(), docAnnotation.value(), docAnnotation.aliasOf(), docAnnotation.deprecated(),
5554
extractParams(docAnnotation.params()), extractSnippets(docAnnotation.snippets()), extractMeta(docAnnotation.meta())));
5655
}
5756
}
5857
}
5958

6059
private void addFilterDocs(JinjavaDoc doc) {
61-
for(Filter f : jinjava.getGlobalContext().getAllFilters()) {
60+
for (Filter f : jinjava.getGlobalContext().getAllFilters()) {
6261
com.hubspot.jinjava.doc.annotations.JinjavaDoc docAnnotation = f.getClass().getAnnotation(com.hubspot.jinjava.doc.annotations.JinjavaDoc.class);
6362

64-
if(docAnnotation == null) {
63+
if (docAnnotation == null) {
6564
LOG.warn("Filter {} doesn't have a @{} annotation", f.getClass(), com.hubspot.jinjava.doc.annotations.JinjavaDoc.class.getName());
66-
doc.addFilter(new JinjavaDocFilter(f.getName(), "", "", false, new JinjavaDocParam[]{}, new JinjavaDocSnippet[]{}, Collections.emptyMap()));
65+
doc.addFilter(new JinjavaDocFilter(f.getName(), "", "", false, new JinjavaDocParam[] {}, new JinjavaDocSnippet[] {}, Collections.emptyMap()));
6766
}
68-
else if(!docAnnotation.hidden()) {
67+
else if (!docAnnotation.hidden()) {
6968
doc.addFilter(new JinjavaDocFilter(f.getName(), docAnnotation.value(), docAnnotation.aliasOf(), docAnnotation.deprecated(),
7069
extractParams(docAnnotation.params()), extractSnippets(docAnnotation.snippets()), extractMeta(docAnnotation.meta())));
7170
}
7271
}
7372
}
7473

7574
private void addFnDocs(JinjavaDoc doc) {
76-
for(ELFunctionDefinition fn : jinjava.getGlobalContext().getAllFunctions()) {
77-
if(StringUtils.isBlank(fn.getNamespace())) {
75+
for (ELFunctionDefinition fn : jinjava.getGlobalContext().getAllFunctions()) {
76+
if (StringUtils.isBlank(fn.getNamespace())) {
7877
Method realMethod = fn.getMethod();
79-
if(realMethod.getDeclaringClass().getName().contains(InjectedContextFunctionProxy.class.getSimpleName())) {
78+
if (realMethod.getDeclaringClass().getName().contains(InjectedContextFunctionProxy.class.getSimpleName())) {
8079
try {
8180
realMethod = (Method) realMethod.getDeclaringClass().getField("delegate").get(null);
8281
} catch (Exception e) {
@@ -86,11 +85,11 @@ private void addFnDocs(JinjavaDoc doc) {
8685

8786
com.hubspot.jinjava.doc.annotations.JinjavaDoc docAnnotation = realMethod.getAnnotation(com.hubspot.jinjava.doc.annotations.JinjavaDoc.class);
8887

89-
if(docAnnotation == null) {
88+
if (docAnnotation == null) {
9089
LOG.warn("Function {} doesn't have a @{} annotation", fn.getName(), com.hubspot.jinjava.doc.annotations.JinjavaDoc.class.getName());
91-
doc.addFunction(new JinjavaDocFunction(fn.getLocalName(), "", "", false, new JinjavaDocParam[]{}, new JinjavaDocSnippet[]{}, Collections.emptyMap()));
90+
doc.addFunction(new JinjavaDocFunction(fn.getLocalName(), "", "", false, new JinjavaDocParam[] {}, new JinjavaDocSnippet[] {}, Collections.emptyMap()));
9291
}
93-
else if(!docAnnotation.hidden()) {
92+
else if (!docAnnotation.hidden()) {
9493
doc.addFunction(new JinjavaDocFunction(fn.getLocalName(), docAnnotation.value(), docAnnotation.aliasOf(), docAnnotation.deprecated(),
9594
extractParams(docAnnotation.params()), extractSnippets(docAnnotation.snippets()), extractMeta(docAnnotation.meta())));
9695
}
@@ -99,17 +98,17 @@ else if(!docAnnotation.hidden()) {
9998
}
10099

101100
private void addTagDocs(JinjavaDoc doc) {
102-
for(Tag t : jinjava.getGlobalContext().getAllTags()) {
103-
if(t instanceof EndTag) {
101+
for (Tag t : jinjava.getGlobalContext().getAllTags()) {
102+
if (t instanceof EndTag) {
104103
continue;
105104
}
106105
com.hubspot.jinjava.doc.annotations.JinjavaDoc docAnnotation = t.getClass().getAnnotation(com.hubspot.jinjava.doc.annotations.JinjavaDoc.class);
107106

108-
if(docAnnotation == null) {
107+
if (docAnnotation == null) {
109108
LOG.warn("Tag {} doesn't have a @{} annotation", t.getName(), com.hubspot.jinjava.doc.annotations.JinjavaDoc.class.getName());
110-
doc.addTag(new JinjavaDocTag(t.getName(), StringUtils.isBlank(t.getEndTagName()), "", "", false, new JinjavaDocParam[]{}, new JinjavaDocSnippet[]{}, Collections.emptyMap()));
109+
doc.addTag(new JinjavaDocTag(t.getName(), StringUtils.isBlank(t.getEndTagName()), "", "", false, new JinjavaDocParam[] {}, new JinjavaDocSnippet[] {}, Collections.emptyMap()));
111110
}
112-
else if(!docAnnotation.hidden()) {
111+
else if (!docAnnotation.hidden()) {
113112
doc.addTag(new JinjavaDocTag(t.getName(), StringUtils.isBlank(t.getEndTagName()), docAnnotation.value(), docAnnotation.aliasOf(), docAnnotation.deprecated(),
114113
extractParams(docAnnotation.params()), extractSnippets(docAnnotation.snippets()), extractMeta(docAnnotation.meta())));
115114
}
@@ -119,7 +118,7 @@ else if(!docAnnotation.hidden()) {
119118
private JinjavaDocParam[] extractParams(JinjavaParam[] params) {
120119
JinjavaDocParam[] result = new JinjavaDocParam[params.length];
121120

122-
for(int i = 0; i < params.length; i++) {
121+
for (int i = 0; i < params.length; i++) {
123122
JinjavaParam p = params[i];
124123
result[i] = new JinjavaDocParam(p.value(), p.type(), p.desc(), p.defaultValue());
125124
}
@@ -130,7 +129,7 @@ private JinjavaDocParam[] extractParams(JinjavaParam[] params) {
130129
private JinjavaDocSnippet[] extractSnippets(JinjavaSnippet[] snippets) {
131130
JinjavaDocSnippet[] result = new JinjavaDocSnippet[snippets.length];
132131

133-
for(int i = 0; i < snippets.length; i++) {
132+
for (int i = 0; i < snippets.length; i++) {
134133
JinjavaSnippet s = snippets[i];
135134
result[i] = new JinjavaDocSnippet(s.desc(), s.code(), s.output());
136135
}
@@ -141,7 +140,7 @@ private JinjavaDocSnippet[] extractSnippets(JinjavaSnippet[] snippets) {
141140
private Map<String, String> extractMeta(JinjavaMetaValue[] metaValues) {
142141
Map<String, String> meta = new LinkedHashMap<>();
143142

144-
for(JinjavaMetaValue metaValue : metaValues) {
143+
for (JinjavaMetaValue metaValue : metaValues) {
145144
meta.put(metaValue.name(), metaValue.value());
146145
}
147146

src/main/java/com/hubspot/jinjava/doc/JinjavaDocParam.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@ public JinjavaDocParam(String name, String type, String desc, String defaultValu
1717
public String getName() {
1818
return name;
1919
}
20+
2021
public String getType() {
2122
return type;
2223
}
24+
2325
public String getDesc() {
2426
return desc;
2527
}
28+
2629
public String getDefaultValue() {
2730
return defaultValue;
2831
}

src/main/java/com/hubspot/jinjava/doc/JinjavaDocSnippet.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ public JinjavaDocSnippet(String desc, String code, String output) {
1515
public String getDesc() {
1616
return desc;
1717
}
18+
1819
public String getCode() {
1920
return code;
2021
}
22+
2123
public String getOutput() {
2224
return output;
2325
}

src/main/java/com/hubspot/jinjava/doc/annotations/JinjavaDoc.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,22 @@
55
import java.lang.annotation.RetentionPolicy;
66
import java.lang.annotation.Target;
77

8-
98
@Retention(RetentionPolicy.RUNTIME)
109
@Target({ ElementType.TYPE, ElementType.METHOD })
1110
public @interface JinjavaDoc {
1211

1312
String value() default "";
13+
1414
JinjavaParam[] params() default {};
1515

1616
JinjavaSnippet[] snippets() default {};
1717

1818
JinjavaMetaValue[] meta() default {};
1919

2020
String aliasOf() default "";
21+
2122
boolean deprecated() default false;
23+
2224
boolean hidden() default false;
2325

2426
}

src/main/java/com/hubspot/jinjava/doc/annotations/JinjavaMetaValue.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
@Target({ ElementType.TYPE, ElementType.METHOD })
1010
public @interface JinjavaMetaValue {
1111
String name();
12+
1213
String value();
1314
}

0 commit comments

Comments
 (0)