1   /*
2    * SPDX-FileCopyrightText: none
3    * SPDX-License-Identifier: CC0-1.0
4    */
5   
6   package dev.metaschema.core.metapath.cst.path;
7   
8   import java.util.List;
9   
10  import dev.metaschema.core.metapath.IExpression;
11  import dev.metaschema.core.metapath.cst.ExpressionUtils;
12  import dev.metaschema.core.metapath.item.node.INodeItem;
13  import edu.umd.cs.findbugs.annotations.NonNull;
14  
15  /**
16   * A base class for Metapath expressions based on the XPath 3.1 <a href=
17   * "https://www.w3.org/TR/xpath-31/#id-relative-path-expressions">relative path
18   * expressions</a>.
19   */
20  public abstract class AbstractRelativePathExpression
21      extends AbstractSearchPathExpression {
22    @NonNull
23    private final IExpression left;
24    @NonNull
25    private final IExpression right;
26  
27    /**
28     * Construct a new relative path expression of "left/right".
29     *
30     * @param text
31     *          the parsed text of the expression
32     * @param left
33     *          the left part of the path
34     * @param right
35     *          the right part of the path
36     */
37    @SuppressWarnings("null")
38    public AbstractRelativePathExpression(
39        @NonNull String text,
40        @NonNull IExpression left,
41        @NonNull IExpression right) {
42      super(text, ExpressionUtils.analyzeStaticResultType(INodeItem.class, List.of(left, right)));
43      this.left = left;
44      this.right = right;
45    }
46  
47    /**
48     * The expression associated with the left path segment.
49     *
50     * @return the expression
51     */
52    @NonNull
53    public IExpression getLeft() {
54      return left;
55    }
56  
57    /**
58     * The expression associated with the right path segment.
59     *
60     * @return the expression
61     */
62    @NonNull
63    public IExpression getRight() {
64      return right;
65    }
66  
67    @SuppressWarnings("null")
68    @Override
69    public List<? extends IExpression> getChildren() {
70      return List.of(left, right);
71    }
72  }