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


Java STGroupFile类代码示例

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


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

示例1: getSpecialCaseSetupBody

import org.stringtemplate.v4.STGroupFile; //导入依赖的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;
}
 
开发者ID:eclecticlogic,项目名称:eclectic-orc,代码行数:22,代码来源:OrcWriterBootstrap.java

示例2: generateContent

import org.stringtemplate.v4.STGroupFile; //导入依赖的package包/类
@VisibleForTesting
String generateContent(URL staticFile, Api api) throws IOException {
    final STGroupFile stGroup = createSTGroup(staticFile);
    final String fileName = new File(staticFile.getPath()).getName();

    final ST st = stGroup.getInstanceOf("main");
    st.add("vendorName", vendorName);
    if (fileName.equals("ResourceClassMap.php.stg")) {
        st.add("package", TypeGenModel.TYPES);
    }
    if (fileName.equals("Config.php.stg")) {
        final String apiUri = api.getBaseUri().getTemplate();
        final String authUri = api.getSecuritySchemes().stream()
                .filter(securityScheme -> securityScheme.getSettings() instanceof OAuth20Settings)
                .map(securityScheme -> ((OAuth20Settings)securityScheme.getSettings()).getAccessTokenUri())
                .findFirst().orElse("");
        st.add("apiUri", apiUri);
        st.add("authUri", authUri);
    }
    return st.render();
}
 
开发者ID:vrapio,项目名称:rest-modeling-framework,代码行数:22,代码来源:StaticGenerator.java

示例3: getTemplateGroupFile

import org.stringtemplate.v4.STGroupFile; //导入依赖的package包/类
private static STGroupFile getTemplateGroupFile(String templatePath) throws MalformedURLException {

        if (templatePath == null) {
             return null;
        }

        if (!templatePath.contains(".jar!")) {
            return new STGroupFile(templatePath);
        }

        String protocol = "jar:";
        if (templatePath.startsWith(protocol)) {
            protocol = "";
        }

        URL url = new URL(protocol + templatePath);
        return  new STGroupFile(url, "US-ASCII", '%', '%');
    }
 
开发者ID:mattkol,项目名称:SugarOnRest,代码行数:19,代码来源:Generators.java

示例4: render

import org.stringtemplate.v4.STGroupFile; //导入依赖的package包/类
private Content render(Renderable renderable, Path rootDir, String templateName) {
	String templateFile = rootDir.resolve(templateName+".stg").toAbsolutePath().toFile().toString();
	STGroupFile groupFile = new STGroupFile(templateFile,'$','$');
	initModelAdapter(groupFile);
	initRenderer(groupFile, renderable.context());
	
	ST template = Preconditions.checkNotNull(groupFile.getInstanceOf("page"),"page template is null: %s -> %s",templateName,groupFile);
	
	try {
		setContext(template, renderable);
		
		return Text.builder()
				.mimeType("text/html")
				.text(template.render())
				.build();
	} catch (RuntimeException rx) {
		throw new RuntimeException("template "+templateName, rx);
	}
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:20,代码来源:StringtemplateTheme.java

示例5: initModelAdapter

import org.stringtemplate.v4.STGroupFile; //导入依赖的package包/类
private void initModelAdapter(STGroupFile groupFile) {
	TypesafeModelAdapter.of(MapLike.class, (m,name) -> m.get(name).orElseNull())
		.register(groupFile);
	
	TypesafeModelAdapter.of(PropertyTree.class, (t,name) -> t.find(Object.class, name).orElseNull())
		.register(groupFile);
	
	TypesafeModelAdapter.of(Optional.class, (o,name) -> {
			if (name.equals("is")) {
				return o.isPresent();
			}
			if (name.equals("get")) {
				return o.get();
			}
			return null;
		})
		.register(groupFile);
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:19,代码来源:StringtemplateTheme.java

示例6: test2

import org.stringtemplate.v4.STGroupFile; //导入依赖的package包/类
@Test
public void test2() {
 // Load the file
    final STGroup stGroup = new STGroupFile(CODEGEN_DIR + "file1.stg");

    // Pick the correct template
    final ST templateExample = stGroup.getInstanceOf("templateExample");

    // Pass on values to use when rendering
    templateExample.add("param", "Hello World");

    Integer k = 99;
    Object[] ar = new Object[] { "Ter", "Parr", k };
    templateExample.addAggr("items.{ firstName ,lastName, id }", ar); // add() uses varargs
    templateExample.addAggr("items.{firstName, lastName ,id}", ar);
    
    // Render
    final String render = templateExample.render();

    // Print
    System.out.println(render);
}
 
开发者ID:ianrae,项目名称:dnal-lang,代码行数:23,代码来源:StringTemplateTests.java

示例7: test2

import org.stringtemplate.v4.STGroupFile; //导入依赖的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();
 }
 
开发者ID:antlr,项目名称:codebuff,代码行数:23,代码来源:STViz.java

示例8: generateFeature

import org.stringtemplate.v4.STGroupFile; //导入依赖的package包/类
private void generateFeature(AutoIndentWriter writer, Repository repository, FlowType flow,
    ActorType actor) {
  final STGroupFile stFeatureGroup = new STGroupFile("templates/feature.stg");

  ST st = stFeatureGroup.getInstanceOf("feature");
  st.add("repository", repository);
  st.add("flow", flow);
  st.add("actor", actor);
  st.write(writer, errorListener);
  
  repository.getMessages().getMessage().stream()
  .filter(m -> flow.getName().equals(m.getFlow())).forEach(message -> {
    Responses responses = message.getResponses();
    if (responses != null)
      responses.getResponse().forEach(response -> generateFeatureScenario(writer, stFeatureGroup, repository, actor, message, response));
  });
}
 
开发者ID:FIXTradingCommunity,项目名称:fix-orchestra,代码行数:18,代码来源:TestGenerator.java

示例9: generateFeatureScenario

import org.stringtemplate.v4.STGroupFile; //导入依赖的package包/类
private void generateFeatureScenario(AutoIndentWriter writer, STGroupFile stFeatureGroup, Repository repository, ActorType actor,
    MessageType message, ResponseType response) {
  ST st = stFeatureGroup.getInstanceOf("scenario");
  st.add("actor", actor);
  st.add("message", message);
  st.add("response", response);
  st.write(writer, errorListener);
  List<Object> messageElements = message.getStructure().getComponentOrComponentRefOrGroup();
  generateFeatureMessageElements(writer, stFeatureGroup, messageElements);
  List<Object> actions = response.getMessageRefOrAssignOrTrigger();
  for (Object action : actions) {
    if (action instanceof MessageRefType) {
      MessageRefType messageRef = (MessageRefType) action;
      ST stMessage = stFeatureGroup.getInstanceOf("messageRef");
      stMessage.add("actor", actor);
      stMessage.add("messageRef", messageRef);
      stMessage.write(writer, errorListener);

      MessageType responseMessage = findMessage(messageRef.getName(), messageRef.getScenario());
      List<Object> responseMessageElements =
          responseMessage.getStructure().getComponentOrComponentRefOrGroup();
      generateFeatureMessageElements(writer, stFeatureGroup, responseMessageElements);
    }
  }
}
 
开发者ID:FIXTradingCommunity,项目名称:fix-orchestra,代码行数:26,代码来源:TestGenerator.java

示例10: generateCodeForFoldersInIndex

import org.stringtemplate.v4.STGroupFile; //导入依赖的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);
			}
		}
	}
}
 
开发者ID:janyou,项目名称:ANTLR-Swift-Target,代码行数:20,代码来源:TestGenerator.java

示例11: run

import org.stringtemplate.v4.STGroupFile; //导入依赖的package包/类
public void run() throws IOException {

    // preload the domains
    for (ParameterDomain pd : domains) {
      pd.load();
    }

    // get the template file
    STGroup templateGroup = new STGroupFile(templateFilename, '$', '$');

    // get the printer
    Printer printer = new SysoutPrinter(templateGroup, contentTemplateName);
    if (filenameTemplateName != null) {
      printer =
          new FilePrinter(templateGroup, contentTemplateName, filenameTemplateName, outputDirname);
    }

    Generator generator = new CartesienGenerator(domains, printer);
    if (generationStrategy.equals("linear")) {
      generator = new LinearGenerator(domains, printer);
    }
    generator.generate();
  }
 
开发者ID:christophelg,项目名称:Patternas,代码行数:24,代码来源:Patternas.java

示例12: init

import org.stringtemplate.v4.STGroupFile; //导入依赖的package包/类
/**
 * Initialize the Duzzt embedded DSL generator.
 * 
 * @param reporter the reporter used to report errors
 * @throws DuzztInitializationException if a fatal error occurs during initialization
 */
public void init(Reporter reporter) throws DuzztInitializationException {
	URL url = GenerateEDSLProcessor.class.getResource(ST_RESOURCE_NAME);
	
	this.sourceGenGroup = new STGroupFile(
			url,
			ST_ENCODING,
			ST_DELIM_START_CHAR,
			ST_DELIM_STOP_CHAR);
	
	sourceGenGroup.setListener(new ReporterDiagnosticListener(reporter));
	
	sourceGenGroup.load();
	if(!sourceGenGroup.isDefined(ST_MAIN_TEMPLATE_NAME)) {
		sourceGenGroup = null;
		throw new DuzztInitializationException("Could not find main template '"
				+ ST_MAIN_TEMPLATE_NAME + "' in template group file " + url.toString());
	}
}
 
开发者ID:misberner,项目名称:duzzt,代码行数:25,代码来源:Duzzt.java

示例13: execute

import org.stringtemplate.v4.STGroupFile; //导入依赖的package包/类
@Override
public void execute() throws MojoExecutionException{
	try {
		STGroup template = new STGroupFile(TEMPLATES_THRIFT_POJO);
		JavaDocBuilder docBuilder = getBuilder();

		getLog().info(
				String.format("Executing ThriftPojoGenerator. Sources [ %s ]; outputDirectory [ %s ]; postfix [ %s ]; inteface [ %s ]", sources,
						outputDirectory, outputPostfix, interfaceName));

		generate(template, docBuilder);

		project.addCompileSourceRoot(outputDirectory.getAbsolutePath());
	} catch (Exception e) {
		getLog().error("General error", e);
           throw new MojoExecutionException("Error generatings Pojos", e);
	}
}
 
开发者ID:sergypv,项目名称:thrift-pojo-generator-maven-plugin,代码行数:19,代码来源:ThriftPojoGenerator.java

示例14: render

import org.stringtemplate.v4.STGroupFile; //导入依赖的package包/类
@Override
public void render(PetriNet pn, Writer writer) throws RenderException, IOException {
	verifyNet(pn);

	STGroup group = new STGroupFile("uniol/apt/io/renderer/impl/LoLAPN.stg");
	ST pnTemplate = group.getInstanceOf("pn");
	pnTemplate.add("name", pn.getName());

	// Handle places
	pnTemplate.add("places", pn.getPlaces());

	// Handle the initial marking
	for (Place p : pn.getPlaces()) {
		Token val = pn.getInitialMarking().getToken(p);
		if (val.getValue() != 0) {
			pnTemplate.addAggr("marking.{place, weight}", p, val.getValue());
		}
	}

	// Handle transitions (and arcs)
	pnTemplate.add("transitions", pn.getTransitions());

	pnTemplate.write(new AutoIndentWriter(writer), new ThrowingErrorListener());
}
 
开发者ID:CvO-Theory,项目名称:apt,代码行数:25,代码来源:LoLAPNRenderer.java

示例15: render

import org.stringtemplate.v4.STGroupFile; //导入依赖的package包/类
@Override
public void render(TransitionSystem ts, Writer writer) throws RenderException, IOException {
	STGroup group = new STGroupFile("uniol/apt/io/renderer/impl/AptLTS.stg");
	ST ltsTemplate = group.getInstanceOf("lts");

	ltsTemplate.add("name", ts.getName());
	if (ts.hasExtension("description")) {
		ltsTemplate.add("description", ts.getExtension("description"));
	}
	ltsTemplate.add("extensions", ts.getWriteToFileExtensions());
	ltsTemplate.add("states", decorateStates(ts));
	ltsTemplate.add("arcs", ts.getEdges());
	ltsTemplate.add("events", ts.getAlphabetEvents());

	ltsTemplate.write(new AutoIndentWriter(writer), new ThrowingErrorListener());
}
 
开发者ID:CvO-Theory,项目名称:apt,代码行数:17,代码来源:AptLTSRenderer.java


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