Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow optional paramters for functions
- guard against null in BooleanValueFunctionWrapper - refactor ParamDescription builder to support more common types - new errors for parameter handling - test cases
- Loading branch information
Showing
10 changed files
with
193 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/java/org/graylog/plugins/messageprocessor/parser/errors/MissingRequiredParam.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.graylog.plugins.messageprocessor.parser.errors; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import org.graylog.plugins.messageprocessor.ast.functions.Function; | ||
import org.graylog.plugins.messageprocessor.ast.functions.ParameterDescriptor; | ||
import org.graylog.plugins.messageprocessor.parser.RuleLangParser; | ||
|
||
public class MissingRequiredParam extends ParseError { | ||
private final Function<?> function; | ||
private final ParameterDescriptor param; | ||
|
||
public MissingRequiredParam(RuleLangParser.FunctionCallContext ctx, | ||
Function<?> function, | ||
ParameterDescriptor param) { | ||
super("missing_required_param", ctx); | ||
this.function = function; | ||
this.param = param; | ||
} | ||
|
||
@JsonProperty("reason") | ||
@Override | ||
public String toString() { | ||
return "Missing required parameter " + param.name() + | ||
" of type " + param.type().getSimpleName() + | ||
" in call to function " + function.descriptor().name() | ||
+ positionString(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...ava/org/graylog/plugins/messageprocessor/parser/errors/OptionalParametersMustBeNamed.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.graylog.plugins.messageprocessor.parser.errors; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import org.graylog.plugins.messageprocessor.ast.functions.Function; | ||
import org.graylog.plugins.messageprocessor.parser.RuleLangParser; | ||
|
||
public class OptionalParametersMustBeNamed extends ParseError { | ||
private final Function<?> function; | ||
|
||
public OptionalParametersMustBeNamed(RuleLangParser.FunctionCallContext ctx, Function<?> function) { | ||
super("must_name_optional_params", ctx); | ||
this.function = function; | ||
} | ||
|
||
@JsonProperty("reason") | ||
@Override | ||
public String toString() { | ||
return "Function " + function.descriptor().name() + " has optional parameters, must use named parameters to call" + positionString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/test/resources/org/graylog/plugins/messageprocessor/parser/optionalArguments.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
rule "optional function arguments" | ||
when | ||
optional(d: 3, a: true, b: "string") | ||
then | ||
trigger_test(); | ||
end |
Oops, something went wrong.