1   /*
2    * SPDX-FileCopyrightText: none
3    * SPDX-License-Identifier: CC0-1.0
4    */
5   
6   package dev.metaschema.core.model.constraint;
7   
8   import dev.metaschema.core.datatype.markup.MarkupMultiline;
9   import dev.metaschema.core.metapath.IMetapathExpression;
10  import dev.metaschema.core.model.ISource;
11  import dev.metaschema.core.model.constraint.impl.DefaultLet;
12  import dev.metaschema.core.qname.IEnhancedQName;
13  import edu.umd.cs.findbugs.annotations.NonNull;
14  import edu.umd.cs.findbugs.annotations.Nullable;
15  
16  /**
17   * Represents a variable assignment for use in Metaschema module constraints.
18   */
19  public interface ILet {
20    /**
21     * Create a new Let expression by compiling the provided Metapath expression
22     * string.
23     * <p>
24     * This method is deprecated. Callers should use
25     * {@link #of(IEnhancedQName, IMetapathExpression, ISource, MarkupMultiline)}
26     * instead.
27     *
28     * @param name
29     *          the let expression variable name
30     * @param valueExpression
31     *          a Metapath expression string representing the variable value
32     * @param source
33     *          the source descriptor for the resource containing the constraint
34     * @param remarks
35     *          remarks about the let statement
36     * @return the original let statement with the same name or {@code null}
37     */
38    @NonNull
39    @Deprecated(since = "2.2.0", forRemoval = true)
40    static ILet of(
41        @NonNull IEnhancedQName name,
42        @NonNull String valueExpression,
43        @NonNull ISource source,
44        @Nullable MarkupMultiline remarks) {
45      return of(
46          name,
47          IMetapathExpression.lazyCompile(valueExpression, source.getStaticContext()),
48          source,
49          remarks);
50    }
51  
52    /**
53     * Create a new Let expression.
54     *
55     * @param name
56     *          the let expression variable name
57     * @param valueExpression
58     *          a Metapath expression representing the variable value
59     * @param source
60     *          the source descriptor for the resource containing the constraint
61     * @param remarks
62     *          remarks about the let statement
63     * @return the original let statement with the same name or {@code null}
64     */
65    @NonNull
66    static ILet of(
67        @NonNull IEnhancedQName name,
68        @NonNull IMetapathExpression valueExpression,
69        @NonNull ISource source,
70        @Nullable MarkupMultiline remarks) {
71      return new DefaultLet(name, valueExpression, source, remarks);
72    }
73  
74    /**
75     * Get the name of the let variable.
76     *
77     * @return the name
78     */
79    @NonNull
80    IEnhancedQName getName();
81  
82    /**
83     * Get the Metapath expression to use to query the value.
84     *
85     * @return the Metapath expression to use to query the value
86     */
87    @NonNull
88    IMetapathExpression getValueExpression();
89  
90    /**
91     * Information about the source resource containing the let statement.
92     *
93     * @return the source information
94     */
95    @NonNull
96    ISource getSource();
97  
98    /**
99     * Get the remarks associated with the let statement.
100    *
101    * @return the remark or {@code null} if no remarks are defined
102    */
103   @Nullable
104   MarkupMultiline getRemarks();
105 }