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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208 | package Torello.Browser.JsonAST;
import Torello.JavaDoc.Annotations.LinkJavaSource;
import Torello.JavaDoc.Annotations.JDHeaderBackgroundImg;
import Torello.Java.ReadOnly.ReadOnlyList;
import Torello.Java.ReadOnly.ReadOnlyMap;
import Torello.Java.ReadOnly.ReadOnlySet;
import Torello.Java.ReadOnly.ReadOnlyTreeSet;
import Torello.Browser.CDPTypes;
import javax.json.JsonObject;
import java.io.IOException;
import java.util.Iterator;
import java.util.Objects;
/**
* An Java Object used within AST to symbolize or encapsulate the data present in any of the
* {@link JsonObject JsonObject's} found within a {@link Domain Domain's} {@code "types"} array.
*
* <EMBED CLASS='external-html' DATA-FILE-ID=AST_TREES>
*/
@JDHeaderBackgroundImg(EmbedTagFileID="AST_NODES_JDHBI")
public class TypeNode extends TCE implements java.io.Serializable, Iterable<PPR>
{
// ********************************************************************************************
// ********************************************************************************************
// STATIC FINAL FIELDS
// ********************************************************************************************
// ********************************************************************************************
/** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */
protected static final long serialVersionUID = 1;
/**
* The list of additional {@link JsonObject} properties that the parser should expect when
* parsing {@code TypeNode} objects from the JSON CDP specification files.
*/
protected static final ReadOnlySet<String> TYPE_JSON_PROPERTIES_SET =
new ReadOnlyTreeSet<>(String::compareTo, "id", "properties");
// ********************************************************************************************
// ********************************************************************************************
// Constant & Final Instance-Fields (Set by the Constructor)
// ********************************************************************************************
// ********************************************************************************************
/**
* Collection of PPR (Property) instances that will be materialized as Java class fields.
* <EMBED CLASS='external-html' DATA-FILE-ID=TypeNode.properties>
*/
public final ReadOnlyList<PPR> properties;
/**
* Flag indicating whether this TypeNode represents a reified inner class in the CDP model.
* <EMBED CLASS='external-html' DATA-FILE-ID=TypeNode.isReifiedInnerClass>
*/
public final boolean isReifiedInnerClass;
/**
* <B>{@code CTAS:} Computed Type as String:</B> is a field which summarizing this TypeNode’s
* resolved Java Type.
*
* <EMBED CLASS='external-html' DATA-FILE-ID=TypeNode.CTAS>
*
* @see CTAB
*/
public final String CTAS;
/**
* <B>{@code CTAB:} Computed Type as Byte:</B> identical to {@link #CTAS}; however the
* information is encoded as a {@code 'byte'} primitive as per the list of types exposed in
* class {@link CDPTypes}.
*
* @see CTAS
* @see CDPTypes
* @see CDPTypes#ctasToByte(String)
*/
public final byte CTAB;
// ********************************************************************************************
// ********************************************************************************************
// Constructor
// ********************************************************************************************
// ********************************************************************************************
// Constructs a class that represents a Java-Script 'type', 'command' or 'event'
TypeNode(
// The domain to which this 'type', 'command' or 'event' belongs
final Domain parent,
// The JSON Object representation of this 'TCE'
final JsonObject jo,
// The JSON Array index from which this JSON Object was retrieved.
final int index
)
{
super(
parent,
jo,
WhichTCE.Type,
TYPE_JSON_PROPERTIES_SET,
index
);
this.properties = Helper$GetPPRLists.get(this, jo, WhichPPR.Property);
this.isReifiedInnerClass = (this.properties != null);
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
// Simple Error Check, Part 1
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
// TypeNode → **MUST** have a "type" JsonProperty ==> 100% pass / TRUE / invariant
if (this.typeProp == null)
verifyThrow("TypeNode (TCE) does not declare a \"type\" Json property.");
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
// CTAS: Computed Type As String
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
if (this.isReifiedInnerClass)
this.CTAS = this.ownerDomain.name + '.' + this.name;
else if (this.arrItemsTypeProp != null)
this.CTAS = this.arrItemsTypeProp.primCTAS.getSimpleName();
else if (this.typeProp == TypeProp.ARRAY)
{
// DOMSnapShot.ArrayOfStrings ==> int[]
// Target.TargetFilter ==> FilterEntry[]
if (SPECIAL_CASES$TypeNode.ARRAY_OF_REF_TYPES.containsKey(this.name))
this.CTAS = SPECIAL_CASES$TypeNode.ARRAY_OF_REF_TYPES.get(this.name);
else throw (ASTError) this.verifyThrow(
"Impossible: A TypeNode declared a \"type\": \"array\", but the \"items\" " +
"property does not have its own \"type\" property declared."
);
}
else this.CTAS = this.typeProp.primCTAS.getSimpleName();
// CTAB: Computed Type As Byte - same information as CTAS, but stored as a byte primitive
this.CTAB = CDPTypes.ctasToByte(this.CTAS);
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
// Simple Error Check, Part 2
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
//
// Logical Rule: If (type == OBJECT) → (properties must be non-null and non-empty)
// 100% Pass / Success Rate
// Case 1: Modus Tollens
//
// Here: properties exist ⇒ Therefore, type must be OBJECT.
// This block catches violations where type ≠ OBJECT but properties are still present.
if ((this.properties != null) && (this.typeProp != TypeProp.OBJECT))
verifyThrow("TypeNode.typeProp != OBJECT, but typeNode.properties is non-null.");
// 99.99% Pass / Success Rate
// Case 2: Modus Ponens
//
// If (type == OBJECT) → (properties exist)
// Here: type == OBJECT ⇒ Therefore, properties must exist.
// This block catches violations where type == OBJECT but no properties are defined.
//
// There were exactly 2 outliers with this one. (out of 1,444 invocations of this method)
// TCE: (MemoryDumpConfig), API: [BrowserAPI], Domain: [Tracing], WhichTCE: "Type"
// TCE: (Headers), API: [BrowserAPI], Domain: [Network], WhichTCE: "Type"
if ((this.typeProp == TypeProp.OBJECT) && (this.properties == null))
if (! SPECIAL_CASES$TypeNode.OBJECT_WITHOUT_PROPERTIES_OK.contains(this.name))
verifyThrow("TypeNode.typeProp == OBJECT, but typeNodeproperties is null");
}
// ********************************************************************************************
// ********************************************************************************************
// toString
// ********************************************************************************************
// ********************************************************************************************
/**
* Returns an {@code Iterator} that iterates the contents of the {@link #properties} list.
*
* @see #properties
* @see Torello.Java.Additional.RemoveUnsupportedIterator
*/
public Iterator<PPR> iterator()
{ return this.properties.iterator(); }
/** Returns a {@code String} representation of {@code 'this'} instance. */
@LinkJavaSource(handle="StringTCE")
public String toString()
{ return StringTCE.get(this); }
}
|