001package Torello.Browser.JsonAST; 002 003import Torello.JavaDoc.Annotations.LinkJavaSource; 004import Torello.JavaDoc.Annotations.JDHeaderBackgroundImg; 005 006import Torello.Java.ReadOnly.ReadOnlyList; 007import Torello.Java.ReadOnly.ReadOnlySet; 008import Torello.Java.ReadOnly.ReadOnlyTreeSet; 009 010import java.util.Iterator; 011import java.util.Objects; 012import javax.json.JsonObject; 013 014/** 015 * An Java Object used within AST to symbolize or encapsulate the data present in any of the 016 * {@link JsonObject JsonObject's} found within a {@link Domain Domain's} {@code "events"} array. 017 * <EMBED CLASS='external-html' DATA-FILE-ID=AST_TREES> 018 */ 019@JDHeaderBackgroundImg(EmbedTagFileID="AST_NODES_JDHBI") 020public class EventNode extends TCE implements java.io.Serializable 021{ 022 // ******************************************************************************************** 023 // ******************************************************************************************** 024 // STATIC FINAL FIELDS 025 // ******************************************************************************************** 026 // ******************************************************************************************** 027 028 029 /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */ 030 protected static final long serialVersionUID = 1; 031 032 /** 033 * The list of additional {@link JsonObject} properties that the parser should expect when 034 * parsing {@code EventNode} objects from the JSON CDP specification files. 035 */ 036 protected static final ReadOnlySet<String> EVENT_JSON_PROPERTIES_SET = 037 new ReadOnlyTreeSet<>(String::compareTo, "name", "parameters"); 038 039 040 // ******************************************************************************************** 041 // ******************************************************************************************** 042 // Constant & Final Instance-Fields (Set by the Constructor) 043 // ******************************************************************************************** 044 // ******************************************************************************************** 045 046 047 /** 048 * Collection of PPR (Parameter) instances that will be materialized as Java Event-Class fields 049 * <EMBED CLASS='external-html' DATA-FILE-ID=EventNode.parameters> 050 */ 051 public final ReadOnlyList<PPR> parameters; 052 053 /** 054 * Flag indicating whether this EventNode represents a reified inner class in the CDP model. 055 * <EMBED CLASS='external-html' DATA-FILE-ID=EventNode.isReifiedInnerClass> 056 */ 057 public final boolean isReifiedInnerClass; 058 059 060 // ******************************************************************************************** 061 // ******************************************************************************************** 062 // Constructor 063 // ******************************************************************************************** 064 // ******************************************************************************************** 065 066 067 // Constructs a class that represents a Java-Script 'type', 'command' or 'event' 068 EventNode( 069 // The domain to which this 'type', 'command' or 'event' belongs 070 final Domain parent, 071 072 // The JSON Object representation of this 'TCE' 073 final JsonObject jo, 074 075 // The JSON Array index from which this JSON Object was retrieved. 076 final int index 077 ) 078 { 079 super( 080 parent, 081 jo, 082 WhichTCE.Event, 083 EVENT_JSON_PROPERTIES_SET, 084 index 085 ); 086 087 this.parameters = Helper$GetPPRLists.get(this, jo, WhichPPR.Parameter); 088 this.isReifiedInnerClass = (this.parameters != null); 089 090 091 // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 092 // EventNode → **MAY NOT** have a "type" JsonProperty ==> 100% pass / TRUE / invariant 093 // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 094 095 if (this.typeProp != null) 096 verifyThrow("EventNode TCE illegally declares a \"type\" Json property."); 097 098 // This check is IDENTICAL to (a subset of) the previous check. Just here to remind you 099 if (this.arrItemsTypeProp != null) 100 verifyThrow("This has an array field, but it is a EventNode TCE"); 101 102 if (this.enumVals != null) 103 verifyThrow("EventNode TCE illegally declares an \"enum\" Json property."); 104 } 105 106 107 // ******************************************************************************************** 108 // ******************************************************************************************** 109 // toString 110 // ******************************************************************************************** 111 // ******************************************************************************************** 112 113 114 /** 115 * Returns an {@code Iterator} that iterates the contents of the {@link #parameters} list. 116 * 117 * @see #parameters 118 * @see Torello.Java.Additional.RemoveUnsupportedIterator 119 */ 120 public Iterator<PPR> iterator() 121 { return this.parameters.iterator(); } 122 123 /** Returns a {@code String} representation of {@code 'this'} instance. */ 124 @LinkJavaSource(handle="StringTCE") 125 public String toString() 126 { return StringTCE.get(this); } 127}