5151@ Accessors (chain = true )
5252public class FunctionCallRecord implements Closeable {
5353 public static FunctionCallRecord functionCallRecord (Optional <Object > argSubject , FunctionCallDesc argFunctionCall , Editor argContext , String argName , int argVariation ) {
54- return new FunctionCallRecord (argSubject , argFunctionCall , argContext , argName , argVariation );
54+ return new FunctionCallRecord (argSubject , argFunctionCall , argContext , argName , argVariation , false );
55+ }
56+
57+ public static FunctionCallRecord functionCallRecord (Optional <Object > argSubject , FunctionCallDesc argFunctionCall , Editor argContext , String argName , int argVariation , boolean argIsRecording ) {
58+ return new FunctionCallRecord (argSubject , argFunctionCall , argContext , argName , argVariation , argIsRecording );
5559 }
5660
5761 @ Getter private final String name ;
@@ -68,13 +72,15 @@ public static FunctionCallRecord functionCallRecord(Optional<Object> argSubject,
6872 private final Editor context ;
6973 private final FunctionCallDesc functionCall ;
7074 private final Optional <Object > subject ;
75+ boolean isRecording ;
7176
72- private FunctionCallRecord (Optional <Object > argSubject , FunctionCallDesc argFunctionCall , Editor argContext , String argName , int argVariation ) {
77+ private FunctionCallRecord (Optional <Object > argSubject , FunctionCallDesc argFunctionCall , Editor argContext , String argName , int argVariation , boolean argIsRecording ) {
7378 name = argName ;
7479 variation = argVariation ;
7580 context = argContext ;
7681 functionCall = argFunctionCall ;
7782 subject = argSubject ;
83+ isRecording = argIsRecording ;
7884 }
7985
8086 public FunctionCallRecord addDescription (String addition ) {
@@ -83,6 +89,9 @@ public FunctionCallRecord addDescription(String addition) {
8389 }
8490
8591 public void requireArgumentCount (int requiredArgumentCount ) {
92+ if (isRecording ) {
93+ return ;
94+ }
8695 if (functionCall .getArguments ().size () != requiredArgumentCount ) {
8796 throw execException (tree ("The "
8897 + name
@@ -96,6 +105,9 @@ public void requireArgumentCount(int requiredArgumentCount) {
96105 }
97106
98107 public void requireArgumentMinimalCount (int requiredMinimum ) {
108+ if (isRecording ) {
109+ return ;
110+ }
99111 if (functionCall .getArguments ().size () < requiredMinimum ) {
100112 throw execException (tree ("The "
101113 + name
@@ -108,6 +120,9 @@ public void requireArgumentMinimalCount(int requiredMinimum) {
108120 }
109121
110122 public NameDesc parseArgumentAsType (int argument , String ... validValues ) {
123+ if (isRecording ) {
124+ return null ;
125+ }
111126 val argumentAsType = parseArgumentAsType (argument );
112127 val validValueList = listWithValuesOf (validValues );
113128 val anyMatch = validValueList .stream ().anyMatch (v -> v .equals (argumentAsType .getValue ()));
@@ -120,6 +135,9 @@ public NameDesc parseArgumentAsType(int argument, String... validValues) {
120135 }
121136
122137 public NameDesc parseArgumentAsType (int argument ) {
138+ if (isRecording ) {
139+ return null ;
140+ }
123141 final var first = context .parse (functionCall .getArguments ().get (argument ));
124142 switch (first ) {
125143 case Type n -> {
@@ -137,6 +155,9 @@ public NameDesc parseArgumentAsType(int argument) {
137155 }
138156
139157 public StringDesc parseArgumentAsStringDesc (int argument ) {
158+ if (isRecording ) {
159+ return null ;
160+ }
140161 final var first = context .parse (functionCall .getArguments ().get (argument ));
141162 switch (first ) {
142163 case String n -> {
@@ -154,6 +175,9 @@ public StringDesc parseArgumentAsStringDesc(int argument) {
154175 }
155176
156177 public void failBecauseOfInvalidType (int argument , NameDesc actualType , String ... allowedTypes ) {
178+ if (isRecording ) {
179+ return ;
180+ }
157181 final var allowedTypeList = Lists .list (allowedTypes ).stream ()
158182 .map (at -> "the " + at + " type" )
159183 .reduce ((a , b ) -> a + " or " + b )
@@ -167,6 +191,9 @@ public void failBecauseOfInvalidType(int argument, NameDesc actualType, String..
167191 }
168192
169193 public Query parseQuerySubject () {
194+ if (isRecording ) {
195+ return null ;
196+ }
170197 if (subject .isEmpty ()) {
171198 throw execException (tree ("The "
172199 + name
@@ -195,6 +222,9 @@ public Query parseQuerySubject() {
195222 }
196223
197224 public <T > T parseSubject (Class <? extends T > type ) {
225+ if (isRecording ) {
226+ return null ;
227+ }
198228 if (subject .isEmpty ()) {
199229 throw execException (tree ("The function " + name + " requires a "
200230 + type .getName ()
@@ -213,16 +243,25 @@ public <T> T parseSubject(Class<? extends T> type) {
213243 }
214244
215245 public List <Attribute <? extends Object >> parseAttributeArguments (int from ) {
246+ if (isRecording ) {
247+ return null ;
248+ }
216249 return functionCall .getArguments ().streamIndexes ()
217250 .filter (i -> i >= from )
218251 .mapToObj (this ::parseAttributeArgument ).collect (toList ());
219252 }
220253
221254 public List <Attribute <? extends Object >> parseAttributeArguments () {
255+ if (isRecording ) {
256+ return null ;
257+ }
222258 return functionCall .getArguments ().streamIndexes ().mapToObj (this ::parseAttributeArgument ).collect (toList ());
223259 }
224260
225261 public Attribute <? extends Object > parseAttributeArgument (int argument ) {
262+ if (isRecording ) {
263+ return null ;
264+ }
226265 final var a = functionCall .getArguments ().get (argument );
227266 final var parsed = context .parse (a );
228267 switch (parsed ) {
@@ -241,6 +280,9 @@ public Attribute<? extends Object> parseAttributeArgument(int argument) {
241280 }
242281
243282 public <T > Attribute <T > parseAttributeArgument (Class <? extends T > type , int argument ) {
283+ if (isRecording ) {
284+ return null ;
285+ }
244286 final Attribute <?> distanceAttribute = parseAttributeArgument (argument );
245287 if (!type .isAssignableFrom (distanceAttribute .type ())) {
246288 throw execException (tree ("The argument "
@@ -258,6 +300,9 @@ public <T> Attribute<T> parseAttributeArgument(Class<? extends T> type, int argu
258300 }
259301
260302 public <T > T parseArgument (Class <? extends T > type , int argument ) {
303+ if (isRecording ) {
304+ return null ;
305+ }
261306 final var parsed = context .parse (functionCall .getArguments ().get (argument ));
262307 if (type .isInstance (parsed )) {
263308 return (T ) parsed ;
@@ -275,6 +320,9 @@ public <T> T parseArgument(Class<? extends T> type, int argument) {
275320 }
276321
277322 public void requireSubjectAbsence () {
323+ if (isRecording ) {
324+ return ;
325+ }
278326 if (subject .isPresent ()) {
279327 throw execException (tree ("The "
280328 + name
0 commit comments