好的,我的问题是如何将包org.antlr.stringtemplate.StringTemplate toDOT(Tree tree)中的StringTemplate toDot(Tree tree)更改为或者以其他方式更改
我的代码就像这样
DOTTreeGenerator gen = new DOTTreeGenerator();
StringTemplate st = gen.toDOT(tree);
所以,它生成.dot文件,但我想改变模板的大小
digraph {
ordering=out;
ranksep=.4;
node [shape=plaintext, fixedsize=true, fontsize=11, fontname="Courier",
width=.25, height=.25];
edge [arrowsize=.5]
n0 [label=""];
n1 [label="ANNOTATION_LIST"];
n2 [label="package"];
n2 [label="package"];
n3 [label="Buat_Test_file"];
n4 [label=";"];
n5 [label="MODIFIER_LIST"];
n5 [label="MODIFIER_LIST"];
n6 [label="public"];
n7 [label="class"];
n7 [label="class"];
n5 [label="MODIFIER_LIST"];
n5 [label="MODIFIER_LIST"];
n6 [label="public"];
n8 [label="Gilang"];
n9 [label="CLASS_TOP_LEVEL_SCOPE"];
n0 -> n1 // "" -> "ANNOTATION_LIST"
n0 -> n2 // "" -> "package"
n2 -> n3 // "package" -> "Buat_Test_file"
n2 -> n4 // "package" -> ";"
n0 -> n5 // "" -> "MODIFIER_LIST"
n5 -> n6 // "MODIFIER_LIST" -> "public"
n0 -> n7 // "" -> "class"
n7 -> n5 // "class" -> "MODIFIER_LIST"
n5 -> n6 // "MODIFIER_LIST" -> "public"
n7 -> n8 // "class" -> "Gilang"
n7 -> n9 // "class" -> "CLASS_TOP_LEVEL_SCOPE"
}
我想改变宽度,高度和边缘。
非常感谢...
答案 0 :(得分:1)
负责输出的StringTemplate
是public
static
和DOTTreeGenerator
内的public class DOTTreeGenerator {
public static StringTemplate _treeST =
new StringTemplate(
"digraph {\n\n" +
"\tordering=out;\n" +
"\tranksep=.4;\n" +
"\tbgcolor=\"lightgrey\"; node [shape=box, fixedsize=false, fontsize=12, fontname=\"Helvetica-bold\", fontcolor=\"blue\"\n" +
"\t\twidth=.25, height=.25, color=\"black\", fillcolor=\"white\", style=\"filled, solid, bold\"];\n" +
"\tedge [arrowsize=.5, color=\"black\", style=\"bold\"]\n\n" +
" $nodes$\n" +
" $edges$\n" +
"}\n");
...
}
:
double width = 0.5;
double height = 0.5;
Strign edge = "[arrowsize=.7, color=\"red\", style=\"bold\"]";
DOTTreeGenerator._treeST = new StringTemplate(
"digraph {\n\n" +
"\tordering=out;\n" +
"\tranksep=.4;\n" +
"\tbgcolor=\"lightgrey\"; node [shape=box, fixedsize=false, fontsize=12, fontname=\"Helvetica-bold\", fontcolor=\"blue\"\n" +
"\t\twidth=" + width + ", height=" + height + ", color=\"black\", fillcolor=\"white\", style=\"filled, solid, bold\"];\n" +
"\tedge " + edge + "\n\n" +
" $nodes$\n" +
" $edges$\n" +
"}\n");
DOTTreeGenerator gen = new DOTTreeGenerator();
StringTemplate st = gen.toDOT(...);
...
换句话说:只需在打印树之前更改模板:
{{1}}