Soy: Make built-in function naming explicit
For builtin functions, explicitly specify the names rather than
calculating it from the enum name.
(this is so that we can decouple the names of new builtin functions
from the corresponding enum values if we want to.)
package com.google.template.soy.shared.internal;
-import com.google.common.base.CaseFormat;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.template.soy.shared.restricted.SoyFunction;
import java.util.Map;
import java.util.Set;
+import javax.annotation.Nullable;
/**
* Enum of built-in functions supported in Soy expressions.
@@ -30,11 +30,11 @@ import java.util.Set;
*
*/
public enum BuiltinFunction implements SoyFunction {
- IS_FIRST,
- IS_LAST,
- INDEX,
- QUOTE_KEYS_IF_JS,
- CHECK_NOT_NULL;
+ IS_FIRST("isFirst"),
+ IS_LAST("isLast"),
+ INDEX("index"),
+ QUOTE_KEYS_IF_JS("quoteKeysIfJs"),
+ CHECK_NOT_NULL("checkNotNull");
/** Map of NonpluginFunctions by function name. */
private static final Map<String, BuiltinFunction> NONPLUGIN_FUNCTIONS_BY_NAME;
@@ -52,6 +52,7 @@ public enum BuiltinFunction implements SoyFunction {
*
* @param functionName The function name to retrieve.
*/
+ @Nullable
public static BuiltinFunction forFunctionName(String functionName) {
return NONPLUGIN_FUNCTIONS_BY_NAME.get(functionName);
}
@@ -59,8 +60,8 @@ public enum BuiltinFunction implements SoyFunction {
/** The function name. */
private final String functionName;
- BuiltinFunction() {
- this.functionName = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name());
+ BuiltinFunction(String name) {
+ this.functionName = name;
}
@Override
