final Macro macro, final Map namedArgs, final List positionalArgs) throws TemplateException, _MiscTemplateException { String catchAllParamName = macro.getCatchAll(); if (namedArgs != null) { final SimpleHash catchAllParamValue; final Map.Entry argNameAndValExp = (Map.Entry) it.next(); final String argName = (String) argNameAndValExp.getKey(); final boolean isArgNameDeclared = macro.hasArgNamed(argName); if (isArgNameDeclared || catchAllParamName != null) { Expression argValueExp = (Expression) argNameAndValExp.getValue(); (macro.isFunction() ? "Function " : "Macro "), new _DelayedJQuote(macro.getName()), " has no parameter with name ", new _DelayedJQuote(argName), "."); String[] argNames = macro.getArgumentNamesInternal(); final int argsCnt = positionalArgs.size(); if (argNames.length < argsCnt && catchAllParamName == null) { throw new _MiscTemplateException(this, (macro.isFunction() ? "Function " : "Macro "), new _DelayedJQuote(macro.getName()), " only accepts ", new _DelayedToString(argNames.length), " parameters, but got ", new _DelayedToString(argsCnt), ".");
visit(macro.getChildBuffer()); } catch (ReturnInstruction.Return re) {
StringBuilder sb = new StringBuilder(); if (canonical) sb.append('<'); sb.append(getNodeTypeSymbol()); sb.append(' '); sb.append(_CoreStringUtils.toFTLTopLevelTragetIdentifier(name)); if (canonical) { sb.append('>'); sb.append(getChildrenCanonicalForm()); sb.append("</").append(getNodeTypeSymbol()).append('>');
static String formatLocationForEvaluationError(Macro macro, int line, int column) { Template t = macro.getTemplate(); return formatLocation("at", t != null ? t.getSourceName() : null, macro.getName(), macro.isFunction(), line, column); }
if (tm instanceof Macro) { Macro macro = (Macro) tm; if (macro.isFunction() && !legacySyntax) { throw new _MiscTemplateException(env, "Routine ", new _DelayedJQuote(macro.getName()), " is a function, not a directive. " + "Functions can only be called from expressions, like in ${f()}, ${x + f()} or ", "<@someDirective someParam=f() />", ".");
Macro result = new Macro(name, argNames, args, catchAll, isFunction, children); result.setLocation(template, start, end); template.addMacro(result); {if ("" != null) return result;}
Macro result = new Macro(name, argNames, args, block); result.setCatchAll(catchAll); result.isFunction = isFunction; result.setLocation(template, start, end); template.addMacro(result); {if (true) return result;}
appendTypeName(sb, typeNamesAppended, ((Macro) tm).isFunction() ? "function" : "macro");
/** * Called by code internally to maintain a table of macros * * @deprecated Should only be used internally, and might will be removed later. */ @Deprecated public void addMacro(Macro macro) { macros.put(macro.getName(), macro); }
static String formatLocationForEvaluationError(Macro macro, int line, int column) { Template t = macro.getTemplate(); return formatLocation("at", t != null ? t.getSourceName() : null, macro.getName(), macro.isFunction(), line, column); }
if (tm instanceof Macro) { Macro macro = (Macro) tm; if (macro.isFunction() && !legacySyntax) { throw new _MiscTemplateException(env, "Routine ", new _DelayedJQuote(macro.getName()), " is a function, not a directive. " + "Functions can only be called from expressions, like in ${f()}, ${x + f()} or ", "<@someDirective someParam=f() />", ".");
Macro result = new Macro(name, argNames, args, catchAll, isFunction, children); result.setLocation(template, start, end); template.addMacro(result); {if ("" != null) return result;}
throw new _MiscTemplateException(env, new _ErrorDescriptionBuilder( "When calling ", (isFunction() ? "function" : "macro"), " ", new _DelayedJQuote(name), ", required parameter ", new _DelayedJQuote(argName),
/** * Defines the given macro in the current namespace (doesn't call it). */ void visitMacroDef(Macro macro) { macroToNamespaceLookup.put(macro, currentNamespace); currentNamespace.put(macro.getName(), macro); }
final Macro macro, final Map namedArgs, final List positionalArgs) throws TemplateException, _MiscTemplateException { String catchAllParamName = macro.getCatchAll(); if (namedArgs != null) { final SimpleHash catchAllParamValue; final Map.Entry argNameAndValExp = (Map.Entry) it.next(); final String argName = (String) argNameAndValExp.getKey(); final boolean isArgNameDeclared = macro.hasArgNamed(argName); if (isArgNameDeclared || catchAllParamName != null) { Expression argValueExp = (Expression) argNameAndValExp.getValue(); (macro.isFunction() ? "Function " : "Macro "), new _DelayedJQuote(macro.getName()), " has no parameter with name ", new _DelayedJQuote(argName), "."); String[] argNames = macro.getArgumentNamesInternal(); final int argsCnt = positionalArgs.size(); if (argNames.length < argsCnt && catchAllParamName == null) { throw new _MiscTemplateException(this, (macro.isFunction() ? "Function " : "Macro "), new _DelayedJQuote(macro.getName()), " only accepts ", new _DelayedToString(argNames.length), " parameters, but got ", new _DelayedToString(argsCnt), ".");
static String formatLocationForEvaluationError(Macro macro, int line, int column) { Template t = macro.getTemplate(); return formatLocation("at", t != null ? t.getSourceName() : null, macro.getName(), macro.isFunction(), line, column); }
if (tm instanceof Macro) { Macro macro = (Macro) tm; if (macro.isFunction() && !legacySyntax) { throw new _MiscTemplateException(env, "Routine ", new _DelayedJQuote(macro.getName()), " is a function, not a directive. " + "Functions can only be called from expressions, like in ${f()}, ${x + f()} or ", "<@someDirective someParam=f() />", ".");
Macro result = new Macro(name, argNames, args, catchAll, isFunction, children); result.setLocation(template, start, end); template.addMacro(result); {if ("" != null) return result;}
Macro func = (Macro) targetModel; env.setLastReturnValue(null); if (!func.isFunction()) { throw new _MiscTemplateException(env, "A macro cannot be called in an expression. (Functions can be.)");
/** * Called by code internally to maintain * a table of macros */ public void addMacro(Macro macro) { macros.put(macro.getName(), macro); }