本文整理汇总了Java中org.stringtemplate.v4.ST类的典型用法代码示例。如果您正苦于以下问题:Java ST类的具体用法?Java ST怎么用?Java ST使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ST类属于org.stringtemplate.v4包,在下文中一共展示了ST类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSpecialCaseSetupBody
import org.stringtemplate.v4.ST; //导入依赖的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: generateContent
import org.stringtemplate.v4.ST; //导入依赖的package包/类
@VisibleForTesting
String generateContent(final URL staticFile, final Api api) throws IOException {
final ST st = getStGroup(staticFile);
final String fileName = new File(staticFile.getPath()).getName();
st.add("api", new ApiGenModel(api));
if (fileName.equals("collection.json.stg")) {
st.add("id", "f367b534-c9ea-e7c5-1f46-7a27dc6a30ba");
final String readme = getStGroup(Resources.getResource("templates/postman/README.md.stg")).render();
st.add("readme", readme);
}
if (fileName.equals("template.json.stg")) {
st.add("id", "5bb74f05-5e78-4aee-b59e-492c947bc160");
}
return st.render();
}
示例3: caseObjectType
import org.stringtemplate.v4.ST; //导入依赖的package包/类
@Override
public String caseObjectType(final ObjectType objectType) {
if (objectType.getName() == null) {
return null;
} else {
final TypeGenModel typeGenModel = new TypeGenModel(objectType);
final ST st = stGroup.getInstanceOf(type);
st.add("vendorName", vendorName);
if (type.equals(TYPE_INTERFACE) || type.equals(TYPE_MODEL)) {
st.add("type", typeGenModel);
} else if (type.equals(TYPE_COLLECTION_INTERFACE) || type.equals(TYPE_COLLECTION_MODEL)) {
st.add("type", new CollectionGenModel(objectType));
}
return st.render();
}
}
示例4: generateContent
import org.stringtemplate.v4.ST; //导入依赖的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();
}
示例5: generateCodeForTable
import org.stringtemplate.v4.ST; //导入依赖的package包/类
/**
* Generates a java code file that can later be used to generate SQL insert strings for the given extractor table.
* All the data are taken from the {@link TableModel}, which was filled by a {@link com.btc.redg.generator.extractor.TableExtractor} (normally used by the
* {@link com.btc.redg.generator.extractor.MetadataExtractor})
* <p>
* For each column in this table the generated class will contain a private variable holding the value and a builder method to set the value. Foreign key
* columns will be a reference to the generated class/object for that table and need to be passed via the constructor to ensure that foreign key constraints
* are met and inserts will be in the right order. Proper {@code null}-checks will be generated.
*
* @param table The extracted table model to generate code for
* @param enableVisualizationSupport If {@code true}, the RedG visualization features will be enabled for the generated code. This will result in a small
* performance hit and slightly more memory usage if activated.
* @return The generated source code
*/
public String generateCodeForTable(final TableModel table, final boolean enableVisualizationSupport) {
final ST template = this.stGroup.getInstanceOf("tableClass");
LOG.debug("Filling template...");
template.add("table", table);
LOG.debug("Package is {} | Class name is {}", table.getPackageName(), table.getClassName());
template.add("colAndForeignKeys", table.hasColumnsAndForeignKeys());
template.add("firstRowComma", (!table.getNullableForeignKeys().isEmpty() || table.hasColumnsAndForeignKeys()) && !table.getNotNullForeignKeys().isEmpty());
template.add("secondRowComma", table.hasColumnsAndForeignKeys() && !table.getNullableForeignKeys().isEmpty());
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(table);
oos.close();
String serializedData = Base64.getEncoder().encodeToString(baos.toByteArray());
template.add("serializedTableModelString", serializedData);
} catch (IOException e) {
LOG.error("Could not serialize table model. Model will not be included in the file", e);
}
template.add("enableVisualizationSupport", enableVisualizationSupport);
LOG.debug("Rendering template...");
return template.render();
}
示例6: generateMainClass
import org.stringtemplate.v4.ST; //导入依赖的package包/类
/**
* Generates the main class used for creating the extractor objects and later generating the insert statements.
* For each passed table a appropriate creation method will be generated that will return the new object and internally add it to the list of objects that
* will be used to generate the insert strings
*
* @param tables All tables that should get a creation method in the main class
* @param enableVisualizationSupport If {@code true}, the RedG visualization features will be enabled for the generated code. This will result in a small
* performance hit and slightly more memory usage if activated.
* @return The generated source code
*/
public String generateMainClass(final Collection<TableModel> tables, final boolean enableVisualizationSupport) {
Objects.requireNonNull(tables);
//get package from the table models
final String targetPackage = ((TableModel) tables.toArray()[0]).getPackageName();
final ST template = this.stGroup.getInstanceOf("mainClass");
LOG.debug("Filling main class template containing helpers for {} classes...", tables.size());
template.add("package", targetPackage);
// TODO: make prefix usable
template.add("prefix", "");
template.add("enableVisualizationSupport", enableVisualizationSupport);
LOG.debug("Package is {} | Prefix is {}", targetPackage, "");
template.add("tables", tables);
return template.render();
}
示例7: generateKitchenConfig
import org.stringtemplate.v4.ST; //导入依赖的package包/类
/**
* Generate the kitchen yaml string for given local/remote work-order.
*
* @param wo work order.
* @param sshKey ssh key path for the work order.
* @param logKey log key
* @return kitchen yaml string for the work-order.
*/
public String generateKitchenConfig(CmsWorkOrderSimpleBase wo, String sshKey, String logKey) {
String inductorHome = config.getCircuitDir().replace("/packer", "");
ST st = new ST(verifyTemplate);
boolean isWin = isWinCompute(wo);
String chefSolo = isWin ? "c:/opscode/chef/embedded/bin/chef-solo" : "/usr/local/bin/chef-solo";
String rubyBindir = isWin ? "c:/opscode/chef/embedded/bin" : "/usr/bin";
String provisionerPath = isWin ? "c:/tmp/kitchen" : "/tmp/kitchen";
st.add("local", !isRemoteChefCall(wo));
st.add("circuit_root", getCircuitDir(wo));
st.add("inductor_home", inductorHome);
st.add("recipe_name", wo.getAction());
st.add("driver_host", getHost(wo, logKey));
st.add("platform_name", "centos-7.1");
st.add("user", ONEOPS_USER);
st.add("ssh_key", sshKey);
st.add("windows", isWin);
st.add("chef_solo_path", chefSolo);
st.add("ruby_bindir", rubyBindir);
st.add("provisioner_root_path", provisionerPath);
st.add("verifier_root_path", getVerifierPath(wo));
return st.render();
}
示例8: render
import org.stringtemplate.v4.ST; //导入依赖的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);
}
}
示例9: generateFeatureScenario
import org.stringtemplate.v4.ST; //导入依赖的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);
}
}
}
示例10: generateComponentDetail
import org.stringtemplate.v4.ST; //导入依赖的package包/类
private void generateComponentDetail(File outputDir, ComponentType component) throws IOException {
ST stComponentStart;
if (component instanceof GroupType) {
stComponentStart = stGroup.getInstanceOf("groupStart");
} else {
stComponentStart = stGroup.getInstanceOf("componentStart");
}
stComponentStart.add("component", component);
ST stComponentEnd = stGroup.getInstanceOf("componentEnd");
stComponentEnd.add("component", component);
File outputFile = new File(outputDir, String.format("%s.html", component.getName()));
List<Object> members = component.getComponentRefOrGroupRefOrFieldRef();
try (OutputStreamWriter fileWriter =
new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8")) {
NoIndentWriter writer = new NoIndentWriter(fileWriter);
stComponentStart.write(writer, templateErrorListener);
generateMembers(members, writer);
stComponentEnd.write(writer, templateErrorListener);
}
}
示例11: evaluate
import org.stringtemplate.v4.ST; //导入依赖的package包/类
@Override
public ReflexValue evaluate(IReflexDebugger debugger, Scope scope) {
debugger.stepStart(this, scope);
ReflexValue template = templateNode.evaluate(debugger, scope);
ReflexValue params = paramsNode.evaluate(debugger, scope);
if (template.isString() && params.isMap()) {
ST t = new ST(template.asString());
Map<String, Object> paramMap = KernelExecutor.convert(params.asMap());
for (Map.Entry<String, Object> param : paramMap.entrySet()) {
String key = param.getKey();
Object value = param.getValue();
t.add(key, value.toString());
}
String ret = t.render();
ReflexValue retVal = new ReflexValue(ret);
debugger.stepEnd(this, retVal, scope);
return retVal;
} else {
throw new ReflexException(lineNumber, "Need a string and a param map");
}
}
示例12: getProperty
import org.stringtemplate.v4.ST; //导入依赖的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;
}
示例13: lexerCommand
import org.stringtemplate.v4.ST; //导入依赖的package包/类
@Override
public Handle lexerCommand(GrammarAST ID) {
LexerAction lexerAction = createLexerAction(ID, null);
if (lexerAction != null) {
return action(ID, lexerAction);
}
// fall back to standard action generation for the command
ST cmdST = codegenTemplates.getInstanceOf("Lexer" +
CharSupport.capitalize(ID.getText()) +
"Command");
if (cmdST == null) {
g.tool.errMgr.grammarError(ErrorType.INVALID_LEXER_COMMAND, g.fileName, ID.token, ID.getText());
return epsilon(ID);
}
if (cmdST.impl.formalArguments != null && cmdST.impl.formalArguments.containsKey("arg")) {
g.tool.errMgr.grammarError(ErrorType.MISSING_LEXER_COMMAND_ARGUMENT, g.fileName, ID.token, ID.getText());
return epsilon(ID);
}
return action(cmdST.render());
}
示例14: getProperty
import org.stringtemplate.v4.ST; //导入依赖的package包/类
@Override
public synchronized Object getProperty(Interpreter interp, ST self, Object o, Object property, String propertyName) throws STNoSuchPropertyException {
if ( o==null ) {
throw new NullPointerException("o");
}
Class<?> c = o.getClass();
if ( property==null ) {
return throwNoSuchProperty(c, propertyName, null);
}
Member member = findMember(c, propertyName);
if ( member!=null ) {
try {
if ( member instanceof Method ) {
return ((Method)member).invoke(o);
}
else if ( member instanceof Field ) {
return ((Field)member).get(o);
}
}
catch (Exception e) {
throwNoSuchProperty(c, propertyName, e);
}
}
return throwNoSuchProperty(c, propertyName, null);
}
示例15: getProperty
import org.stringtemplate.v4.ST; //导入依赖的package包/类
@Override
public synchronized Object getProperty(Interpreter interp, ST self, Object o, Object property, String propertyName) throws STNoSuchPropertyException {
if ( o==null ) {
throw new NullPointerException("o");
}
Class<?> c = o.getClass();
if ( property==null ) {
return throwNoSuchProperty(c, propertyName, null);
}
Member member = findMember(c, propertyName);
if ( member!=null ) {
try {
if ( member instanceof Method ) {
return ((Method)member).invoke(o);
}
else if ( member instanceof Field ) {
return ((Field)member).get(o);
}
}
catch (Exception e) {
throwNoSuchProperty(c, propertyName, e);
}
}
return throwNoSuchProperty(c, propertyName, null);
}