Package Torello.Browser.JsonAST
Class PPR
- java.lang.Object
-
- Torello.Browser.JsonAST.Entity
-
- Torello.Browser.JsonAST.PPR
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<Entity>
public class PPR extends Entity implements java.io.Serializable
The class class comprises the intended public facing API for theJsonAST-Package. It is easy to load the Abstract Syntax Tree's from disk by invoking thedeserializeFromJAR()method inside of classSERIALIZED_AST. Remember that the entire packageTorello.Browser.JsonASTis used primarily by a proprietary, and yet unreleased code generator, and is only made public for informational & reference purposes.
Loading the the serialized trees from the'.jar'file, perhaps, may elucidate some of Google's Browser CDP API. The nodes themselves have quite a bit of read only data available.Contains the data needed to represent a property, parameter or return value.
The following two tree diagrams, with explanation, are repeated verbatim across all eight AST Node Classes.Object Inheritance for AST Nodes, and RunTime Tree Organization
The Objects which are generated by the JSON Parser are converted into AST Node Object-Instances, all of which are listed here, below. An in depth study of the CDP Specification, a programmer must realize that there are actually three (possibly four) different trees functioning simultaneously. The Classes themselves have their own "Inheritance Tree." Then, additionally, by its very nature, the original JSON Spec Files are organized in a Tree Structure (as is all JSON, you may view these trees here:Browser API JSONandJavaScript API JSON
Finally, and most importantly, at RunTime as Objects Instances, themselves, are created by the Parser; they are saved into the "Abstract Syntax Tree" (AST for short). These instances are placed into this AST, by saving them intoReadOnlyList'sfrom theReadOnly Collections Framework.
Class Inheritance Tree:The diagram below shows the static class hierarchy: how the core JsonAST classes inherit from one another at the type level.
Runtime Object Instance Tree:In contrast, this diagram shows the dynamic structure at runtime: how reified instances of those same classes are organized into an AST, with parent–child container relationships.
API└─Domain├─TypeNode│ └─PPR➜ [P]roperties ➜ Generate to Java Class Fields ├─CommandNode│ ├─PPR➜ [P]arameters ➜ Generate to Java Method Parameters │ └─PPR➜ [R]eturn-Values ➜ Generate to Java Method Return Values └─EventNode└─PPR➜ [P]arameters ➜ Generate to Java "Event Class" Fields
The following sixJsonObjectproperties are mapped to the followingEntitysubclasses:Json Object Type AST Node Java Conversion "Target" Type TypeNodeConverted into Java Inner Classes / Nested Types of the Primary Domain Java-Classes Command CommandNodeConverted into Java Methods within the Primary Domain Java-Classes Event EventNodeAlso Converted into Inner Classes / Nested Types of the Primary Domain Java-Classes Property PPRConverted into typical Java Fields within the Inner Types / Nested Classes.
(See note †† below.)Parameter PPRFor Commands, these are Converted by the Code Generator into Method Parameters. For Events, these are actually also just converted into Fields of the Nested Event Class too.
(See note †† below.)Return Value PPRThese are converted (for Commands), into Return-Values for the Methods. Using the "Multi-Return Tuples" RetNdefined in theJava.Additionalpackage, it is possible (and quite common, actually) to return multiple values from a single method invocation.
(See note †† below.)
†† UnlikeTCE, Properties, Parameters, and Return-Values do not have their own dedicated AST nodes, because their content is always identical to that in base classPPR.- See Also:
- Serialized Form
Hi-Lited Source-Code:- View Here: Torello/Browser/JsonAST/PPR.java
- Open New Browser-Tab: Torello/Browser/JsonAST/PPR.java
File Size: 9,957 Bytes Line Count: 240 '\n' Characters Found
-
-
Field Summary
Serializable ID Modifier and Type Field Description protected static longserialVersionUIDStatic Field: Internally Used String List. PPR Node-Specific JsonObject Property-Names Modifier and Type Field Description protected static ReadOnlySet<String>PPR_JSON_PROPERTIESThe list of additionalJsonObjectproperties that the parser should expect when parsingPPRobjects from the JSON CDP specification files.Instance Fields: Fundamental Details about this PPR Modifier and Type Field Description TCEownerTCEThis is a "Back Pointer" to theTCE(either aTypeNode,CommandNodeorEventNode) that is the parent or owner of'this'PPR instance.WhichPPRwhichExpresses, explicitly, (without requiring an'instanceof'operator), whether or not'this'instance repesents a property, a parameter or a return-value.Instance Fields: Unlinked, Still-In-String-Format, Raw References. Modifier and Type Field Description StringrefThis field is declaredfinal, and contains the raw-Stringvalue which is retrieved (during JSON parsing) from the"$ref"JsonObjectproperty which defines'this' PPRinstanceStringrefArrayThisStringis declaredfinal, and contains the raw-Stringvalue which is retrieved during the parsing of an'items'JsonObjectwithin thisPPRdefinition.-
Fields inherited from class Torello.Browser.JsonAST.Entity
arrItemsTypeProp, deprecated, description, enumVals, enumValsStr, experimental, id, index, name, optional, ownerDomain, propNames, typeProp, whichEntity
-
-
Method Summary
Getters: Return Linked References. These Methods Return the Values of non-Final Fields Modifier and Type Method Description byteCTAB()Returns the value of the private field'ctab'; a field that represents the "Computed Type as Byte".StringCTAS()Returns the value of the private field'ctas'; a field that represents the "Computed Type as String" - the Java Type of this PPR, as aString).TypeNodereference()Returns the value of theprivatefield'reference'; a field that represents the resolved target of a'$ref'property.TypeNodereferenceArray()Returns the value of theprivatefield'referenceArray'; a field that represents the resolved target of a'$ref'property which was extracted from an'items'object.Methods: class java.lang.Object Modifier and Type Method Description StringtoString()Returns aStringrepresentation of'this'instance.StringtoStringShort()-
Methods inherited from class Torello.Browser.JsonAST.Entity
compareTo, equals, exceptionLocationSummary, hashCode
-
-
-
-
Field Detail
-
serialVersionUID
protected static final long serialVersionUID
This fulfils the SerialVersion UID requirement for all classes that implement Java'sinterface java.io.Serializable. Using theSerializableImplementation offered by java is very easy, and can make saving program state when debugging a lot easier. It can also be used in place of more complicated systems like "hibernate" to store data as well.- See Also:
- Constant Field Values
- Code:
- Exact Field Declaration Expression:
protected static final long serialVersionUID = 1;
-
PPR_JSON_PROPERTIES
protected static final ReadOnlySet<java.lang.String> PPR_JSON_PROPERTIES
The list of additionalJsonObjectproperties that the parser should expect when parsingPPRobjects from the JSON CDP specification files.- Code:
- Exact Field Declaration Expression:
protected static final ReadOnlySet<String> PPR_JSON_PROPERTIES = new ReadOnlyTreeSet<>(String::compareTo, "name", "$ref");
-
ownerTCE
-
which
public final WhichPPR which
Expresses, explicitly, (without requiring an'instanceof'operator), whether or not'this'instance repesents a property, a parameter or a return-value. TheJsonASTpackage has a particular class (this one,'PPR') that it uses to represent three different kinds of Json elements from the Json API Definition / grammar. Class'PPR'is used to represent all three kinds ofJsonObjects:PROPERTIES,PROPERTIESandRETURNS.
This field is declared bothpublicandfinal, and identifies which of the three possibilities'this'instance was derived ('P', 'P' or 'R' 😃).- Code:
- Exact Field Declaration Expression:
public final WhichPPR which;
-
ref
public final java.lang.String ref
This field is declaredfinal, and contains the raw-Stringvalue which is retrieved (during JSON parsing) from the"$ref"JsonObjectproperty which defines'this' PPRinstance
This field is declared bothpublicandfinal, and is treated like an instance-specific / object-specific (READ: it is not declaredstatic) constant. The value assigned to this field by the constructor is the rawStringcontents of the JSON Object Property named'$ref'.
Every instance ofPPRmust contain exactly one definition for either theprimitiveField, or for this'$ref'Field. Precisely one of these two fields (in this class) must be non-null, while the other field must be assigned null.
While the complete list of available options that Google might assign to the'primitive'Json-Property are listed as constants in the JavaenumnamedTypeProp(STRING,INTEGERorBOOLEAN, etc...) the allowedString-Values which may be assigned to this field are, essentially, the list of declared types (all of the 'Nested Data Classes' amongst all of CDP's domains) that are defined by CDP.
A non-null value in this'$ref'Field indicates that the definition should be understood in terms of an existing named type declared elsewhere in the protocol (for example,TargetInfoin theTargetdomain).During the Linking Phase of AST-Building, a non-null$refField will be converted into a non-null (andprivate)'reference'field which actually points to the actualTCE-Instance for the Java nested class defined for the type named by theString-Value of this field.
Remember, the more you look right at "reflection" in any programming language, the more complicated it is to say, mention or document anything about the Source-Code which is operating on the reflective variables. Programmers take words like'String'and'reference'for granted - until the day that the variables and values that they are using have names or values (or both names and values) like'STRING'and'REFERENCE'- Code:
- Exact Field Declaration Expression:
public final String ref;
-
refArray
public final java.lang.String refArray
ThisStringis declaredfinal, and contains the raw-Stringvalue which is retrieved during the parsing of an'items'JsonObjectwithin thisPPRdefinition.
It is assigned a non-null value when the JsonObject contans the following *TWO* Object-Properties:"type" : "array""items" : { "ref$" : "SomeCDPDefinedType" }
There are on the order of (my Diagnostic-Tool counted 354, to be exact) PPR's that have a value assigned to 'Entity.refArray' inside the Browser-API. There are exactly *TWO* Type-TCE's that have a value assigned to 'Entity.refArray'... Those 2 TCE's were: Target.TargetFilter & DOMSnapshot.ArrayOfStrings
This field will eventually have to be linked / 'cross-referenced' into an actual object instance of classTCE(from ajava.lang.String, which is the format in which it is stored here). Since the linking cannot be done until after the parsing is finished, the Version of fieldreferenceArrayis saved here.This field is non-null if and only if this'PPR'instance represents an array; but moreover an array of an actual and reified CDP Class / Type.- Code:
- Exact Field Declaration Expression:
public final String refArray;
-
-
Method Detail
-
reference
public final TypeNode reference()
Returns the value of theprivatefield'reference'; a field that represents the resolved target of a'$ref'property. This is a public facing getter for a non-final (and, ergo,private) field. The value assigned to this field cannot be calculated or computed during this object's construction. It is computed after the entireAPI'sAST has been built, and is evaluated during the "Linking Phase" of AST-Building.
In the CDP protocol JSON specification files, there are numerous Properties, Parameters, and Return-Value definitions that do not declare themselves as simple raw types (such asstring,boolean&numberetc..), but instead reference another type by name (as aJsonString) using a'$ref'property. This is actually a somewhat common trick among programmers who do use JSON as a means of expessing API Definitions. These'$ref'properties function very similarly to reference variables inside of standard Java Programs. These references are used, simply, to point to other classes, elsewhere in the package tree or project tree.
Linking Note:
At object construction time, this cannot yet be resolved, since the target type may be defined later in the same domain or even in another domain. Specifically, if'this'instance' constructor is invoked before the class constructor named by'$ref', then it is patently impossible to save a reference to that which'$ref'is specifying until after all of the other classes & types have been constructed by the parser.
During the linking phase, the'$ref'object property is matched to its correspondingTCE(Type,CommandorEvent), and this `reference` field is updated to point directly to it.
Because this happens after construction, the internal field namedreferencealso cannot be declaredpubliceither. (Againreferencecannot be declardfinalbecause it cannot be initialized in the constructor, as per explained above)
As a result there is also a method namedreference()(this method) which functions as a 'getter', thereby providing read-only access to this resolvedTCE.- Code:
- Exact Method Body:
return reference;
-
referenceArray
public final TypeNode referenceArray()
Returns the value of theprivatefield'referenceArray'; a field that represents the resolved target of a'$ref'property which was extracted from an'items'object.
This field will contain a non-nullString-reference if and only if this JSON for thisPPRdefinition contains:- a
"type" : "array"property
- an
"items"JsonObjectproperty.
- That internal
"items"object, itself, has a"$ref" : "SomeCDPDefinedType"property which names & specifies a class or type that is defined elsewhere in the CDP specification files.
This method provides read only access to a private and internal field of the exact same name. The private & internal field namedreferenceArrayis declaredprivateprecisely because it cannot be delcaredfinal. It is not declaredfinal(unlike everything else in the AST Node classes) beause it cannot be set by the constructor at object construction time.
Fields which are to be assigned to some other object reference that may not have yet been instantiated yet have to assigned during the "Linking Phase" instead. The need for a Linking Phase is precisely because the PPR's and TCE's that are parsed during the early / beginning part of the parsing process (at the beginning or top of the CDP JSON spec-files) often name PPR's and TCE's that are defined at the end of that file.
To combat this "Catch 22", there is a Linking Phase that occurs after the constructor phase, and fields which have to be linked are keptprivate, rather thanpublic.- Code:
- Exact Method Body:
return referenceArray;
- a
-
CTAS
public final java.lang.String CTAS()
Returns the value of the private field'ctas'; a field that represents the "Computed Type as String" - the Java Type of this PPR, as ajava.lang.String).
The value assigned to thisStringis the one that is ultiately used by the Browser-CDP Code Generator, during the Code-Generation Phase. The value assigned to thisStringcould either be a simple / standard Java-Type such asString, intorboolean, but it could also be one of the types which are defined in Google CDP - such asTarget.TargetInfoorNetwork.Cookie- See Also:
CTAB()- Code:
- Exact Method Body:
return ctas;
-
CTAB
public final byte CTAB()
Returns the value of the private field'ctab'; a field that represents the "Computed Type as Byte".
This is an identical piece of informatio as the value returned byCTAS(). This method merely returns an encoded version of a private & internal'ctab'field.'ctab', rather than storing thisPPR'stype information as aString-literal, it saves it as a simple Javabyte-primitive.
The value stored here is consistent with the numbered list of types available in classCDPTypes.
-
toString
public java.lang.String toString()
Returns aStringrepresentation of'this'instance.- Overrides:
toStringin classjava.lang.Object- Code:
- Exact Method Body:
return StringPPR.get(this);
-
toStringShort
public java.lang.String toStringShort()
- Code:
- Exact Method Body:
return this.ownerDomain.ownerAPI.name + '.' + // API-Name this.ownerDomain.name + '.' + // Domain-Name this.ownerTCE.name + '.' + // TCE-Name this.name + ' ' + // PPR-Name "[WhichTCE." + this.ownerTCE.which + ", WhichPPR." + this.which + ']';
-
-