public JetTemplateMacro resolve(String name, Class<?>[] argumentTypes, boolean reloadable) { JetTemplateMacro macro; if (decleardMacros != null) { macro = decleardMacros.get(name); if (macro != null) { return macro; } } if (loadedTemplates != null) { if (reloadable) { checkImportedMacrosReload(); } for (JetTemplate template : loadedTemplates) { macro = template.resolveMacro(name, argumentTypes, false); if (macro != null) { return macro; } } } return null; }
@Override public void execute(InterpretContext ctx) throws InterpretException { Object[] arguments; if (argumentList == null) { arguments = ArrayUtils.EMPTY_OBJECT_ARRAY; } else { arguments = argumentList.execute(ctx); } JetTemplateMacro macro = last; JetTemplate template = ctx.getTemplate(); if (macro == null || template.isReloadable()) { Class<?>[] argumentTypes = ParameterUtils.getParameterTypes(arguments); macro = template.resolveMacro(name, argumentTypes, true); if (macro == null) { throw new InterpretException(Errors.MACRO_NOT_FOUND, name).set(position); } this.last = macro; } ctx.doMacroCall(macro, arguments); }
public static String macroGet(String name, Object... arguments) { InterpretContext ctx = InterpretContext.current(); Class<?>[] argumentTypes = ParameterUtils.getParameterTypes(arguments); JetTemplateMacro macro = ctx.getTemplate().resolveMacro(name, argumentTypes, true); if (macro == null) { throw new IllegalStateException(Errors.format(Errors.MACRO_NOT_FOUND, name)); } JetWriter originWriter = ctx.getWriter(); UnsafeCharArrayWriter out = new UnsafeCharArrayWriter(128); ctx.setWriter(JetWriter.create(out, originWriter.getCharset(), false, false)); ctx.doMacroCall(macro, arguments); ctx.setWriter(originWriter); return out.toString(); }