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 | package Torello.Browser;
import static Torello.Java.StrPrint.I4;
import Torello.Java.ReadOnly.ReadOnlyList;
import java.util.Objects;
import java.util.TreeMap;
import javax.json.JsonObject;
/**
* Reflected information / data which has been extracted from one of the nested CDP types declared
* inside a generated domain class.
*
* <BR /><BR />
* A "Nested Type" is any CDP data-class, event-class, or command-return class that is generated as
* an inner class of one of the primary browser domain classes. For example:
*
* <BR /><BR />
* <B><CODE>{@link Torello.Browser.BrowserAPI.Animation.AnimationEffect}</CODE></B>
*
* <BR /><BR />
* is a nested type declared inside the {@code Animation} domain class. Its corresponding
* {@code NestedDescriptor} singleton is created and stored inside that type's generated helper
* class:
*
* <BR /><BR />
* <B><CODE><A HREF='BrowserAPI/hilite-files/Animation$$AnimationEffect$$.java.html'>
* Animation$$AnimationEffect$$</A></CODE></B>
*
* <BR /><BR />
* The descriptor stores the field names, CDP type constants, optional-field flags,
* experimental-field flags, and the concrete Java {@link Class} represented by the nested type.
* This metadata is used by reflection-based tools such as {@link TypeBuilder}, JSON parsers, and
* generated helper classes.
*
* @param <DOMAIN_NESTED> The concrete nested CDP type described by this descriptor.
*/
public class NestedDescriptor<DOMAIN_NESTED extends BaseType<DOMAIN_NESTED>>
extends AbstractDescriptor
implements java.io.Serializable
{
// ********************************************************************************************
// ********************************************************************************************
// Fields
// ********************************************************************************************
// ********************************************************************************************
/** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */
protected static final long serialVersionUID = 1L;
/**
* This just keeps a pointer / reference back to the actual {@code java.lang.Class} which is
* described by this "Nested Descriptor."
*
* <BR /><BR /><DIV CLASS=JDHint>
* In the JDK, it is sometimes stated that "reifying generic types" could conceivably have
* a value to the end user. The only purpose of this field is to do just that, "reify" the
* Type Parameter represented by {@code 'DOMAIN_NESTED'}.
* </DIV>
*/
public final Class<DOMAIN_NESTED> baseTypeClass;
// This package-private field is used by the "TypeBuilder" class's "build()" method
transient java.lang.reflect.Constructor<DOMAIN_NESTED> ctor = null;
// ********************************************************************************************
// ********************************************************************************************
// Constructor & toString
// ********************************************************************************************
// ********************************************************************************************
/**
* This is a public constructor, but it's primarily intended for internal use.
*
* <!-- NOTE: Chat-GPT wrote these "Single Line Summaries!" Pretty nifty... -->
*
* @param name The name of the CDP type described by this descriptor.
* @param domain The Browser Domain containing the described CDP type.
* @param names Parallel list of CDP property names.
* @param types Parallel list of {@link CDPTypes CDP Type Constants}.
* @param optionals Parallel list indicating which properties are {@code optional}.
* @param experimentals Parallel list indicating which properties are {@code experimental}.
* @param baseTypeClass The concrete Java {@code Class} represented by this descriptor.
*/
public NestedDescriptor(
final Domains domain,
final String name,
final ReadOnlyList<String> names,
final ReadOnlyList<Byte> types,
final ReadOnlyList<Boolean> optionals,
final ReadOnlyList<Boolean> experimentals,
final Class<DOMAIN_NESTED> baseTypeClass
)
{
super(name, domain, names, types, optionals, experimentals);
Objects.requireNonNull(baseTypeClass, "Constructor parameter 'baseTypeClass' is null");
this.baseTypeClass = baseTypeClass;
}
/**
* Generates a reasonable {@code String} representation of {@code 'this'} instance.
* @return A Java {@code String}
*/
@Override
public String toString()
{
return
"NestedDescriptor:\n" +
"{\n" +
super.toString() +
'\n' +
I4 + "baseTypeClass: " + this.baseTypeClass.getCanonicalName() + '\n' +
"}\n";
}
// ********************************************************************************************
// ********************************************************************************************
// Package-Private Reflection Methods
// ********************************************************************************************
// ********************************************************************************************
// Allows the TypeBuilder to verify if a user has passed a valid class
Class<?> getClass(final String name, final int index)
{
final java.lang.reflect.Field field;
try
{ field = baseTypeClass.getField(name); }
catch (NoSuchFieldException | SecurityException e)
{ throw new Error("Exception retrieving field [" + name + ']', e); }
if (field == null) throw new Error(
"Class " + baseTypeClass.getCanonicalName() + " did not contain a field " +
"named: " + name
);
return field.getType();
}
}
|