当前位置: 首页>>代码示例>>Java>>正文


Java StringTemplateGroup类代码示例

本文整理汇总了Java中org.antlr.stringtemplate.StringTemplateGroup的典型用法代码示例。如果您正苦于以下问题:Java StringTemplateGroup类的具体用法?Java StringTemplateGroup怎么用?Java StringTemplateGroup使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


StringTemplateGroup类属于org.antlr.stringtemplate包,在下文中一共展示了StringTemplateGroup类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: StringTemplateHelper

import org.antlr.stringtemplate.StringTemplateGroup; //导入依赖的package包/类
/**
 * Creates a new template helper.
 *
 * @param templateContextClass Classpath context for the location of the template file.
 * @param templateName Template file name (excluding .st suffix) relative to
 *     {@code templateContextClass}.
 * @param cacheTemplates Whether the template should be cached.
 */
public StringTemplateHelper(
    Class<?> templateContextClass,
    String templateName,
    boolean cacheTemplates) {

  MorePreconditions.checkNotBlank(templateName);
  String templatePath =
      templateContextClass.getPackage().getName().replace('.', '/') + "/" + templateName;
  StringTemplateGroup group = new StringTemplateGroup(templateName);
  Preconditions.checkNotNull(group.getInstanceOf(templatePath),
      "Failed to load template at: %s", templatePath);

  this.group = group;
  if (!cacheTemplates) {
    group.setRefreshInterval(0);
  }
  this.templatePath = templatePath;
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:27,代码来源:StringTemplateHelper.java

示例2: createIndexTemplate

import org.antlr.stringtemplate.StringTemplateGroup; //导入依赖的package包/类
public static StringTemplate createIndexTemplate(String typeName, String sdkName, String packageName, List<IndexedAnnotation> indices,
        Map<String, String> fieldNameToType, StringTemplateGroup templateLib) {
    AbstractTTree.STAttrMap attrMap = new AbstractTTree.STAttrMap().put("name", typeName).put("sdkName", sdkName).put("package", packageName);

    List<StringTemplate> functionCalls = new LinkedList<StringTemplate>();
    List<StringTemplate> functionDefinitions = new LinkedList<StringTemplate>();
    for (IndexedAnnotation indexedAnnotation : indices) {
        StringTemplate createIndexDefinition = createIndexDefinitionTemplate(templateLib, packageName, typeName, indexedAnnotation, fieldNameToType);
        functionDefinitions.add(createIndexDefinition);

        StringTemplate indexCall = createIndexCallTemplate(templateLib, indexedAnnotation);
        functionCalls.add(indexCall);
    }

    if (indices.size() > 0) {
        attrMap.put("functionDefinitions", functionDefinitions);
        attrMap.put("functionCalls", functionCalls);
    }

    return templateLib.getInstanceOf("beanIndexInfoClass", attrMap);
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:22,代码来源:IndexTemplateFactory.java

示例3: TemplateTypeBuilder

import org.antlr.stringtemplate.StringTemplateGroup; //导入依赖的package包/类
public TemplateTypeBuilder(TypeSpecification spec) {
  CommonGroupLoader loader = new CommonGroupLoader("org/lemurproject/galago/tupleflow/templates", null);
  StringTemplateGroup.registerGroupLoader(loader);
  StringTemplateGroup.registerDefaultLexer(AngleBracketTemplateLexer.class);
  this.template = StringTemplateGroup.loadGroup("GalagoType");

  this.typeName = spec.getTypeName();
  this.typePackage = spec.getPackageName();
  this.typeFields = new ArrayList<Field>();
  this.typeOrders = new ArrayList<OrderSpec>();

  for (FieldSpecification fieldSpec : spec.getFields()) {
    Field field = new Field(fieldSpec.getType(), fieldSpec.getName());
    typeFields.add(field);
  }

  for (OrderSpecification orderSpec : spec.getOrders()) {
    OrderSpec order = new OrderSpec(orderSpec, typeFields);
    typeOrders.add(order);
  }
}
 
开发者ID:teanalab,项目名称:demidovii,代码行数:22,代码来源:TemplateTypeBuilder.java

示例4: testEscapedLessThanInAction

import org.antlr.stringtemplate.StringTemplateGroup; //导入依赖的package包/类
public void testEscapedLessThanInAction() throws Exception {
	Grammar g = new Grammar();
	Tool antlr = newTool();
	CodeGenerator generator = new CodeGenerator(antlr, g, "Java");
	String action = "i<3; '<xmltag>'";
	ActionTranslatorLexer translator = new ActionTranslatorLexer(generator,"a",
																 new antlr.CommonToken(ANTLRParser.ACTION,action),0);
	String expecting = action;
	String rawTranslation =
		translator.translate();
	StringTemplateGroup templates =
		new StringTemplateGroup(".", AngleBracketTemplateLexer.class);
	StringTemplate actionST = new StringTemplate(templates, "<action>");
	actionST.setAttribute("action", rawTranslation);
	String found = actionST.toString();
	assertEquals(expecting, found);
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:18,代码来源:TestAttributes.java

示例5: Grammar

import org.antlr.stringtemplate.StringTemplateGroup; //导入依赖的package包/类
public void testEscaped$InAction() throws Exception {
	String action = "int \\$n; \"\\$in string\\$\"";
	String expecting = "int $n; \"$in string$\"";
	Grammar g = new Grammar(
		"parser grammar t;\n"+
			"@members {"+action+"}\n"+
			"a[User u, int i]\n" +
			"        : {"+action+"}\n" +
			"        ;");
	Tool antlr = newTool();
	CodeGenerator generator = new CodeGenerator(antlr, g, "Java");
	g.setCodeGenerator(generator);
	generator.genRecognizer(); // forces load of templates
	ActionTranslatorLexer translator =
		new ActionTranslatorLexer(generator,
								  "a",
								  new antlr.CommonToken(ANTLRParser.ACTION,action),0);
	String rawTranslation =
		translator.translate();
	StringTemplateGroup templates =
		new StringTemplateGroup(".", AngleBracketTemplateLexer.class);
	StringTemplate actionST = new StringTemplate(templates, rawTranslation);
	String found = actionST.toString();
	assertEquals(expecting, found);
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:26,代码来源:TestAttributes.java

示例6: testFullyQualifiedRefToCurrentRuleParameter

import org.antlr.stringtemplate.StringTemplateGroup; //导入依赖的package包/类
public void testFullyQualifiedRefToCurrentRuleParameter() throws Exception {
	String action = "$a.i;";
	String expecting = "i;";

	ErrorQueue equeue = new ErrorQueue();
	ErrorManager.setErrorListener(equeue);
	Grammar g = new Grammar(
		"grammar t;\n"+
			"a[int i]: {"+action+"}\n" +
			"  ;\n");
	Tool antlr = newTool();
	CodeGenerator generator = new CodeGenerator(antlr, g, "Java");
	g.setCodeGenerator(generator);
	generator.genRecognizer(); // forces load of templates
	ActionTranslatorLexer translator = new ActionTranslatorLexer(generator,"a",
																 new antlr.CommonToken(ANTLRParser.ACTION,action),1);
	String rawTranslation =
		translator.translate();
	StringTemplateGroup templates =
		new StringTemplateGroup(".", AngleBracketTemplateLexer.class);
	StringTemplate actionST = new StringTemplate(templates, rawTranslation);
	String found = actionST.toString();
	assertEquals(expecting, found);

	assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size());
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:27,代码来源:TestAttributes.java

示例7: testFullyQualifiedRefToCurrentRuleRetVal

import org.antlr.stringtemplate.StringTemplateGroup; //导入依赖的package包/类
public void testFullyQualifiedRefToCurrentRuleRetVal() throws Exception {
	String action = "$a.i;";
	String expecting = "retval.i;";

	ErrorQueue equeue = new ErrorQueue();
	ErrorManager.setErrorListener(equeue);
	Grammar g = new Grammar(
		"grammar t;\n"+
			"a returns [int i, int j]: {"+action+"}\n" +
			"  ;\n");
	Tool antlr = newTool();
	CodeGenerator generator = new CodeGenerator(antlr, g, "Java");
	g.setCodeGenerator(generator);
	generator.genRecognizer(); // forces load of templates
	ActionTranslatorLexer translator = new ActionTranslatorLexer(generator,"a",
																 new antlr.CommonToken(ANTLRParser.ACTION,action),1);
	String rawTranslation =
		translator.translate();
	StringTemplateGroup templates =
		new StringTemplateGroup(".", AngleBracketTemplateLexer.class);
	StringTemplate actionST = new StringTemplate(templates, rawTranslation);
	String found = actionST.toString();
	assertEquals(expecting, found);

	assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size());
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:27,代码来源:TestAttributes.java

示例8: testSetFullyQualifiedRefToCurrentRuleRetVal

import org.antlr.stringtemplate.StringTemplateGroup; //导入依赖的package包/类
public void testSetFullyQualifiedRefToCurrentRuleRetVal() throws Exception {
	String action = "$a.i = 1;";
	String expecting = "retval.i = 1;";

	ErrorQueue equeue = new ErrorQueue();
	ErrorManager.setErrorListener(equeue);
	Grammar g = new Grammar(
		"grammar t;\n"+
		"a returns [int i, int j]: {"+action+"}\n" +
		"  ;\n");
	Tool antlr = newTool();
	CodeGenerator generator = new CodeGenerator(antlr, g, "Java");
	g.setCodeGenerator(generator);
	generator.genRecognizer(); // forces load of templates
	ActionTranslatorLexer translator = new ActionTranslatorLexer(generator,"a",
																 new antlr.CommonToken(ANTLRParser.ACTION,action),1);
	String rawTranslation =
		translator.translate();
	StringTemplateGroup templates =
		new StringTemplateGroup(".", AngleBracketTemplateLexer.class);
	StringTemplate actionST = new StringTemplate(templates, rawTranslation);
	String found = actionST.toString();
	assertEquals(expecting, found);

	assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size());
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:27,代码来源:TestAttributes.java

示例9: testTokenRefTreeProperty

import org.antlr.stringtemplate.StringTemplateGroup; //导入依赖的package包/类
public void testTokenRefTreeProperty() throws Exception {
	String action = "$ID.tree;";
	String expecting = "ID1_tree;";

	ErrorQueue equeue = new ErrorQueue();
	ErrorManager.setErrorListener(equeue);
	Grammar g = new Grammar(
		"grammar t;\n"+
			"a : ID {"+action+"} ;" +
			"ID : 'a';\n");
	Tool antlr = newTool();
	antlr.setOutputDirectory(null); // write to /dev/null
	CodeGenerator generator = new CodeGenerator(antlr, g, "Java");
	g.setCodeGenerator(generator);
	generator.genRecognizer();

	ActionTranslatorLexer translator = new ActionTranslatorLexer(generator,"a",
																 new antlr.CommonToken(ANTLRParser.ACTION,action),1);
	String rawTranslation =
		translator.translate();
	StringTemplateGroup templates =
		new StringTemplateGroup(".", AngleBracketTemplateLexer.class);
	StringTemplate actionST = new StringTemplate(templates, rawTranslation);
	String found = actionST.toString();
	assertEquals(expecting, found);
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:27,代码来源:TestAttributes.java

示例10: initializeEngine

import org.antlr.stringtemplate.StringTemplateGroup; //导入依赖的package包/类
public void initializeEngine()
{
  initializeWorkPath();
  InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("batch/batch-template.stg");
  fileGenerator = new StringTemplateGroup(new InputStreamReader(in));
  try
  {
    in.close();
  }
  catch (IOException e)
  {
    LogUtil.getCoreLog().info("-> StringTemplate initailize error");
    if (LogUtil.getCoreLog().isErrorEnabled())
      LogUtil.getCoreLog().error("fileGenerator", e);
    throw new GemliteException(e);
  }
}
 
开发者ID:iisi-nj,项目名称:GemFireLite,代码行数:18,代码来源:BatchGenenator.java

示例11: TemplateTypeBuilder

import org.antlr.stringtemplate.StringTemplateGroup; //导入依赖的package包/类
public TemplateTypeBuilder(TypeSpecification spec) {
    CommonGroupLoader loader = new CommonGroupLoader("org/galagosearch/tupleflow/templates", null);
    StringTemplateGroup.registerGroupLoader(loader);
    StringTemplateGroup.registerDefaultLexer(AngleBracketTemplateLexer.class);
    this.template = StringTemplateGroup.loadGroup("GalagoType");

    this.typeName = spec.getTypeName();
    this.typePackage = spec.getPackageName();
    this.typeFields = new ArrayList<Field>();
    this.typeOrders = new ArrayList<OrderSpec>();

    for (FieldSpecification fieldSpec : spec.getFields()) {
        Field field = new Field(fieldSpec.getType(), fieldSpec.getName());
        typeFields.add(field);
    }

    for (OrderSpecification orderSpec : spec.getOrders()) {
        OrderSpec order = new OrderSpec(orderSpec, typeFields);
        typeOrders.add(order);
    }
}
 
开发者ID:jjfiv,项目名称:galagosearch,代码行数:22,代码来源:TemplateTypeBuilder.java

示例12: getHtml

import org.antlr.stringtemplate.StringTemplateGroup; //导入依赖的package包/类
private String getHtml()
{
	final StringTemplateGroup templates = new StringTemplateGroup( "manager" );
	final StringTemplate t = templates.getInstanceOf( "templates/manager" );

	t.setAttribute( "bytesSent", getByteSizeString( statHandler.getResponsesBytesTotal() ) );
	t.setAttribute( "msgPerSec", connectorStats.getMessagesOutPerSecond() );
	t.setAttribute( "openConnections", connectorStats.getConnectionsOpen() );
	t.setAttribute( "maxOpenConnections", connectorStats.getConnectionsOpenMax() );

	getContexts();

	t.setAttribute( "contexts", contexts );

	t.setAttribute( "noDataSets", noDataSets );
	t.setAttribute( "sizeDataSets", getByteSizeString( sizeDataSets ) );

	t.setAttribute( "statHtml", statHandler.toStatsHTML() );

	return t.toString();
}
 
开发者ID:bigdataviewer,项目名称:bigdataviewer-server,代码行数:22,代码来源:ManagerHandler.java

示例13: createPackageIndexPage

import org.antlr.stringtemplate.StringTemplateGroup; //导入依赖的package包/类
private void createPackageIndexPage(final PackageSummaryData psData) {
  final StringTemplateGroup group = new StringTemplateGroup("mutation_test");
  final StringTemplate st = group
      .getInstanceOf("templates/mutation/package_index");

  final Writer writer = this.outputStrategy.createWriterForFile(psData
      .getPackageDirectory() + File.separator + "index.html");
  st.setAttribute("packageData", psData);
  try {
    writer.write(st.toString());
    writer.close();
  } catch (final IOException e) {
    e.printStackTrace();
  }

}
 
开发者ID:hcoles,项目名称:pitest,代码行数:17,代码来源:MutationHtmlReportListener.java

示例14: compile

import org.antlr.stringtemplate.StringTemplateGroup; //导入依赖的package包/类
public void compile() throws IOException{
	String junitFileName;
	if ( grammarInfo.getTreeGrammarName()!=null ) {
		junitFileName = "Test"+grammarInfo.getTreeGrammarName();
	}
	else {
		junitFileName = "Test"+grammarInfo.getGrammarName();
	}
	String lexerName = grammarInfo.getGrammarName()+"Lexer";
	String parserName = grammarInfo.getGrammarName()+"Parser";
	
	StringTemplateGroupLoader loader = new CommonGroupLoader("org/antlr/gunit", null);
	StringTemplateGroup.registerGroupLoader(loader);
	StringTemplateGroup.registerDefaultLexer(AngleBracketTemplateLexer.class);
	StringBuffer buf = compileToBuffer(junitFileName, lexerName, parserName);
	writeTestFile(".", junitFileName+".java", buf.toString());
}
 
开发者ID:pcingola,项目名称:jFuzzyLogic,代码行数:18,代码来源:JUnitCodeGen.java

示例15: genExpr

import org.antlr.stringtemplate.StringTemplateGroup; //导入依赖的package包/类
public StringTemplate genExpr(CodeGenerator generator,
							  StringTemplateGroup templates,
							  DFA dfa)
{
	StringTemplate eST = null;
	if ( templates!=null ) {
		eST = templates.getInstanceOf("orPredicates");
	}
	else {
		eST = new StringTemplate("($first(operands)$$rest(operands):{o | ||$o$}$)");
	}
	for (Iterator it = operands.iterator(); it.hasNext();) {
		SemanticContext semctx = (SemanticContext) it.next();
		eST.setAttribute("operands", semctx.genExpr(generator,templates,dfa));
	}
	return eST;
}
 
开发者ID:pcingola,项目名称:jFuzzyLogic,代码行数:18,代码来源:SemanticContext.java


注:本文中的org.antlr.stringtemplate.StringTemplateGroup类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。