Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

38
LINES

< > BotCompany Repo | #1005466 // printConceptGraph

JavaX fragment (include)

1  
sbool printConceptGraph_showIDs;
2  
3  
static void printConceptGraph(Concept c) {
4  
  printConceptGraph_impl(c, 0, "", new IdentityHashMap);
5  
}
6  
7  
static void printConceptGraph_impl(Concept c, int indent, S prefix, IdentityHashMap seen) {
8  
  bool isSeen = seen.containsKey(c);
9  
  seen.put(c, c);
10  
  
11  
  StringBuilder buf = new StringBuilder;
12  
  buf.append(prefix);
13  
  S cname = dynamicShortName(c);
14  
  if (eq(cname, "Str"))
15  
    buf.append("Str " + quote(cget(c, "name")));
16  
  else {
17  
    buf.append(cname);
18  
    if (printConceptGraph_showIDs)
19  
      buf.append(" [" + c.id + (isSeen ? ", seen" : "") + "]");
20  
    else if (isSeen)
21  
      buf.append(" [seen]");
22  
    for (S field : conceptFields(c)) {
23  
      O val = cget(c, field);
24  
      if (val != null && !val instanceof Concept)
25  
        buf.append(" " + field + "=" + struct(val));
26  
    }
27  
  }
28  
  
29  
  printIndent(indent, buf);
30  
  if (isSeen) ret;
31  
  
32  
  L<S> names = dynGetRefNames(c);
33  
  for (S name : names) {
34  
    Concept val = cast cget(c, name);
35  
    if (eq(name, "_if")) name = "if"; // prettify
36  
    printConceptGraph_impl(val, indent + 2, l(names) == 1 ? "" : name + "=", seen);
37  
  }
38  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1005466
Snippet name: printConceptGraph
Eternal ID of this version: #1005466/1
Text MD5: 1fc41bf3e476776522d173dc96c2d45c
Author: stefan
Category: javax / concepts
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-11-20 13:32:08
Source code size: 1145 bytes / 38 lines
Pitched / IR pitched: No / No
Views / Downloads: 526 / 515
Referenced in: [show references]