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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152 | package Torello.Browser.JsonAST;
import static Torello.Java.C.RESET;
import static Torello.Java.C.BYELLOW;
import java.io.IOException;
import Torello.Java.FileRW;
import Torello.Java.StorageWriter;
import Torello.Java.Additional.Ret2;
import Torello.Java.ReadOnly.ReadOnlyList;
import Torello.Java.ReadOnly.ROArrayListBuilder;
import Torello.Java.UnreachableError;
/**
* This is a "Cute Little Tree Walk" or "Tree Traversal" class that simply iterates every single
* node inside of an AST, and fills the {@link InfoData} with the relevant facts that are needed
* to buid an {@link InfoData} object.
*
* <BR /><BR />There is absolutely nothing complicated going on here. This class just "traverses"
* an AST, and then calls & invokes all of the Data Collection Methods that are exposed inside
* of the {@code InfoData} class.
*
* <BR /><BR />
* For all intents and purposes, this class functions as "the constructor" for the {@link InfoData}
* class. It actually iterates the nodes in the Abstract Syntax Tree and builds the data-lists
* which are eventually stored into an instance of class {@link InfoData}. No more, no less.
*
* @see InfoData
*/
@Torello.JavaDoc.Annotations.StaticFunctional
@Torello.JavaDoc.Annotations.JDHeaderBackgroundImg(EmbedTagFileID="SERIALIZER_JDHBI")
public class ExtraData
{
private ExtraData() { }
// ********************************************************************************************
// ********************************************************************************************
// Simple String Constants
// ********************************************************************************************
// ********************************************************************************************
private static final String FS = java.io.File.separator;
private static final String DIR =
"Torello" + FS + "Browser" + FS + "CodeGen" + FS + "FILE" + FS;
/**
* The package {@code Torello.Browser} uses this filename for event processing
* @see Torello.Browser.MarkerEvent
* @see Torello.Browser.BrowserEvent
*/
public static final String MARKER_EVENT_TYPES_DATA_FILE_NAME =
"Torello" + FS + "Browser" + FS + "data-files" + FS + "marker-events.roldat";
// ********************************************************************************************
// ********************************************************************************************
// Top-Level "Run" (or "main") Method. This method is "Package Private"
// ********************************************************************************************
// ********************************************************************************************
static Ret2<InfoData, InfoData> run(
final StorageWriter sw,
final API browser,
final API js
)
throws IOException
{
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
// Traverse the AST built for the CDP "Browser API"; and shove everything into the Builder
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
InfoData.Builder b = InfoData.builder();
traverseTree(browser, b);
final InfoData browserData = b.build();
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
// Traverse the AST built for the CDP "JavaScript API"; add stuff to the Builder
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
b = InfoData.builder();
traverseTree(js, b);
final InfoData jsData = b.build();
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
// There is an actual data-file that is needed (and used in real time) by Torello.Browser
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
//
// Write the "Marker Event" (Events without any fields or "parameters") to a data file
final ReadOnlyList<String> meROL = markerEventsSeparateDataFile(browserData, jsData);
sw.println("Writing File: " + BYELLOW + MARKER_EVENT_TYPES_DATA_FILE_NAME + RESET);
FileRW.writeObjectToFileNOCNFE(meROL, MARKER_EVENT_TYPES_DATA_FILE_NAME, true);
// Return the two instances of "InfoData" in a Ret2
return new Ret2<>(browserData, jsData);
}
// ********************************************************************************************
// ********************************************************************************************
// Traverse the complete Abstract Syntax Tree (AST) - PRIVATE METHODS
// ********************************************************************************************
// ********************************************************************************************
private static void traverseTree(final API api, final InfoData.Builder b)
{ for (final Domain d : api.domains) traverseTree(d, b); }
private static void traverseTree(final Domain d, final InfoData.Builder b)
{
for (final TypeNode tn : d.types)
if (tn.enumVals != null) b.enumValType(tn);
else if (tn.isReifiedInnerClass) b.reifiedInnerType(tn);
else b.simpleType(tn);
for (final CommandNode cn : d.commands)
if (cn.hasReifiedRetInnerClass) b.reifiedReturnType(cn);
for (final EventNode en : d.events)
if (en.isReifiedInnerClass) b.reifiedEvent(en);
else b.markerEvent(en);
}
private static ReadOnlyList<String> markerEventsSeparateDataFile
(final InfoData browserData, final InfoData jsData)
{
ROArrayListBuilder<String> roalb = new ROArrayListBuilder<>();
for (final EventNode en : browserData.markerEventNodes)
roalb.add(en.ownerDomain.name + '.' + en.name);
for (final EventNode en : jsData.markerEventNodes)
roalb.add(en.ownerDomain.name + '.' + en.name);
return roalb.build();
}
}
|