Skip to content

Commit

Permalink
Starting a bit of code cleanup of the builtins stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
revusky committed Nov 24, 2023
1 parent 23af5ef commit 4477244
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 54 deletions.
4 changes: 2 additions & 2 deletions src/freemarker/builtins/BuiltIn.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
import freemarker.core.Environment;
import freemarker.core.nodes.generated.BuiltInExpression;

abstract public class BuiltIn {
abstract public Object get(Environment env, BuiltInExpression caller);
public interface BuiltIn {
Object get(Environment env, BuiltInExpression caller);
}
2 changes: 1 addition & 1 deletion src/freemarker/builtins/ExistenceBuiltIn.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import static freemarker.core.variables.Wrap.*;

public abstract class ExistenceBuiltIn extends BuiltIn {
public abstract class ExistenceBuiltIn implements BuiltIn {
public Object get(Environment env, BuiltInExpression caller)
{
final Expression target = caller.getTarget();
Expand Down
2 changes: 1 addition & 1 deletion src/freemarker/builtins/ExpressionEvaluatingBuiltIn.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @author Attila Szegedi
* @version $Id: $
*/
public abstract class ExpressionEvaluatingBuiltIn extends BuiltIn {
public abstract class ExpressionEvaluatingBuiltIn implements BuiltIn {

@Override
public Object get(Environment env, BuiltInExpression caller)
Expand Down
7 changes: 0 additions & 7 deletions src/freemarker/builtins/StringFunctions.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,6 @@ public Object get(Environment env, BuiltInExpression caller, Object model) {

public abstract Object apply(final String string, final Environment env, final BuiltInExpression callingExpression);

public static class Length extends StringFunctions {
@Override
public Object apply(String string, Environment env, BuiltInExpression caller) {
return string.length();
}
}

public static class Substring extends StringFunctions {
@Override
public Object apply(String string, Environment env, BuiltInExpression caller) {
Expand Down
21 changes: 0 additions & 21 deletions src/freemarker/builtins/StringTransformations.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,6 @@ public Object get(Environment env, BuiltInExpression caller, Object lhs) {

public abstract String apply(String string);

public static class UpperCase extends StringTransformations {
@Override
public String apply(String string) {
return string.toUpperCase();
}
}

public static class LowerCase extends StringTransformations {
@Override
public String apply(String string) {
return string.toLowerCase();
}
}

public static class Html extends StringTransformations {
@Override
public String apply(String string) {
Expand Down Expand Up @@ -98,13 +84,6 @@ public String apply(String string) {
}
}

public static class Trim extends StringTransformations {
@Override
public String apply(String string) {
return string.trim();
}
}

public static class Java extends StringTransformations {
@Override
public String apply(String string) {
Expand Down
17 changes: 0 additions & 17 deletions src/freemarker/builtins/sourceBI.java

This file was deleted.

16 changes: 11 additions & 5 deletions src/parser/Expressions.inc.ccc
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,7 @@ INJECT BuiltInExpression :
import freemarker.builtins.*;
import freemarker.template.TemplateDateModel;
import freemarker.template.TemplateHashModel;
import static freemarker.core.variables.Wrap.asString;
implements Expression;
{
private static final HashMap<String, BuiltIn> knownBuiltins = new HashMap<String, BuiltIn>();
Expand Down Expand Up @@ -1056,14 +1057,11 @@ INJECT BuiltInExpression :
knownBuiltins.put("ceiling", numericalCast);
knownBuiltins.put("round", numericalCast);
knownBuiltins.put("capitalize", new StringTransformations.Capitalize());
knownBuiltins.put("lower_case", new StringTransformations.LowerCase());
knownBuiltins.put("upper_case", new StringTransformations.UpperCase());
knownBuiltins.put("cap_first", new StringTransformations.CapFirst(true));
knownBuiltins.put("uncap_first", new StringTransformations.CapFirst(false));
knownBuiltins.put("j_string", new StringTransformations.Java());
knownBuiltins.put("js_string", new StringTransformations.JavaScript());
knownBuiltins.put("chop_linebreak", new StringTransformations.Chomp());
knownBuiltins.put("trim", new StringTransformations.Trim());
knownBuiltins.put("html", new StringTransformations.Html());
knownBuiltins.put("rtf", new StringTransformations.Rtf());
knownBuiltins.put("xml", new StringTransformations.Xml());
Expand Down Expand Up @@ -1093,7 +1091,6 @@ INJECT BuiltInExpression :
knownBuiltins.put("number", new numberBI());
knownBuiltins.put("left_pad", new StringFunctions.LeftPad());
knownBuiltins.put("right_pad", new StringFunctions.RightPad());
knownBuiltins.put("length", new StringFunctions.Length());
knownBuiltins.put("replace", new StringFunctions.Replace());
knownBuiltins.put("split", new StringFunctions.Split());
knownBuiltins.put("groups", new groupsBI());
Expand Down Expand Up @@ -1126,7 +1123,16 @@ INJECT BuiltInExpression :
knownBuiltins.put("is_defined", new ExistenceBuiltIn.IsDefinedBuiltIn());
knownBuiltins.put("default", new ExistenceBuiltIn.DefaultBuiltIn());
knownBuiltins.put("has_content", new ExistenceBuiltIn.HasContentBuiltIn());
knownBuiltins.put("source", new sourceBI());
//knownBuiltins.put("length", new StringFunctions.Length());
//knownBuiltins.put("source", new sourceBI());
//knownBuiltins.put("lower_case", new StringTransformations.LowerCase());
//knownBuiltins.put("upper_case", new StringTransformations.UpperCase());
//knownBuiltins.put("trim", new StringTransformations.Trim());
knownBuiltins.put("source", (env,caller)->caller.getTarget().getSource());
knownBuiltins.put("upper_case", (env,caller)->asString(caller.getTarget().evaluate(env)).toUpperCase(env.getLocale()));
knownBuiltins.put("lower_case", (env,caller)->asString(caller.getTarget().evaluate(env)).toLowerCase(env.getLocale()));
knownBuiltins.put("length", (env,caller)->asString(caller.getTarget().evaluate(env)).length());
knownBuiltins.put("trim", (env,caller)->asString(caller.getTarget().evaluate(env)).trim());
}

private String key;
Expand Down

0 comments on commit 4477244

Please sign in to comment.