StringTemplate list of attributes defined for a given template

你。 提交于 2019-11-29 07:54:31
Sam Harwell

You can use st.impl.formalArguments to access the Map<String, FormalArgument> where the arguments are defined. Note that for some templates this field will be null.

The documentation for CompiledST states tokens is only for debug. Not sure what that means.

ST template = new ST("Hello <username>, how are you? Using <if(condition)>expression<endif> in condition works, and repeating <username> is not a problem.");
Set<String> expressions = new HashSet<String>();
TokenStream tokens = template.impl.tokens;
for (int i = 0; i < tokens.range(); i++) {
    Token token = tokens.get(i);
    if (token.getType() == STLexer.ID) {
        expressions.add(token.getText());
    }
}

Gives you the Strings username and condition.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!