3 public abstract class NodeWriter : Object {
6 protected JsRender file;
10 protected string inpad; // the pad for the class outer
11 protected string pad; // the padd for the methods / properties.
12 protected string ipad;
14 protected Gee.ArrayList<Node> top_level_items; // top level items (was vitems)
15 protected int cur_line;
16 protected NodeWriter top;
23 GLib.error("set called on nodewriter ret");
27 string output = ""; // the result of outputing..
29 Gee.ArrayList<string> ignoreList;
30 static Gee.ArrayList<string>? globalIgnoreList = null;
32 globalIgnoreList = new Gee.ArrayList<string>();
36 * ctor - just initializes things
37 * - wraps a render node
39 protected NodeWriter( JsRender file, Node node, int depth, NodeWriter? parent)
45 this.top_level_items = new Gee.ArrayList<Node>();
46 this.cur_line = parent == null ? 0 : parent.cur_line;
47 this.top = parent == null ? this : parent.top;
49 // initialize line data..
50 node.line_start = this.cur_line;
51 node.line_end = this.cur_line;
52 node.lines = new Gee.ArrayList<int>();
53 node.line_map = new Gee.HashMap<int,string>();
55 node.node_lines = new Gee.ArrayList<int>();
56 node.node_lines_map = new Gee.HashMap<int,Node>();
59 this.ignoreList = new Gee.ArrayList<string>();
63 //int var_name_count = 0; // was vcnt
65 string toValaNS(Node item)
67 return item.get("xns") + ".";
70 fills in all the xvala_cls names into the nodes
75 public void initPadding(char pad, int len)
78 var has_ns = this.file.xtype == "Gtk" && this.file.file_namespace.length > 0;
80 if (has_ns) { // namespaced..
81 this.inpad = string.nfill((depth > 0 ? 2 : 1)* len, pad);
83 this.inpad = string.nfill((depth > 0 ? 1 : 0) * len , pad);
85 this.pad = this.inpad + string.nfill(len, pad);
86 this.node.node_pad = this.inpad;
87 this.ipad = this.inpad + string.nfill(2* len, pad);;
92 public void toValaName(Node item, int depth =0)
96 var ns = this.toValaNS(item) ;
97 var cls = ns + item.get("xtype");
101 string id = item.get("id").length > 0 ?
102 item.get("id") : "%s%d".printf(item.get("xtype"), item.oid);
107 if (id[0] == '*' || id[0] == '+') {
108 item.xvala_xcls = "Xcls_" + id.substring(1);
110 item.xvala_xcls = "Xcls_" + id;
116 this.top_level_items.add(item);
118 // setting id on top level class changes it classname..
119 // oddly enough we havent really thought about namespacing here.
121 } else if (!item.props.has_key("id")) {
122 // use the file name..
123 item.xvala_xcls = this.file.file_without_namespace;
125 item.xvala_id = this.file.file_without_namespace;
130 if (item.readItems().size < 1) {
133 for(var i =0;i<item.readItems().size;i++) {
134 this.toValaName(item.readItems().get(i), depth+1);
139 protected void addLine(string str= "")
142 if (str.contains("\n")) {
143 this.addMultiLine(str);
148 //if (BuilderApplication.opt_bjs_compile != null) {
149 // this.output += "/*%d*/ ".printf(this.cur_line) + str + "\n";
151 this.output += str + "\n";
154 protected void addMultiLine(string str= "")
157 this.cur_line += str.split("\n").length;
158 //this.ret += "/*%d*/ ".printf(l) + str + "\n";
160 this.output += str + "\n";
162 protected string padMultiline(string pad, string str)
164 var ar = str.strip().split("\n");
165 return string.joinv("\n" + pad , ar);
167 protected static void globalIgnore(string i) {
168 if (globalIgnoreList == null) {
169 globalIgnoreList = new Gee.ArrayList<string>(); // should not happend.. but dont know about ctor process..
171 globalIgnoreList.add(i);
174 protected void ignore(string i) {
175 this.ignoreList.add(i);
179 protected bool shouldIgnore(string i)
181 return globalIgnoreList.contains(i) || ignoreList.contains(i);
186 public abstract string munge();