本文整理汇总了Java中org.antlr.stringtemplate.StringTemplate.toString方法的典型用法代码示例。如果您正苦于以下问题:Java StringTemplate.toString方法的具体用法?Java StringTemplate.toString怎么用?Java StringTemplate.toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.antlr.stringtemplate.StringTemplate
的用法示例。
在下文中一共展示了StringTemplate.toString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toString
import org.antlr.stringtemplate.StringTemplate; //导入方法依赖的package包/类
/**
* @return the text of a Type<T> object for the T class.
*/
@Override
public String toString() {
StringTemplate t = template.getInstanceOf("type");
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("typeName", this.typeName);
map.put("package", this.typePackage);
map.put("orders", this.typeOrders);
map.put("fields", this.typeFields);
boolean containsArray = false;
for (Field f : typeFields) {
containsArray = containsArray || f.isArray;
}
map.put("containsArray", containsArray);
t.setAttributes(map);
return t.toString();
}
示例2: testFullyQualifiedRefToCurrentRuleRetVal
import org.antlr.stringtemplate.StringTemplate; //导入方法依赖的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());
}
示例3: toString
import org.antlr.stringtemplate.StringTemplate; //导入方法依赖的package包/类
/**
* Returns the text of a Type<T> object for the T class.
*/
@Override
public String toString() {
StringTemplate t = template.getInstanceOf("type");
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("typeName", this.typeName);
map.put("package", this.typePackage);
map.put("orders", this.typeOrders);
map.put("fields", this.typeFields);
boolean containsArray = false;
for (Field f : typeFields) {
containsArray = containsArray || f.isArray;
}
map.put("containsArray", containsArray);
t.setAttributes(map);
return t.toString();
}
示例4: testReuseExistingListLabelWithImplicitRuleLabel
import org.antlr.stringtemplate.StringTemplate; //导入方法依赖的package包/类
public void testReuseExistingListLabelWithImplicitRuleLabel() throws Exception {
String action = "$r.start;";
String expecting = "((Token)x.start);";
ErrorQueue equeue = new ErrorQueue();
ErrorManager.setErrorListener(equeue);
Grammar g = new Grammar(
"grammar t;\n"+
"options {output=AST;}\n" +
"a : x+=r {###"+action+"!!!} ;" +
"r : 'a';\n");
Tool antlr = newTool();
antlr.setOutputDirectory(null); // write to /dev/null
CodeGenerator generator = new CodeGenerator(antlr, g, "Java");
g.setCodeGenerator(generator);
generator.genRecognizer();
StringTemplate codeST = generator.getRecognizerST();
String code = codeST.toString();
String found = code.substring(code.indexOf("###")+3,code.indexOf("!!!"));
assertEquals(expecting, found);
assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size());
}
示例5: getDOT
import org.antlr.stringtemplate.StringTemplate; //导入方法依赖的package包/类
/** Return a String containing a DOT description that, when displayed,
* will show the incoming state machine visually. All nodes reachable
* from startState will be included.
*/
public String getDOT(State startState) {
// The output DOT graph for visualization
StringTemplate dot = null;
markedStates = new HashSet();
if ( startState instanceof DFAState ) {
dot = stlib.getInstanceOf("org/antlr/tool/templates/dot/dfa");
dot.setAttribute("startState",
Utils.integer(startState.stateNumber));
dot.setAttribute("useBox",
Boolean.valueOf(Tool.internalOption_ShowNFConfigsInDFA));
walkCreatingDFADOT(dot, (DFAState)startState);
}
else {
dot = stlib.getInstanceOf("org/antlr/tool/templates/dot/nfa");
dot.setAttribute("startState",
Utils.integer(startState.stateNumber));
walkRuleNFACreatingDOT(dot, startState);
}
dot.setAttribute("rankdir", rankdir);
return dot.toString();
}
示例6: testFormWithTextFieldNoValidations
import org.antlr.stringtemplate.StringTemplate; //导入方法依赖的package包/类
@Test
public void testFormWithTextFieldNoValidations() throws SAXException,
IOException {
ActionScriptType entityType = new ActionScriptType("com.foo.Person");
StringTemplate listViewTemplate = templateGroup
.getInstanceOf("org/gvnix/flex/roo/addon/ui/entity_form");
listViewTemplate.setAttribute("entityType", entityType);
listViewTemplate.setAttribute("flexScaffoldMetadata",
flexScaffoldMetadata);
List<FieldMetadata> elegibleFields = new ArrayList<FieldMetadata>();
FieldMetadata field = new FieldMetadataBuilder("MID:person#1",
Modifier.PRIVATE, new JavaSymbolName("name"),
JavaType.STRING_OBJECT, null).build();
elegibleFields.add(field);
listViewTemplate.setAttribute("fields",
FlexUIMetadataProvider.wrapFields(elegibleFields));
String result = listViewTemplate.toString();
log.debug(result);
assertFalse(result.contains("mx:StringValidator"));
assertTrue(result.contains("s:TextInput"));
ByteArrayInputStream stream = new ByteArrayInputStream(
result.getBytes("UTF-8"));
XmlUtils.getDocumentBuilder().parse(stream);
}
示例7: testFormWithTextFieldSingleValidation
import org.antlr.stringtemplate.StringTemplate; //导入方法依赖的package包/类
@Test
public void testFormWithTextFieldSingleValidation() throws SAXException,
IOException {
ActionScriptType entityType = new ActionScriptType("com.foo.Person");
StringTemplate listViewTemplate = templateGroup
.getInstanceOf("org/gvnix/flex/roo/addon/ui/entity_form");
listViewTemplate.setAttribute("entityType", entityType);
listViewTemplate.setAttribute("flexScaffoldMetadata",
flexScaffoldMetadata);
List<FieldMetadata> elegibleFields = new ArrayList<FieldMetadata>();
AnnotationMetadataBuilder annotation = new AnnotationMetadataBuilder(
new JavaType("javax.validation.constraints.NotNull"),
Collections.EMPTY_LIST);
FieldMetadata field = new FieldMetadataBuilder("MID:person#1",
Modifier.PRIVATE, Collections.singletonList(annotation),
new JavaSymbolName("name"), JavaType.STRING_OBJECT).build();
elegibleFields.add(field);
listViewTemplate.setAttribute("fields",
FlexUIMetadataProvider.wrapFields(elegibleFields));
String result = listViewTemplate.toString();
log.debug(result);
assertTrue(result.contains("mx:StringValidator"));
assertTrue(result.contains("s:TextInput"));
ByteArrayInputStream stream = new ByteArrayInputStream(
result.getBytes("UTF-8"));
XmlUtils.getDocumentBuilder().parse(stream);
}
示例8: testFormWithTextFieldMultipleValidations
import org.antlr.stringtemplate.StringTemplate; //导入方法依赖的package包/类
@Test
public void testFormWithTextFieldMultipleValidations() throws SAXException,
IOException {
ActionScriptType entityType = new ActionScriptType("com.foo.Person");
StringTemplate listViewTemplate = templateGroup
.getInstanceOf("org/gvnix/flex/roo/addon/ui/entity_form");
listViewTemplate.setAttribute("entityType", entityType);
listViewTemplate.setAttribute("flexScaffoldMetadata",
flexScaffoldMetadata);
List<FieldMetadata> elegibleFields = new ArrayList<FieldMetadata>();
AnnotationMetadataBuilder annotation1 = new AnnotationMetadataBuilder(
new JavaType("javax.validation.constraints.NotNull"),
Collections.EMPTY_LIST);
List<AnnotationAttributeValue<?>> attrs = new ArrayList<AnnotationAttributeValue<?>>();
attrs.add(new IntegerAttributeValue(new JavaSymbolName("min"), 2));
AnnotationMetadataBuilder annotation2 = new AnnotationMetadataBuilder(
new JavaType("javax.validation.constraints.Size"), attrs);
List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
annotations.add(annotation1);
annotations.add(annotation2);
FieldMetadata field = new FieldMetadataBuilder("MID:person#1",
Modifier.PRIVATE, annotations, new JavaSymbolName("name"),
JavaType.STRING_OBJECT).build();
elegibleFields.add(field);
listViewTemplate.setAttribute("fields",
FlexUIMetadataProvider.wrapFields(elegibleFields));
String result = listViewTemplate.toString();
log.debug(result);
assertTrue(result.contains("mx:StringValidator"));
assertTrue(result.contains("s:TextInput"));
ByteArrayInputStream stream = new ByteArrayInputStream(
result.getBytes("UTF-8"));
XmlUtils.getDocumentBuilder().parse(stream);
}
示例9: testFormWithNumberFieldNoValidations
import org.antlr.stringtemplate.StringTemplate; //导入方法依赖的package包/类
@Test
public void testFormWithNumberFieldNoValidations() throws SAXException,
IOException {
ActionScriptType entityType = new ActionScriptType("com.foo.Person");
StringTemplate listViewTemplate = templateGroup
.getInstanceOf("org/gvnix/flex/roo/addon/ui/entity_form");
listViewTemplate.setAttribute("entityType", entityType);
listViewTemplate.setAttribute("flexScaffoldMetadata",
flexScaffoldMetadata);
List<FieldMetadata> elegibleFields = new ArrayList<FieldMetadata>();
FieldMetadata field = new FieldMetadataBuilder("MID:person#1",
Modifier.PRIVATE, new JavaSymbolName("age"),
JavaType.INT_OBJECT, null).build();
elegibleFields.add(field);
listViewTemplate.setAttribute("fields",
FlexUIMetadataProvider.wrapFields(elegibleFields));
String result = listViewTemplate.toString();
log.debug(result);
assertFalse(result.contains("mx:NumberValidator"));
assertTrue(result.contains("s:TextInput"));
ByteArrayInputStream stream = new ByteArrayInputStream(
result.getBytes("UTF-8"));
XmlUtils.getDocumentBuilder().parse(stream);
}
示例10: testFormWithNumberFieldSingleValidation
import org.antlr.stringtemplate.StringTemplate; //导入方法依赖的package包/类
@Test
public void testFormWithNumberFieldSingleValidation() throws SAXException,
IOException {
ActionScriptType entityType = new ActionScriptType("com.foo.Person");
StringTemplate listViewTemplate = templateGroup
.getInstanceOf("org/gvnix/flex/roo/addon/ui/entity_form");
listViewTemplate.setAttribute("entityType", entityType);
listViewTemplate.setAttribute("flexScaffoldMetadata",
flexScaffoldMetadata);
List<FieldMetadata> elegibleFields = new ArrayList<FieldMetadata>();
AnnotationMetadataBuilder annotation = new AnnotationMetadataBuilder(
new JavaType("javax.validation.constraints.NotNull"),
Collections.EMPTY_LIST);
FieldMetadata field = new FieldMetadataBuilder("MID:person#1",
Modifier.PRIVATE, Collections.singletonList(annotation),
new JavaSymbolName("age"), JavaType.INT_OBJECT).build();
elegibleFields.add(field);
listViewTemplate.setAttribute("fields",
FlexUIMetadataProvider.wrapFields(elegibleFields));
String result = listViewTemplate.toString();
log.debug(result);
assertTrue(result.contains("mx:NumberValidator"));
assertTrue(result.contains("s:TextInput"));
ByteArrayInputStream stream = new ByteArrayInputStream(
result.getBytes("UTF-8"));
XmlUtils.getDocumentBuilder().parse(stream);
}
示例11: testFormWithNumberFieldMultipleValidations
import org.antlr.stringtemplate.StringTemplate; //导入方法依赖的package包/类
@Test
public void testFormWithNumberFieldMultipleValidations()
throws SAXException, IOException {
ActionScriptType entityType = new ActionScriptType("com.foo.Person");
StringTemplate listViewTemplate = templateGroup
.getInstanceOf("org/gvnix/flex/roo/addon/ui/entity_form");
listViewTemplate.setAttribute("entityType", entityType);
listViewTemplate.setAttribute("flexScaffoldMetadata",
flexScaffoldMetadata);
List<FieldMetadata> elegibleFields = new ArrayList<FieldMetadata>();
AnnotationMetadataBuilder annotation1 = new AnnotationMetadataBuilder(
new JavaType("javax.validation.constraints.NotNull"),
Collections.EMPTY_LIST);
List<AnnotationAttributeValue<?>> attrs = new ArrayList<AnnotationAttributeValue<?>>();
attrs.add(new IntegerAttributeValue(new JavaSymbolName("value"), 2));
AnnotationMetadataBuilder annotation2 = new AnnotationMetadataBuilder(
new JavaType("javax.validation.constraints.Min"), attrs);
List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
annotations.add(annotation1);
annotations.add(annotation2);
FieldMetadata field = new FieldMetadataBuilder("MID:person#1",
Modifier.PRIVATE, annotations, new JavaSymbolName("name"),
JavaType.INT_OBJECT).build();
elegibleFields.add(field);
listViewTemplate.setAttribute("fields",
FlexUIMetadataProvider.wrapFields(elegibleFields));
String result = listViewTemplate.toString();
log.debug(result);
assertTrue(result.contains("mx:NumberValidator"));
assertTrue(result.contains("s:TextInput"));
ByteArrayInputStream stream = new ByteArrayInputStream(
result.getBytes("UTF-8"));
XmlUtils.getDocumentBuilder().parse(stream);
}
示例12: testFormWithDateFieldNoValidations
import org.antlr.stringtemplate.StringTemplate; //导入方法依赖的package包/类
@Test
public void testFormWithDateFieldNoValidations() throws SAXException,
IOException {
ActionScriptType entityType = new ActionScriptType("com.foo.Person");
StringTemplate listViewTemplate = templateGroup
.getInstanceOf("org/gvnix/flex/roo/addon/ui/entity_form");
listViewTemplate.setAttribute("entityType", entityType);
listViewTemplate.setAttribute("flexScaffoldMetadata",
flexScaffoldMetadata);
List<FieldMetadata> elegibleFields = new ArrayList<FieldMetadata>();
FieldMetadata field = new FieldMetadataBuilder("MID:person#1",
Modifier.PRIVATE, new JavaSymbolName("birthday"), new JavaType(
"java.util.Date"), null).build();
elegibleFields.add(field);
listViewTemplate.setAttribute("fields",
FlexUIMetadataProvider.wrapFields(elegibleFields));
String result = listViewTemplate.toString();
log.debug(result);
assertFalse(result.contains("mx:DateValidator"));
assertTrue(result.contains("mx:DateField"));
ByteArrayInputStream stream = new ByteArrayInputStream(
result.getBytes("UTF-8"));
XmlUtils.getDocumentBuilder().parse(stream);
}
示例13: testFormWithDateFieldSingleValidation
import org.antlr.stringtemplate.StringTemplate; //导入方法依赖的package包/类
@Test
public void testFormWithDateFieldSingleValidation() throws SAXException,
IOException {
ActionScriptType entityType = new ActionScriptType("com.foo.Person");
StringTemplate listViewTemplate = templateGroup
.getInstanceOf("org/gvnix/flex/roo/addon/ui/entity_form");
listViewTemplate.setAttribute("entityType", entityType);
listViewTemplate.setAttribute("flexScaffoldMetadata",
flexScaffoldMetadata);
List<FieldMetadata> elegibleFields = new ArrayList<FieldMetadata>();
AnnotationMetadataBuilder annotation = new AnnotationMetadataBuilder(
new JavaType("javax.validation.constraints.NotNull"),
Collections.EMPTY_LIST);
FieldMetadata field = new FieldMetadataBuilder("MID:person#1",
Modifier.PRIVATE, Collections.singletonList(annotation),
new JavaSymbolName("birthday"), new JavaType("java.util.Date"))
.build();
elegibleFields.add(field);
listViewTemplate.setAttribute("fields",
FlexUIMetadataProvider.wrapFields(elegibleFields));
String result = listViewTemplate.toString();
log.debug(result);
assertTrue(result.contains("mx:DateValidator"));
assertTrue(result.contains("mx:DateField"));
ByteArrayInputStream stream = new ByteArrayInputStream(
result.getBytes("UTF-8"));
XmlUtils.getDocumentBuilder().parse(stream);
}
示例14: test0IndexedGlobalScope
import org.antlr.stringtemplate.StringTemplate; //导入方法依赖的package包/类
public void test0IndexedGlobalScope() throws Exception {
String action = "$Symbols[0]::names.add($id.text);";
String expecting =
"((Symbols_scope)Symbols_stack.elementAt(0)).names.add(id.getText());";
ErrorQueue equeue = new ErrorQueue();
ErrorManager.setErrorListener(equeue);
Grammar g = new Grammar(
"grammar t;\n"+
"scope Symbols {\n" +
" int n;\n" +
" List names;\n" +
"}\n" +
"a scope Symbols; : (id=ID ';' {"+action+"} )+\n" +
" ;\n" +
"ID : 'a';\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());
}
示例15: testIsolatedGlobalScopeRef
import org.antlr.stringtemplate.StringTemplate; //导入方法依赖的package包/类
public void testIsolatedGlobalScopeRef() throws Exception {
String action = "$Symbols;";
String expecting = "Symbols_stack;";
ErrorQueue equeue = new ErrorQueue();
ErrorManager.setErrorListener(equeue);
Grammar g = new Grammar(
"grammar t;\n"+
"scope Symbols {\n" +
" String x;\n" +
"}\n" +
"a\n"+
"scope { int y; }\n"+
"scope Symbols;\n" +
" : b {"+action+"}\n" +
" ;\n" +
"b : ID {$Symbols::x=$ID.text} ;\n" +
"ID : 'a';\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());
}