1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package Torello.Browser.JsonAST;

import Torello.Java.StrCSV;
import Torello.Java.UnreachableError;
import Torello.Java.ReadOnly.ReadOnlyList;

class StringTCE 
{
    static String get(final TCE tce)
    {
        final String lists = getLists(tce);

        return
            "TCE: (" + tce.name + "):\n" +
            "{\n" +

            "    API               [" + tce.ownerDomain.ownerAPI.name + "]\n" +
            "    Domain            [" + tce.ownerDomain.name           + "]\n" +
            "    TCE               [WhichTCE." + tce.which + ", " + tce.name + "]\n" +
            "    typeProp:         [" + tce.typeProp + "]\n" +
            "    propNames:        [" + StrCSV.toCSV(tce.propNames, true, true, 78) + "]\n" +
            lists +
            "}\n";
    }

    private static String getLists(final TCE tce)
    {
        if (tce instanceof TypeNode)
            return "    Fields            " + pprList(((TypeNode) tce).properties);

        if (tce instanceof EventNode)
            return "    Fields            " + pprList(((EventNode) tce).parameters);

        if (tce instanceof CommandNode) return
            "    Parameters        " + pprList(((CommandNode) tce).parameters) +
            "    Returns           " + pprList(((CommandNode) tce).returns);

        throw new UnreachableError();
    }

    private static String pprList(final ReadOnlyList<PPR> list)
    {
        if (list == null) return "<null-empty>\n";
        return '[' + StrCSV.toCSV(list, (PPR ppr) -> ppr.name, true, 78) + "]\n";
    }
}