Package Torello.Browser.JsonAST
Class CommandNode
- java.lang.Object
-
- Torello.Browser.JsonAST.Entity
-
- Torello.Browser.JsonAST.TCE
-
- Torello.Browser.JsonAST.CommandNode
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<Entity>
public class CommandNode extends TCE 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.An Java Object used within AST to symbolize or encapsulate the data present in any of theJsonObject'sfound within aDomain's"commands"array.
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/CommandNode.java
- Open New Browser-Tab: Torello/Browser/JsonAST/CommandNode.java
File Size: 7,886 Bytes Line Count: 174 '\n' Characters Found
-
-
Field Summary
Serializable ID Modifier and Type Field Description protected static longserialVersionUIDStatic Field: Internally Used String List. CommandNode Specific JsonObject Property-Names Modifier and Type Field Description protected static ReadOnlySet<String>COMMAND_JSON_PROPERTIES_SETThe list of additionalJsonObjectproperties that the parser should expect when parsingCommandNodeobjects from the JSON CDP specification files.Instance Fields: List of PPR (Parameter) instances which Will Generate into Method-Parameters & Return-Values Modifier and Type Field Description ReadOnlyList<PPR>parametersAPPRlist which, during the Code Generator Phase, is translated into the input parameters for the Java Method which ultimately materializes and implements this CDP Command.ReadOnlyList<PPR>returnsAPPRlist which, during the Code Generator Phase, is translated into the output return values of the Java Method which ultimately materializes and implements this CDP Command.Instance Fields: Fundamental Details about this TypeNode Modifier and Type Field Description booleanhasReifiedRetInnerClassFlag which indicates whether the CDP Command represented by this node returns multiple values, which therefore necessitates a dedicated inner type to represesnt those return values.StringredirectThis field contains the rawStringvalue of the"redirect"Json Property.-
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: Returns the Value of a Private, non-Final, Field Modifier and Type Method Description DomainredirectDomain()This method retrieves the value of aprivatefield which isn't assigned inside of the constructor, but rather during the Linking Phase, and is therefore not declaredfinal.Methods: class java.lang.Object Modifier and Type Method Description StringtoString()Returns aStringrepresentation of'this'instance.-
Methods inherited from class Torello.Browser.JsonAST.TCE
toStringShort
-
Methods inherited from class Torello.Browser.JsonAST.Entity
compareTo, equals, exceptionLocationSummary, hashCode
-
-
-
-
Field Detail
-
serialVersionUID
protected static final long serialVersionUID
- See Also:
- Constant Field Values
- Code:
- Exact Field Declaration Expression:
protected static final long serialVersionUID = 1;
-
COMMAND_JSON_PROPERTIES_SET
protected static final ReadOnlySet<java.lang.String> COMMAND_JSON_PROPERTIES_SET
The list of additionalJsonObjectproperties that the parser should expect when parsingCommandNodeobjects from the JSON CDP specification files.- Code:
- Exact Field Declaration Expression:
protected static final ReadOnlySet<String> COMMAND_JSON_PROPERTIES_SET = new ReadOnlyTreeSet<>(String::compareTo, "name", "parameters", "returns", "redirect");
-
redirect
public final java.lang.String redirect
This field contains the rawStringvalue of the"redirect"Json Property. ThisStringwill be linked during the Linking Phase of a Build, into an instance ofDomainThe domain to which this refence points, merely identifies a CDP domain (which is similar to a Java Package) in in which this Command (like a Java Method) is actually deferred. "Redirect Domains" are just ways for the CDP Spec to place commands (methods) that are identical into multiple domains (again, CDP Domains are highly similar to Java Packages - they group features and functionality in one location and give it a name).
The Java-HTML CDP Implementation (the'Browser'package and its two sub-packages), do not actually make any use of "Redirect Domains." Any redirection that occurs is actually handled on the other side of the Web-Sockets Wall, and takes place inside the browsers code, not the Java Implementation with which the browser is communicating.
Instead, this Json Property is merely extracted and placed into this field for reference purposes only. It is not actually used (nor is its "linked version", namely the output of methodredirectDomain()) used either!- Code:
- Exact Field Declaration Expression:
public final String redirect;
-
hasReifiedRetInnerClass
public final boolean hasReifiedRetInnerClass
Flag which indicates whether the CDP Command represented by this node returns multiple values, which therefore necessitates a dedicated inner type to represesnt those return values.
A "Reified Return Class" is an instance of aCommandNodefor which the Code Generator shall emit astaticJava nested type as astaticmember of theownerDomainclass to represent the method's return values. In short, if aCommandNode's 'hasReifiedReturnClass' booleanhas been assignedTRUE, then you should be able to count on finding a nested type whose name ends with$$RET. This class will be found in the Generated Java Class for the exact domain in which the originalCommandNoderesides.
As an example, in theBrowserAPI, there is domain calledCSS. The class for that domain, has a nested type / inner class named CSS.getAnimatedStylesForNode$$RET. The inner classgetAnimatedStylesForNode$$RETis, indeed, astaticnested inner class; and if you were to traverse or "search" the AST tree for the following nodes:
BrowserAPI(APINode) ➜CSS(Domain) ➜getAnimatedStylesForNode(CommandNode)
and check the value of itshasReifiedRetInnerClassflag, you would see instantly that it had been assignedTRUE. This flag relays to the Code Generator that it must generate a nested type in order to properly represent the return values of this particular command.What is important to know is that Java does not provide an easy way to return multiple values from a method invocation. Thusly, whenever a command which has multiple return-PPR'sin itsreturnsarray the Code Generator will emit a dedicated Java Nested Class to represent & encapsulate those return values.- Code:
- Exact Field Declaration Expression:
public final boolean hasReifiedRetInnerClass;
-
parameters
public final ReadOnlyList<PPR> parameters
APPRlist which, during the Code Generator Phase, is translated into the input parameters for the Java Method which ultimately materializes and implements this CDP Command.- Code:
- Exact Field Declaration Expression:
public final ReadOnlyList<PPR> parameters;
-
returns
public final ReadOnlyList<PPR> returns
APPRlist which, during the Code Generator Phase, is translated into the output return values of the Java Method which ultimately materializes and implements this CDP Command.- Code:
- Exact Field Declaration Expression:
public final ReadOnlyList<PPR> returns;
-
-
Method Detail
-
redirectDomain
public Domain redirectDomain()
This method retrieves the value of aprivatefield which isn't assigned inside of the constructor, but rather during the Linking Phase, and is therefore not declaredfinal.
Represents the resolved target of a browser-internal'redirect'. In the CDP JSON specifications, some commands or types define a'redirect'property, whose value is just the name of another domain. This indicates that the actual definition (implementation) has been moved or "aliased" from another domain. Programmers / Users of any Command which has a non-null "redirectDomain" value assigned should just be aware that the browser will be evaluating your instructions by a different Web Browser Domain.
This is all handled internally by the Web-Browser, and there aren't any intermediate actions that a programmer needs to take based on a CDP Command which has a non-null Redirect Domain value assigned. This has just been placed here for reference and understanding purposes only1
Example: a command may be listed in one domain with JSON Property:
Java Script Object Notation (JSON):
"redirect": "Target"
This means that thisCommandNodeinstance will be translated into a Java Method (by the Code Generator, during the Code Generation Phase) which is actually just a forwarder to theTargetdomain.
Since a redirect target cannot be resolved at object construction time, this field is initialized to null and later linked to the appropriateDomainobject instance during the "Linking Phase". ThisredirectDomain()method provides access to theprivatefield once linking is complete.- Code:
- Exact Method Body:
return redirectDomain;
-
toString
public java.lang.String toString()
Returns aStringrepresentation of'this'instance.- Overrides:
toStringin classjava.lang.Object- Code:
- Exact Method Body:
return StringTCE.get(this);
-
-