本文整理汇总了Java中org.stringtemplate.v4.STGroup类的典型用法代码示例。如果您正苦于以下问题:Java STGroup类的具体用法?Java STGroup怎么用?Java STGroup使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
STGroup类属于org.stringtemplate.v4包,在下文中一共展示了STGroup类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSpecialCaseSetupBody
import org.stringtemplate.v4.STGroup; //导入依赖的package包/类
static String getSpecialCaseSetupBody(SchemaColumn schemaColumn) {
STGroup group = new STGroupFile("eclectic/orc/template/methodSpecialCaseSetup.stg");
// Special case setup is needed for lists to adjust list child vector size.
List<SchemaColumn> listSchemaTypes = new ArrayList<>();
Stack<SchemaColumn> structTypes = new Stack<>();
structTypes.push(schemaColumn);
while (!structTypes.isEmpty()) {
for (SchemaColumn child : structTypes.pop().getComplexType().getStructChildren()) {
if (child.getTypeInfo().isTypeStruct()) {
structTypes.push(child);
} else if (child.getTypeInfo().isTypeList()) {
listSchemaTypes.add(child);
}
}
}
ST st = group.getInstanceOf("methodSpecialCaseSetup");
st.add("list", listSchemaTypes);
String s = st.render();
logger.trace(s);
return s;
}
示例2: swapEnvironmentVariables
import org.stringtemplate.v4.STGroup; //导入依赖的package包/类
/**
* Parses an input String and replaces instances of {@literal <XXX>}" with the value of the XXX OS
* Environment Variable. This is used as a pre-parser for the Config files, allowing environment
* variables to be swapped at run-time.
*
* @param raw A raw string (not necessarily valid configuration data)
* @return A parsed string with OS variables swapped in
* @throws ConfigurationException If any discovered {@literal <WRAPPED_VALUES>} are not found in
* System.getenv().
*/
public static String swapEnvironmentVariables(String raw) throws ConfigurationException {
ErrorBuffer errors = new ErrorBuffer();
ST template = new ST(raw);
STGroup g = template.groupThatCreatedThisInstance;
g.setListener(errors);
Map<String, String> env = System.getenv();
for (String envName : env.keySet()) {
template.add(envName, env.get(envName));
}
String parsed = template.render();
if (errors.errors.size() > 0) {
throw new ConfigurationException(errors.toString());
}
return parsed;
}
示例3: getProperty
import org.stringtemplate.v4.STGroup; //导入依赖的package包/类
@Override
public Object getProperty(Interpreter interp, ST self, Object o, Object property, String propertyName) throws STNoSuchPropertyException {
Object value;
Map<?, ?> map = (Map<?, ?>)o;
if ( property==null ) value = map.get(STGroup.DEFAULT_KEY);
else if ( property.equals("keys") ) value = map.keySet();
else if ( property.equals("values") ) value = map.values();
else if ( map.containsKey(property) ) value = map.get(property);
else if ( map.containsKey(propertyName) ) { // if can't find the key, try toString version
value = map.get(propertyName);
}
else value = map.get(STGroup.DEFAULT_KEY); // not found, use default
if ( value==STGroup.DICT_KEY ) {
value = property;
}
return value;
}
示例4: getProperty
import org.stringtemplate.v4.STGroup; //导入依赖的package包/类
@Override
public Object getProperty(Interpreter interp, ST self, Object o, Object property, String propertyName) throws STNoSuchPropertyException {
Object value;
Map<?, ?> map = (Map<?, ?>)o;
if ( property==null ) value = map.get(STGroup.DEFAULT_KEY);
else if ( property.equals("keys") ) value = map.keySet();
else if ( property.equals("values") ) value = map.values();
else if ( map.containsKey(property) ) value = map.get(property);
else if ( map.containsKey(propertyName) ) { // if can't find the key, try toString version
value = map.get(propertyName);
}
else value = map.get(STGroup.DEFAULT_KEY); // not found, use default
if ( value==STGroup.DICT_KEY ) {
value = property;
}
return value;
}
示例5: generateCodeForFoldersInIndex
import org.stringtemplate.v4.STGroup; //导入依赖的package包/类
protected void generateCodeForFoldersInIndex(STGroup targetGroup) {
File targetFolder = getOutputDir(testTemplates+"");
STGroup index = new STGroupFile(testTemplates+"/Index.stg");
index.load(); // make sure the index group is loaded since we call rawGetDictionary
Map<String, Object> folders = index.rawGetDictionary("TestFolders");
if (folders != null) {
for (String key : folders.keySet()) {
final String testDir = testTemplates + "/" + key;
STGroup testIndex = new STGroupFile(testDir + "/Index.stg");
testIndex.load();
Map<String, Object> templateNames = testIndex.rawGetDictionary("TestTemplates");
if ( templateNames != null && !templateNames.isEmpty() ) {
final ArrayList<String> sortedTemplateNames = new ArrayList<String>(templateNames.keySet());
Collections.sort(sortedTemplateNames);
generateTestFile(testIndex, targetGroup, testDir, sortedTemplateNames, targetFolder);
}
}
}
}
示例6: getProperty
import org.stringtemplate.v4.STGroup; //导入依赖的package包/类
@Override
public Object getProperty(Interpreter interp, ST self, Object o, Object property, String propertyName)
throws STNoSuchPropertyException
{
Object value;
Map<?, ?> map = (Map<?, ?>)o;
if ( property==null ) value = map.get(STGroup.DEFAULT_KEY);
else if ( property.equals("keys") ) value = map.keySet();
else if ( property.equals("values") ) value = map.values();
else if ( map.containsKey(property) ) value = map.get(property);
else if ( map.containsKey(propertyName) ) { // if can't find the key, try toString version
value = map.get(propertyName);
}
else value = map.get(STGroup.DEFAULT_KEY); // not found, use default
if ( value == STGroup.DICT_KEY ) {
value = property;
}
return value;
}
示例7: test4
import org.stringtemplate.v4.STGroup; //导入依赖的package包/类
public static void test4() throws IOException
{
String templates = "main(t) ::= <<\n"+"hi: <t>\n"+">>\n"+"foo(x,y={hi}) ::= \"<bar(x,y)>\"\n"+"bar(x,y) ::= << <y> >>\n"+"ignore(m) ::= \"<m>\"\n";
STGroup group = new STGroupString(templates);
ST st = group.getInstanceOf("main");
ST foo = group.getInstanceOf("foo");
st.add("t", foo);
ST ignore = group.getInstanceOf("ignore");
ignore.add("m", foo); // embed foo twice!
st.inspect();
st.render();
}
示例8: createTypeDescriptionBody
import org.stringtemplate.v4.STGroup; //导入依赖的package包/类
static String createTypeDescriptionBody(SchemaColumn schemaColumn) {
STGroup group = new STGroupFile("eclectic/orc/template/methodCreateTypeDescription.stg");
ST st = group.getInstanceOf("methodGetTypeDescription");
st.add("schemaColumn", schemaColumn);
String s = st.render();
logger.trace(s);
return s;
}
示例9: getWriteBody
import org.stringtemplate.v4.STGroup; //导入依赖的package包/类
static String getWriteBody(SchemaColumn schemaColumn, Class<?> schemaClass) {
STGroup group = new STGroupFile("eclectic/orc/template/methodWrite.stg");
ST st = group.getInstanceOf("methodWrite");
st.add("schemaColumn", schemaColumn);
st.add("sclass", schemaClass);
String s = st.render();
logger.trace(s);
return s;
}
示例10: generateResource
import org.stringtemplate.v4.STGroup; //导入依赖的package包/类
String generateResource(final ResourceGenModel resource) {
final STGroup stGroup = createSTGroup(Resources.getResource(resourcesPath + TYPE_RESOURCE + ".stg"));
final ST st = stGroup.getInstanceOf("resource");
st.add("vendorName", vendorName);
st.add("resource", resource);
return st.render();
}
示例11: test1
import org.stringtemplate.v4.STGroup; //导入依赖的package包/类
public static void test1() throws IOException
{ // test rig
String templates = "method(type,name,locals,args,stats) ::= <<\n"+"public <type> <name>(<args:{a| int <a>}; separator=\", \">) {\n"+" <if(locals)>int locals[<locals>];<endif>\n"+" <stats;separator=\"\\n\">\n"+"}\n"+">>\n"+"assign(a,b) ::= \"<a> = <b>;\"\n"+"return(x) ::= <<return <x>;>>\n"+"paren(x) ::= \"(<x>)\"\n";
String tmpdir = System.getProperty("java.io.tmpdir");
writeFile(tmpdir, "t.stg", templates);
STGroup group = new STGroupFile(tmpdir+"/"+"t.stg");
ST st = group.getInstanceOf("method");
st.impl.dump();
st.add("type", "float");
st.add("name", "foo");
st.add("locals", 3);
st.add("args", new String[] {"x",
"y",
"z"});
ST s1 = group.getInstanceOf("assign");
ST paren = group.getInstanceOf("paren");
paren.add("x", "x");
s1.add("a", paren);
s1.add("b", "y");
ST s2 = group.getInstanceOf("assign");
s2.add("a", "y");
s2.add("b", "z");
ST s3 = group.getInstanceOf("return");
s3.add("x", "3.14159");
st.add("stats", s1);
st.add("stats", s2);
st.add("stats", s3);
STViz viz = st.inspect();
System.out.println(st.render()); // should not mess up ST event lists
}
示例12: setFormat
import org.stringtemplate.v4.STGroup; //导入依赖的package包/类
/** The format gets reset either from the Tool if the user supplied a command line option to that effect
* Otherwise we just use the default "antlr".
*/
public void setFormat(String formatName) {
this.formatName = formatName;
String fileName = FORMATS_DIR +formatName+STGroup.GROUP_FILE_EXTENSION;
ClassLoader cl = Thread.currentThread().getContextClassLoader();
URL url = cl.getResource(fileName);
if ( url==null ) {
cl = ErrorManager.class.getClassLoader();
url = cl.getResource(fileName);
}
if ( url==null && formatName.equals("antlr") ) {
rawError("ANTLR installation corrupted; cannot find ANTLR messages format file "+fileName);
panic();
}
else if ( url==null ) {
rawError("no such message format file "+fileName+" retrying with default ANTLR format");
setFormat("antlr"); // recurse on this rule, trying the default message format
return;
}
format = new STGroupFile(fileName, "UTF-8");
format.load();
if ( !initSTListener.errors.isEmpty() ) {
rawError("ANTLR installation corrupted; can't load messages format file:\n"+
initSTListener.toString());
panic();
}
boolean formatOK = verifyFormat();
if ( !formatOK && formatName.equals("antlr") ) {
rawError("ANTLR installation corrupted; ANTLR messages format file "+formatName+".stg incomplete");
panic();
}
else if ( !formatOK ) {
setFormat("antlr"); // recurse on this rule, trying the default message format
}
}
示例13: test4
import org.stringtemplate.v4.STGroup; //导入依赖的package包/类
public static void test4() throws IOException
{
String templates = "main(t) ::= <<\n"+"hi: <t>\n"+">>\n"+"foo(x,y={hi}) ::= \"<bar(x,y)>\"\n"+
"bar(x,y) ::= << <y> >>\n" +"ignore(m) ::= \"<m>\"\n";
STGroup group = new STGroupString(templates);
ST st = group.getInstanceOf("main");
ST foo = group.getInstanceOf("foo");
st.add("t", foo);
ST ignore = group.getInstanceOf("ignore");
ignore.add("m", foo); // embed foo twice!
st.inspect();
st.render();
}
示例14: defineBlankRegion
import org.stringtemplate.v4.STGroup; //导入依赖的package包/类
public static CompiledST defineBlankRegion(CompiledST outermostImpl, Token nameToken) {
String outermostTemplateName = outermostImpl.name;
String mangled = STGroup.getMangledRegionName(outermostTemplateName, nameToken.getText());
CompiledST blank = new CompiledST();
blank.isRegion = true;
blank.templateDefStartToken = nameToken;
blank.regionDefType = ST.RegionType.IMPLICIT;
blank.name = mangled;
outermostImpl.addImplicitlyDefinedTemplate(blank);
return blank;
}
示例15: test2
import org.stringtemplate.v4.STGroup; //导入依赖的package包/类
public static void test2() throws IOException
{ // test rig
String templates = "t1(q1=\"Some\\nText\") ::= <<\n"+
"<q1>\n" +">>\n"+"\n"+"t2(p1) ::= <<\n"+
"<p1>\n"+
">>\n"+
"\n"+
"main() ::= <<\n" +"START-<t1()>-END\n"+"\n"+"START-<t2(p1=\"Some\\nText\")>-END\n"+">>\n";
String tmpdir = System.getProperty("java.io.tmpdir");
writeFile(tmpdir, "t.stg", templates);
STGroup group = new STGroupFile(tmpdir+"/"+"t.stg");
ST st = group.getInstanceOf("main");
STViz viz = st.inspect();
}