1 /* 2 * SPDX-FileCopyrightText: none 3 * SPDX-License-Identifier: CC0-1.0 4 */ 5 6 package gov.nist.secauto.metaschema.core.metapath.cst; 7 8 import gov.nist.secauto.metaschema.core.metapath.DynamicContext; 9 import gov.nist.secauto.metaschema.core.metapath.ISequence; 10 import gov.nist.secauto.metaschema.core.metapath.item.IItem; 11 12 import java.util.List; 13 14 import edu.umd.cs.findbugs.annotations.NonNull; 15 16 public interface IExpression { 17 /** 18 * Retrieve the child expressions associated with this expression. 19 * 20 * @return a list of expressions, which may be empty 21 */ 22 @NonNull 23 List<? extends IExpression> getChildren(); 24 25 /** 26 * The minimum expected result type to be produced when evaluating the 27 * expression. The result may be a sub-class or sub-interface of this value. 28 * 29 * @return the base result type 30 */ 31 @NonNull 32 default Class<? extends IItem> getBaseResultType() { 33 return IItem.class; 34 } 35 36 /** 37 * The expected result type produced by evaluating the expression. The result 38 * must be the same or a sub-class or sub-interface of the value provided by 39 * {@link #getBaseResultType()}. 40 * <p> 41 * This method can be overloaded to provide static analysis of the expression to 42 * determine a more specific result type. 43 * 44 * @return the result type 45 */ 46 @NonNull 47 default Class<? extends IItem> getStaticResultType() { 48 return getBaseResultType(); 49 } 50 51 /** 52 * Produce a string representation of this expression including the expression's 53 * name. 54 * <p> 55 * This method can be overloaded to provide a more appropriate representation of 56 * the expression. 57 * 58 * @return a string representing the data elements of the expression 59 */ 60 @SuppressWarnings("null") 61 @NonNull 62 default String toASTString() { 63 return String.format("%s[]", getClass().getName()); 64 } 65 66 /** 67 * Provides a double dispatch callback for visitor handling. 68 * 69 * @param dynamicContext 70 * the dynamic evaluation context 71 * @param focus 72 * the outer focus of the expression 73 * @return the result of evaluation 74 */ 75 @NonNull 76 ISequence<? extends IItem> accept(@NonNull DynamicContext dynamicContext, @NonNull ISequence<?> focus); 77 78 /** 79 * Provides a double dispatch callback for visitor handling. 80 * 81 * @param <RESULT> 82 * the type of the evaluation result 83 * @param <CONTEXT> 84 * the type of the visitor context 85 * @param visitor 86 * the visitor calling this method 87 * @param context 88 * the visitor context 89 * @return the result of evaluation 90 */ 91 <RESULT, CONTEXT> RESULT accept(@NonNull IExpressionVisitor<RESULT, CONTEXT> visitor, @NonNull CONTEXT context); 92 }