Make DObject.get null-safe
ci/woodpecker/manual/woodpecker Pipeline was successful
Details
ci/woodpecker/manual/woodpecker Pipeline was successful
Details
This commit is contained in:
parent
7b6c0fb93f
commit
9fdcd3dfd1
|
@ -3,13 +3,15 @@ package io.gitlab.jfronny.muscript.data.dynamic;
|
|||
import io.gitlab.jfronny.muscript.ast.DynamicExpr;
|
||||
import io.gitlab.jfronny.muscript.ast.dynamic.ObjectLiteral;
|
||||
import io.gitlab.jfronny.muscript.compiler.CodeLocation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public non-sealed interface DObject extends Dynamic<Map<String, Dynamic<?>>> {
|
||||
default Dynamic<?> get(String key) {
|
||||
return getValue().get(key);
|
||||
default @NotNull Dynamic<?> get(String key) {
|
||||
return Dynamic.fromNullable(getValue().get(key));
|
||||
}
|
||||
|
||||
default boolean has(String key) {
|
||||
|
|
|
@ -7,6 +7,8 @@ import io.gitlab.jfronny.muscript.ast.Expr;
|
|||
import io.gitlab.jfronny.muscript.compiler.ExprWriter;
|
||||
import io.gitlab.jfronny.muscript.compiler.Parser;
|
||||
import io.gitlab.jfronny.muscript.data.dynamic.additional.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
@ -40,6 +42,10 @@ public sealed interface Dynamic<T> permits DBool, DNumber, DString, DObject, DLi
|
|||
return dynamic == null || dynamic instanceof DNull;
|
||||
}
|
||||
|
||||
static @NotNull Dynamic<?> fromNullable(@Nullable Dynamic<?> dynamic) {
|
||||
return dynamic == null ? new DNull() : dynamic;
|
||||
}
|
||||
|
||||
default void serialize(ExprWriter writer) throws IOException {
|
||||
toExpr().decompile(writer);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue