Skip to content

Commit f0b766c

Browse files
committed
Record argument type's arguments #37
Signed-off-by: Mārtiņš Avots <martins.avots@splitcells.net>
1 parent 8a5722e commit f0b766c

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

projects/net.splitcells.gel.editor/src/main/java/net/splitcells/gel/editor/geal/FunctionCallRecord.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@
3535

3636
import java.util.Optional;
3737

38-
import static net.splitcells.dem.data.set.list.Lists.listWithValuesOf;
39-
import static net.splitcells.dem.data.set.list.Lists.toList;
38+
import static net.splitcells.dem.data.set.list.Lists.*;
4039
import static net.splitcells.dem.data.set.map.Maps.map;
4140
import static net.splitcells.dem.lang.CommonMarkUtils.joinDocuments;
4241
import static net.splitcells.dem.lang.tree.TreeI.tree;
@@ -79,6 +78,7 @@ public static FunctionCallRecord functionCallRecord(Optional<Object> argSubject,
7978
boolean isRecording;
8079
@Getter Optional<Boolean> subjectAbsent = Optional.empty();
8180
@Getter Map<Integer, Class<?>> argumentTypes = map();
81+
@Getter Map<Integer, List<Class<?>>> argumentTypeArguments = map();
8282

8383
private FunctionCallRecord(Optional<Object> argSubject, FunctionCallDesc argFunctionCall, Editor argContext, String argName, int argVariation, boolean argIsRecording) {
8484
name = argName;
@@ -127,6 +127,7 @@ public void requireArgumentMinimalCount(int requiredMinimum) {
127127

128128
public NameDesc parseArgumentAsType(int argument, String... validValues) {
129129
if (isRecording) {
130+
argumentTypes.ensurePresence(argument, NameDesc.class);
130131
return null;
131132
}
132133
val argumentAsType = parseArgumentAsType(argument);
@@ -142,6 +143,7 @@ public NameDesc parseArgumentAsType(int argument, String... validValues) {
142143

143144
public NameDesc parseArgumentAsType(int argument) {
144145
if (isRecording) {
146+
argumentTypes.ensurePresence(argument, NameDesc.class);
145147
return null;
146148
}
147149
final var first = context.parse(functionCall.getArguments().get(argument));
@@ -162,6 +164,7 @@ public NameDesc parseArgumentAsType(int argument) {
162164

163165
public StringDesc parseArgumentAsStringDesc(int argument) {
164166
if (isRecording) {
167+
argumentTypes.ensurePresence(argument, StringDesc.class);
165168
return stringDesc("", emptySourceCodeQuote());
166169
}
167170
final var first = context.parse(functionCall.getArguments().get(argument));
@@ -184,7 +187,7 @@ public void failBecauseOfInvalidType(int argument, NameDesc actualType, String..
184187
if (isRecording) {
185188
return;
186189
}
187-
final var allowedTypeList = Lists.list(allowedTypes).stream()
190+
final var allowedTypeList = list(allowedTypes).stream()
188191
.map(at -> "the " + at + " type")
189192
.reduce((a, b) -> a + " or " + b)
190193
.orElseThrow();
@@ -266,6 +269,7 @@ public List<Attribute<? extends Object>> parseAttributeArguments() {
266269

267270
public Attribute<? extends Object> parseAttributeArgument(int argument) {
268271
if (isRecording) {
272+
argumentTypes.ensurePresence(argument, Attribute.class);
269273
return null;
270274
}
271275
final var a = functionCall.getArguments().get(argument);
@@ -287,6 +291,8 @@ public Attribute<? extends Object> parseAttributeArgument(int argument) {
287291

288292
public <T> Attribute<T> parseAttributeArgument(Class<? extends T> type, int argument) {
289293
if (isRecording) {
294+
argumentTypes.ensurePresence(argument, Attribute.class);
295+
argumentTypeArguments.ensurePresence(argument, list(type));
290296
return null;
291297
}
292298
final Attribute<?> distanceAttribute = parseAttributeArgument(argument);
@@ -307,7 +313,7 @@ public <T> Attribute<T> parseAttributeArgument(Class<? extends T> type, int argu
307313

308314
public <T> T parseArgument(Class<? extends T> type, int argument) {
309315
if (isRecording) {
310-
argumentTypes.put(argument, type);
316+
argumentTypes.ensurePresence(argument, type);
311317
return null;
312318
}
313319
final var parsed = context.parse(functionCall.getArguments().get(argument));

0 commit comments

Comments
 (0)