本文整理汇总了Java中org.stringtemplate.v4.STGroupFile.getInstanceOf方法的典型用法代码示例。如果您正苦于以下问题:Java STGroupFile.getInstanceOf方法的具体用法?Java STGroupFile.getInstanceOf怎么用?Java STGroupFile.getInstanceOf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.stringtemplate.v4.STGroupFile
的用法示例。
在下文中一共展示了STGroupFile.getInstanceOf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
示例2: 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));
});
}
示例3: 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);
}
}
}
示例4: writeGeneric
import org.stringtemplate.v4.STGroupFile; //导入方法依赖的package包/类
protected void writeGeneric(File directory, String templateFileName, String templateName, String tlTemplateArg[], Object tlNamesClass[],
String headerFooterName, boolean headerUsesDT, String fileName) throws TbFailure {
File genericFile = new File(directory, fileName);
String path = genericFile.getAbsolutePath();
try (BufferedWriter writer = new BufferedWriter(new FileWriter(genericFile))) {
STGroupFile stg = this.createTemplate(templateFileName);
writeBoilerplateDTHeader(headerFooterName, path, writer, stg.getInstanceOf("filePrefix"), headerUsesDT);
ST st = stg.getInstanceOf(templateName);
assert(tlTemplateArg.length== tlNamesClass.length);
for (int i = 0; i < tlTemplateArg.length; i++) {
st.add(tlTemplateArg[i], tlNamesClass[i]);
}
writer.append(st.render() + System.lineSeparator());
writeBoilerplateFooter(headerFooterName, path, writer, stg.getInstanceOf("filePostfix"));
} catch (IOException e) {
log.error("IO Exception occurred when creating file: " + fileName);
throw new TbFailure();
}
}
示例5: generateBuilder
import org.stringtemplate.v4.STGroupFile; //导入方法依赖的package包/类
String generateBuilder(final RootResourceGenModel resource) {
final STGroupFile stGroup = createSTGroup(Resources.getResource(resourcesPath + TYPE_RESOURCE + ".stg"));
final ST st = stGroup.getInstanceOf("builder");
st.add("vendorName", vendorName);
st.add("resource", resource);
return st.render();
}
示例6: generateRequest
import org.stringtemplate.v4.STGroupFile; //导入方法依赖的package包/类
String generateRequest(final RequestGenModel request) {
final STGroupFile stGroup = createSTGroup(Resources.getResource(resourcesPath + TYPE_RESOURCE + ".stg"));
final ST st = stGroup.getInstanceOf("request");
st.add("vendorName", vendorName);
st.add("request", request);
return st.render();
}
示例7: generateMain
import org.stringtemplate.v4.STGroupFile; //导入方法依赖的package包/类
/**
* Generates the main class.
*
* @return Map assigning Java code to a file name
*/
private Map<String, String> generateMain(MainCompiler<?> mainCompiler) {
Map<String, String> files = new HashMap<String, String>();
String mainClassName = "Main";
MainSignature signature = mainCompiler.getGeneratee().getSignature();
Map<String, MemberSignature> protocolSignatures = new HashMap<>();
Map<String, WorkerSignature> workerSignatures = new HashMap<>();
for (InterpretedProtocol p : mainCompiler.getGeneratee().getProtocols())
protocolSignatures.put((String) p.getAnnotation("className"), p.getSignature()); // pr.main.Protocol_d20170127_t103917_197_FifoK=FifoK[3](A$1;B$1)
for (InterpretedWorker w : mainCompiler.getGeneratee().getWorkers())
workerSignatures.put((String) w.getAnnotation("className"), w.getSignature());
// Get string templates for main
STGroupFile mainTemplates = new STGroupFile(eclipse ? "src/main/resources/java-main.stg" : "java-main.stg");
ST mainHeaderTemplate = mainTemplates.getInstanceOf("header");
ST mainClassTemplate = mainTemplates.getInstanceOf("mainClass");
String mainCode = "";
// Generate header
if (!packagename.equals(""))
mainHeaderTemplate.add("packageName", packagename);
mainCode += mainHeaderTemplate.render();
// Generate body
mainClassTemplate.add("signature", signature);
mainClassTemplate.add("protocolSignatures", protocolSignatures);
mainClassTemplate.add("workerSignatures", workerSignatures);
mainCode += "\n\n" + mainClassTemplate.render();
files.put(mainClassName + ".java", mainCode);
return files;
}
示例8: generateWorkers
import org.stringtemplate.v4.STGroupFile; //导入方法依赖的package包/类
/**
* Generates the worker classes.
*
* @return Map assigning Java code to a file name
*/
private Map<String, String> generateWorkers(WorkerCompiler<?> w) {
Map<String, String> files = new HashMap<String, String>();
WorkerSignature workerSignature = w.getGeneratee().getSignature();
String[] identifiers = workerSignature.getName().split("\\.");
String workerSimpleClassName = identifiers[identifiers.length - 1];
String workerClassName = "Worker_" + workerSimpleClassName.substring(0, 1).toUpperCase()
+ workerSimpleClassName.substring(1)+"_"+counterWorkerName;
counterWorkerName++;
STGroupFile workerTemplates = new STGroupFile(
eclipse ? "src/main/resources/java-worker.stg" : "java-worker.stg");
String workerCode = "";
w.getGeneratee().addAnnotation("className", workerClassName);
// Generate header
ST workerHeaderTemplate = workerTemplates.getInstanceOf("header");
if (!packagename.equals(""))
workerHeaderTemplate.add("packageName", packagename);
workerCode += workerHeaderTemplate.render();
// Generate body
ST workerClassTemplate = workerTemplates.getInstanceOf("workerClass");
workerClassTemplate.add("simpleClassName", workerClassName);
workerClassTemplate.add("signature", workerSignature);
workerCode += "\n\n" + workerClassTemplate.render();
files.put(workerClassName + ".java", workerCode);
return files;
}
示例9: createTemplateFile
import org.stringtemplate.v4.STGroupFile; //导入方法依赖的package包/类
public void createTemplateFile(File directory, String fileName, String templateFile, String templateName) throws TbFailure {
File HFile = new File(directory, fileName);
try (BufferedWriter hwriter = new BufferedWriter(new FileWriter(HFile))) {
STGroupFile stg = this.createTemplate(templateFile);
String name = getLastDir();
String CapName = name.toUpperCase();
ST st = stg.getInstanceOf(templateName);
st.add("name", name);
st.add("CapName", CapName);
hwriter.append(st.render());
} catch (IOException e) {
log.error("IOException occurred during CAmkES write: " + e);
throw new TbFailure();
}
}
示例10: camkesAddComponentLevelDeclarations
import org.stringtemplate.v4.STGroupFile; //导入方法依赖的package包/类
@Override
public String camkesAddComponentLevelDeclarations(ThreadImplementation ti, List<PortFeature> pl) {
String result = "";
STGroupFile template = Util.createTemplate("CamkesComponentCamkes.stg");
for (Type t: relevantPortTypes(pl)) {
ST st = template.getInstanceOf("importReaderWriterIdl");
st.add("type", EmitterFactory.type(t));
result += st.render() + System.lineSeparator();
}
return result;
}
示例11: getPerVmConfigDefs
import org.stringtemplate.v4.STGroupFile; //导入方法依赖的package包/类
public String getPerVmConfigDefs() {
String result = "";
String configFileName =
Util.getStringValueOpt(m.getProcessorImpl(), VM_CONFIG_FILE);
ST st;
if (configFileName != null) {
File aadlDirectory = Util.getDirectory(m.getProcessorImpl());
File srcFilePath = new File(aadlDirectory, configFileName);
STGroupFile templates = new STGroupFile(srcFilePath.getAbsolutePath());
templates.setListener(Util.getListener());
st = templates.getInstanceOf("VmConfig");
if (st == null) {
throw new TbException("Error: Vm configuration file: " + srcFilePath + " not found, or does not contain a template named 'VmConfig'");
}
} else {
st = Util.createTemplate("CamkesVmConfig.stg").getInstanceOf("VmConfig");
}
st.add("model", this);
result += st.render();
for (PortListEmitterCamkesVM pe: EmitterListRegistry.getVMPortListEmitters()) {
result += pe.getCamkesAddAssemblyFileVMConfigDeclarations(m, m.getVmCrossingPorts());
}
return result;
}
示例12: createTypesHeader
import org.stringtemplate.v4.STGroupFile; //导入方法依赖的package包/类
protected void createTypesHeader() throws TbFailure {
ModelNames mn = new ModelNames(model);
String hname = mn.getSystemTypeHeaderName();
String sysInstanceName = model.getInstanceName();
File HFile = new File(includeDirectory, hname);
String path = HFile.getAbsolutePath();
try (BufferedWriter hwriter = new BufferedWriter(new FileWriter(HFile))) {
STGroupFile stg = this.createTemplate("TypesHeader.stg");
writeBoilerplateHeader(sysInstanceName, path, hwriter, stg.getInstanceOf("filePrefix"));
ST st = stg.getInstanceOf("externalTypeDecls");
st.add("model", mn);
hwriter.append(st.render());
st = stg.getInstanceOf("mutexOP");
hwriter.append(st.render());
st = stg.getInstanceOf("callbackOP");
hwriter.append(st.render());
// TODO: MWW: this needs to be refactored for new architecture.
// createComponentDispatchTypes();
createPortTypes();
C_Type_Writer.writeTypes(hwriter, model, 6);
writeBoilerplateFooter(sysInstanceName, hname, hwriter, stg.getInstanceOf("filePostfix"));
} catch (IOException e) {
log.error("IOException occurred during file write: " + e);
throw new TbFailure();
}
}
示例13: getStGroup
import org.stringtemplate.v4.STGroupFile; //导入方法依赖的package包/类
private ST getStGroup(final URL staticFile) {
final STGroupFile stGroup = createSTGroup(staticFile);
return stGroup.getInstanceOf("main");
}
示例14: generateNameOfClass
import org.stringtemplate.v4.STGroupFile; //导入方法依赖的package包/类
public static void generateNameOfClass(String destFolder) throws Exception {
ClassLoader loader = Generators.class.getClassLoader();
URL templateUrl = loader.getResource("NameOfTemplate.stg");
StringBuilder stringBuilder = new StringBuilder();
STGroupFile group = getTemplateGroupFile(templateUrl.getPath());
// Class comment start
ST template = group.getInstanceOf("templateComment");
stringBuilder.append(template.render());
stringBuilder.append(Utils.NewLine);
// Package
template = group.getInstanceOf("packageLine");
template.add("packageLine", "package com.sugaronrest;");
stringBuilder.append(template.render());
stringBuilder.append(Utils.NewLine);
stringBuilder.append(Utils.NewLine);
// Class start
template = group.getInstanceOf("classStart");
stringBuilder.append(template.render());
stringBuilder.append(Utils.NewLine);
List<Table> tableList = getTables();
for (Table table : tableList) {
// Inner class start
template = group.getInstanceOf("innerClassStart");
template.add("name", table.getClassName());
stringBuilder.append(template.render());
stringBuilder.append(Utils.NewLine);
// Set Modulename
template = group.getInstanceOf("property");
template.add("name", "SugarModuleName");
template.add("columnname", table.getName());
stringBuilder.append(template.render());
stringBuilder.append(Utils.NewLine);
// Set properties
for (Column column : table.getColumns()) {
template = group.getInstanceOf("property");
template.add("name", column.getPropertyName());
template.add("columnname", column.getName());
stringBuilder.append(template.render());
stringBuilder.append(Utils.NewLine);
}
// Inner class end
template = group.getInstanceOf("innerClassEnd");
stringBuilder.append(template.render());
stringBuilder.append(Utils.NewLine);
stringBuilder.append(Utils.NewLine);
}
// Class end
template = group.getInstanceOf("classEnd");
stringBuilder.append(template.render());
String joinedPath = new File(destFolder, "NameOf.java").toString();
File file = new File(joinedPath);
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write(stringBuilder.toString());
bw.close();
}
示例15: generateModuleMapper
import org.stringtemplate.v4.STGroupFile; //导入方法依赖的package包/类
public static void generateModuleMapper(String destFolder) throws Exception {
ClassLoader loader = Generators.class.getClassLoader();
URL templateUrl = loader.getResource("ModuleMapperTemplate.stg");
StringBuilder stringBuilder = new StringBuilder();
STGroupFile group = getTemplateGroupFile(templateUrl.getPath());
// Class comment start
ST template = group.getInstanceOf("packageAndImport");
stringBuilder.append(template.render());
stringBuilder.append(Utils.NewLine);
// Class start
template = group.getInstanceOf("classStart");
stringBuilder.append(template.render());
stringBuilder.append(Utils.NewLine);
Map<String, String> allModules = readAllModules();
List<Table> tableList = getTables();
for (Table table : tableList) {
String tablename = table.getName();
String modulename = Utils.toPascalCase(table.getName());
if (allModules.containsKey(tablename)) {
modulename = allModules.get(tablename);
// Add to map
template = group.getInstanceOf("addToMap");
template.add("tablename", tablename);
template.add("modulename", modulename);
stringBuilder.append(template.render());
stringBuilder.append(Utils.NewLine);
}
}
// Class end
template = group.getInstanceOf("classEnd");
stringBuilder.append(template.render());
String joinedPath = new File(destFolder, "ModuleMapper.java").toString();
File file = new File(joinedPath);
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write(stringBuilder.toString());
bw.close();
}