Skip to content

Commit 8da9f9e

Browse files
committed
Record argument count requirements #37
Signed-off-by: Mārtiņš Avots <martins.avots@splitcells.net>
1 parent d3267a7 commit 8da9f9e

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ public static FunctionCallRecord functionCallRecord(Optional<Object> argSubject,
8282
@Getter Map<Integer, List<Class<?>>> argumentTypeArguments = map();
8383
@Getter Boolean onlyAttributesAsArgument = false;
8484
@Getter int onlyAttributesAsArgumentsFrom = -1;
85+
@Getter int requiredArgumentCount = -1;
86+
@Getter int requiredMinimalArgumentCount = -1;
8587

8688
private FunctionCallRecord(Optional<Object> argSubject, FunctionCallDesc argFunctionCall, Editor argContext, String argName, int argVariation, boolean argIsRecording) {
8789
name = argName;
@@ -99,6 +101,7 @@ public FunctionCallRecord addDescription(String addition) {
99101

100102
public void requireArgumentCount(int requiredArgumentCount) {
101103
if (isRecording) {
104+
this.requiredArgumentCount = requiredArgumentCount;
102105
return;
103106
}
104107
if (functionCall.getArguments().size() != requiredArgumentCount) {
@@ -115,6 +118,7 @@ public void requireArgumentCount(int requiredArgumentCount) {
115118

116119
public void requireArgumentMinimalCount(int requiredMinimum) {
117120
if (isRecording) {
121+
requiredMinimalArgumentCount = requiredMinimum;
118122
return;
119123
}
120124
if (functionCall.getArguments().size() < requiredMinimum) {

projects/net.splitcells.gel.editor/src/main/java/net/splitcells/gel/editor/geal/runners/FunctionCallRunnerParser.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ public Tree document(Editor context) {
7272
.orElseThrow();
7373
list.withChild(tree("item", SEW).withText("The subject has to be one of the following types: " + typesDescription));
7474
}
75+
if (fcr.getRequiredArgumentCount() != -1) {
76+
list.withChild(tree("item", SEW).withText("Exactly " + fcr.getRequiredArgumentCount() + " arguments have to be present."));
77+
}
78+
if (fcr.getRequiredMinimalArgumentCount() != -1) {
79+
list.withChild(tree("item", SEW).withText("At least " + fcr.getRequiredMinimalArgumentCount() + " arguments have to be present."));
80+
}
7581
if (fcr.getOnlyAttributesAsArgument()) {
7682
tree("list", SEW).withParent(functionCallDoc).withText("Only attribute references are allowed as arguments.");
7783
} else {

0 commit comments

Comments
 (0)