1   /*
2    * SPDX-FileCopyrightText: none
3    * SPDX-License-Identifier: CC0-1.0
4    */
5   
6   package dev.metaschema.core.metapath.cst;
7   
8   import java.util.List;
9   import java.util.Objects;
10  
11  import dev.metaschema.core.metapath.IExpression;
12  import edu.umd.cs.findbugs.annotations.NonNull;
13  
14  /**
15   * An immutable expression with a single sub-expression.
16   */
17  public abstract class AbstractUnaryExpression
18      extends AbstractExpression {
19    @NonNull
20    private final IExpression expr;
21  
22    /**
23     * Construct a new unary expression.
24     *
25     * @param text
26     *          the parsed text of the expression
27     * @param expr
28     *          the single sub-expression
29     */
30    public AbstractUnaryExpression(@NonNull String text, @NonNull IExpression expr) {
31      super(text);
32      this.expr = Objects.requireNonNull(expr, "expr");
33    }
34  
35    /**
36     * Retrieve the single child sub-expression.
37     *
38     * @return the sub-expression
39     */
40    @NonNull
41    public IExpression getChild() {
42      return expr;
43    }
44  
45    @SuppressWarnings("null")
46    @Override
47    public List<? extends IExpression> getChildren() {
48      return List.of(expr);
49    }
50  }