From 89c4d17c408926dad23f72e01763de5a10462502 Mon Sep 17 00:00:00 2001 From: JP Date: Wed, 11 Dec 2024 21:02:21 -0700 Subject: [PATCH] Conversion of the `elm` module to Kotin (#1466) * ChoiceType * ClassTypeElement * InstantiationContext * TupleType, TupleTypeelement, SearchType, Relationship * NamespaceInfo * ModelContext * ModelIdentifier * ModelInfoProvider, NamespaceAware, ModelInfoReader, ModelInfoReaderFactory, ModelInfoReaderProvider * small clean up * NamespaceManager, SystemModelInfoProvider * clean up * NamedType, InvalidRedeclarationException * Break out DataType interface * DataType * BaseDataType * Little bit of cleanup for choice types * Fixing Locale for string format * ClassType * ProfileType * ListType * IntervalType * TypeParameter * TupleType, ClassType * Bug fixes for classes and tuples * GenericClassSignatureParser * More cleanup of GenericClassSignatureParser * Remove unused assertion * TrackBack * Trackable * ElmLibraryReader/Writer and factories * SimpleElmEngine, SimpleElmEvaluator * ElmVisitor interfaces * Fix spelling * LibrarySourceProvider * Fix spelling errors * BaseElmVisitor * Remove some usages of Apache commons --- .../fhir/npm/NpmLibrarySourceProvider.java | 10 + .../cqframework/cql/cql2elm/Cql2ElmVisitor.kt | 64 +- .../cqframework/cql/cql2elm/CqlTranslator.kt | 12 +- .../cql2elm/DefaultLibrarySourceProvider.kt | 11 + .../cqframework/cql/cql2elm/LibraryBuilder.kt | 64 +- .../cqframework/cql/cql2elm/LibraryManager.kt | 3 +- .../cql/cql2elm/LibrarySourceProvider.java | 16 - .../cql/cql2elm/LibrarySourceProvider.kt | 19 + .../cql2elm/StringLibrarySourceProvider.kt | 11 + .../cql/cql2elm/SystemFunctionResolver.kt | 10 +- .../cql/cql2elm/SystemMethodResolver.kt | 12 +- .../cqframework/cql/cql2elm/model/Operator.kt | 2 +- .../CqlPreprocessorElmCommonVisitor.kt | 17 +- .../cql/cql2elm/NamespaceTests.java | 9 + .../evaluation/TestLibrarySourceProvider.java | 10 + .../jackson/ElmJsonLibraryWriter.java | 6 +- .../jackson/ElmXmlLibraryWriter.java | 3 +- .../cqframework/cql/elm/IdObjectFactory.kt | 48 - .../cql/elm/evaluating/SimpleElmEngine.java | 1490 ------- .../cql/elm/evaluating/SimpleElmEngine.kt | 1547 +++++++ .../elm/evaluating/SimpleElmEvaluator.java | 54 - .../cql/elm/evaluating/SimpleElmEvaluator.kt | 60 + .../cql/elm/serializing/ElmLibraryReader.java | 24 - .../cql/elm/serializing/ElmLibraryReader.kt | 23 + .../serializing/ElmLibraryReaderFactory.java | 38 - .../serializing/ElmLibraryReaderFactory.kt | 38 + .../serializing/ElmLibraryReaderProvider.java | 5 - .../serializing/ElmLibraryReaderProvider.kt | 5 + .../cql/elm/serializing/ElmLibraryWriter.java | 11 - .../cql/elm/serializing/ElmLibraryWriter.kt | 11 + .../serializing/ElmLibraryWriterFactory.java | 38 - .../serializing/ElmLibraryWriterFactory.kt | 38 + .../serializing/ElmLibraryWriterProvider.java | 5 - .../serializing/ElmLibraryWriterProvider.kt | 5 + .../cql/elm/serializing/LibraryWrapper.java | 15 - .../cql/elm/serializing/LibraryWrapper.kt | 5 + .../cql/elm/tracking/TrackBack.java | 95 - .../cqframework/cql/elm/tracking/TrackBack.kt | 35 + .../cql/elm/tracking/Trackable.java | 43 - .../cqframework/cql/elm/tracking/Trackable.kt | 18 + .../cqframework/cql/elm/utility/Visitors.java | 23 - .../cqframework/cql/elm/utility/Visitors.kt | 20 + .../elm/visiting/BaseElmClinicalVisitor.java | 629 --- .../elm/visiting/BaseElmClinicalVisitor.kt | 656 +++ .../cql/elm/visiting/BaseElmLibraryVisitor.kt | 10 +- .../cql/elm/visiting/BaseElmVisitor.java | 3632 ---------------- .../cql/elm/visiting/BaseElmVisitor.kt | 3734 +++++++++++++++++ .../cql/elm/visiting/ElmClinicalVisitor.java | 273 -- .../cql/elm/visiting/ElmClinicalVisitor.kt | 289 ++ .../cql/elm/visiting/ElmLibraryVisitor.java | 52 - .../cql/elm/visiting/ElmLibraryVisitor.kt | 54 + .../cql/elm/visiting/ElmVisitor.java | 2142 ---------- .../cql/elm/visiting/ElmVisitor.kt | 2228 ++++++++++ .../cql/elm/visiting/FunctionalElmVisitor.kt | 8 +- .../cql/elm/visiting/RandomElmGraphTest.kt | 4 +- .../fhirpath/TestLibrarySourceProvider.java | 10 + .../fhir/data/TestLibrarySourceProvider.java | 10 + .../execution/MapLibrarySourceProvider.java | 11 + .../execution/TestLibrarySourceProvider.java | 10 + .../quick/FhirLibrarySourceProvider.java | 10 + 60 files changed, 8996 insertions(+), 8739 deletions(-) delete mode 100644 Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/LibrarySourceProvider.java create mode 100644 Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/LibrarySourceProvider.kt delete mode 100644 Src/java/elm/src/main/java/org/cqframework/cql/elm/evaluating/SimpleElmEngine.java create mode 100644 Src/java/elm/src/main/java/org/cqframework/cql/elm/evaluating/SimpleElmEngine.kt delete mode 100644 Src/java/elm/src/main/java/org/cqframework/cql/elm/evaluating/SimpleElmEvaluator.java create mode 100644 Src/java/elm/src/main/java/org/cqframework/cql/elm/evaluating/SimpleElmEvaluator.kt delete mode 100644 Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryReader.java create mode 100644 Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryReader.kt delete mode 100644 Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryReaderFactory.java create mode 100644 Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryReaderFactory.kt delete mode 100644 Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryReaderProvider.java create mode 100644 Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryReaderProvider.kt delete mode 100644 Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryWriter.java create mode 100644 Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryWriter.kt delete mode 100644 Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryWriterFactory.java create mode 100644 Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryWriterFactory.kt delete mode 100644 Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryWriterProvider.java create mode 100644 Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryWriterProvider.kt delete mode 100644 Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/LibraryWrapper.java create mode 100644 Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/LibraryWrapper.kt delete mode 100644 Src/java/elm/src/main/java/org/cqframework/cql/elm/tracking/TrackBack.java create mode 100644 Src/java/elm/src/main/java/org/cqframework/cql/elm/tracking/TrackBack.kt delete mode 100644 Src/java/elm/src/main/java/org/cqframework/cql/elm/tracking/Trackable.java create mode 100644 Src/java/elm/src/main/java/org/cqframework/cql/elm/tracking/Trackable.kt delete mode 100644 Src/java/elm/src/main/java/org/cqframework/cql/elm/utility/Visitors.java create mode 100644 Src/java/elm/src/main/java/org/cqframework/cql/elm/utility/Visitors.kt delete mode 100644 Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/BaseElmClinicalVisitor.java create mode 100644 Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/BaseElmClinicalVisitor.kt delete mode 100644 Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/BaseElmVisitor.java create mode 100644 Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/BaseElmVisitor.kt delete mode 100644 Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/ElmClinicalVisitor.java create mode 100644 Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/ElmClinicalVisitor.kt delete mode 100644 Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/ElmLibraryVisitor.java create mode 100644 Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/ElmLibraryVisitor.kt delete mode 100644 Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/ElmVisitor.java create mode 100644 Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/ElmVisitor.kt diff --git a/Src/java/cqf-fhir-npm/src/main/java/org/cqframework/fhir/npm/NpmLibrarySourceProvider.java b/Src/java/cqf-fhir-npm/src/main/java/org/cqframework/fhir/npm/NpmLibrarySourceProvider.java index bf35eb5cc..4a9fd140d 100644 --- a/Src/java/cqf-fhir-npm/src/main/java/org/cqframework/fhir/npm/NpmLibrarySourceProvider.java +++ b/Src/java/cqf-fhir-npm/src/main/java/org/cqframework/fhir/npm/NpmLibrarySourceProvider.java @@ -4,6 +4,7 @@ import java.io.IOException; import java.io.InputStream; import java.util.List; +import org.cqframework.cql.cql2elm.LibraryContentType; import org.cqframework.cql.cql2elm.LibrarySourceProvider; import org.hl7.elm.r1.VersionedIdentifier; import org.hl7.fhir.r5.context.ILoggingService; @@ -67,4 +68,13 @@ public InputStream getLibrarySource(VersionedIdentifier identifier) { return null; } + + @Override + public InputStream getLibraryContent(VersionedIdentifier libraryIdentifier, LibraryContentType type) { + if (LibraryContentType.CQL == type) { + return getLibrarySource(libraryIdentifier); + } + + return null; + } } diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/Cql2ElmVisitor.kt b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/Cql2ElmVisitor.kt index 638bc2353..7a1c03f15 100755 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/Cql2ElmVisitor.kt +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/Cql2ElmVisitor.kt @@ -221,7 +221,7 @@ class Cql2ElmVisitor( } if (param.default != null) { if (paramType != null) { - libraryBuilder.verifyType(param.default.resultType, paramType) + libraryBuilder.verifyType(param.default.resultType!!, paramType) } else { paramType = param.default.resultType } @@ -476,7 +476,7 @@ class Cql2ElmVisitor( ) track(modelContextDefinition, ctx) modelContextDefinition.expression.resultType = contextType - modelContextDefinition.setResultType(contextType) + modelContextDefinition.resultType = contextType libraryBuilder.addExpression(modelContextDefinition) contextDefinitions[modelContext.name] = modelContextDefinition } @@ -489,9 +489,7 @@ class Cql2ElmVisitor( track(modelContextDefinition, ctx) modelContextDefinition.expression.resultType = libraryBuilder.resolveTypeName("System", "Any") - modelContextDefinition.setResultType( - modelContextDefinition.expression.resultType - ) + modelContextDefinition.resultType = modelContextDefinition.expression.resultType libraryBuilder.addExpression(modelContextDefinition) contextDefinitions[modelContext.name] = modelContextDefinition } @@ -635,7 +633,7 @@ class Cql2ElmVisitor( val tupleType = TupleType() for (elementContext in ctx.tupleElementSelector()) { val element = visit(elementContext) as TupleElement - tupleType.addElement(TupleTypeElement(element.name, element.resultType)) + tupleType.addElement(TupleTypeElement(element.name, element.resultType!!)) tuple.element.add(element) } tuple.resultType = tupleType @@ -701,7 +699,7 @@ class Cql2ElmVisitor( val listTypeSpecifier = of.createListTypeSpecifier().withElementType(elementTypeSpecifier) track(listTypeSpecifier, ctx.typeSpecifier()!!) - listType = ListType(elementTypeSpecifier.resultType) + listType = ListType(elementTypeSpecifier.resultType!!) listTypeSpecifier.resultType = listType } var elementType = elementTypeSpecifier?.resultType @@ -714,7 +712,7 @@ class Cql2ElmVisitor( ?: @Suppress("TooGenericExceptionThrown") throw RuntimeException("Element failed to parse") if (elementType != null) { - libraryBuilder.verifyType(element.resultType, elementType) + libraryBuilder.verifyType(element.resultType!!, elementType) } else { if (initialInferredElementType == null) { initialInferredElementType = element.resultType @@ -746,9 +744,9 @@ class Cql2ElmVisitor( elementType = inferredElementType ?: libraryBuilder.resolveTypeName("System", "Any") } for (element in elements) { - if (!elementType!!.isSuperTypeOf(element.resultType)) { + if (!elementType!!.isSuperTypeOf(element.resultType!!)) { val conversion = - libraryBuilder.findConversion(element.resultType, elementType, true, false) + libraryBuilder.findConversion(element.resultType!!, elementType, true, false) if (conversion != null) { list.element.add(libraryBuilder.convertExpression(element, conversion)) } else { @@ -1252,10 +1250,10 @@ class Cql2ElmVisitor( parseExpression(ctx.expressionTerm(1)) ) libraryBuilder.resolveBinaryCall("System", operatorName, (exp as BinaryExpression?)!!) - if (exp.getResultType() === libraryBuilder.resolveTypeName("System", "String")) { + if (exp.resultType === libraryBuilder.resolveTypeName("System", "String")) { val concatenate: Concatenate = of.createConcatenate() concatenate.operand.addAll(exp.operand) - concatenate.resultType = exp.getResultType() + concatenate.resultType = exp.resultType exp = concatenate } } else { @@ -1833,8 +1831,8 @@ class Cql2ElmVisitor( if (!equal(operand!!.resultType, targetType!!.resultType)) { val conversion: Conversion = libraryBuilder.findConversion( - operand.resultType, - targetType.resultType, + operand.resultType!!, + targetType.resultType!!, false, true ) @@ -2753,7 +2751,7 @@ class Cql2ElmVisitor( val resultType: DataType? = libraryBuilder.ensureCompatibleTypes( ifObject.then.resultType, - ifObject.getElse().resultType + ifObject.getElse().resultType!! ) ifObject.resultType = resultType ifObject.then = libraryBuilder.ensureCompatible(ifObject.then, resultType) @@ -2785,7 +2783,7 @@ class Cql2ElmVisitor( resultType = libraryBuilder.ensureCompatibleTypes( resultType, - result.getElse().resultType + result.getElse().resultType!! ) } else { result.comparand = parseExpression(pt) @@ -2795,8 +2793,8 @@ class Cql2ElmVisitor( val caseItem = visit(pt) as CaseItem if (result.comparand != null) { libraryBuilder.verifyType( - caseItem.getWhen().resultType, - result.comparand.resultType + caseItem.getWhen().resultType!!, + result.comparand.resultType!! ) } else { verifyType( @@ -2808,7 +2806,7 @@ class Cql2ElmVisitor( if (resultType == null) { caseItem.then.resultType } else { - libraryBuilder.ensureCompatibleTypes(resultType, caseItem.then.resultType) + libraryBuilder.ensureCompatibleTypes(resultType, caseItem.then.resultType!!) } result.caseItem.add(caseItem) } @@ -3105,7 +3103,7 @@ class Cql2ElmVisitor( } else if (libraryBuilder.isCompatibleWith("1.5")) { mCodeComparator = if ( - terminology.resultType.isSubTypeOf( + terminology.resultType!!.isSubTypeOf( libraryBuilder.resolveTypeName("System", "Vocabulary")!! ) ) @@ -3225,7 +3223,7 @@ class Cql2ElmVisitor( )) ) { if ( - terminology.resultType.isSubTypeOf( + terminology.resultType!!.isSubTypeOf( libraryBuilder.resolveTypeName("System", "Vocabulary")!! ) ) @@ -3233,7 +3231,7 @@ class Cql2ElmVisitor( else "contains" } else { if ( - terminology.resultType.isSubTypeOf( + terminology.resultType!!.isSubTypeOf( libraryBuilder.resolveTypeName("System", "Vocabulary")!! ) ) @@ -3318,7 +3316,7 @@ class Cql2ElmVisitor( !((equivalent.operand[1].resultType is ListType || (libraryBuilder.isCompatibleWith("1.5") && equivalent.operand[1] - .resultType + .resultType!! .isSubTypeOf( libraryBuilder.resolveTypeName("System", "Vocabulary")!! )))) @@ -3340,7 +3338,7 @@ class Cql2ElmVisitor( !((equal.operand[1].resultType is ListType || (libraryBuilder.isCompatibleWith("1.5") && equal.operand[1] - .resultType + .resultType!! .isSubTypeOf( libraryBuilder.resolveTypeName("System", "Vocabulary")!! )))) @@ -3419,7 +3417,7 @@ class Cql2ElmVisitor( // retrieve typing if ( ((libraryBuilder.isCompatibleWith("1.5") && - !(terminology.resultType.isSubTypeOf( + !(terminology.resultType!!.isSubTypeOf( libraryBuilder.resolveTypeName("System", "Vocabulary")!! ))) || (!libraryBuilder.isCompatibleWith("1.5") && @@ -3536,7 +3534,7 @@ class Cql2ElmVisitor( element.value.resultType = sourceType // Doesn't use the fluent API to avoid casting element.resultType = element.value.resultType - returnType.addElement(TupleTypeElement(element.name, element.resultType)) + returnType.addElement(TupleTypeElement(element.name, element.resultType!!)) returnExpression.element.add(element) } returnExpression.resultType = @@ -3730,8 +3728,8 @@ class Cql2ElmVisitor( ) { val o: Operator? = libraryBuilder.conversionMap.getConversionOperator( - functionRef.operand[0].resultType, - functionRef.resultType + functionRef.operand[0].resultType!!, + functionRef.resultType!! ) if ( ((o != null) && @@ -3829,10 +3827,10 @@ class Cql2ElmVisitor( * @return `true` if the RHS supports refactoring to a `Retrieve`, `false` otherwise. */ private fun isRHSEligibleForDateRangeOptimization(rhs: Expression): Boolean { - return (rhs.resultType.isSubTypeOf( + return (rhs.resultType!!.isSubTypeOf( libraryBuilder.resolveTypeName("System", "DateTime")!! ) || - rhs.resultType.isSubTypeOf( + rhs.resultType!!.isSubTypeOf( IntervalType(libraryBuilder.resolveTypeName("System", "DateTime")!!) )) @@ -3962,7 +3960,7 @@ class Cql2ElmVisitor( returnClause.expression = parseExpression(ctx.expression()) returnClause.resultType = if (libraryBuilder.peekQueryContext().isSingular) returnClause.expression.resultType - else ListType(returnClause.expression.resultType) + else ListType(returnClause.expression.resultType!!) return returnClause } @@ -4011,7 +4009,7 @@ class Cql2ElmVisitor( aggregateClause.expression = parseExpression(ctx.expression()) aggregateClause.resultType = aggregateClause.expression.resultType if (aggregateClause.starting == null) { - accumulator.setResultType(aggregateClause.resultType) + accumulator.resultType = aggregateClause.resultType aggregateClause.starting = accumulator } return aggregateClause @@ -4033,7 +4031,7 @@ class Cql2ElmVisitor( of.createByColumn() .withPath(sortExpression.name) .withDirection(parseSortDirection(ctx.sortDirection())) - .withResultType(sortExpression.getResultType()) as SortByItem + .withResultType(sortExpression.resultType) as SortByItem } else of.createByExpression() .withExpression(sortExpression) diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/CqlTranslator.kt b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/CqlTranslator.kt index e700a0a71..7476b1cdf 100644 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/CqlTranslator.kt +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/CqlTranslator.kt @@ -28,7 +28,7 @@ class CqlTranslator( compiler.run(`is`) } - private fun toXml(library: Library?): String { + private fun toXml(library: Library): String { return try { convertToXml(library) } catch (e: IOException) { @@ -36,7 +36,7 @@ class CqlTranslator( } } - private fun toJson(library: Library?): String { + private fun toJson(library: Library): String { return try { convertToJson(library) } catch (e: IOException) { @@ -48,11 +48,11 @@ class CqlTranslator( } fun toXml(): String { - return toXml(compiler.library) + return toXml(compiler.library!!) } fun toJson(): String { - return toJson(compiler.library) + return toJson(compiler.library!!) } fun toELM(): Library? { @@ -251,7 +251,7 @@ class CqlTranslator( } @Throws(IOException::class) - fun convertToXml(library: Library?): String { + fun convertToXml(library: Library): String { val writer = StringWriter() ElmLibraryWriterFactory.getWriter(LibraryContentType.XML.mimeType()) .write(library, writer) @@ -260,7 +260,7 @@ class CqlTranslator( @JvmStatic @Throws(IOException::class) - fun convertToJson(library: Library?): String { + fun convertToJson(library: Library): String { val writer = StringWriter() ElmLibraryWriterFactory.getWriter(LibraryContentType.JSON.mimeType()) .write(library, writer) diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/DefaultLibrarySourceProvider.kt b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/DefaultLibrarySourceProvider.kt index 6ed22f74d..23d05091e 100644 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/DefaultLibrarySourceProvider.kt +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/DefaultLibrarySourceProvider.kt @@ -117,4 +117,15 @@ class DefaultLibrarySourceProvider(path: Path) : LibrarySourceProvider, PathAwar } return null } + + override fun getLibraryContent( + libraryIdentifier: VersionedIdentifier, + type: LibraryContentType + ): InputStream? { + if (LibraryContentType.CQL == type) { + return getLibrarySource(libraryIdentifier) + } + + return null + } } diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/LibraryBuilder.kt b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/LibraryBuilder.kt index 288187bf9..0820af4b2 100644 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/LibraryBuilder.kt +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/LibraryBuilder.kt @@ -5,7 +5,6 @@ package org.cqframework.cql.cql2elm import java.math.BigDecimal import java.util.* import javax.xml.namespace.QName -import org.apache.commons.lang3.StringUtils import org.cqframework.cql.cql2elm.model.* import org.cqframework.cql.cql2elm.model.SystemLibraryHelper.load import org.cqframework.cql.cql2elm.model.invocation.* @@ -589,9 +588,9 @@ class LibraryBuilder( err.errorSeverity = toErrorSeverity(e.severity) if (e.locator != null) { if (e.locator.library != null) { - err.librarySystem = e.locator.library.system - err.libraryId = e.locator.library.id - err.libraryVersion = e.locator.library.version + err.librarySystem = e.locator.library?.system + err.libraryId = e.locator.library?.id + err.libraryVersion = e.locator.library?.version } err.startLine = e.locator.startLine err.endLine = e.locator.endLine @@ -954,13 +953,13 @@ class LibraryBuilder( .createAs() .withOperand(left) .withAsTypeSpecifier(dataTypeToTypeSpecifier(targetType)) - left.setResultType(targetType) + left.resultType = targetType right = objectFactory .createAs() .withOperand(right) .withAsTypeSpecifier(dataTypeToTypeSpecifier(targetType)) - right.setResultType(targetType) + right.resultType = targetType } } } @@ -1022,7 +1021,7 @@ class LibraryBuilder( if ( right is ValueSetRef || (isCompatibleWith("1.5") && - right.resultType.isCompatibleWith(resolveTypeName("System", "ValueSet")!!) && + right.resultType!!.isCompatibleWith(resolveTypeName("System", "ValueSet")!!) && right.resultType != resolveTypeName("System", "Any")) ) { if (left.resultType is ListType) { @@ -1048,7 +1047,9 @@ class LibraryBuilder( if ( right is CodeSystemRef || (isCompatibleWith("1.5") && - right.resultType.isCompatibleWith(resolveTypeName("System", "CodeSystem")!!) && + right.resultType!!.isCompatibleWith( + resolveTypeName("System", "CodeSystem")!! + ) && right.resultType != resolveTypeName("System", "Any")) ) { if (left.resultType is ListType) { @@ -1377,7 +1378,7 @@ class LibraryBuilder( operatorName ) } - dataTypes.add(operand.resultType) + dataTypes.add(operand.resultType!!) } return CallContext( libraryName, @@ -1491,7 +1492,7 @@ class LibraryBuilder( operatorName ) } - dataTypes.add(operand.resultType) + dataTypes.add(operand.resultType!!) } val callContext = CallContext( @@ -1556,7 +1557,7 @@ class LibraryBuilder( } private fun isInterFunctionAccess(f1: String, f2: String?): Boolean { - return if (StringUtils.isNoneBlank(f1) && StringUtils.isNoneBlank(f2)) { + return if (f1.isNotBlank() && !f2.isNullOrBlank()) { !f1.equals(f2, ignoreCase = true) } else false } @@ -1728,7 +1729,7 @@ class LibraryBuilder( targetType: DataType, implicit: Boolean = true ): Expression { - val conversion = findConversion(expression.resultType, targetType, implicit, false) + val conversion = findConversion(expression.resultType!!, targetType, implicit, false) if (conversion != null) { return convertExpression(expression, conversion) } @@ -1809,7 +1810,7 @@ class LibraryBuilder( fun resolveToList(expression: Expression?): Expression { // Use a ToList operator here to avoid duplicate evaluation of the operand. val toList = objectFactory.createToList().withOperand(expression) - toList.resultType = ListType(expression!!.resultType) + toList.resultType = ListType(expression!!.resultType!!) return toList } @@ -1848,7 +1849,7 @@ class LibraryBuilder( fun resolveToInterval(expression: Expression?): Expression { val condition = objectFactory.createIf() condition.condition = buildIsNull(expression) - condition.then = buildNull(IntervalType(expression!!.resultType)) + condition.then = buildNull(IntervalType(expression!!.resultType!!)) val toInterval = objectFactory .createInterval() @@ -1856,7 +1857,7 @@ class LibraryBuilder( .withHigh(expression) .withLowClosed(true) .withHighClosed(true) - toInterval.resultType = IntervalType(expression.resultType) + toInterval.resultType = IntervalType(expression.resultType!!) condition.setElse(toInterval) condition.resultType = resolveTypeName("System", "Boolean") return condition @@ -2260,7 +2261,7 @@ class LibraryBuilder( if (targetType == null) { return objectFactory.createNull() } - return if (!targetType.isSuperTypeOf(expression!!.resultType)) { + return if (!targetType.isSuperTypeOf(expression!!.resultType!!)) { convertExpression(expression, targetType, true) } else expression } @@ -2269,7 +2270,7 @@ class LibraryBuilder( if (targetType == null) { return objectFactory.createNull() } - return if (!targetType.isSuperTypeOf(expression!!.resultType)) { + return if (!targetType.isSuperTypeOf(expression!!.resultType!!)) { convertExpression(expression, targetType, false) } else expression } @@ -2410,7 +2411,7 @@ class LibraryBuilder( .withHigh(high) .withHighClosed(highClosed) val pointType: DataType? = - ensureCompatibleTypes(result.low.resultType, result.high.resultType) + ensureCompatibleTypes(result.low.resultType, result.high.resultType!!) result.resultType = IntervalType(pointType!!) result.low = ensureCompatible(result.low, pointType) result.high = ensureCompatible(result.high, pointType) @@ -2683,7 +2684,7 @@ class LibraryBuilder( checkLiteralContext() val parameterRef: ParameterRef = objectFactory.createParameterRef().withName(element.name) - parameterRef.resultType = element.getResultType() + parameterRef.resultType = element.resultType if (parameterRef.resultType == null) { // ERROR: throw IllegalArgumentException( @@ -2700,7 +2701,7 @@ class LibraryBuilder( checkLiteralContext() val valuesetRef: ValueSetRef = objectFactory.createValueSetRef().withName(element.name) - valuesetRef.resultType = element.getResultType() + valuesetRef.resultType = element.resultType if (valuesetRef.resultType == null) { // ERROR: throw IllegalArgumentException( @@ -2720,7 +2721,7 @@ class LibraryBuilder( checkLiteralContext() val codesystemRef: CodeSystemRef = objectFactory.createCodeSystemRef().withName(element.name) - codesystemRef.resultType = element.getResultType() + codesystemRef.resultType = element.resultType if (codesystemRef.resultType == null) { // ERROR: throw IllegalArgumentException( @@ -2736,7 +2737,7 @@ class LibraryBuilder( if (element is CodeDef) { checkLiteralContext() val codeRef: CodeRef = objectFactory.createCodeRef().withName(element.name) - codeRef.resultType = element.getResultType() + codeRef.resultType = element.resultType if (codeRef.resultType == null) { // ERROR: throw IllegalArgumentException( @@ -2752,7 +2753,7 @@ class LibraryBuilder( if (element is ConceptDef) { checkLiteralContext() val conceptRef: ConceptRef = objectFactory.createConceptRef().withName(element.name) - conceptRef.resultType = element.getResultType() + conceptRef.resultType = element.resultType if (conceptRef.resultType == null) { // ERROR: throw IllegalArgumentException( @@ -3351,7 +3352,7 @@ class LibraryBuilder( .createParameterRef() .withLibraryName(libraryName) .withName(memberIdentifier) - result.resultType = element.getResultType() + result.resultType = element.resultType return result } if (element is ValueSetDef) { @@ -3361,7 +3362,7 @@ class LibraryBuilder( .createValueSetRef() .withLibraryName(libraryName) .withName(memberIdentifier) - result.resultType = element.getResultType() + result.resultType = element.resultType if (isCompatibleWith("1.5")) { result.isPreserve = true } @@ -3374,7 +3375,7 @@ class LibraryBuilder( .createCodeSystemRef() .withLibraryName(libraryName) .withName(memberIdentifier) - result.resultType = element.getResultType() + result.resultType = element.resultType return result } if (element is CodeDef) { @@ -3384,7 +3385,7 @@ class LibraryBuilder( .createCodeRef() .withLibraryName(libraryName) .withName(memberIdentifier) - result.resultType = element.getResultType() + result.resultType = element.resultType return result } if (element is ConceptDef) { @@ -3394,7 +3395,7 @@ class LibraryBuilder( .createConceptRef() .withLibraryName(libraryName) .withName(memberIdentifier) - result.resultType = element.getResultType() + result.resultType = element.resultType return result } } @@ -3409,8 +3410,7 @@ class LibraryBuilder( ) ) } else if (left is AliasRef) { - val resolution: PropertyResolution? = - resolveProperty(left.getResultType(), memberIdentifier) + val resolution: PropertyResolution? = resolveProperty(left.resultType, memberIdentifier) val result: Expression = buildProperty(left.name, resolution!!.name, resolution.isSearch, resolution.type) return applyTargetMap(result, resolution.targetMap) @@ -3454,7 +3454,7 @@ class LibraryBuilder( .withDistinct(false) .withExpression(accessor) ) - query.resultType = ListType(accessor!!.resultType) + query.resultType = ListType(accessor!!.resultType!!) if (accessor.resultType is ListType) { val result: Flatten = objectFactory.createFlatten().withOperand(query) result.resultType = accessor.resultType @@ -3579,7 +3579,7 @@ class LibraryBuilder( if (inQueryContext() && scope.queries.peek().inSourceClause()) { scope.queries.peek().referencesSpecificContextValue = true } - val resultType: DataType = expressionDef.resultType + val resultType: DataType = expressionDef.resultType!! return if (resultType !is ListType) { ListType(resultType) } else { diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/LibraryManager.kt b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/LibraryManager.kt index d475d2c65..a6eea7205 100644 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/LibraryManager.kt +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/LibraryManager.kt @@ -7,7 +7,6 @@ import java.util.* import kotlin.collections.ArrayList import kotlin.collections.HashMap import kotlin.collections.HashSet -import org.apache.commons.lang3.StringUtils import org.cqframework.cql.cql2elm.model.CompiledLibrary import org.cqframework.cql.elm.serializing.ElmLibraryReaderFactory import org.fhir.ucum.UcumEssenceService @@ -368,7 +367,7 @@ constructor( } private fun isVersionCompatible(library: Library): Boolean { - if (!StringUtils.isEmpty(cqlCompilerOptions.compatibilityLevel)) { + if (cqlCompilerOptions.compatibilityLevel.isNotBlank()) { if (library.annotation != null) { val version: String? = CompilerOptions.getCompilerVersion(library) if (version != null) { diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/LibrarySourceProvider.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/LibrarySourceProvider.java deleted file mode 100644 index 038c0b307..000000000 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/LibrarySourceProvider.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.cqframework.cql.cql2elm; - -import java.io.InputStream; -import org.hl7.elm.r1.VersionedIdentifier; - -public interface LibrarySourceProvider { - InputStream getLibrarySource(VersionedIdentifier libraryIdentifier); - - default InputStream getLibraryContent(VersionedIdentifier libraryIdentifier, LibraryContentType type) { - if (LibraryContentType.CQL == type) { - return getLibrarySource(libraryIdentifier); - } - - return null; - } -} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/LibrarySourceProvider.kt b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/LibrarySourceProvider.kt new file mode 100644 index 000000000..87eaa9cbd --- /dev/null +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/LibrarySourceProvider.kt @@ -0,0 +1,19 @@ +package org.cqframework.cql.cql2elm + +import java.io.InputStream +import org.hl7.elm.r1.VersionedIdentifier + +interface LibrarySourceProvider { + fun getLibrarySource(libraryIdentifier: VersionedIdentifier): InputStream? + + fun getLibraryContent( + libraryIdentifier: VersionedIdentifier, + type: LibraryContentType + ): InputStream? { + if (LibraryContentType.CQL == type) { + return getLibrarySource(libraryIdentifier) + } + + return null + } +} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/StringLibrarySourceProvider.kt b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/StringLibrarySourceProvider.kt index cb437f58b..20d383577 100644 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/StringLibrarySourceProvider.kt +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/StringLibrarySourceProvider.kt @@ -39,4 +39,15 @@ class StringLibrarySourceProvider(private val libraries: List) : Library } return if (matches.size == 1) ByteArrayInputStream(matches[0].toByteArray()) else null } + + override fun getLibraryContent( + libraryIdentifier: VersionedIdentifier, + type: LibraryContentType + ): InputStream? { + if (LibraryContentType.CQL == type) { + return getLibrarySource(libraryIdentifier) + } + + return null + } } diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/SystemFunctionResolver.kt b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/SystemFunctionResolver.kt index 129c0d436..3618c1002 100644 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/SystemFunctionResolver.kt +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/SystemFunctionResolver.kt @@ -98,21 +98,23 @@ class SystemFunctionResolver(private val builder: LibraryBuilder, of: IdObjectFa // If the op can be converted to both a Date and a DateTime, throw an ambiguous // error if ( - !(op.resultType.isSubTypeOf(builder.resolveTypeName("System", "Date")!!) || - op.resultType.isSubTypeOf( + !(op.resultType!!.isSubTypeOf( + builder.resolveTypeName("System", "Date")!! + ) || + op.resultType!!.isSubTypeOf( builder.resolveTypeName("System", "DateTime")!! )) ) { val dateConversion = builder.findConversion( - op.resultType, + op.resultType!!, builder.resolveTypeName("System", "Date")!!, true, false ) val dateTimeConversion = builder.findConversion( - op.resultType, + op.resultType!!, builder.resolveTypeName("System", "DateTime")!!, true, false diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/SystemMethodResolver.kt b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/SystemMethodResolver.kt index 7e768d68c..0508662e6 100644 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/SystemMethodResolver.kt +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/SystemMethodResolver.kt @@ -174,7 +174,7 @@ class SystemMethodResolver( // may include the result // of invoking the element expression on intermediate results if (isSingular) { - repeat.resultType = ListType(select!!.resultType) + repeat.resultType = ListType(select!!.resultType!!) } else { repeat.resultType = select!!.resultType } @@ -214,7 +214,7 @@ class SystemMethodResolver( letRef.resultType = select.resultType returnClause.expression = letRef returnClause.resultType = - if (isSingular) letRef.resultType else ListType(letRef.resultType) + if (isSingular) letRef.resultType else ListType(letRef.resultType!!) val query = createQuery(source, let, where, returnClause) if (!isSingular && isListResult) { params = ArrayList() @@ -281,7 +281,7 @@ class SystemMethodResolver( val returnClause = of.createReturnClause() returnClause.expression = builder.createLiteral(java.lang.Boolean.valueOf(true)) if (query.resultType is ListType) { - returnClause.resultType = ListType(returnClause.expression.resultType) + returnClause.resultType = ListType(returnClause.expression.resultType!!) } else { returnClause.resultType = returnClause.expression.resultType } @@ -301,7 +301,7 @@ class SystemMethodResolver( val children = of.createChildren() children.source = target val dataTypes: MutableSet = HashSet() - gatherChildTypes(target.resultType, false, dataTypes) + gatherChildTypes(target.resultType!!, false, dataTypes) if (dataTypes.size == 1) { children.resultType = ListType(dataTypes.iterator().next()) } else { @@ -316,7 +316,7 @@ class SystemMethodResolver( elements.add(target) elements.add(argument) val elementType = - builder.ensureCompatibleTypes(target.resultType, argument!!.resultType)!! + builder.ensureCompatibleTypes(target.resultType, argument!!.resultType!!)!! val list = of.createList() list.resultType = ListType(elementType) list.element.add(builder.ensureCompatible(target, elementType)) @@ -359,7 +359,7 @@ class SystemMethodResolver( val descendents = of.createDescendents() descendents.source = target val dataTypes: MutableSet = HashSet() - gatherChildTypes(target.resultType, true, dataTypes) + gatherChildTypes(target.resultType!!, true, dataTypes) if (dataTypes.size == 1) { descendents.resultType = ListType(dataTypes.toTypedArray()[0]) } else { diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/Operator.kt b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/Operator.kt index d7541216e..abcd16db0 100644 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/Operator.kt +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/Operator.kt @@ -24,7 +24,7 @@ open class Operator( functionDef: FunctionDef ) : this( functionDef.name, - Signature(functionDef.operand.map { it.resultType }), + Signature(functionDef.operand.map { it.resultType!! }), functionDef.resultType, functionDef, functionDef.accessLevel, diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/preprocessor/CqlPreprocessorElmCommonVisitor.kt b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/preprocessor/CqlPreprocessorElmCommonVisitor.kt index 241a59c01..c9812461c 100644 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/preprocessor/CqlPreprocessorElmCommonVisitor.kt +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/preprocessor/CqlPreprocessorElmCommonVisitor.kt @@ -11,7 +11,6 @@ import org.antlr.v4.kotlinruntime.TokenStream import org.antlr.v4.kotlinruntime.misc.Interval import org.antlr.v4.kotlinruntime.tree.ParseTree import org.antlr.v4.kotlinruntime.tree.TerminalNode -import org.apache.commons.lang3.tuple.Pair import org.cqframework.cql.cql2elm.* import org.cqframework.cql.cql2elm.model.Chunk import org.cqframework.cql.cql2elm.model.FunctionHeader @@ -156,7 +155,7 @@ abstract class CqlPreprocessorElmCommonVisitor( val typeSpecifier = of.createTupleTypeSpecifier() for (definitionContext in ctx.tupleElementDefinition()) { val element = visit(definitionContext) as TupleElementDefinition - resultType.addElement(TupleTypeElement(element.name, element.elementType.resultType)) + resultType.addElement(TupleTypeElement(element.name, element.elementType.resultType!!)) typeSpecifier.element.add(element) } typeSpecifier.resultType = resultType @@ -169,7 +168,7 @@ abstract class CqlPreprocessorElmCommonVisitor( for (typeSpecifierContext in ctx.typeSpecifier()) { val typeSpecifier = parseTypeSpecifier(typeSpecifierContext)!! typeSpecifiers.add(typeSpecifier) - types.add(typeSpecifier.resultType) + types.add(typeSpecifier.resultType!!) } val result = of.createChoiceTypeSpecifier().withChoice(typeSpecifiers) if (includeDeprecatedElements) { @@ -185,7 +184,7 @@ abstract class CqlPreprocessorElmCommonVisitor( ): IntervalTypeSpecifier { val result = of.createIntervalTypeSpecifier().withPointType(parseTypeSpecifier(ctx.typeSpecifier())) - val intervalType = IntervalType(result.pointType.resultType) + val intervalType = IntervalType(result.pointType.resultType!!) result.resultType = intervalType return result } @@ -193,7 +192,7 @@ abstract class CqlPreprocessorElmCommonVisitor( override fun visitListTypeSpecifier(ctx: ListTypeSpecifierContext): ListTypeSpecifier { val result = of.createListTypeSpecifier().withElementType(parseTypeSpecifier(ctx.typeSpecifier())) - val listType = ListType(result.elementType.resultType) + val listType = ListType(result.elementType.resultType!!) result.resultType = listType return result } @@ -588,6 +587,14 @@ abstract class CqlPreprocessorElmCommonVisitor( } } + data class Pair(val left: L, val right: R) { + companion object { + fun of(left: L, right: R): Pair { + return Pair(left, right) + } + } + } + private fun lookForTagName(header: String, startFrom: Int): Pair? { if (startFrom >= header.length) { return null diff --git a/Src/java/cql-to-elm/src/test/java/org/cqframework/cql/cql2elm/NamespaceTests.java b/Src/java/cql-to-elm/src/test/java/org/cqframework/cql/cql2elm/NamespaceTests.java index ea3f54ab3..c1fc947e1 100644 --- a/Src/java/cql-to-elm/src/test/java/org/cqframework/cql/cql2elm/NamespaceTests.java +++ b/Src/java/cql-to-elm/src/test/java/org/cqframework/cql/cql2elm/NamespaceTests.java @@ -40,6 +40,15 @@ public InputStream getLibrarySource(VersionedIdentifier libraryIdentifier) { libraryIdentifier.getVersion() != null ? ("-" + libraryIdentifier.getVersion()) : ""); return org.cqframework.cql.cql2elm.NamespaceTests.class.getResourceAsStream(libraryFileName); } + + @Override + public InputStream getLibraryContent(VersionedIdentifier libraryIdentifier, LibraryContentType type) { + if (LibraryContentType.CQL == type) { + return getLibrarySource(libraryIdentifier); + } + + return null; + } } @BeforeAll diff --git a/Src/java/elm-fhir/src/main/java/org/cqframework/cql/elm/evaluation/TestLibrarySourceProvider.java b/Src/java/elm-fhir/src/main/java/org/cqframework/cql/elm/evaluation/TestLibrarySourceProvider.java index 7b0ee53fb..ffd307980 100644 --- a/Src/java/elm-fhir/src/main/java/org/cqframework/cql/elm/evaluation/TestLibrarySourceProvider.java +++ b/Src/java/elm-fhir/src/main/java/org/cqframework/cql/elm/evaluation/TestLibrarySourceProvider.java @@ -1,6 +1,7 @@ package org.cqframework.cql.elm.evaluation; import java.io.InputStream; +import org.cqframework.cql.cql2elm.LibraryContentType; import org.cqframework.cql.cql2elm.LibrarySourceProvider; import org.hl7.elm.r1.VersionedIdentifier; @@ -14,4 +15,13 @@ public InputStream getLibrarySource(VersionedIdentifier libraryIdentifier) { // : ""); return TestLibrarySourceProvider.class.getResourceAsStream(libraryFileName); } + + @Override + public InputStream getLibraryContent(VersionedIdentifier libraryIdentifier, LibraryContentType type) { + if (LibraryContentType.CQL == type) { + return getLibrarySource(libraryIdentifier); + } + + return null; + } } diff --git a/Src/java/elm-jackson/src/main/java/org/cqframework/cql/elm/serializing/jackson/ElmJsonLibraryWriter.java b/Src/java/elm-jackson/src/main/java/org/cqframework/cql/elm/serializing/jackson/ElmJsonLibraryWriter.java index e661534f8..8453da244 100644 --- a/Src/java/elm-jackson/src/main/java/org/cqframework/cql/elm/serializing/jackson/ElmJsonLibraryWriter.java +++ b/Src/java/elm-jackson/src/main/java/org/cqframework/cql/elm/serializing/jackson/ElmJsonLibraryWriter.java @@ -10,16 +10,14 @@ public class ElmJsonLibraryWriter implements ElmLibraryWriter { @Override public void write(Library library, Writer writer) throws IOException { - LibraryWrapper wrapper = new LibraryWrapper(); - wrapper.setLibrary(library); + LibraryWrapper wrapper = new LibraryWrapper(library); ElmJsonMapper.getMapper().writeValue(writer, wrapper); } @Override public String writeAsString(Library library) { try { - LibraryWrapper wrapper = new LibraryWrapper(); - wrapper.setLibrary(library); + LibraryWrapper wrapper = new LibraryWrapper(library); return ElmJsonMapper.getMapper().writeValueAsString(wrapper); } catch (JsonProcessingException e) { throw new RuntimeException(e); diff --git a/Src/java/elm-jackson/src/main/java/org/cqframework/cql/elm/serializing/jackson/ElmXmlLibraryWriter.java b/Src/java/elm-jackson/src/main/java/org/cqframework/cql/elm/serializing/jackson/ElmXmlLibraryWriter.java index 10b7d88b7..76ce5bf12 100644 --- a/Src/java/elm-jackson/src/main/java/org/cqframework/cql/elm/serializing/jackson/ElmXmlLibraryWriter.java +++ b/Src/java/elm-jackson/src/main/java/org/cqframework/cql/elm/serializing/jackson/ElmXmlLibraryWriter.java @@ -21,8 +21,7 @@ public void write(Library library, Writer writer) throws IOException { @Override public String writeAsString(Library library) { try { - LibraryWrapper wrapper = new LibraryWrapper(); - wrapper.setLibrary(library); + LibraryWrapper wrapper = new LibraryWrapper(library); return ElmXmlMapper.getMapper().writeValueAsString(wrapper); } catch (JsonProcessingException e) { throw new RuntimeException(e); diff --git a/Src/java/elm/src/main/java/org/cqframework/cql/elm/IdObjectFactory.kt b/Src/java/elm/src/main/java/org/cqframework/cql/elm/IdObjectFactory.kt index c32557776..39a12dc6c 100644 --- a/Src/java/elm/src/main/java/org/cqframework/cql/elm/IdObjectFactory.kt +++ b/Src/java/elm/src/main/java/org/cqframework/cql/elm/IdObjectFactory.kt @@ -657,10 +657,6 @@ open class IdObjectFactory : ObjectFactory() { return super.createInstance().withLocalId(nextId()) } - // @Override - // public InstanceElement createInstanceElement() { - // return super.createInstanceElement().withLocalId(nextId()); - // } override fun createIntersect(): Intersect { return super.createIntersect().withLocalId(nextId()) } @@ -725,42 +721,6 @@ open class IdObjectFactory : ObjectFactory() { return super.createLibrary(value) } - // @Override - // public CodeSystems createLibraryCodeSystems() { - // return super.createLibraryCodeSystems().withLocalId(nextId()); - // } - // @Override - // public Codes createLibraryCodes() { - // return super.createLibraryCodes().withLocalId(nextId()); - // } - // @Override - // public Concepts createLibraryConcepts() { - // return super.createLibraryConcepts().withLocalId(nextId()); - // } - // @Override - // public Contexts createLibraryContexts() { - // return super.createLibraryContexts().withLocalId(nextId()); - // } - // @Override - // public Includes createLibraryIncludes() { - // return super.createLibraryIncludes().withLocalId(nextId()); - // } - // @Override - // public Parameters createLibraryParameters() { - // return super.createLibraryParameters().withLocalId(nextId()); - // } - // @Override - // public Statements createLibraryStatements() { - // return super.createLibraryStatements().withLocalId(nextId()); - // } - // @Override - // public Usings createLibraryUsings() { - // return super.createLibraryUsings().withLocalId(nextId()); - // } - // @Override - // public ValueSets createLibraryValueSets() { - // return super.createLibraryValueSets().withLocalId(nextId()); - // } override fun createList(): List { return super.createList().withLocalId(nextId()) } @@ -1173,10 +1133,6 @@ open class IdObjectFactory : ObjectFactory() { return super.createTuple().withLocalId(nextId()) } - // @Override - // public TupleElement createTupleElement() { - // return super.createTupleElement().withLocalId(nextId()); - // } override fun createTupleElementDefinition(): TupleElementDefinition { return super.createTupleElementDefinition().withLocalId(nextId()) } @@ -1209,10 +1165,6 @@ open class IdObjectFactory : ObjectFactory() { return super.createVariance().withLocalId(nextId()) } - // @Override - // public VersionedIdentifier createVersionedIdentifier() { - // return super.createVersionedIdentifier().withLocalId(nextId()); - // } override fun createWidth(): Width { return super.createWidth().withLocalId(nextId()) } diff --git a/Src/java/elm/src/main/java/org/cqframework/cql/elm/evaluating/SimpleElmEngine.java b/Src/java/elm/src/main/java/org/cqframework/cql/elm/evaluating/SimpleElmEngine.java deleted file mode 100644 index f096303cd..000000000 --- a/Src/java/elm/src/main/java/org/cqframework/cql/elm/evaluating/SimpleElmEngine.java +++ /dev/null @@ -1,1490 +0,0 @@ -package org.cqframework.cql.elm.evaluating; - -import java.math.BigDecimal; -import javax.xml.namespace.QName; -import org.hl7.elm.r1.*; - -/* -A simple ELM engine that is capable of limited evaluation of ELM -required for static analysis and other optimization use cases (such as -constant folding, data requirements analysis, limited constraint validation, -etc.) - */ -public class SimpleElmEngine { - public SimpleElmEngine() {} - - private boolean literalsEqual(Literal left, Literal right) { - return (left == null && right == null) - || (left != null - && left.getValueType() != null - && left.getValueType().equals(right.getValueType()) - && stringsEqual(left.getValue(), right.getValue())); - } - - public boolean booleansEqual(Expression left, Expression right) { - return expressionsEqual(left, right); - } - - public boolean integersEqual(Expression left, Expression right) { - return expressionsEqual(left, right); - } - - public boolean decimalsEqual(Expression left, Expression right) { - return expressionsEqual(left, right); - } - - public boolean decimalsEqual(BigDecimal left, BigDecimal right) { - if (left == null && right == null) { - return true; - } - - if (left == null || right == null) { - return false; - } - - return left.equals(right); - } - - public boolean quantitiesEqual(Quantity left, Quantity right) { - if (left == null && right == null) { - return true; - } - - if (left == null || right == null) { - return true; - } - - return decimalsEqual(left.getValue(), right.getValue()) && stringsEqual(left.getUnit(), right.getUnit()); - } - - public boolean stringsEqual(Expression left, Expression right) { - return expressionsEqual(left, right); - } - - public boolean dateTimesEqual(Expression left, Expression right) { - return expressionsEqual(left, right); - } - - public boolean dateRangesEqual(Expression left, Expression right) { - return expressionsEqual(left, right); - } - - public boolean stringsEqual(String left, String right) { - return (left == null && right == null) || (left != null && left.equals(right)); - } - - public boolean systemsEqual(CodeSystemRef left, CodeSystemRef right) { - // TODO: Needs to do the comparison on the URI, but I don't want to have to resolve here - return (left == null && right == null) - || (left != null - && stringsEqual(left.getLibraryName(), right.getLibraryName()) - && stringsEqual(left.getName(), right.getName())); - } - - public boolean valueSetsEqual(ValueSetRef left, ValueSetRef right) { - // TODO: Needs to do the comparison on the URI, but I don't want to have to resolve here - return (left == null && right == null) - || (left != null - && stringsEqual(left.getLibraryName(), right.getLibraryName()) - && stringsEqual(left.getName(), right.getName())); - } - - public boolean codesEqual(Expression left, Expression right) { - return expressionsEqual(left, right); - } - - public boolean qnamesEqual(QName left, QName right) { - if (left == null && right == null) { - return true; - } - - if (left == null || right == null) { - return false; - } - - return left.equals(right); - } - - public boolean typeSpecifiersEqual(TypeSpecifier left, TypeSpecifier right) { - if (left == null && right == null) { - return true; - } - - if (left == null || right == null) { - return false; - } - - // NamedTypeSpecifier - if (left instanceof NamedTypeSpecifier) { - if (right instanceof NamedTypeSpecifier) { - NamedTypeSpecifier leftArg = (NamedTypeSpecifier) left; - NamedTypeSpecifier rightArg = (NamedTypeSpecifier) right; - return qnamesEqual(leftArg.getName(), rightArg.getName()); - } - - return false; - } - - // IntervalTypeSpecifier - if (left instanceof IntervalTypeSpecifier) { - if (right instanceof IntervalTypeSpecifier) { - IntervalTypeSpecifier leftArg = (IntervalTypeSpecifier) left; - IntervalTypeSpecifier rightArg = (IntervalTypeSpecifier) right; - return typeSpecifiersEqual(leftArg.getPointType(), rightArg.getPointType()); - } - - return false; - } - - // ListTypeSpecifier - if (left instanceof ListTypeSpecifier) { - if (right instanceof ListTypeSpecifier) { - ListTypeSpecifier leftArg = (ListTypeSpecifier) left; - ListTypeSpecifier rightArg = (ListTypeSpecifier) right; - return typeSpecifiersEqual(leftArg.getElementType(), rightArg.getElementType()); - } - - return false; - } - - // TupleTypeSpecifier - if (left instanceof TupleTypeSpecifier) { - if (right instanceof TupleTypeSpecifier) { - TupleTypeSpecifier leftArg = (TupleTypeSpecifier) left; - TupleTypeSpecifier rightArg = (TupleTypeSpecifier) right; - if (leftArg.getElement() != null - && rightArg.getElement() != null - && leftArg.getElement().size() == rightArg.getElement().size()) { - for (int i = 0; i < leftArg.getElement().size(); i++) { - TupleElementDefinition leftElement = - leftArg.getElement().get(i); - TupleElementDefinition rightElement = - rightArg.getElement().get(i); - if (!typeSpecifiersEqual(leftElement.getType(), rightElement.getType()) - || !typeSpecifiersEqual(leftElement.getElementType(), rightElement.getElementType()) - || !stringsEqual(leftElement.getName(), rightElement.getName())) { - return false; - } - } - - return true; - } - - return false; - } - - return false; - } - - // ChoiceTypeSpecifier - if (left instanceof ChoiceTypeSpecifier) { - if (right instanceof ChoiceTypeSpecifier) { - ChoiceTypeSpecifier leftArg = (ChoiceTypeSpecifier) left; - ChoiceTypeSpecifier rightArg = (ChoiceTypeSpecifier) right; - if (leftArg.getType() != null - && rightArg.getType() != null - && leftArg.getType().size() == rightArg.getType().size()) { - for (int i = 0; i < leftArg.getType().size(); i++) { - TypeSpecifier leftType = leftArg.getType().get(i); - TypeSpecifier rightType = rightArg.getType().get(i); - if (!typeSpecifiersEqual(leftType, rightType)) { - return false; - } - } - } - - if (leftArg.getChoice() != null - && rightArg.getChoice() != null - && leftArg.getChoice().size() == rightArg.getChoice().size()) { - for (int i = 0; i < leftArg.getChoice().size(); i++) { - TypeSpecifier leftType = leftArg.getChoice().get(i); - TypeSpecifier rightType = rightArg.getChoice().get(i); - if (!typeSpecifiersEqual(leftType, rightType)) { - return false; - } - } - - return true; - } - - return false; - } - - return false; - } - - // False for the possibility of an unrecognized type specifier type - return false; - } - - public boolean expressionsEqual(Expression left, Expression right) { - if (left == null && right == null) { - return true; - } - - if (left == null || right == null) { - return false; - } - - if (left instanceof Literal) { - if (right instanceof Literal) { - return literalsEqual((Literal) left, (Literal) right); - } - - return false; - } - - if (left instanceof Date) { - if (right instanceof Date) { - Date leftDate = (Date) left; - Date rightDate = (Date) right; - - return integersEqual(leftDate.getYear(), rightDate.getYear()) - && integersEqual(leftDate.getMonth(), rightDate.getMonth()) - && integersEqual(leftDate.getDay(), rightDate.getDay()); - } - - return false; - } - - if (left instanceof Time) { - if (right instanceof Time) { - Time leftTime = (Time) left; - Time rightTime = (Time) right; - - return integersEqual(leftTime.getHour(), rightTime.getHour()) - && integersEqual(leftTime.getMinute(), rightTime.getMinute()) - && integersEqual(leftTime.getSecond(), rightTime.getSecond()) - && integersEqual(leftTime.getMillisecond(), rightTime.getMillisecond()); - } - - return false; - } - - if (left instanceof DateTime) { - if (right instanceof DateTime) { - DateTime leftDateTime = (DateTime) left; - DateTime rightDateTime = (DateTime) right; - - return integersEqual(leftDateTime.getYear(), rightDateTime.getYear()) - && integersEqual(leftDateTime.getMonth(), rightDateTime.getMonth()) - && integersEqual(leftDateTime.getDay(), rightDateTime.getDay()) - && integersEqual(leftDateTime.getHour(), rightDateTime.getHour()) - && integersEqual(leftDateTime.getMinute(), rightDateTime.getMinute()) - && integersEqual(leftDateTime.getSecond(), rightDateTime.getSecond()) - && integersEqual(leftDateTime.getMillisecond(), rightDateTime.getMillisecond()) - && decimalsEqual(leftDateTime.getTimezoneOffset(), rightDateTime.getTimezoneOffset()); - } - - return false; - } - - if (left instanceof Interval) { - if (right instanceof Interval) { - Interval leftInterval = (Interval) left; - Interval rightInterval = (Interval) right; - - return booleansEqual(leftInterval.getLowClosedExpression(), rightInterval.getLowClosedExpression()) - && dateTimesEqual(leftInterval.getLow(), rightInterval.getLow()) - && leftInterval.isLowClosed() == rightInterval.isLowClosed() - && booleansEqual( - leftInterval.getHighClosedExpression(), rightInterval.getHighClosedExpression()) - && dateTimesEqual(leftInterval.getHigh(), rightInterval.getHigh()) - && leftInterval.isHighClosed() == rightInterval.isHighClosed(); - } - - return false; - } - - // TODO: Strictly speaking this would need to resolve the parameter library since it's not in the ELM if it's a - // local parameter reference - if (left instanceof ParameterRef) { - if (right instanceof ParameterRef) { - ParameterRef leftParameter = (ParameterRef) left; - ParameterRef rightParameter = (ParameterRef) right; - return stringsEqual(leftParameter.getLibraryName(), rightParameter.getLibraryName()) - && stringsEqual(leftParameter.getName(), rightParameter.getName()); - } - - return false; - } - - if (left instanceof ValueSetRef) { - if (right instanceof ValueSetRef) { - return valueSetsEqual((ValueSetRef) left, (ValueSetRef) right); - } - - return false; - } - - if (left instanceof CodeSystemRef) { - if (right instanceof CodeSystemRef) { - return systemsEqual((CodeSystemRef) left, (CodeSystemRef) right); - } - - return false; - } - - if (left instanceof ConceptRef) { - if (right instanceof ConceptRef) { - ConceptRef leftConcept = (ConceptRef) left; - ConceptRef rightConcept = (ConceptRef) right; - // TODO: Needs to do the comparison on the URI, but I don't want to resolve here - return stringsEqual(leftConcept.getLibraryName(), rightConcept.getLibraryName()) - && stringsEqual(leftConcept.getName(), rightConcept.getName()); - } - - return false; - } - - if (left instanceof CodeRef) { - if (right instanceof CodeRef) { - CodeRef leftCode = (CodeRef) left; - CodeRef rightCode = (CodeRef) right; - // TODO: Needs to do the comparison on the URI, but I don't want to resolve here - return stringsEqual(leftCode.getLibraryName(), rightCode.getLibraryName()) - && stringsEqual(leftCode.getName(), rightCode.getName()); - } - - return false; - } - - if (left instanceof Code) { - if (right instanceof Code) { - Code leftCode = (Code) left; - Code rightCode = (Code) right; - return stringsEqual(leftCode.getCode(), rightCode.getCode()) - && systemsEqual(leftCode.getSystem(), rightCode.getSystem()); - } - - return false; - } - - if (left instanceof Concept) { - if (right instanceof Concept) { - Concept leftConcept = (Concept) left; - Concept rightConcept = (Concept) right; - if (leftConcept.getCode() != null && rightConcept.getCode() != null) { - for (Code lc : leftConcept.getCode()) { - for (Code rc : rightConcept.getCode()) { - if (codesEqual(lc, rc)) { - return true; - } - } - } - } - } - - return false; - } - - if (left instanceof List) { - if (right instanceof List) { - List leftList = (List) left; - List rightList = (List) right; - // TODO: Potentially use a hashSet to avoid order-dependence here - if (leftList.getElement().size() == rightList.getElement().size()) { - for (int i = 0; i < leftList.getElement().size(); i++) { - if (!codesEqual( - leftList.getElement().get(i), - rightList.getElement().get(i))) { - return false; - } - } - } - } - - return false; - } - - if (left instanceof ToList) { - if (right instanceof ToList) { - Expression leftSingleton = ((ToList) left).getOperand(); - Expression rightSingleton = ((ToList) right).getOperand(); - return codesEqual(leftSingleton, rightSingleton); - } - - return false; - } - - // Quantity - if (left instanceof Quantity) { - if (right instanceof Quantity) { - return quantitiesEqual((Quantity) left, (Quantity) right); - } - - return false; - } - - // Ratio - if (left instanceof Ratio) { - if (right instanceof Ratio) { - return quantitiesEqual(((Ratio) left).getDenominator(), ((Ratio) right).getDenominator()) - && quantitiesEqual(((Ratio) left).getNumerator(), ((Ratio) right).getNumerator()); - } - - return false; - } - - // TODO: Consider refactoring ComparableElmRequirement? - // Retrieve - - // InCodeSystem - if (left instanceof InCodeSystem) { - if (right instanceof InCodeSystem) { - InCodeSystem inCodeSystemLeft = (InCodeSystem) left; - InCodeSystem inCodeSystemRight = (InCodeSystem) right; - return expressionsEqual(inCodeSystemLeft.getCode(), inCodeSystemRight.getCode()) - && systemsEqual(inCodeSystemLeft.getCodesystem(), inCodeSystemRight.getCodesystem()) - && expressionsEqual( - inCodeSystemLeft.getCodesystemExpression(), - inCodeSystemRight.getCodesystemExpression()); - } - - return false; - } - - // AnyInCodeSystem - if (left instanceof AnyInCodeSystem) { - if (right instanceof AnyInCodeSystem) { - AnyInCodeSystem anyInCodeSystemLeft = (AnyInCodeSystem) left; - AnyInCodeSystem anyInCodeSystemRight = (AnyInCodeSystem) right; - return expressionsEqual(anyInCodeSystemLeft.getCodes(), anyInCodeSystemRight.getCodes()) - && systemsEqual(anyInCodeSystemLeft.getCodesystem(), anyInCodeSystemRight.getCodesystem()) - && expressionsEqual( - anyInCodeSystemLeft.getCodesystemExpression(), - anyInCodeSystemRight.getCodesystemExpression()); - } - - return false; - } - - // InValueSet - if (left instanceof InValueSet) { - if (right instanceof InValueSet) { - InValueSet inLeft = (InValueSet) left; - InValueSet inRight = (InValueSet) right; - return expressionsEqual(inLeft.getCode(), inRight.getCode()) - && valueSetsEqual(inLeft.getValueset(), inRight.getValueset()) - && expressionsEqual(inLeft.getValuesetExpression(), inRight.getValuesetExpression()); - } - - return false; - } - - // AnyInValueSet - if (left instanceof AnyInValueSet) { - if (right instanceof AnyInValueSet) { - AnyInValueSet inLeft = (AnyInValueSet) left; - AnyInValueSet inRight = (AnyInValueSet) right; - return expressionsEqual(inLeft.getCodes(), inRight.getCodes()) - && valueSetsEqual(inLeft.getValueset(), inRight.getValueset()) - && expressionsEqual(inLeft.getValuesetExpression(), inRight.getValuesetExpression()); - } - - return false; - } - - // CalculateAge - if (left instanceof CalculateAge) { - if (right instanceof CalculateAge) { - CalculateAge leftArg = (CalculateAge) left; - CalculateAge rightArg = (CalculateAge) right; - return expressionsEqual(leftArg.getOperand(), rightArg.getOperand()) - && leftArg.getPrecision().equals(rightArg.getPrecision()); - } - - return false; - } - - // Subsumes - if (left instanceof Subsumes) { - if (right instanceof Subsumes) { - Subsumes leftArg = (Subsumes) left; - Subsumes rightArg = (Subsumes) right; - if (operandsEqual(leftArg, rightArg)) { - return true; - } - - return false; - } - - return false; - } - - // SubsumedBy - if (left instanceof SubsumedBy) { - if (right instanceof SubsumedBy) { - SubsumedBy leftArg = (SubsumedBy) left; - SubsumedBy rightArg = (SubsumedBy) right; - if (operandsEqual(leftArg, rightArg)) { - return true; - } - - return false; - } - - return false; - } - - // AggregateExpression - if (left instanceof AggregateExpression) { - if (right instanceof AggregateExpression) { - AggregateExpression leftArg = (AggregateExpression) left; - AggregateExpression rightArg = (AggregateExpression) right; - return aggregateExpressionsEqual(leftArg, rightArg); - } - - return false; - } - - // OperatorExpression - if (left instanceof OperatorExpression) { - if (right instanceof OperatorExpression) { - OperatorExpression leftArg = (OperatorExpression) left; - OperatorExpression rightArg = (OperatorExpression) right; - return operatorExpressionsEqual(leftArg, rightArg); - } - - return false; - } - - if (!left.getClass().getCanonicalName().equals(right.getClass().getCanonicalName())) { - return false; - } - - // AliasRef - if (left instanceof AliasRef) { - if (right instanceof AliasRef) { - AliasRef leftArg = (AliasRef) left; - AliasRef rightArg = (AliasRef) right; - return stringsEqual(leftArg.getName(), rightArg.getName()); - } - - return false; - } - - // Case - if (left instanceof Case) { - if (right instanceof Case) { - Case leftArg = (Case) left; - Case rightArg = (Case) right; - if (!expressionsEqual(leftArg.getComparand(), rightArg.getComparand())) { - return false; - } - - if (!expressionsEqual(leftArg.getElse(), rightArg.getElse())) { - return false; - } - - if (leftArg.getCaseItem() != null - && rightArg.getCaseItem() != null - && leftArg.getCaseItem().size() - == rightArg.getCaseItem().size()) { - for (int i = 0; i < leftArg.getCaseItem().size(); i++) { - CaseItem leftCaseItem = leftArg.getCaseItem().get(i); - CaseItem rightCaseItem = rightArg.getCaseItem().get(i); - if (!expressionsEqual(leftCaseItem.getWhen(), rightCaseItem.getWhen()) - || !expressionsEqual(leftCaseItem.getThen(), rightCaseItem.getThen())) { - return false; - } - } - - return true; - } - - return false; - } - - return false; - } - - // Current - if (left instanceof Current) { - if (right instanceof Current) { - Current leftArg = (Current) left; - Current rightArg = (Current) right; - return stringsEqual(leftArg.getScope(), rightArg.getScope()); - } - - return false; - } - - // FunctionRef - if (left instanceof FunctionRef) { - if (right instanceof FunctionRef) { - FunctionRef leftArg = (FunctionRef) left; - FunctionRef rightArg = (FunctionRef) right; - return stringsEqual(leftArg.getLibraryName(), rightArg.getLibraryName()) - && stringsEqual(leftArg.getName(), rightArg.getName()) - && operandsEqual(leftArg, rightArg); - } - } - - // ExpressionRef - if (left instanceof ExpressionRef) { - if (right instanceof ExpressionRef) { - ExpressionRef leftArg = (ExpressionRef) left; - ExpressionRef rightArg = (ExpressionRef) right; - return stringsEqual(leftArg.getLibraryName(), rightArg.getLibraryName()) - && stringsEqual(leftArg.getName(), rightArg.getName()); - } - - return false; - } - - // Filter - if (left instanceof Filter) { - if (right instanceof Filter) { - Filter leftArg = (Filter) left; - Filter rightArg = (Filter) right; - return expressionsEqual(leftArg.getSource(), rightArg.getSource()) - && expressionsEqual(leftArg.getCondition(), rightArg.getCondition()) - && stringsEqual(leftArg.getScope(), rightArg.getScope()); - } - - return false; - } - - // ForEach - if (left instanceof ForEach) { - if (right instanceof ForEach) { - ForEach leftArg = (ForEach) left; - ForEach rightArg = (ForEach) right; - return expressionsEqual(leftArg.getSource(), rightArg.getSource()) - && expressionsEqual(leftArg.getElement(), rightArg.getElement()) - && stringsEqual(leftArg.getScope(), rightArg.getScope()); - } - - return false; - } - - // IdentifierRef - if (left instanceof IdentifierRef) { - if (right instanceof IdentifierRef) { - IdentifierRef leftArg = (IdentifierRef) left; - IdentifierRef rightArg = (IdentifierRef) right; - return stringsEqual(leftArg.getLibraryName(), rightArg.getLibraryName()) - && stringsEqual(leftArg.getName(), rightArg.getName()); - } - - return false; - } - - // If - if (left instanceof If) { - if (right instanceof If) { - If leftArg = (If) left; - If rightArg = (If) right; - return expressionsEqual(leftArg.getCondition(), rightArg.getCondition()) - && expressionsEqual(leftArg.getThen(), rightArg.getThen()) - && expressionsEqual(leftArg.getElse(), rightArg.getElse()); - } - - return false; - } - - // Instance - if (left instanceof Instance) { - if (right instanceof Instance) { - Instance leftArg = (Instance) left; - Instance rightArg = (Instance) right; - if (!qnamesEqual(leftArg.getClassType(), rightArg.getClassType())) { - return false; - } - - if (leftArg.getElement() != null - && rightArg.getElement() != null - && leftArg.getElement().size() == rightArg.getElement().size()) { - for (int i = 0; i < leftArg.getElement().size(); i++) { - InstanceElement leftElement = leftArg.getElement().get(i); - InstanceElement rightElement = rightArg.getElement().get(i); - if (!stringsEqual(leftElement.getName(), rightElement.getName()) - || !expressionsEqual(leftElement.getValue(), rightElement.getValue())) { - return false; - } - } - - return true; - } - - return false; - } - - return false; - } - - // Iteration - if (left instanceof Iteration) { - if (right instanceof Iteration) { - Iteration leftArg = (Iteration) left; - Iteration rightArg = (Iteration) right; - return stringsEqual(leftArg.getScope(), rightArg.getScope()); - } - - return false; - } - - // MaxValue - if (left instanceof MaxValue) { - if (right instanceof MaxValue) { - MaxValue leftArg = (MaxValue) left; - MaxValue rightArg = (MaxValue) right; - return qnamesEqual(leftArg.getValueType(), rightArg.getValueType()); - } - - return false; - } - - // MinValue - if (left instanceof MinValue) { - if (right instanceof MinValue) { - MinValue leftArg = (MinValue) left; - MinValue rightArg = (MinValue) right; - return qnamesEqual(leftArg.getValueType(), rightArg.getValueType()); - } - - return false; - } - - // Null - if (left instanceof Null) { - if (right instanceof Null) { - return true; - } - - return false; - } - - // OperandRef - if (left instanceof OperandRef) { - if (right instanceof OperandRef) { - OperandRef leftArg = (OperandRef) left; - OperandRef rightArg = (OperandRef) right; - return stringsEqual(leftArg.getName(), rightArg.getName()); - } - - return false; - } - - // Property - if (left instanceof Property) { - if (right instanceof Property) { - Property leftArg = (Property) left; - Property rightArg = (Property) right; - return stringsEqual(leftArg.getScope(), rightArg.getScope()) - && stringsEqual(leftArg.getPath(), rightArg.getPath()); - } - - return false; - } - - // Query - if (left instanceof Query) { - if (right instanceof Query) { - Query leftArg = (Query) left; - Query rightArg = (Query) right; - } - - return false; - } - - // QueryLetRef - if (left instanceof QueryLetRef) { - if (right instanceof QueryLetRef) { - QueryLetRef leftArg = (QueryLetRef) left; - QueryLetRef rightArg = (QueryLetRef) right; - return stringsEqual(leftArg.getName(), rightArg.getName()); - } - - return false; - } - - // Repeat - if (left instanceof Repeat) { - if (right instanceof Repeat) { - Repeat leftArg = (Repeat) left; - Repeat rightArg = (Repeat) right; - } - - return false; - } - - // Sort - if (left instanceof Sort) { - if (right instanceof Sort) { - Sort leftArg = (Sort) left; - Sort rightArg = (Sort) right; - } - - return false; - } - - // Total - if (left instanceof Total) { - if (right instanceof Total) { - Total leftArg = (Total) left; - Total rightArg = (Total) right; - } - - return false; - } - - // Tuple - if (left instanceof Tuple) { - if (right instanceof Tuple) { - Tuple leftArg = (Tuple) left; - Tuple rightArg = (Tuple) right; - } - - return false; - } - - return false; - } - - public boolean operandsEqual(FunctionRef left, FunctionRef right) { - if (left.getOperand() != null - && right.getOperand() != null - && left.getOperand().size() == right.getOperand().size()) { - for (int i = 0; i < left.getOperand().size(); i++) { - if (!expressionsEqual( - left.getOperand().get(i), right.getOperand().get(i))) { - return false; - } - } - - return true; - } - - return false; - } - - public boolean operandsEqual(BinaryExpression left, BinaryExpression right) { - if (left.getOperand() != null - && right.getOperand() != null - && left.getOperand().size() == right.getOperand().size()) { - for (int i = 0; i < left.getOperand().size(); i++) { - if (!expressionsEqual( - left.getOperand().get(i), right.getOperand().get(i))) { - return false; - } - } - - return true; - } - - return false; - } - - public boolean operandsEqual(TernaryExpression left, TernaryExpression right) { - if (left.getOperand() != null - && right.getOperand() != null - && left.getOperand().size() == right.getOperand().size()) { - for (int i = 0; i < left.getOperand().size(); i++) { - if (!expressionsEqual( - left.getOperand().get(i), right.getOperand().get(i))) { - return false; - } - } - - return true; - } - - return false; - } - - public boolean operandsEqual(NaryExpression left, NaryExpression right) { - if (left.getOperand() != null - && right.getOperand() != null - && left.getOperand().size() == right.getOperand().size()) { - for (int i = 0; i < left.getOperand().size(); i++) { - if (!expressionsEqual( - left.getOperand().get(i), right.getOperand().get(i))) { - return false; - } - } - - return true; - } - - return false; - } - - public boolean operatorExpressionsEqual(OperatorExpression left, OperatorExpression right) { - if (left == null && right == null) { - return true; - } - - if (left == null || right == null) { - return false; - } - - // UnaryExpression - if (left instanceof UnaryExpression) { - if (right instanceof UnaryExpression) { - UnaryExpression leftArg = (UnaryExpression) left; - UnaryExpression rightArg = (UnaryExpression) right; - return unaryExpressionsEqual(leftArg, rightArg); - } - - return false; - } - - // BinaryExpression - if (left instanceof BinaryExpression) { - if (right instanceof BinaryExpression) { - BinaryExpression leftArg = (BinaryExpression) left; - BinaryExpression rightArg = (BinaryExpression) right; - return binaryExpressionsEqual(leftArg, rightArg); - } - - return false; - } - - // TernaryExpression - if (left instanceof TernaryExpression) { - if (right instanceof TernaryExpression) { - TernaryExpression leftArg = (TernaryExpression) left; - TernaryExpression rightArg = (TernaryExpression) right; - return ternaryExpressionsEqual(leftArg, rightArg); - } - - return false; - } - - // NaryExpression - if (left instanceof NaryExpression) { - if (right instanceof NaryExpression) { - NaryExpression leftArg = (NaryExpression) left; - NaryExpression rightArg = (NaryExpression) right; - return naryExpressionsEqual(leftArg, rightArg); - } - - return false; - } - - if (!left.getClass().getCanonicalName().equals(right.getClass().getCanonicalName())) { - return false; - } - - // Round - if (left instanceof Round) { - if (right instanceof Round) { - Round leftArg = (Round) left; - Round rightArg = (Round) right; - return expressionsEqual(leftArg.getOperand(), rightArg.getOperand()) - && expressionsEqual(leftArg.getPrecision(), rightArg.getPrecision()); - } - - return false; - } - - // Combine - if (left instanceof Combine) { - if (right instanceof Combine) { - Combine leftArg = (Combine) left; - Combine rightArg = (Combine) right; - return expressionsEqual(leftArg.getSource(), rightArg.getSource()) - && expressionsEqual(leftArg.getSeparator(), rightArg.getSeparator()); - } - - return false; - } - - // Split - if (left instanceof Split) { - if (right instanceof Split) { - Split leftArg = (Split) left; - Split rightArg = (Split) right; - return expressionsEqual(leftArg.getStringToSplit(), rightArg.getStringToSplit()) - && expressionsEqual(leftArg.getSeparator(), rightArg.getSeparator()); - } - - return false; - } - - // SplitOnMatches - if (left instanceof SplitOnMatches) { - if (right instanceof SplitOnMatches) { - SplitOnMatches leftArg = (SplitOnMatches) left; - SplitOnMatches rightArg = (SplitOnMatches) right; - return expressionsEqual(leftArg.getStringToSplit(), rightArg.getStringToSplit()) - && expressionsEqual(leftArg.getSeparatorPattern(), rightArg.getSeparatorPattern()); - } - - return false; - } - - // PositionOf - if (left instanceof PositionOf) { - if (right instanceof PositionOf) { - PositionOf leftArg = (PositionOf) left; - PositionOf rightArg = (PositionOf) right; - return expressionsEqual(leftArg.getString(), rightArg.getString()) - && expressionsEqual(leftArg.getPattern(), rightArg.getPattern()); - } - - return false; - } - - // LastPositionOf - if (left instanceof LastPositionOf) { - if (right instanceof LastPositionOf) { - LastPositionOf leftArg = (LastPositionOf) left; - LastPositionOf rightArg = (LastPositionOf) right; - return expressionsEqual(leftArg.getString(), rightArg.getString()) - && expressionsEqual(leftArg.getPattern(), rightArg.getPattern()); - } - - return false; - } - - // Substring - if (left instanceof Substring) { - if (right instanceof Substring) { - Substring leftArg = (Substring) left; - Substring rightArg = (Substring) right; - return expressionsEqual(leftArg.getStringToSub(), rightArg.getStringToSub()) - && expressionsEqual(leftArg.getStartIndex(), rightArg.getStartIndex()) - && expressionsEqual(leftArg.getLength(), rightArg.getLength()); - } - - return false; - } - - // TimeOfDay - // Today - // Now - - // Time - if (left instanceof Time) { - if (right instanceof Time) { - Time leftArg = (Time) left; - Time rightArg = (Time) right; - return expressionsEqual(leftArg.getHour(), rightArg.getHour()) - && expressionsEqual(leftArg.getMinute(), rightArg.getMinute()) - && expressionsEqual(leftArg.getSecond(), rightArg.getSecond()) - && expressionsEqual(leftArg.getMillisecond(), rightArg.getMillisecond()); - } - - return false; - } - - // Date - if (left instanceof Date) { - if (right instanceof Date) { - Date leftArg = (Date) left; - Date rightArg = (Date) right; - return expressionsEqual(leftArg.getYear(), rightArg.getYear()) - && expressionsEqual(leftArg.getMonth(), rightArg.getMonth()) - && expressionsEqual(leftArg.getDay(), rightArg.getDay()); - } - - return false; - } - - // DateTime - if (left instanceof DateTime) { - if (right instanceof DateTime) { - DateTime leftArg = (DateTime) left; - DateTime rightArg = (DateTime) right; - return expressionsEqual(leftArg.getYear(), rightArg.getYear()) - && expressionsEqual(leftArg.getMonth(), rightArg.getMonth()) - && expressionsEqual(leftArg.getDay(), rightArg.getDay()) - && expressionsEqual(leftArg.getHour(), rightArg.getHour()) - && expressionsEqual(leftArg.getMinute(), rightArg.getMinute()) - && expressionsEqual(leftArg.getSecond(), rightArg.getSecond()) - && expressionsEqual(leftArg.getMillisecond(), rightArg.getMillisecond()) - && expressionsEqual(leftArg.getTimezoneOffset(), rightArg.getTimezoneOffset()); - } - - return false; - } - - // First - if (left instanceof First) { - if (right instanceof First) { - First leftArg = (First) left; - First rightArg = (First) right; - return expressionsEqual(leftArg.getSource(), rightArg.getSource()) - && stringsEqual(leftArg.getOrderBy(), rightArg.getOrderBy()); - } - - return false; - } - - // Last - if (left instanceof Last) { - if (right instanceof Last) { - Last leftArg = (Last) left; - Last rightArg = (Last) right; - return expressionsEqual(leftArg.getSource(), rightArg.getSource()) - && stringsEqual(leftArg.getOrderBy(), rightArg.getOrderBy()); - } - - return false; - } - - // IndexOf - if (left instanceof IndexOf) { - if (right instanceof IndexOf) { - IndexOf leftArg = (IndexOf) left; - IndexOf rightArg = (IndexOf) right; - return expressionsEqual(leftArg.getSource(), rightArg.getSource()) - && expressionsEqual(leftArg.getElement(), rightArg.getElement()); - } - - return false; - } - - // Slice - if (left instanceof Slice) { - if (right instanceof Slice) { - Slice leftArg = (Slice) left; - Slice rightArg = (Slice) right; - return expressionsEqual(leftArg.getSource(), rightArg.getSource()) - && expressionsEqual(leftArg.getStartIndex(), rightArg.getStartIndex()) - && expressionsEqual(leftArg.getEndIndex(), rightArg.getEndIndex()); - } - - return false; - } - - // Children - if (left instanceof Children) { - if (right instanceof Children) { - Children leftArg = (Children) left; - Children rightArg = (Children) right; - return expressionsEqual(leftArg.getSource(), rightArg.getSource()); - } - - return false; - } - - // Descendents - if (left instanceof Descendents) { - if (right instanceof Descendents) { - Descendents leftArg = (Descendents) left; - Descendents rightArg = (Descendents) right; - return expressionsEqual(leftArg.getSource(), rightArg.getSource()); - } - - return false; - } - - // Message - if (left instanceof Message) { - if (right instanceof Message) { - Message leftArg = (Message) left; - Message rightArg = (Message) right; - return expressionsEqual(leftArg.getSource(), rightArg.getSource()) - && expressionsEqual(leftArg.getCode(), rightArg.getCode()) - && expressionsEqual(leftArg.getCondition(), rightArg.getCondition()) - && expressionsEqual(leftArg.getMessage(), rightArg.getMessage()) - && expressionsEqual(leftArg.getSeverity(), rightArg.getSeverity()); - } - - return false; - } - - // Generally speaking we would return false here, but because we've covered all the cases, we return true - return true; - } - - public boolean operandsEqual(UnaryExpression left, UnaryExpression right) { - return expressionsEqual(left.getOperand(), right.getOperand()); - } - - public boolean unaryExpressionsEqual(UnaryExpression left, UnaryExpression right) { - if (left == null && right == null) { - return true; - } - - if (left == null || right == null) { - return false; - } - - if (!left.getClass().getCanonicalName().equals(right.getClass().getCanonicalName())) { - return false; - } - - if (!operandsEqual(left, right)) { - return false; - } - - // Abs - // As - if (left instanceof As) { - if (right instanceof As) { - As leftArg = (As) left; - As rightArg = (As) right; - return qnamesEqual(leftArg.getAsType(), rightArg.getAsType()) - && typeSpecifiersEqual(leftArg.getAsTypeSpecifier(), rightArg.getAsTypeSpecifier()) - && leftArg.isStrict() == rightArg.isStrict(); - } - } - // Ceiling - // CanConvert - if (left instanceof CanConvert) { - if (right instanceof CanConvert) { - CanConvert leftArg = (CanConvert) left; - CanConvert rightArg = (CanConvert) right; - return qnamesEqual(leftArg.getToType(), rightArg.getToType()) - && typeSpecifiersEqual(leftArg.getToTypeSpecifier(), rightArg.getToTypeSpecifier()); - } - - return false; - } - // Convert - if (left instanceof Convert) { - if (right instanceof Convert) { - Convert leftArg = (Convert) left; - Convert rightArg = (Convert) right; - return qnamesEqual(leftArg.getToType(), rightArg.getToType()) - && typeSpecifiersEqual(leftArg.getToTypeSpecifier(), rightArg.getToTypeSpecifier()); - } - - return false; - } - // ConvertsToBoolean - // ConvertsToDate - // ConvertsToDateTime - // ConvertsToDecimal - // ConvertsToInteger - // ConvertsToLong - // ConvertsToQuantity - // ConvertsToRatio - // ConvertsToString - // ConvertsToTime - // DateFrom - // DateTimeComponentFrom - if (left instanceof DateTimeComponentFrom) { - if (right instanceof DateTimeComponentFrom) { - DateTimeComponentFrom leftArg = (DateTimeComponentFrom) left; - DateTimeComponentFrom rightArg = (DateTimeComponentFrom) right; - return leftArg.getPrecision() == rightArg.getPrecision(); - } - return false; - } - // Distinct - // End - // Exists - // Exp - // Flatten - // Floor - // Is - if (left instanceof Is) { - if (right instanceof Is) { - Is leftArg = (Is) left; - Is rightArg = (Is) right; - return qnamesEqual(leftArg.getIsType(), rightArg.getIsType()) - && typeSpecifiersEqual(leftArg.getIsTypeSpecifier(), rightArg.getIsTypeSpecifier()); - } - return false; - } - // IsFalse - // IsNull - // IsTrue - // Length - // Ln - // Lower - // Negate - // Not - // PointFrom - // Precision - // Predecessor - // SingletonFrom - // Size - // Start - // Successor - // TimeFrom - // TimezoneFrom - // TimezoneOffsetFrom - // ToBoolean - // ToConcept - // ToChars - // ToDate - // ToDateTime - // ToDecimal - // ToInteger - // ToLong - // ToList - // ToQuantity - // ToRatio - // ToString - // ToTime - // Truncate - // Upper - // Width - - // We've covered all the special cases above, so if we make it here, the expressions are equal - return true; - } - - public boolean binaryExpressionsEqual(BinaryExpression left, BinaryExpression right) { - if (left == null && right == null) { - return true; - } - - if (left == null || right == null) { - return false; - } - - if (!left.getClass().getCanonicalName().equals(right.getClass().getCanonicalName())) { - return false; - } - - if (!operandsEqual(left, right)) { - return false; - } - - // TODO: Handle special cases for operators that have a precision modifier - // Add - // After - // And - // Before - // CanConvertQuantity - // Contains - // ConvertQuantity - // Collapse - // DifferenceBetween - // Divide - // DurationBetween - // Ends - // EndsWith - // Equal - // Equivalent - // Expand - // Greater - // GreaterOrEqual - // HighBoundary - // Implies - // In - // IncludedIn - // Includes - // Indexer - // Less - // LessOrEqual - // Log - // LowBoundary - // Matches - // Meets - // MeetsAfter - // MeetsBefore - // Modulo - // Multiply - // NotEqual - // Or - // Overlaps - // OverlapsAfter - // OverlapsBefore - // Power - // ProperContains - // ProperIn - // ProperIncludedIn - // ProperIncludes - // SameAs - // SameOrAfter - // SameOrBefore - // Starts - // StartsWith - // Subtract - // Times - // TruncatedDivide - // Xor - - return true; - } - - public boolean ternaryExpressionsEqual(TernaryExpression left, TernaryExpression right) { - if (left == null && right == null) { - return true; - } - - if (left == null || right == null) { - return false; - } - - if (!left.getClass().getCanonicalName().equals(right.getClass().getCanonicalName())) { - return false; - } - - if (!operandsEqual(left, right)) { - return false; - } - - // ReplaceMatches - return true; - } - - public boolean naryExpressionsEqual(NaryExpression left, NaryExpression right) { - if (left == null && right == null) { - return true; - } - - if (left == null || right == null) { - return false; - } - - if (!left.getClass().getCanonicalName().equals(right.getClass().getCanonicalName())) { - return false; - } - - if (!operandsEqual(left, right)) { - return false; - } - - // Coalesce - // Concatenate - // Except - // Intersect - // Union - return false; - } - - public boolean aggregateExpressionsEqual(AggregateExpression left, AggregateExpression right) { - if (left == null && right == null) { - return true; - } - - if (left == null || right == null) { - return false; - } - - if (!left.getClass().getCanonicalName().equals(right.getClass().getCanonicalName())) { - return false; - } - - if (!expressionsEqual(left.getSource(), right.getSource()) || !stringsEqual(left.getPath(), right.getPath())) { - return false; - } - - // Aggregate - if (left instanceof Aggregate) { - if (right instanceof Aggregate) { - Aggregate leftArg = (Aggregate) left; - Aggregate rightArg = (Aggregate) right; - return expressionsEqual(leftArg.getInitialValue(), rightArg.getInitialValue()) - && expressionsEqual(leftArg.getIteration(), rightArg.getIteration()); - } - } - // Count - // Sum - // Product - // Min - // Max - // Avg - // GeometricMean - // Median - // Mode - // Variance - // StdDev - // PopulationVariance - // PopulationStdDev - // AllTrue - // AnyTrue - - return true; - } -} diff --git a/Src/java/elm/src/main/java/org/cqframework/cql/elm/evaluating/SimpleElmEngine.kt b/Src/java/elm/src/main/java/org/cqframework/cql/elm/evaluating/SimpleElmEngine.kt new file mode 100644 index 000000000..c978aef92 --- /dev/null +++ b/Src/java/elm/src/main/java/org/cqframework/cql/elm/evaluating/SimpleElmEngine.kt @@ -0,0 +1,1547 @@ +package org.cqframework.cql.elm.evaluating + +import java.math.BigDecimal +import javax.xml.namespace.QName +import org.hl7.elm.r1.Aggregate +import org.hl7.elm.r1.AggregateExpression +import org.hl7.elm.r1.AliasRef +import org.hl7.elm.r1.AnyInCodeSystem +import org.hl7.elm.r1.AnyInValueSet +import org.hl7.elm.r1.As +import org.hl7.elm.r1.BinaryExpression +import org.hl7.elm.r1.CalculateAge +import org.hl7.elm.r1.CanConvert +import org.hl7.elm.r1.Case +import org.hl7.elm.r1.Children +import org.hl7.elm.r1.ChoiceTypeSpecifier +import org.hl7.elm.r1.Code +import org.hl7.elm.r1.CodeRef +import org.hl7.elm.r1.CodeSystemRef +import org.hl7.elm.r1.Combine +import org.hl7.elm.r1.Concept +import org.hl7.elm.r1.ConceptRef +import org.hl7.elm.r1.Convert +import org.hl7.elm.r1.Current +import org.hl7.elm.r1.Date +import org.hl7.elm.r1.DateTime +import org.hl7.elm.r1.DateTimeComponentFrom +import org.hl7.elm.r1.Descendents +import org.hl7.elm.r1.Expression +import org.hl7.elm.r1.ExpressionRef +import org.hl7.elm.r1.Filter +import org.hl7.elm.r1.First +import org.hl7.elm.r1.ForEach +import org.hl7.elm.r1.FunctionRef +import org.hl7.elm.r1.IdentifierRef +import org.hl7.elm.r1.If +import org.hl7.elm.r1.InCodeSystem +import org.hl7.elm.r1.InValueSet +import org.hl7.elm.r1.IndexOf +import org.hl7.elm.r1.Instance +import org.hl7.elm.r1.Interval +import org.hl7.elm.r1.IntervalTypeSpecifier +import org.hl7.elm.r1.Is +import org.hl7.elm.r1.Iteration +import org.hl7.elm.r1.Last +import org.hl7.elm.r1.LastPositionOf +import org.hl7.elm.r1.List +import org.hl7.elm.r1.ListTypeSpecifier +import org.hl7.elm.r1.Literal +import org.hl7.elm.r1.MaxValue +import org.hl7.elm.r1.Message +import org.hl7.elm.r1.MinValue +import org.hl7.elm.r1.NamedTypeSpecifier +import org.hl7.elm.r1.NaryExpression +import org.hl7.elm.r1.Null +import org.hl7.elm.r1.OperandRef +import org.hl7.elm.r1.OperatorExpression +import org.hl7.elm.r1.ParameterRef +import org.hl7.elm.r1.PositionOf +import org.hl7.elm.r1.Property +import org.hl7.elm.r1.Quantity +import org.hl7.elm.r1.Query +import org.hl7.elm.r1.QueryLetRef +import org.hl7.elm.r1.Ratio +import org.hl7.elm.r1.Repeat +import org.hl7.elm.r1.Round +import org.hl7.elm.r1.Slice +import org.hl7.elm.r1.Sort +import org.hl7.elm.r1.Split +import org.hl7.elm.r1.SplitOnMatches +import org.hl7.elm.r1.Substring +import org.hl7.elm.r1.SubsumedBy +import org.hl7.elm.r1.Subsumes +import org.hl7.elm.r1.TernaryExpression +import org.hl7.elm.r1.Time +import org.hl7.elm.r1.ToList +import org.hl7.elm.r1.Total +import org.hl7.elm.r1.Tuple +import org.hl7.elm.r1.TupleTypeSpecifier +import org.hl7.elm.r1.TypeSpecifier +import org.hl7.elm.r1.UnaryExpression +import org.hl7.elm.r1.ValueSetRef + +/* +A simple ELM engine that is capable of limited evaluation of ELM +required for static analysis and other optimization use cases (such as +constant folding, data requirements analysis, limited constraint validation, +etc.) +*/ +@Suppress("detekt:all") +class SimpleElmEngine { + private fun literalsEqual(left: Literal?, right: Literal?): Boolean { + return (left == null && right == null) || + (left != null && + left.valueType != null && + left.valueType == right!!.valueType && + stringsEqual(left.value, right.value)) + } + + fun booleansEqual(left: Expression?, right: Expression?): Boolean { + return expressionsEqual(left, right) + } + + fun integersEqual(left: Expression?, right: Expression?): Boolean { + return expressionsEqual(left, right) + } + + fun decimalsEqual(left: Expression?, right: Expression?): Boolean { + return expressionsEqual(left, right) + } + + fun decimalsEqual(left: BigDecimal?, right: BigDecimal?): Boolean { + if (left == null && right == null) { + return true + } + + if (left == null || right == null) { + return false + } + + return left == right + } + + fun quantitiesEqual(left: Quantity?, right: Quantity?): Boolean { + if (left == null && right == null) { + return true + } + + if (left == null || right == null) { + return true + } + + return decimalsEqual(left.value, right.value) && stringsEqual(left.unit, right.unit) + } + + fun stringsEqual(left: Expression?, right: Expression?): Boolean { + return expressionsEqual(left, right) + } + + fun dateTimesEqual(left: Expression?, right: Expression?): Boolean { + return expressionsEqual(left, right) + } + + fun dateRangesEqual(left: Expression?, right: Expression?): Boolean { + return expressionsEqual(left, right) + } + + fun stringsEqual(left: String?, right: String?): Boolean { + return (left == null && right == null) || (left != null && left == right) + } + + fun systemsEqual(left: CodeSystemRef?, right: CodeSystemRef?): Boolean { + // TODO: Needs to do the comparison on the URI, but I don't want to have to resolve here + return (left == null && right == null) || + (left != null && + stringsEqual(left.libraryName, right!!.libraryName) && + stringsEqual(left.name, right.name)) + } + + fun valueSetsEqual(left: ValueSetRef?, right: ValueSetRef?): Boolean { + // TODO: Needs to do the comparison on the URI, but I don't want to have to resolve here + return (left == null && right == null) || + (left != null && + stringsEqual(left.libraryName, right!!.libraryName) && + stringsEqual(left.name, right.name)) + } + + fun codesEqual(left: Expression?, right: Expression?): Boolean { + return expressionsEqual(left, right) + } + + fun qnamesEqual(left: QName?, right: QName?): Boolean { + if (left == null && right == null) { + return true + } + + if (left == null || right == null) { + return false + } + + return left == right + } + + fun typeSpecifiersEqual(left: TypeSpecifier?, right: TypeSpecifier?): Boolean { + if (left == null && right == null) { + return true + } + + if (left == null || right == null) { + return false + } + + // NamedTypeSpecifier + if (left is NamedTypeSpecifier) { + if (right is NamedTypeSpecifier) { + return qnamesEqual(left.name, right.name) + } + + return false + } + + // IntervalTypeSpecifier + if (left is IntervalTypeSpecifier) { + if (right is IntervalTypeSpecifier) { + return typeSpecifiersEqual(left.pointType, right.pointType) + } + + return false + } + + // ListTypeSpecifier + if (left is ListTypeSpecifier) { + if (right is ListTypeSpecifier) { + return typeSpecifiersEqual(left.elementType, right.elementType) + } + + return false + } + + // TupleTypeSpecifier + if (left is TupleTypeSpecifier) { + if (right is TupleTypeSpecifier) { + val leftArg = left + val rightArg = right + if ( + leftArg.element != null && + rightArg.element != null && + leftArg.element.size == rightArg.element.size + ) { + for (i in leftArg.element.indices) { + val leftElement = leftArg.element[i] + val rightElement = rightArg.element[i] + if ( + !typeSpecifiersEqual(leftElement.type, rightElement.type) || + !typeSpecifiersEqual( + leftElement.elementType, + rightElement.elementType + ) || + !stringsEqual(leftElement.name, rightElement.name) + ) { + return false + } + } + + return true + } + + return false + } + + return false + } + + // ChoiceTypeSpecifier + if (left is ChoiceTypeSpecifier) { + if (right is ChoiceTypeSpecifier) { + val leftArg = left + val rightArg = right + if ( + leftArg.type != null && + rightArg.type != null && + leftArg.type.size == rightArg.type.size + ) { + for (i in leftArg.type.indices) { + val leftType = leftArg.type[i] + val rightType = rightArg.type[i] + if (!typeSpecifiersEqual(leftType, rightType)) { + return false + } + } + } + + if ( + leftArg.choice != null && + rightArg.choice != null && + leftArg.choice.size == rightArg.choice.size + ) { + for (i in leftArg.choice.indices) { + val leftType = leftArg.choice[i] + val rightType = rightArg.choice[i] + if (!typeSpecifiersEqual(leftType, rightType)) { + return false + } + } + + return true + } + + return false + } + + return false + } + + // False for the possibility of an unrecognized type specifier type + return false + } + + fun expressionsEqual(left: Expression?, right: Expression?): Boolean { + if (left == null && right == null) { + return true + } + + if (left == null || right == null) { + return false + } + + if (left is Literal) { + if (right is Literal) { + return literalsEqual(left, right) + } + + return false + } + + if (left is Date) { + if (right is Date) { + val leftDate = left + val rightDate = right + + return integersEqual(leftDate.year, rightDate.year) && + integersEqual(leftDate.month, rightDate.month) && + integersEqual(leftDate.day, rightDate.day) + } + + return false + } + + if (left is Time) { + if (right is Time) { + val leftTime = left + val rightTime = right + + return integersEqual(leftTime.hour, rightTime.hour) && + integersEqual(leftTime.minute, rightTime.minute) && + integersEqual(leftTime.second, rightTime.second) && + integersEqual(leftTime.millisecond, rightTime.millisecond) + } + + return false + } + + if (left is DateTime) { + if (right is DateTime) { + val leftDateTime = left + val rightDateTime = right + + return integersEqual(leftDateTime.year, rightDateTime.year) && + integersEqual(leftDateTime.month, rightDateTime.month) && + integersEqual(leftDateTime.day, rightDateTime.day) && + integersEqual(leftDateTime.hour, rightDateTime.hour) && + integersEqual(leftDateTime.minute, rightDateTime.minute) && + integersEqual(leftDateTime.second, rightDateTime.second) && + integersEqual(leftDateTime.millisecond, rightDateTime.millisecond) && + decimalsEqual(leftDateTime.timezoneOffset, rightDateTime.timezoneOffset) + } + + return false + } + + if (left is Interval) { + if (right is Interval) { + val leftInterval = left + val rightInterval = right + + return booleansEqual( + leftInterval.lowClosedExpression, + rightInterval.lowClosedExpression + ) && + dateTimesEqual(leftInterval.low, rightInterval.low) && + leftInterval.isLowClosed == rightInterval.isLowClosed && + booleansEqual( + leftInterval.highClosedExpression, + rightInterval.highClosedExpression + ) && + dateTimesEqual(leftInterval.high, rightInterval.high) && + leftInterval.isHighClosed == rightInterval.isHighClosed + } + + return false + } + + // TODO: Strictly speaking this would need to resolve the parameter library since it's not + // in the ELM if it's a + // local parameter reference + if (left is ParameterRef) { + if (right is ParameterRef) { + val leftParameter = left + val rightParameter = right + return stringsEqual(leftParameter.libraryName, rightParameter.libraryName) && + stringsEqual(leftParameter.name, rightParameter.name) + } + + return false + } + + if (left is ValueSetRef) { + if (right is ValueSetRef) { + return valueSetsEqual(left, right) + } + + return false + } + + if (left is CodeSystemRef) { + if (right is CodeSystemRef) { + return systemsEqual(left, right) + } + + return false + } + + if (left is ConceptRef) { + if (right is ConceptRef) { + val leftConcept = left + val rightConcept = right + // TODO: Needs to do the comparison on the URI, but I don't want to resolve here + return stringsEqual(leftConcept.libraryName, rightConcept.libraryName) && + stringsEqual(leftConcept.name, rightConcept.name) + } + + return false + } + + if (left is CodeRef) { + if (right is CodeRef) { + val leftCode = left + val rightCode = right + // TODO: Needs to do the comparison on the URI, but I don't want to resolve here + return stringsEqual(leftCode.libraryName, rightCode.libraryName) && + stringsEqual(leftCode.name, rightCode.name) + } + + return false + } + + if (left is Code) { + if (right is Code) { + val leftCode = left + val rightCode = right + return stringsEqual(leftCode.code, rightCode.code) && + systemsEqual(leftCode.system, rightCode.system) + } + + return false + } + + if (left is Concept) { + if (right is Concept) { + val leftConcept = left + val rightConcept = right + if (leftConcept.code != null && rightConcept.code != null) { + for (lc in leftConcept.code) { + for (rc in rightConcept.code) { + if (codesEqual(lc, rc)) { + return true + } + } + } + } + } + + return false + } + + if (left is List) { + if (right is List) { + val leftList = left + val rightList = right + // TODO: Potentially use a hashSet to avoid order-dependence here + if (leftList.element.size == rightList.element.size) { + for (i in leftList.element.indices) { + if (!codesEqual(leftList.element[i], rightList.element[i])) { + return false + } + } + } + } + + return false + } + + if (left is ToList) { + if (right is ToList) { + val leftSingleton = left.operand + val rightSingleton = right.operand + return codesEqual(leftSingleton, rightSingleton) + } + + return false + } + + // Quantity + if (left is Quantity) { + if (right is Quantity) { + return quantitiesEqual(left, right) + } + + return false + } + + // Ratio + if (left is Ratio) { + if (right is Ratio) { + return quantitiesEqual(left.denominator, right.denominator) && + quantitiesEqual(left.numerator, right.numerator) + } + + return false + } + + // TODO: Consider refactoring ComparableElmRequirement? + // Retrieve + + // InCodeSystem + if (left is InCodeSystem) { + if (right is InCodeSystem) { + val inCodeSystemLeft = left + val inCodeSystemRight = right + return expressionsEqual(inCodeSystemLeft.code, inCodeSystemRight.code) && + systemsEqual(inCodeSystemLeft.codesystem, inCodeSystemRight.codesystem) && + expressionsEqual( + inCodeSystemLeft.codesystemExpression, + inCodeSystemRight.codesystemExpression + ) + } + + return false + } + + // AnyInCodeSystem + if (left is AnyInCodeSystem) { + if (right is AnyInCodeSystem) { + val anyInCodeSystemLeft = left + val anyInCodeSystemRight = right + return expressionsEqual(anyInCodeSystemLeft.codes, anyInCodeSystemRight.codes) && + systemsEqual(anyInCodeSystemLeft.codesystem, anyInCodeSystemRight.codesystem) && + expressionsEqual( + anyInCodeSystemLeft.codesystemExpression, + anyInCodeSystemRight.codesystemExpression + ) + } + + return false + } + + // InValueSet + if (left is InValueSet) { + if (right is InValueSet) { + val inLeft = left + val inRight = right + return expressionsEqual(inLeft.code, inRight.code) && + valueSetsEqual(inLeft.valueset, inRight.valueset) && + expressionsEqual(inLeft.valuesetExpression, inRight.valuesetExpression) + } + + return false + } + + // AnyInValueSet + if (left is AnyInValueSet) { + if (right is AnyInValueSet) { + val inLeft = left + val inRight = right + return expressionsEqual(inLeft.codes, inRight.codes) && + valueSetsEqual(inLeft.valueset, inRight.valueset) && + expressionsEqual(inLeft.valuesetExpression, inRight.valuesetExpression) + } + + return false + } + + // CalculateAge + if (left is CalculateAge) { + if (right is CalculateAge) { + val leftArg = left + val rightArg = right + return expressionsEqual(leftArg.operand, rightArg.operand) && + leftArg.precision == rightArg.precision + } + + return false + } + + // Subsumes + if (left is Subsumes) { + if (right is Subsumes) { + if (operandsEqual(left, right)) { + return true + } + + return false + } + + return false + } + + // SubsumedBy + if (left is SubsumedBy) { + if (right is SubsumedBy) { + if (operandsEqual(left, right)) { + return true + } + + return false + } + + return false + } + + // AggregateExpression + if (left is AggregateExpression) { + if (right is AggregateExpression) { + return aggregateExpressionsEqual(left, right) + } + + return false + } + + // OperatorExpression + if (left is OperatorExpression) { + if (right is OperatorExpression) { + return operatorExpressionsEqual(left, right) + } + + return false + } + + if (left.javaClass.canonicalName != right.javaClass.canonicalName) { + return false + } + + // AliasRef + if (left is AliasRef) { + if (right is AliasRef) { + return stringsEqual(left.name, right.name) + } + + return false + } + + // Case + if (left is Case) { + if (right is Case) { + val leftArg = left + val rightArg = right + if (!expressionsEqual(leftArg.comparand, rightArg.comparand)) { + return false + } + + if (!expressionsEqual(leftArg.getElse(), rightArg.getElse())) { + return false + } + + if ( + leftArg.caseItem != null && + rightArg.caseItem != null && + (leftArg.caseItem.size == rightArg.caseItem.size) + ) { + for (i in leftArg.caseItem.indices) { + val leftCaseItem = leftArg.caseItem[i] + val rightCaseItem = rightArg.caseItem[i] + if ( + !expressionsEqual(leftCaseItem.getWhen(), rightCaseItem.getWhen()) || + !expressionsEqual(leftCaseItem.then, rightCaseItem.then) + ) { + return false + } + } + + return true + } + + return false + } + + return false + } + + // Current + if (left is Current) { + if (right is Current) { + return stringsEqual(left.scope, right.scope) + } + + return false + } + + // FunctionRef + if (left is FunctionRef) { + if (right is FunctionRef) { + val leftArg = left + val rightArg = right + return stringsEqual(leftArg.libraryName, rightArg.libraryName) && + stringsEqual(leftArg.name, rightArg.name) && + operandsEqual(leftArg, rightArg) + } + } + + // ExpressionRef + if (left is ExpressionRef) { + if (right is ExpressionRef) { + val leftArg = left + val rightArg = right + return stringsEqual(leftArg.libraryName, rightArg.libraryName) && + stringsEqual(leftArg.name, rightArg.name) + } + + return false + } + + // Filter + if (left is Filter) { + if (right is Filter) { + val leftArg = left + val rightArg = right + return expressionsEqual(leftArg.source, rightArg.source) && + expressionsEqual(leftArg.condition, rightArg.condition) && + stringsEqual(leftArg.scope, rightArg.scope) + } + + return false + } + + // ForEach + if (left is ForEach) { + if (right is ForEach) { + val leftArg = left + val rightArg = right + return expressionsEqual(leftArg.source, rightArg.source) && + expressionsEqual(leftArg.element, rightArg.element) && + stringsEqual(leftArg.scope, rightArg.scope) + } + + return false + } + + // IdentifierRef + if (left is IdentifierRef) { + if (right is IdentifierRef) { + val leftArg = left + val rightArg = right + return stringsEqual(leftArg.libraryName, rightArg.libraryName) && + stringsEqual(leftArg.name, rightArg.name) + } + + return false + } + + // If + if (left is If) { + if (right is If) { + val leftArg = left + val rightArg = right + return expressionsEqual(leftArg.condition, rightArg.condition) && + expressionsEqual(leftArg.then, rightArg.then) && + expressionsEqual(leftArg.getElse(), rightArg.getElse()) + } + + return false + } + + // Instance + if (left is Instance) { + if (right is Instance) { + val leftArg = left + val rightArg = right + if (!qnamesEqual(leftArg.classType, rightArg.classType)) { + return false + } + + if ( + leftArg.element != null && + rightArg.element != null && + leftArg.element.size == rightArg.element.size + ) { + for (i in leftArg.element.indices) { + val leftElement = leftArg.element[i] + val rightElement = rightArg.element[i] + if ( + !stringsEqual(leftElement.name, rightElement.name) || + !expressionsEqual(leftElement.value, rightElement.value) + ) { + return false + } + } + + return true + } + + return false + } + + return false + } + + // Iteration + if (left is Iteration) { + if (right is Iteration) { + return stringsEqual(left.scope, right.scope) + } + + return false + } + + // MaxValue + if (left is MaxValue) { + if (right is MaxValue) { + return qnamesEqual(left.valueType, right.valueType) + } + + return false + } + + // MinValue + if (left is MinValue) { + if (right is MinValue) { + return qnamesEqual(left.valueType, right.valueType) + } + + return false + } + + // Null + if (left is Null) { + if (right is Null) { + return true + } + + return false + } + + // OperandRef + if (left is OperandRef) { + if (right is OperandRef) { + return stringsEqual(left.name, right.name) + } + + return false + } + + // Property + if (left is Property) { + if (right is Property) { + val leftArg = left + val rightArg = right + return stringsEqual(leftArg.scope, rightArg.scope) && + stringsEqual(leftArg.path, rightArg.path) + } + + return false + } + + // Query + if (left is Query) { + if (right is Query) { + val leftArg = left + val rightArg = right + } + + return false + } + + // QueryLetRef + if (left is QueryLetRef) { + if (right is QueryLetRef) { + return stringsEqual(left.name, right.name) + } + + return false + } + + // Repeat + if (left is Repeat) { + if (right is Repeat) { + val leftArg = left + val rightArg = right + } + + return false + } + + // Sort + if (left is Sort) { + if (right is Sort) { + val leftArg = left + val rightArg = right + } + + return false + } + + // Total + if (left is Total) { + if (right is Total) { + val leftArg = left + val rightArg = right + } + + return false + } + + // Tuple + if (left is Tuple) { + if (right is Tuple) { + val leftArg = left + val rightArg = right + } + + return false + } + + return false + } + + fun operandsEqual(left: FunctionRef, right: FunctionRef): Boolean { + if ( + left.operand != null && right.operand != null && left.operand.size == right.operand.size + ) { + for (i in left.operand.indices) { + if (!expressionsEqual(left.operand[i], right.operand[i])) { + return false + } + } + + return true + } + + return false + } + + fun operandsEqual(left: BinaryExpression, right: BinaryExpression): Boolean { + if ( + left.operand != null && right.operand != null && left.operand.size == right.operand.size + ) { + for (i in left.operand.indices) { + if (!expressionsEqual(left.operand[i], right.operand[i])) { + return false + } + } + + return true + } + + return false + } + + fun operandsEqual(left: TernaryExpression, right: TernaryExpression): Boolean { + if ( + left.operand != null && right.operand != null && left.operand.size == right.operand.size + ) { + for (i in left.operand.indices) { + if (!expressionsEqual(left.operand[i], right.operand[i])) { + return false + } + } + + return true + } + + return false + } + + fun operandsEqual(left: NaryExpression, right: NaryExpression): Boolean { + if ( + left.operand != null && right.operand != null && left.operand.size == right.operand.size + ) { + for (i in left.operand.indices) { + if (!expressionsEqual(left.operand[i], right.operand[i])) { + return false + } + } + + return true + } + + return false + } + + fun operatorExpressionsEqual(left: OperatorExpression?, right: OperatorExpression?): Boolean { + if (left == null && right == null) { + return true + } + + if (left == null || right == null) { + return false + } + + // UnaryExpression + if (left is UnaryExpression) { + if (right is UnaryExpression) { + return unaryExpressionsEqual(left, right) + } + + return false + } + + // BinaryExpression + if (left is BinaryExpression) { + if (right is BinaryExpression) { + return binaryExpressionsEqual(left, right) + } + + return false + } + + // TernaryExpression + if (left is TernaryExpression) { + if (right is TernaryExpression) { + return ternaryExpressionsEqual(left, right) + } + + return false + } + + // NaryExpression + if (left is NaryExpression) { + if (right is NaryExpression) { + return naryExpressionsEqual(left, right) + } + + return false + } + + if (left.javaClass.canonicalName != right.javaClass.canonicalName) { + return false + } + + // Round + if (left is Round) { + if (right is Round) { + val leftArg = left + val rightArg = right + return expressionsEqual(leftArg.operand, rightArg.operand) && + expressionsEqual(leftArg.precision, rightArg.precision) + } + + return false + } + + // Combine + if (left is Combine) { + if (right is Combine) { + val leftArg = left + val rightArg = right + return expressionsEqual(leftArg.source, rightArg.source) && + expressionsEqual(leftArg.separator, rightArg.separator) + } + + return false + } + + // Split + if (left is Split) { + if (right is Split) { + val leftArg = left + val rightArg = right + return expressionsEqual(leftArg.stringToSplit, rightArg.stringToSplit) && + expressionsEqual(leftArg.separator, rightArg.separator) + } + + return false + } + + // SplitOnMatches + if (left is SplitOnMatches) { + if (right is SplitOnMatches) { + val leftArg = left + val rightArg = right + return expressionsEqual(leftArg.stringToSplit, rightArg.stringToSplit) && + expressionsEqual(leftArg.separatorPattern, rightArg.separatorPattern) + } + + return false + } + + // PositionOf + if (left is PositionOf) { + if (right is PositionOf) { + val leftArg = left + val rightArg = right + return expressionsEqual(leftArg.string, rightArg.string) && + expressionsEqual(leftArg.pattern, rightArg.pattern) + } + + return false + } + + // LastPositionOf + if (left is LastPositionOf) { + if (right is LastPositionOf) { + val leftArg = left + val rightArg = right + return expressionsEqual(leftArg.string, rightArg.string) && + expressionsEqual(leftArg.pattern, rightArg.pattern) + } + + return false + } + + // Substring + if (left is Substring) { + if (right is Substring) { + val leftArg = left + val rightArg = right + return expressionsEqual(leftArg.stringToSub, rightArg.stringToSub) && + expressionsEqual(leftArg.startIndex, rightArg.startIndex) && + expressionsEqual(leftArg.length, rightArg.length) + } + + return false + } + + // TimeOfDay + // Today + // Now + + // Time + if (left is Time) { + if (right is Time) { + val leftArg = left + val rightArg = right + return expressionsEqual(leftArg.hour, rightArg.hour) && + expressionsEqual(leftArg.minute, rightArg.minute) && + expressionsEqual(leftArg.second, rightArg.second) && + expressionsEqual(leftArg.millisecond, rightArg.millisecond) + } + + return false + } + + // Date + if (left is Date) { + if (right is Date) { + val leftArg = left + val rightArg = right + return expressionsEqual(leftArg.year, rightArg.year) && + expressionsEqual(leftArg.month, rightArg.month) && + expressionsEqual(leftArg.day, rightArg.day) + } + + return false + } + + // DateTime + if (left is DateTime) { + if (right is DateTime) { + val leftArg = left + val rightArg = right + return expressionsEqual(leftArg.year, rightArg.year) && + expressionsEqual(leftArg.month, rightArg.month) && + expressionsEqual(leftArg.day, rightArg.day) && + expressionsEqual(leftArg.hour, rightArg.hour) && + expressionsEqual(leftArg.minute, rightArg.minute) && + expressionsEqual(leftArg.second, rightArg.second) && + expressionsEqual(leftArg.millisecond, rightArg.millisecond) && + expressionsEqual(leftArg.timezoneOffset, rightArg.timezoneOffset) + } + + return false + } + + // First + if (left is First) { + if (right is First) { + val leftArg = left + val rightArg = right + return expressionsEqual(leftArg.source, rightArg.source) && + stringsEqual(leftArg.orderBy, rightArg.orderBy) + } + + return false + } + + // Last + if (left is Last) { + if (right is Last) { + val leftArg = left + val rightArg = right + return expressionsEqual(leftArg.source, rightArg.source) && + stringsEqual(leftArg.orderBy, rightArg.orderBy) + } + + return false + } + + // IndexOf + if (left is IndexOf) { + if (right is IndexOf) { + val leftArg = left + val rightArg = right + return expressionsEqual(leftArg.source, rightArg.source) && + expressionsEqual(leftArg.element, rightArg.element) + } + + return false + } + + // Slice + if (left is Slice) { + if (right is Slice) { + val leftArg = left + val rightArg = right + return expressionsEqual(leftArg.source, rightArg.source) && + expressionsEqual(leftArg.startIndex, rightArg.startIndex) && + expressionsEqual(leftArg.endIndex, rightArg.endIndex) + } + + return false + } + + // Children + if (left is Children) { + if (right is Children) { + return expressionsEqual(left.source, right.source) + } + + return false + } + + // Descendents + if (left is Descendents) { + if (right is Descendents) { + return expressionsEqual(left.source, right.source) + } + + return false + } + + // Message + if (left is Message) { + if (right is Message) { + val leftArg = left + val rightArg = right + return expressionsEqual(leftArg.source, rightArg.source) && + expressionsEqual(leftArg.code, rightArg.code) && + expressionsEqual(leftArg.condition, rightArg.condition) && + expressionsEqual(leftArg.message, rightArg.message) && + expressionsEqual(leftArg.severity, rightArg.severity) + } + + return false + } + + // Generally speaking we would return false here, but because we've covered all the cases, + // we return true + return true + } + + fun operandsEqual(left: UnaryExpression, right: UnaryExpression): Boolean { + return expressionsEqual(left.operand, right.operand) + } + + fun unaryExpressionsEqual(left: UnaryExpression?, right: UnaryExpression?): Boolean { + if (left == null && right == null) { + return true + } + + if (left == null || right == null) { + return false + } + + if (left.javaClass.canonicalName != right.javaClass.canonicalName) { + return false + } + + if (!operandsEqual(left, right)) { + return false + } + + // Abs + // As + if (left is As) { + if (right is As) { + val leftArg = left + val rightArg = right + return qnamesEqual(leftArg.asType, rightArg.asType) && + typeSpecifiersEqual(leftArg.asTypeSpecifier, rightArg.asTypeSpecifier) && + leftArg.isStrict == rightArg.isStrict + } + } + // Ceiling + // CanConvert + if (left is CanConvert) { + if (right is CanConvert) { + val leftArg = left + val rightArg = right + return qnamesEqual(leftArg.toType, rightArg.toType) && + typeSpecifiersEqual(leftArg.toTypeSpecifier, rightArg.toTypeSpecifier) + } + + return false + } + // Convert + if (left is Convert) { + if (right is Convert) { + val leftArg = left + val rightArg = right + return qnamesEqual(leftArg.toType, rightArg.toType) && + typeSpecifiersEqual(leftArg.toTypeSpecifier, rightArg.toTypeSpecifier) + } + + return false + } + // ConvertsToBoolean + // ConvertsToDate + // ConvertsToDateTime + // ConvertsToDecimal + // ConvertsToInteger + // ConvertsToLong + // ConvertsToQuantity + // ConvertsToRatio + // ConvertsToString + // ConvertsToTime + // DateFrom + // DateTimeComponentFrom + if (left is DateTimeComponentFrom) { + if (right is DateTimeComponentFrom) { + return left.precision == right.precision + } + return false + } + // Distinct + // End + // Exists + // Exp + // Flatten + // Floor + // Is + if (left is Is) { + if (right is Is) { + val leftArg = left + val rightArg = right + return qnamesEqual(leftArg.isType, rightArg.isType) && + typeSpecifiersEqual(leftArg.isTypeSpecifier, rightArg.isTypeSpecifier) + } + return false + } + + // IsFalse + // IsNull + // IsTrue + // Length + // Ln + // Lower + // Negate + // Not + // PointFrom + // Precision + // Predecessor + // SingletonFrom + // Size + // Start + // Successor + // TimeFrom + // TimezoneFrom + // TimezoneOffsetFrom + // ToBoolean + // ToConcept + // ToChars + // ToDate + // ToDateTime + // ToDecimal + // ToInteger + // ToLong + // ToList + // ToQuantity + // ToRatio + // ToString + // ToTime + // Truncate + // Upper + // Width + + // We've covered all the special cases above, so if we make it here, the expressions are + // equal + return true + } + + fun binaryExpressionsEqual(left: BinaryExpression?, right: BinaryExpression?): Boolean { + if (left == null && right == null) { + return true + } + + if (left == null || right == null) { + return false + } + + if (left.javaClass.canonicalName != right.javaClass.canonicalName) { + return false + } + + if (!operandsEqual(left, right)) { + return false + } + + // TODO: Handle special cases for operators that have a precision modifier + // Add + // After + // And + // Before + // CanConvertQuantity + // Contains + // ConvertQuantity + // Collapse + // DifferenceBetween + // Divide + // DurationBetween + // Ends + // EndsWith + // Equal + // Equivalent + // Expand + // Greater + // GreaterOrEqual + // HighBoundary + // Implies + // In + // IncludedIn + // Includes + // Indexer + // Less + // LessOrEqual + // Log + // LowBoundary + // Matches + // Meets + // MeetsAfter + // MeetsBefore + // Modulo + // Multiply + // NotEqual + // Or + // Overlaps + // OverlapsAfter + // OverlapsBefore + // Power + // ProperContains + // ProperIn + // ProperIncludedIn + // ProperIncludes + // SameAs + // SameOrAfter + // SameOrBefore + // Starts + // StartsWith + // Subtract + // Times + // TruncatedDivide + // Xor + return true + } + + fun ternaryExpressionsEqual(left: TernaryExpression?, right: TernaryExpression?): Boolean { + if (left == null && right == null) { + return true + } + + if (left == null || right == null) { + return false + } + + if (left.javaClass.canonicalName != right.javaClass.canonicalName) { + return false + } + + if (!operandsEqual(left, right)) { + return false + } + + // ReplaceMatches + return true + } + + fun naryExpressionsEqual(left: NaryExpression?, right: NaryExpression?): Boolean { + if (left == null && right == null) { + return true + } + + if (left == null || right == null) { + return false + } + + if (left.javaClass.canonicalName != right.javaClass.canonicalName) { + return false + } + + if (!operandsEqual(left, right)) { + return false + } + + // Coalesce + // Concatenate + // Except + // Intersect + // Union + return false + } + + fun aggregateExpressionsEqual( + left: AggregateExpression?, + right: AggregateExpression? + ): Boolean { + if (left == null && right == null) { + return true + } + + if (left == null || right == null) { + return false + } + + if (left.javaClass.canonicalName != right.javaClass.canonicalName) { + return false + } + + if (!expressionsEqual(left.source, right.source) || !stringsEqual(left.path, right.path)) { + return false + } + + // Aggregate + if (left is Aggregate) { + if (right is Aggregate) { + val leftArg = left + val rightArg = right + return expressionsEqual(leftArg.initialValue, rightArg.initialValue) && + expressionsEqual(leftArg.iteration, rightArg.iteration) + } + } + + // Count + // Sum + // Product + // Min + // Max + // Avg + // GeometricMean + // Median + // Mode + // Variance + // StdDev + // PopulationVariance + // PopulationStdDev + // AllTrue + // AnyTrue + return true + } +} diff --git a/Src/java/elm/src/main/java/org/cqframework/cql/elm/evaluating/SimpleElmEvaluator.java b/Src/java/elm/src/main/java/org/cqframework/cql/elm/evaluating/SimpleElmEvaluator.java deleted file mode 100644 index 4d9294069..000000000 --- a/Src/java/elm/src/main/java/org/cqframework/cql/elm/evaluating/SimpleElmEvaluator.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.cqframework.cql.elm.evaluating; - -import javax.xml.namespace.QName; -import org.hl7.elm.r1.Expression; -import org.hl7.elm.r1.TypeSpecifier; - -public class SimpleElmEvaluator { - - private static final SimpleElmEngine engine = new SimpleElmEngine(); - - public static SimpleElmEngine simpleElmEngine() { - return engine; - } - - public static boolean booleansEqual(Expression left, Expression right) { - return engine.booleansEqual(left, right); - } - - public static boolean integersEqual(Expression left, Expression right) { - return engine.integersEqual(left, right); - } - - public static boolean decimalsEqual(Expression left, Expression right) { - return engine.decimalsEqual(left, right); - } - - public static boolean stringsEqual(Expression left, Expression right) { - return engine.stringsEqual(left, right); - } - - public static boolean stringsEqual(String left, String right) { - return engine.stringsEqual(left, right); - } - - public static boolean dateTimesEqual(Expression left, Expression right) { - return engine.dateTimesEqual(left, right); - } - - public static boolean dateRangesEqual(Expression left, Expression right) { - return engine.dateRangesEqual(left, right); - } - - public static boolean codesEqual(Expression left, Expression right) { - return engine.codesEqual(left, right); - } - - public static boolean typeSpecifiersEqual(TypeSpecifier left, TypeSpecifier right) { - return engine.typeSpecifiersEqual(left, right); - } - - public static boolean qnamesEqual(QName left, QName right) { - return engine.qnamesEqual(left, right); - } -} diff --git a/Src/java/elm/src/main/java/org/cqframework/cql/elm/evaluating/SimpleElmEvaluator.kt b/Src/java/elm/src/main/java/org/cqframework/cql/elm/evaluating/SimpleElmEvaluator.kt new file mode 100644 index 000000000..824ae6f33 --- /dev/null +++ b/Src/java/elm/src/main/java/org/cqframework/cql/elm/evaluating/SimpleElmEvaluator.kt @@ -0,0 +1,60 @@ +package org.cqframework.cql.elm.evaluating + +import javax.xml.namespace.QName +import org.hl7.elm.r1.Expression +import org.hl7.elm.r1.TypeSpecifier + +@Suppress("TooManyFunctions") +object SimpleElmEvaluator { + private val engine = SimpleElmEngine() + + fun simpleElmEngine(): SimpleElmEngine { + return engine + } + + fun booleansEqual(left: Expression?, right: Expression?): Boolean { + return engine.booleansEqual(left, right) + } + + fun integersEqual(left: Expression?, right: Expression?): Boolean { + return engine.integersEqual(left, right) + } + + fun decimalsEqual(left: Expression?, right: Expression?): Boolean { + return engine.decimalsEqual(left, right) + } + + @JvmStatic + fun stringsEqual(left: Expression?, right: Expression?): Boolean { + return engine.stringsEqual(left, right) + } + + @JvmStatic + fun stringsEqual(left: String?, right: String?): Boolean { + return engine.stringsEqual(left, right) + } + + fun dateTimesEqual(left: Expression?, right: Expression?): Boolean { + return engine.dateTimesEqual(left, right) + } + + @JvmStatic + fun dateRangesEqual(left: Expression?, right: Expression?): Boolean { + return engine.dateRangesEqual(left, right) + } + + @JvmStatic + fun codesEqual(left: Expression?, right: Expression?): Boolean { + return engine.codesEqual(left, right) + } + + @JvmStatic + fun typeSpecifiersEqual(left: TypeSpecifier?, right: TypeSpecifier?): Boolean { + return engine.typeSpecifiersEqual(left, right) + } + + @JvmStatic + fun qnamesEqual(left: QName?, right: QName?): Boolean { + return engine.qnamesEqual(left, right) + } +} diff --git a/Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryReader.java b/Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryReader.java deleted file mode 100644 index 336ba0337..000000000 --- a/Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryReader.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.cqframework.cql.elm.serializing; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.Reader; -import java.net.URI; -import java.net.URL; -import org.hl7.elm.r1.Library; - -public interface ElmLibraryReader { - - public Library read(File file) throws IOException; - - public Library read(URL url) throws IOException; - - public Library read(URI uri) throws IOException; - - public Library read(String string) throws IOException; - - public Library read(InputStream inputStream) throws IOException; - - public Library read(Reader reader) throws IOException; -} diff --git a/Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryReader.kt b/Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryReader.kt new file mode 100644 index 000000000..3d4156715 --- /dev/null +++ b/Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryReader.kt @@ -0,0 +1,23 @@ +package org.cqframework.cql.elm.serializing + +import java.io.File +import java.io.IOException +import java.io.InputStream +import java.io.Reader +import java.net.URI +import java.net.URL +import org.hl7.elm.r1.Library + +interface ElmLibraryReader { + @Throws(IOException::class) fun read(file: File): Library? + + @Throws(IOException::class) fun read(url: URL): Library? + + @Throws(IOException::class) fun read(uri: URI): Library? + + @Throws(IOException::class) fun read(string: String): Library? + + @Throws(IOException::class) fun read(inputStream: InputStream): Library? + + @Throws(IOException::class) fun read(reader: Reader): Library? +} diff --git a/Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryReaderFactory.java b/Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryReaderFactory.java deleted file mode 100644 index 331218868..000000000 --- a/Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryReaderFactory.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.cqframework.cql.elm.serializing; - -import java.util.Iterator; -import java.util.ServiceLoader; - -public class ElmLibraryReaderFactory { - private ElmLibraryReaderFactory() {} - - public static Iterator providers(boolean refresh) { - var loader = ServiceLoader.load(ElmLibraryReaderProvider.class); - if (refresh) { - loader.reload(); - } - - return loader.iterator(); - } - - public static ElmLibraryReader getReader(String contentType) { - var providers = providers(false); - if (providers.hasNext()) { - ElmLibraryReaderProvider p = providers.next(); - if (providers.hasNext()) { - throw new RuntimeException(String.join( - " ", - "Multiple ElmLibraryReaderProviders found on the classpath.", - "You need to remove a reference to either the 'elm-jackson' or the 'elm-jaxb' package")); - } - - return p.create(contentType); - } - - throw new RuntimeException(String.join( - " ", - "No ElmLibraryReaderProviders found on the classpath.", - "You need to add a reference to one of the 'elm-jackson' or 'elm-jaxb' packages,", - "or provide your own implementation.")); - } -} diff --git a/Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryReaderFactory.kt b/Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryReaderFactory.kt new file mode 100644 index 000000000..a642ffe0b --- /dev/null +++ b/Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryReaderFactory.kt @@ -0,0 +1,38 @@ +package org.cqframework.cql.elm.serializing + +import java.util.* + +@Suppress("TooGenericExceptionThrown") +object ElmLibraryReaderFactory { + fun providers(refresh: Boolean): Iterator { + val loader = ServiceLoader.load(ElmLibraryReaderProvider::class.java) + if (refresh) { + loader.reload() + } + + return loader.iterator() + } + + fun getReader(contentType: String): ElmLibraryReader { + val providers = providers(false) + if (providers.hasNext()) { + val p = providers.next() + if (providers.hasNext()) { + throw RuntimeException( + """Multiple ElmLibraryReaderProviders found on the classpath. + You need to remove a reference to either the 'elm-jackson' or the 'elm-jaxb' package""" + .trimIndent() + ) + } + + return p.create(contentType) + } + + throw RuntimeException( + """No ElmLibraryReaderProviders found on the classpath., + You need to add a reference to one of the 'elm-jackson' or 'elm-jaxb' packages, + or provide your own implementation.""" + .trimIndent() + ) + } +} diff --git a/Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryReaderProvider.java b/Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryReaderProvider.java deleted file mode 100644 index d8df5deee..000000000 --- a/Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryReaderProvider.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.cqframework.cql.elm.serializing; - -public interface ElmLibraryReaderProvider { - ElmLibraryReader create(String contentType); -} diff --git a/Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryReaderProvider.kt b/Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryReaderProvider.kt new file mode 100644 index 000000000..32e7058c5 --- /dev/null +++ b/Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryReaderProvider.kt @@ -0,0 +1,5 @@ +package org.cqframework.cql.elm.serializing + +interface ElmLibraryReaderProvider { + fun create(contentType: String): ElmLibraryReader +} diff --git a/Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryWriter.java b/Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryWriter.java deleted file mode 100644 index 1325c34c8..000000000 --- a/Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryWriter.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.cqframework.cql.elm.serializing; - -import java.io.*; -import org.hl7.elm.r1.Library; - -public interface ElmLibraryWriter { - - public void write(Library library, Writer writer) throws IOException; - - public String writeAsString(Library library); -} diff --git a/Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryWriter.kt b/Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryWriter.kt new file mode 100644 index 000000000..a7d6f03fd --- /dev/null +++ b/Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryWriter.kt @@ -0,0 +1,11 @@ +package org.cqframework.cql.elm.serializing + +import java.io.IOException +import java.io.Writer +import org.hl7.elm.r1.Library + +interface ElmLibraryWriter { + @Throws(IOException::class) fun write(library: Library, writer: Writer) + + fun writeAsString(library: Library): String +} diff --git a/Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryWriterFactory.java b/Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryWriterFactory.java deleted file mode 100644 index a79ee41ec..000000000 --- a/Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryWriterFactory.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.cqframework.cql.elm.serializing; - -import java.util.Iterator; -import java.util.ServiceLoader; - -public class ElmLibraryWriterFactory { - private ElmLibraryWriterFactory() {} - - public static Iterator providers(boolean refresh) { - var loader = ServiceLoader.load(ElmLibraryWriterProvider.class); - if (refresh) { - loader.reload(); - } - - return loader.iterator(); - } - - public static ElmLibraryWriter getWriter(String contentType) { - var providers = providers(false); - if (providers.hasNext()) { - ElmLibraryWriterProvider p = providers.next(); - if (providers.hasNext()) { - throw new RuntimeException(String.join( - " ", - "Multiple ElmLibraryWriterProviders found on the classpath.", - "You need to remove a reference to either the 'elm-jackson' or the 'elm-jaxb' package")); - } - - return p.create(contentType); - } - - throw new RuntimeException(String.join( - " ", - "No ElmLibraryWriterProviders found on the classpath.", - "You need to add a reference to one of the 'elm-jackson' or 'elm-jaxb' packages,", - "or provide your own implementation.")); - } -} diff --git a/Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryWriterFactory.kt b/Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryWriterFactory.kt new file mode 100644 index 000000000..bb8b251d6 --- /dev/null +++ b/Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryWriterFactory.kt @@ -0,0 +1,38 @@ +package org.cqframework.cql.elm.serializing + +import java.util.* + +@Suppress("TooGenericExceptionThrown") +object ElmLibraryWriterFactory { + fun providers(refresh: Boolean): Iterator { + val loader = ServiceLoader.load(ElmLibraryWriterProvider::class.java) + if (refresh) { + loader.reload() + } + + return loader.iterator() + } + + fun getWriter(contentType: String): ElmLibraryWriter { + val providers = providers(false) + if (providers.hasNext()) { + val p = providers.next() + if (providers.hasNext()) { + throw RuntimeException( + """Multiple ElmLibraryWriterProviders found on the classpath. + "You need to remove a reference to either the 'elm-jackson' or the 'elm-jaxb' package""" + .trimIndent() + ) + } + + return p.create(contentType) + } + + throw RuntimeException( + """No ElmLibraryWriterProviders found on the classpath. + You need to add a reference to one of the 'elm-jackson' or 'elm-jaxb' packages, + or provide your own implementation.""" + .trimIndent() + ) + } +} diff --git a/Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryWriterProvider.java b/Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryWriterProvider.java deleted file mode 100644 index e231a77d5..000000000 --- a/Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryWriterProvider.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.cqframework.cql.elm.serializing; - -public interface ElmLibraryWriterProvider { - ElmLibraryWriter create(String contentType); -} diff --git a/Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryWriterProvider.kt b/Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryWriterProvider.kt new file mode 100644 index 000000000..b0c60f97c --- /dev/null +++ b/Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/ElmLibraryWriterProvider.kt @@ -0,0 +1,5 @@ +package org.cqframework.cql.elm.serializing + +interface ElmLibraryWriterProvider { + fun create(contentType: String): ElmLibraryWriter +} diff --git a/Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/LibraryWrapper.java b/Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/LibraryWrapper.java deleted file mode 100644 index 45777ba5d..000000000 --- a/Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/LibraryWrapper.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.cqframework.cql.elm.serializing; - -import org.hl7.elm.r1.Library; - -public class LibraryWrapper { - private Library library; - - public Library getLibrary() { - return this.library; - } - - public void setLibrary(Library library) { - this.library = library; - } -} diff --git a/Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/LibraryWrapper.kt b/Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/LibraryWrapper.kt new file mode 100644 index 000000000..cf45ca6a4 --- /dev/null +++ b/Src/java/elm/src/main/java/org/cqframework/cql/elm/serializing/LibraryWrapper.kt @@ -0,0 +1,5 @@ +package org.cqframework.cql.elm.serializing + +import org.hl7.elm.r1.Library + +class LibraryWrapper(val library: Library) diff --git a/Src/java/elm/src/main/java/org/cqframework/cql/elm/tracking/TrackBack.java b/Src/java/elm/src/main/java/org/cqframework/cql/elm/tracking/TrackBack.java deleted file mode 100644 index 66164a49f..000000000 --- a/Src/java/elm/src/main/java/org/cqframework/cql/elm/tracking/TrackBack.java +++ /dev/null @@ -1,95 +0,0 @@ -package org.cqframework.cql.elm.tracking; - -import org.hl7.elm.r1.VersionedIdentifier; - -public class TrackBack { - private final VersionedIdentifier library; - private final int startLine; - private final int startChar; - private final int endLine; - private final int endChar; - - public TrackBack(VersionedIdentifier library, int startLine, int startChar, int endLine, int endChar) { - this.library = library; - this.startLine = startLine; - this.startChar = startChar; - this.endLine = endLine; - this.endChar = endChar; - } - - public VersionedIdentifier getLibrary() { - return library; - } - - public int getStartLine() { - return startLine; - } - - public int getStartChar() { - return startChar; - } - - public int getEndLine() { - return endLine; - } - - public int getEndChar() { - return endChar; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - TrackBack trackBack = (TrackBack) o; - - if (endChar != trackBack.endChar) { - return false; - } - if (endLine != trackBack.endLine) { - return false; - } - if (startChar != trackBack.startChar) { - return false; - } - if (startLine != trackBack.startLine) { - return false; - } - if (!library.equals(trackBack.library)) { - return false; - } - - return true; - } - - @Override - public int hashCode() { - int result = library.hashCode(); - result = 31 * result + startLine; - result = 31 * result + startChar; - result = 31 * result + endLine; - result = 31 * result + endChar; - return result; - } - - @Override - public String toString() { - return "TrackBack{" + "library='" - + library + '\'' + ", startLine=" - + startLine + ", startChar=" - + startChar + ", endLine=" - + endLine + ", endChar=" - + endChar + '}'; - } - - public String toLocator() { - return startLine == endLine && startChar == endChar - ? String.format("%s:%s", startLine, startChar) - : String.format("%s:%s-%s:%s", startLine, startChar, endLine, endChar); - } -} diff --git a/Src/java/elm/src/main/java/org/cqframework/cql/elm/tracking/TrackBack.kt b/Src/java/elm/src/main/java/org/cqframework/cql/elm/tracking/TrackBack.kt new file mode 100644 index 000000000..8bcabfb2e --- /dev/null +++ b/Src/java/elm/src/main/java/org/cqframework/cql/elm/tracking/TrackBack.kt @@ -0,0 +1,35 @@ +package org.cqframework.cql.elm.tracking + +import java.util.* +import org.hl7.elm.r1.VersionedIdentifier + +data class TrackBack( + val library: VersionedIdentifier?, + val startLine: Int, + val startChar: Int, + val endLine: Int, + val endChar: Int +) { + + override fun toString(): String { + return ("TrackBack{" + + "library='" + + library + + '\'' + + ", startLine=" + + startLine + + ", startChar=" + + startChar + + ", endLine=" + + endLine + + ", endChar=" + + endChar + + '}') + } + + fun toLocator(): String { + return if (startLine == endLine && startChar == endChar) + String.format(Locale.US, "%s:%s", startLine, startChar) + else String.format(Locale.US, "%s:%s-%s:%s", startLine, startChar, endLine, endChar) + } +} diff --git a/Src/java/elm/src/main/java/org/cqframework/cql/elm/tracking/Trackable.java b/Src/java/elm/src/main/java/org/cqframework/cql/elm/tracking/Trackable.java deleted file mode 100644 index ab323bb6f..000000000 --- a/Src/java/elm/src/main/java/org/cqframework/cql/elm/tracking/Trackable.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.cqframework.cql.elm.tracking; - -import jakarta.xml.bind.annotation.XmlTransient; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import org.hl7.cql.model.DataType; - -public class Trackable { - private final UUID trackerId; - private final List trackbacks; - - private DataType resultType; - - public Trackable() { - this.trackerId = UUID.randomUUID(); - this.trackbacks = new ArrayList<>(); - } - - @XmlTransient - public UUID getTrackerId() { - return trackerId; - } - - @XmlTransient - public List getTrackbacks() { - return trackbacks; - } - - @XmlTransient - public DataType getResultType() { - return resultType; - } - - public void setResultType(DataType resultType) { - this.resultType = resultType; - } - - public Trackable withResultType(DataType resultType) { - setResultType(resultType); - return this; - } -} diff --git a/Src/java/elm/src/main/java/org/cqframework/cql/elm/tracking/Trackable.kt b/Src/java/elm/src/main/java/org/cqframework/cql/elm/tracking/Trackable.kt new file mode 100644 index 000000000..6236c7e95 --- /dev/null +++ b/Src/java/elm/src/main/java/org/cqframework/cql/elm/tracking/Trackable.kt @@ -0,0 +1,18 @@ +package org.cqframework.cql.elm.tracking + +import jakarta.xml.bind.annotation.XmlTransient +import java.util.* +import org.hl7.cql.model.DataType + +open class Trackable { + @get:XmlTransient val trackerId: UUID = UUID.randomUUID() + + @get:XmlTransient val trackbacks: MutableList = ArrayList() + + @get:XmlTransient var resultType: DataType? = null + + fun withResultType(resultType: DataType?): Trackable { + this.resultType = resultType + return this + } +} diff --git a/Src/java/elm/src/main/java/org/cqframework/cql/elm/utility/Visitors.java b/Src/java/elm/src/main/java/org/cqframework/cql/elm/utility/Visitors.java deleted file mode 100644 index b03f3d74d..000000000 --- a/Src/java/elm/src/main/java/org/cqframework/cql/elm/utility/Visitors.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.cqframework.cql.elm.utility; - -import java.util.Objects; -import java.util.function.BiFunction; -import org.cqframework.cql.elm.tracking.Trackable; -import org.cqframework.cql.elm.visiting.FunctionalElmVisitor; - -public class Visitors { - - private Visitors() {} - - public static FunctionalElmVisitor from( - BiFunction defaultResult, BiFunction aggregateResult) { - Objects.requireNonNull(defaultResult, "defaultResult required"); - Objects.requireNonNull(aggregateResult, "aggregateResult required"); - return new FunctionalElmVisitor<>(defaultResult, aggregateResult); - } - - public static FunctionalElmVisitor from(BiFunction defaultResult) { - Objects.requireNonNull(defaultResult, "defaultResult required"); - return from(defaultResult, (a, b) -> b); - } -} diff --git a/Src/java/elm/src/main/java/org/cqframework/cql/elm/utility/Visitors.kt b/Src/java/elm/src/main/java/org/cqframework/cql/elm/utility/Visitors.kt new file mode 100644 index 000000000..695779836 --- /dev/null +++ b/Src/java/elm/src/main/java/org/cqframework/cql/elm/utility/Visitors.kt @@ -0,0 +1,20 @@ +package org.cqframework.cql.elm.utility + +import java.util.function.BiFunction +import org.cqframework.cql.elm.tracking.Trackable +import org.cqframework.cql.elm.visiting.FunctionalElmVisitor + +object Visitors { + @JvmStatic + fun from( + defaultResult: BiFunction, + aggregateResult: BiFunction + ): FunctionalElmVisitor { + return FunctionalElmVisitor(defaultResult, aggregateResult) + } + + @JvmStatic + fun from(defaultResult: BiFunction): FunctionalElmVisitor { + return from(defaultResult) { _: T?, b: T? -> b } + } +} diff --git a/Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/BaseElmClinicalVisitor.java b/Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/BaseElmClinicalVisitor.java deleted file mode 100644 index 410ffdfdf..000000000 --- a/Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/BaseElmClinicalVisitor.java +++ /dev/null @@ -1,629 +0,0 @@ -package org.cqframework.cql.elm.visiting; - -import org.hl7.elm.r1.*; - -/** - * Provides the base implementation for an ElmClinicalVisitor - * - * @param The return type of the visit operation. Use {@link Void} for - * @param The type of context passed to each visit method - * operations with no return type. - */ -public abstract class BaseElmClinicalVisitor extends BaseElmVisitor implements ElmClinicalVisitor { - - @Override - public T visitElement(Element elm, C context) { - if (elm instanceof ExpressionDef) return visitExpressionDef((ExpressionDef) elm, context); - else if (elm instanceof CodeDef) return visitCodeDef((CodeDef) elm, context); - else if (elm instanceof CodeSystemDef) return visitCodeSystemDef((CodeSystemDef) elm, context); - else if (elm instanceof ValueSetDef) return visitValueSetDef((ValueSetDef) elm, context); - else if (elm instanceof ConceptDef) return visitConceptDef((ConceptDef) elm, context); - else if (elm instanceof CodeFilterElement) return visitCodeFilterElement((CodeFilterElement) elm, context); - else if (elm instanceof DateFilterElement) return visitDateFilterElement((DateFilterElement) elm, context); - else if (elm instanceof OtherFilterElement) return visitOtherFilterElement((OtherFilterElement) elm, context); - else if (elm instanceof IncludeElement) return visitIncludeElement((IncludeElement) elm, context); - return super.visitElement(elm, context); - } - - /** - * Visit an Expression. This method will be called for - * every node in the tree that is an Expression. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - @Override - public T visitExpression(Expression elm, C context) { - if (elm instanceof FunctionRef) return visitFunctionRef((FunctionRef) elm, context); - else if (elm instanceof ExpressionRef) return visitExpressionRef((ExpressionRef) elm, context); - else if (elm instanceof CodeSystemRef) return visitCodeSystemRef((CodeSystemRef) elm, context); - else if (elm instanceof ValueSetRef) return visitValueSetRef((ValueSetRef) elm, context); - else if (elm instanceof CodeRef) return visitCodeRef((CodeRef) elm, context); - else if (elm instanceof ConceptRef) return visitConceptRef((ConceptRef) elm, context); - else if (elm instanceof Code) return visitCode((Code) elm, context); - else if (elm instanceof Concept) return visitConcept((Concept) elm, context); - else if (elm instanceof Quantity) return visitQuantity((Quantity) elm, context); - else if (elm instanceof Ratio) return visitRatio((Ratio) elm, context); - else if (elm instanceof Retrieve) return visitRetrieve((Retrieve) elm, context); - else return super.visitExpression(elm, context); - } - - /** - * Visit an OperatorExpression. This method will be called for - * every node in the tree that is a OperatorExpression. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - @Override - public T visitOperatorExpression(OperatorExpression elm, C context) { - if (elm instanceof InCodeSystem) return visitInCodeSystem((InCodeSystem) elm, context); - else if (elm instanceof AnyInCodeSystem) return visitAnyInCodeSystem((AnyInCodeSystem) elm, context); - else if (elm instanceof InValueSet) return visitInValueSet((InValueSet) elm, context); - else if (elm instanceof AnyInValueSet) return visitAnyInValueSet((AnyInValueSet) elm, context); - else return super.visitOperatorExpression(elm, context); - } - - /** - * Visit a UnaryExpression. This method will be called for - * every node in the tree that is a UnaryExpression. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - @Override - public T visitUnaryExpression(UnaryExpression elm, C context) { - if (elm instanceof ExpandValueSet) return visitExpandValueSet((ExpandValueSet) elm, context); - if (elm instanceof CalculateAge) return visitCalculateAge((CalculateAge) elm, context); - else return super.visitUnaryExpression(elm, context); - } - - /** - * Visit a BinaryExpression. This method will be called for - * every node in the tree that is a BinaryExpression. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - @Override - public T visitBinaryExpression(BinaryExpression elm, C context) { - if (elm instanceof CalculateAgeAt) return visitCalculateAgeAt((CalculateAgeAt) elm, context); - else if (elm instanceof Subsumes) return visitSubsumes((Subsumes) elm, context); - else if (elm instanceof SubsumedBy) return visitSubsumedBy((SubsumedBy) elm, context); - else return super.visitBinaryExpression(elm, context); - } - - /** - * Visit an ExpandValueSet. This method will be called for - * every node in the tree that is an ExpandValueSet. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitExpandValueSet(ExpandValueSet elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a CodeFilterElement. This method will be called for - * every node in the tree that is a CodeFilterElement. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitCodeFilterElement(CodeFilterElement elm, C context) { - T result = visitFields(elm, context); - if (elm.getValue() != null) { - T childResult = visitExpression(elm.getValue(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a DateFilterElement. This method will be called for - * every node in the tree that is a DateFilterElement. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitDateFilterElement(DateFilterElement elm, C context) { - T result = visitFields(elm, context); - - if (elm.getValue() != null) { - T childResult = visitExpression(elm.getValue(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit an OtherFilterElement. This method will be called for - * every node in the tree that is an OtherFilterElement. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitOtherFilterElement(OtherFilterElement elm, C context) { - T result = visitFields(elm, context); - - if (elm.getValue() != null) { - T childResult = visitExpression(elm.getValue(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit an IncludeElement. This method will be called for - * every node in the tree that is an IncludeElement. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitIncludeElement(IncludeElement elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Retrieve. This method will be called for - * every node in the tree that is a Retrieve. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitRetrieve(Retrieve elm, C context) { - T result = visitFields(elm, context); - - for (var cfe : elm.getCodeFilter()) { - T childResult = visitCodeFilterElement(cfe, context); - result = aggregateResult(result, childResult); - } - - if (elm.getCodes() != null) { - T childResult = visitExpression(elm.getCodes(), context); - result = aggregateResult(result, childResult); - } - if (elm.getContext() != null) { - T childResult = visitExpression(elm.getContext(), context); - result = aggregateResult(result, childResult); - } - for (var dfe : elm.getDateFilter()) { - T childResult = visitDateFilterElement(dfe, context); - result = aggregateResult(result, childResult); - } - if (elm.getDateRange() != null) { - T childResult = visitExpression(elm.getDateRange(), context); - result = aggregateResult(result, childResult); - } - - if (elm.getId() != null) { - T childResult = visitExpression(elm.getId(), context); - result = aggregateResult(result, childResult); - } - - for (var ie : elm.getInclude()) { - T childResult = visitIncludeElement(ie, context); - result = aggregateResult(result, childResult); - } - - for (var ofe : elm.getOtherFilter()) { - T childResult = visitOtherFilterElement(ofe, context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a Property. This method will be called for - * every node in the tree that is a Property. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - @Override - public T visitProperty(Property elm, C context) { - if (elm instanceof Search) { - return visitSearch((Search) elm, context); - } - return super.visitProperty(elm, context); - } - - /** - * Visit a Search. This method will be called for - * every node in the tree that is a Search. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitSearch(Search elm, C context) { - T result = visitFields(elm, context); - - if (elm.getSource() != null) { - T childResult = visitExpression(elm.getSource(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a CodeSystemDef. This method will be called for - * every node in the tree that is a CodeSystemDef. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitCodeSystemDef(CodeSystemDef elm, C context) { - T result = visitFields(elm, context); - if (elm.getAccessLevel() != null) { - T childResult = visitAccessModifier(elm.getAccessLevel(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a ValueSetDef. This method will be called for - * every node in the tree that is a ValueSetDef. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitValueSetDef(ValueSetDef elm, C context) { - T result = visitFields(elm, context); - - if (elm.getAccessLevel() != null) { - T childResult = visitAccessModifier(elm.getAccessLevel(), context); - result = aggregateResult(result, childResult); - } - for (CodeSystemRef codeSystemRef : elm.getCodeSystem()) { - T childResult = visitCodeSystemRef(codeSystemRef, context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a CodeDef. This method will be called for - * every node in the tree that is a CodeDef. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitCodeDef(CodeDef elm, C context) { - T result = visitFields(elm, context); - - if (elm.getAccessLevel() != null) { - T childResult = visitAccessModifier(elm.getAccessLevel(), context); - result = aggregateResult(result, childResult); - } - if (elm.getCodeSystem() != null) { - T childResult = visitCodeSystemRef(elm.getCodeSystem(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit an ConceptDef. This method will be called for - * every node in the tree that is an ConceptDef. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitConceptDef(ConceptDef elm, C context) { - T result = visitFields(elm, context); - - if (elm.getAccessLevel() != null) { - T childResult = visitAccessModifier(elm.getAccessLevel(), context); - result = aggregateResult(result, childResult); - } - for (CodeRef cr : elm.getCode()) { - T childResult = visitCodeRef(cr, context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a CodeSystemRef. This method will be called for - * every node in the tree that is a CodeSystemRef. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitCodeSystemRef(CodeSystemRef elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a ValueSetRef. This method will be called for - * every node in the tree that is a ValueSetRef. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitValueSetRef(ValueSetRef elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a CodeRef. This method will be called for - * every node in the tree that is a CodeRef. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitCodeRef(CodeRef elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a ConceptRef. This method will be called for - * every node in the tree that is a ConceptRef. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitConceptRef(ConceptRef elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Code. This method will be called for - * every node in the tree that is a Code. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitCode(Code elm, C context) { - T result = visitFields(elm, context); - - if (elm.getSystem() != null) { - T childResult = visitCodeSystemRef(elm.getSystem(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a Concept. This method will be called for - * every node in the tree that is a Concept. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitConcept(Concept elm, C context) { - T result = visitFields(elm, context); - - for (Code c : elm.getCode()) { - T childResult = visitCode(c, context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a InCodeSystem. This method will be called for - * every node in the tree that is a InCodeSystem. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitInCodeSystem(InCodeSystem elm, C context) { - T result = visitFields(elm, context); - - if (elm.getCode() != null) { - T childResult = visitExpression(elm.getCode(), context); - result = aggregateResult(result, childResult); - } - if (elm.getCodesystem() != null) { - T childResult = visitCodeSystemRef(elm.getCodesystem(), context); - result = aggregateResult(result, childResult); - } - if (elm.getCodesystemExpression() != null) { - T childResult = visitExpression(elm.getCodesystemExpression(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit an AnyInCodeSystem. This method will be called for - * every node in the tree that is an AnyInCodeSystem. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitAnyInCodeSystem(AnyInCodeSystem elm, C context) { - T result = visitFields(elm, context); - - if (elm.getCodes() != null) { - T childResult = visitExpression(elm.getCodes(), context); - result = aggregateResult(result, childResult); - } - if (elm.getCodesystem() != null) { - T childResult = visitCodeSystemRef(elm.getCodesystem(), context); - result = aggregateResult(result, childResult); - } - if (elm.getCodesystemExpression() != null) { - T childResult = visitExpression(elm.getCodesystemExpression(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a InValueSet. This method will be called for - * every node in the tree that is a InValueSet. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitInValueSet(InValueSet elm, C context) { - T result = visitFields(elm, context); - - if (elm.getCode() != null) { - T childResult = visitExpression(elm.getCode(), context); - result = aggregateResult(result, childResult); - } - if (elm.getValueset() != null) { - T childResult = visitValueSetRef(elm.getValueset(), context); - result = aggregateResult(result, childResult); - } - if (elm.getValuesetExpression() != null) { - T childResult = visitExpression(elm.getValuesetExpression(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit an AnyInValueSet. This method will be called for - * every node in the tree that is an AnyInValueSet. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitAnyInValueSet(AnyInValueSet elm, C context) { - T result = visitFields(elm, context); - - if (elm.getCodes() != null) { - T childResult = visitExpression(elm.getCodes(), context); - result = aggregateResult(result, childResult); - } - if (elm.getValueset() != null) { - T childResult = visitValueSetRef(elm.getValueset(), context); - result = aggregateResult(result, childResult); - } - if (elm.getValuesetExpression() != null) { - T childResult = visitExpression(elm.getValuesetExpression(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit an Subsumes. This method will be called for - * every node in the tree that is an Subsumes. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitSubsumes(Subsumes elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit an SubsumedBy. This method will be called for - * every node in the tree that is an SubsumedBy. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitSubsumedBy(SubsumedBy elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Quantity. This method will be called for - * every node in the tree that is a Quantity. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitQuantity(Quantity elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Ratio. This method will be called for - * every node in the tree that is a Ratio. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitRatio(Ratio elm, C context) { - T result = visitFields(elm, context); - - if (elm.getDenominator() != null) { - T childResult = visitQuantity(elm.getDenominator(), context); - result = aggregateResult(result, childResult); - } - if (elm.getNumerator() != null) { - T childResult = visitQuantity(elm.getNumerator(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a CalculateAge. This method will be called for - * every node in the tree that is a CalculateAge. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitCalculateAge(CalculateAge elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a CalculateAgeAt. This method will be called for - * every node in the tree that is a CalculateAgeAt. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitCalculateAgeAt(CalculateAgeAt elm, C context) { - return visitFields(elm, context); - } -} diff --git a/Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/BaseElmClinicalVisitor.kt b/Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/BaseElmClinicalVisitor.kt new file mode 100644 index 000000000..43f6cc6cd --- /dev/null +++ b/Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/BaseElmClinicalVisitor.kt @@ -0,0 +1,656 @@ +package org.cqframework.cql.elm.visiting + +import org.hl7.elm.r1.AnyInCodeSystem +import org.hl7.elm.r1.AnyInValueSet +import org.hl7.elm.r1.BinaryExpression +import org.hl7.elm.r1.CalculateAge +import org.hl7.elm.r1.CalculateAgeAt +import org.hl7.elm.r1.Code +import org.hl7.elm.r1.CodeDef +import org.hl7.elm.r1.CodeFilterElement +import org.hl7.elm.r1.CodeRef +import org.hl7.elm.r1.CodeSystemDef +import org.hl7.elm.r1.CodeSystemRef +import org.hl7.elm.r1.Concept +import org.hl7.elm.r1.ConceptDef +import org.hl7.elm.r1.ConceptRef +import org.hl7.elm.r1.DateFilterElement +import org.hl7.elm.r1.Element +import org.hl7.elm.r1.ExpandValueSet +import org.hl7.elm.r1.Expression +import org.hl7.elm.r1.ExpressionDef +import org.hl7.elm.r1.ExpressionRef +import org.hl7.elm.r1.FunctionRef +import org.hl7.elm.r1.InCodeSystem +import org.hl7.elm.r1.InValueSet +import org.hl7.elm.r1.IncludeElement +import org.hl7.elm.r1.OperatorExpression +import org.hl7.elm.r1.OtherFilterElement +import org.hl7.elm.r1.Property +import org.hl7.elm.r1.Quantity +import org.hl7.elm.r1.Ratio +import org.hl7.elm.r1.Retrieve +import org.hl7.elm.r1.Search +import org.hl7.elm.r1.SubsumedBy +import org.hl7.elm.r1.Subsumes +import org.hl7.elm.r1.UnaryExpression +import org.hl7.elm.r1.ValueSetDef +import org.hl7.elm.r1.ValueSetRef + +/** + * Provides the base implementation for an ElmClinicalVisitor + * + * @param The return type of the visit operation. Use [Void] for + * @param The type of context passed to each visit method operations with no return type. + * + */ +@Suppress("TooManyFunctions") +abstract class BaseElmClinicalVisitor : BaseElmVisitor(), ElmClinicalVisitor { + override fun visitElement(elm: Element, context: C): T?? { + return when (elm) { + is ExpressionDef -> visitExpressionDef(elm, context) + is CodeDef -> visitCodeDef(elm, context) + is CodeSystemDef -> visitCodeSystemDef(elm, context) + is ValueSetDef -> visitValueSetDef(elm, context) + is ConceptDef -> visitConceptDef(elm, context) + is CodeFilterElement -> visitCodeFilterElement(elm, context) + is DateFilterElement -> visitDateFilterElement(elm, context) + is OtherFilterElement -> visitOtherFilterElement(elm, context) + is IncludeElement -> visitIncludeElement(elm, context) + else -> super.visitElement(elm, context) + } + } + + /** + * Visit an Expression. This method will be called for every node in the tree that is an + * Expression. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitExpression(elm: Expression, context: C): T?? { + return when (elm) { + is FunctionRef -> visitFunctionRef(elm, context) + is ExpressionRef -> visitExpressionRef(elm, context) + is CodeSystemRef -> visitCodeSystemRef(elm, context) + is ValueSetRef -> visitValueSetRef(elm, context) + is CodeRef -> visitCodeRef(elm, context) + is ConceptRef -> visitConceptRef(elm, context) + is Code -> visitCode(elm, context) + is Concept -> visitConcept(elm, context) + is Quantity -> visitQuantity(elm, context) + is Ratio -> visitRatio(elm, context) + is Retrieve -> visitRetrieve(elm, context) + else -> super.visitExpression(elm, context) + } + } + + /** + * Visit an OperatorExpression. This method will be called for every node in the tree that is a + * OperatorExpression. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitOperatorExpression(elm: OperatorExpression, context: C): T?? { + return when (elm) { + is InCodeSystem -> visitInCodeSystem(elm, context) + is AnyInCodeSystem -> visitAnyInCodeSystem(elm, context) + is InValueSet -> visitInValueSet(elm, context) + is AnyInValueSet -> visitAnyInValueSet(elm, context) + else -> super.visitOperatorExpression(elm, context) + } + } + + /** + * Visit a UnaryExpression. This method will be called for every node in the tree that is a + * UnaryExpression. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitUnaryExpression(elm: UnaryExpression, context: C): T?? { + if (elm is ExpandValueSet) return visitExpandValueSet(elm, context) + return if (elm is CalculateAge) visitCalculateAge(elm, context) + else super.visitUnaryExpression(elm, context) + } + + /** + * Visit a BinaryExpression. This method will be called for every node in the tree that is a + * BinaryExpression. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitBinaryExpression(elm: BinaryExpression, context: C): T?? { + return when (elm) { + is CalculateAgeAt -> visitCalculateAgeAt(elm, context) + is Subsumes -> visitSubsumes(elm, context) + is SubsumedBy -> visitSubsumedBy(elm, context) + else -> super.visitBinaryExpression(elm, context) + } + } + + /** + * Visit an ExpandValueSet. This method will be called for every node in the tree that is an + * ExpandValueSet. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + open fun visitExpandValueSet(elm: ExpandValueSet, context: C): T?? { + return visitFields(elm, context) + } + + /** + * Visit a CodeFilterElement. This method will be called for every node in the tree that is a + * CodeFilterElement. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitCodeFilterElement(elm: CodeFilterElement, context: C): T? { + var result = visitFields(elm, context) + if (elm.value != null) { + val childResult = visitExpression(elm.value, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a DateFilterElement. This method will be called for every node in the tree that is a + * DateFilterElement. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitDateFilterElement(elm: DateFilterElement, context: C): T? { + var result = visitFields(elm, context) + + if (elm.value != null) { + val childResult = visitExpression(elm.value, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit an OtherFilterElement. This method will be called for every node in the tree that is an + * OtherFilterElement. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitOtherFilterElement(elm: OtherFilterElement, context: C): T? { + var result = visitFields(elm, context) + + if (elm.value != null) { + val childResult = visitExpression(elm.value, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit an IncludeElement. This method will be called for every node in the tree that is an + * IncludeElement. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitIncludeElement(elm: IncludeElement, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Retrieve. This method will be called for every node in the tree that is a Retrieve. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitRetrieve(elm: Retrieve, context: C): T? { + var result = visitFields(elm, context) + + for (cfe in elm.codeFilter) { + val childResult = visitCodeFilterElement(cfe, context) + result = aggregateResult(result, childResult) + } + + if (elm.codes != null) { + val childResult = visitExpression(elm.codes, context) + result = aggregateResult(result, childResult) + } + if (elm.context != null) { + val childResult = visitExpression(elm.context, context) + result = aggregateResult(result, childResult) + } + for (dfe in elm.dateFilter) { + val childResult = visitDateFilterElement(dfe, context) + result = aggregateResult(result, childResult) + } + if (elm.dateRange != null) { + val childResult = visitExpression(elm.dateRange, context) + result = aggregateResult(result, childResult) + } + + if (elm.id != null) { + val childResult = visitExpression(elm.id, context) + result = aggregateResult(result, childResult) + } + + for (ie in elm.include) { + val childResult = visitIncludeElement(ie, context) + result = aggregateResult(result, childResult) + } + + for (ofe in elm.otherFilter) { + val childResult = visitOtherFilterElement(ofe, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a Property. This method will be called for every node in the tree that is a Property. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitProperty(elm: Property, context: C): T?? { + if (elm is Search) { + return visitSearch(elm, context) + } + return super.visitProperty(elm, context) + } + + /** + * Visit a Search. This method will be called for every node in the tree that is a Search. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitSearch(elm: Search, context: C): T? { + var result = visitFields(elm, context) + + if (elm.source != null) { + val childResult = visitExpression(elm.source, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a CodeSystemDef. This method will be called for every node in the tree that is a + * CodeSystemDef. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitCodeSystemDef(elm: CodeSystemDef, context: C): T? { + var result = visitFields(elm, context) + if (elm.accessLevel != null) { + val childResult = visitAccessModifier(elm.accessLevel, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a ValueSetDef. This method will be called for every node in the tree that is a + * ValueSetDef. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitValueSetDef(elm: ValueSetDef, context: C): T? { + var result = visitFields(elm, context) + + if (elm.accessLevel != null) { + val childResult = visitAccessModifier(elm.accessLevel, context) + result = aggregateResult(result, childResult) + } + for (codeSystemRef in elm.codeSystem) { + val childResult = visitCodeSystemRef(codeSystemRef, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a CodeDef. This method will be called for every node in the tree that is a CodeDef. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitCodeDef(elm: CodeDef, context: C): T? { + var result = visitFields(elm, context) + + if (elm.accessLevel != null) { + val childResult = visitAccessModifier(elm.accessLevel, context) + result = aggregateResult(result, childResult) + } + if (elm.codeSystem != null) { + val childResult: T? = visitCodeSystemRef(elm.codeSystem, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit an ConceptDef. This method will be called for every node in the tree that is an + * ConceptDef. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitConceptDef(elm: ConceptDef, context: C): T? { + var result = visitFields(elm, context) + + if (elm.accessLevel != null) { + val childResult = visitAccessModifier(elm.accessLevel, context) + result = aggregateResult(result, childResult) + } + for (cr in elm.code) { + val childResult = visitCodeRef(cr, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a CodeSystemRef. This method will be called for every node in the tree that is a + * CodeSystemRef. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitCodeSystemRef(elm: CodeSystemRef, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a ValueSetRef. This method will be called for every node in the tree that is a + * ValueSetRef. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitValueSetRef(elm: ValueSetRef, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a CodeRef. This method will be called for every node in the tree that is a CodeRef. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitCodeRef(elm: CodeRef, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a ConceptRef. This method will be called for every node in the tree that is a + * ConceptRef. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitConceptRef(elm: ConceptRef, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Code. This method will be called for every node in the tree that is a Code. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitCode(elm: Code, context: C): T? { + var result = visitFields(elm, context) + + if (elm.system != null) { + val childResult: T? = visitCodeSystemRef(elm.system, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a Concept. This method will be called for every node in the tree that is a Concept. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitConcept(elm: Concept, context: C): T? { + var result = visitFields(elm, context) + + for (c in elm.code) { + val childResult = visitCode(c, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a InCodeSystem. This method will be called for every node in the tree that is a + * InCodeSystem. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitInCodeSystem(elm: InCodeSystem, context: C): T? { + var result = visitFields(elm, context) + + if (elm.code != null) { + val childResult = visitExpression(elm.code, context) + result = aggregateResult(result, childResult) + } + if (elm.codesystem != null) { + val childResult: T? = visitCodeSystemRef(elm.codesystem, context) + result = aggregateResult(result, childResult) + } + if (elm.codesystemExpression != null) { + val childResult = visitExpression(elm.codesystemExpression, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit an AnyInCodeSystem. This method will be called for every node in the tree that is an + * AnyInCodeSystem. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitAnyInCodeSystem(elm: AnyInCodeSystem, context: C): T? { + var result = visitFields(elm, context) + + if (elm.codes != null) { + val childResult = visitExpression(elm.codes, context) + result = aggregateResult(result, childResult) + } + if (elm.codesystem != null) { + val childResult: T? = visitCodeSystemRef(elm.codesystem, context) + result = aggregateResult(result, childResult) + } + if (elm.codesystemExpression != null) { + val childResult = visitExpression(elm.codesystemExpression, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a InValueSet. This method will be called for every node in the tree that is a + * InValueSet. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitInValueSet(elm: InValueSet, context: C): T? { + var result = visitFields(elm, context) + + if (elm.code != null) { + val childResult = visitExpression(elm.code, context) + result = aggregateResult(result, childResult) + } + if (elm.valueset != null) { + val childResult: T? = visitValueSetRef(elm.valueset, context) + result = aggregateResult(result, childResult) + } + if (elm.valuesetExpression != null) { + val childResult = visitExpression(elm.valuesetExpression, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit an AnyInValueSet. This method will be called for every node in the tree that is an + * AnyInValueSet. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitAnyInValueSet(elm: AnyInValueSet, context: C): T? { + var result = visitFields(elm, context) + + if (elm.codes != null) { + val childResult = visitExpression(elm.codes, context) + result = aggregateResult(result, childResult) + } + if (elm.valueset != null) { + val childResult: T? = visitValueSetRef(elm.valueset, context) + result = aggregateResult(result, childResult) + } + if (elm.valuesetExpression != null) { + val childResult = visitExpression(elm.valuesetExpression, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a Subsumes. This method will be called for every node in the tree that is a Subsumes. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitSubsumes(elm: Subsumes, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit an SubsumedBy. This method will be called for every node in the tree that is an + * SubsumedBy. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitSubsumedBy(elm: SubsumedBy, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Quantity. This method will be called for every node in the tree that is a Quantity. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitQuantity(elm: Quantity, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Ratio. This method will be called for every node in the tree that is a Ratio. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitRatio(elm: Ratio, context: C): T? { + var result = visitFields(elm, context) + + if (elm.denominator != null) { + val childResult: T? = visitQuantity(elm.denominator, context) + result = aggregateResult(result, childResult) + } + if (elm.numerator != null) { + val childResult: T? = visitQuantity(elm.numerator, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a CalculateAge. This method will be called for every node in the tree that is a + * CalculateAge. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitCalculateAge(elm: CalculateAge, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a CalculateAgeAt. This method will be called for every node in the tree that is a + * CalculateAgeAt. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitCalculateAgeAt(elm: CalculateAgeAt, context: C): T? { + return visitFields(elm, context) + } +} diff --git a/Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/BaseElmLibraryVisitor.kt b/Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/BaseElmLibraryVisitor.kt index 90e58ad4d..7b20c3b75 100644 --- a/Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/BaseElmLibraryVisitor.kt +++ b/Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/BaseElmLibraryVisitor.kt @@ -17,7 +17,7 @@ abstract class BaseElmLibraryVisitor : * @param context the context passed to the visitor * @return the visitor result */ - override fun visitElement(elm: Element, context: C): T = + override fun visitElement(elm: Element, context: C): T? = when (elm) { is IncludeDef -> visitIncludeDef(elm, context) is ContextDef -> visitContextDef(elm, context) @@ -33,7 +33,7 @@ abstract class BaseElmLibraryVisitor : * @param context the context passed to the visitor * @return the visitor result */ - override fun visitLibrary(elm: Library, context: C): T { + override fun visitLibrary(elm: Library, context: C): T? { var result = visitFields(elm, context) elm.usings?.def?.forEach { val childResult = visitUsingDef(it, context) @@ -90,7 +90,7 @@ abstract class BaseElmLibraryVisitor : * @param context the context passed to the visitor * @return the visitor result */ - override fun visitUsingDef(elm: UsingDef, context: C): T = visitFields(elm, context) + override fun visitUsingDef(elm: UsingDef, context: C): T? = visitFields(elm, context) /** * Visit a IncludeDef. This method will be called for every node in the tree that is a @@ -100,7 +100,7 @@ abstract class BaseElmLibraryVisitor : * @param context the context passed to the visitor * @return the visitor result */ - override fun visitIncludeDef(elm: IncludeDef, context: C): T = visitFields(elm, context) + override fun visitIncludeDef(elm: IncludeDef, context: C): T? = visitFields(elm, context) /** * Visit a ContextDef. This method will be called for every node in the tree that is a @@ -110,5 +110,5 @@ abstract class BaseElmLibraryVisitor : * @param context the context passed to the visitor * @return the visitor result */ - override fun visitContextDef(elm: ContextDef, context: C): T = visitFields(elm, context) + override fun visitContextDef(elm: ContextDef, context: C): T? = visitFields(elm, context) } diff --git a/Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/BaseElmVisitor.java b/Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/BaseElmVisitor.java deleted file mode 100644 index e4cec60ad..000000000 --- a/Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/BaseElmVisitor.java +++ /dev/null @@ -1,3632 +0,0 @@ -package org.cqframework.cql.elm.visiting; - -import org.cqframework.cql.elm.tracking.Trackable; -import org.hl7.elm.r1.*; - -/* - Design notes: - There are two types of methods in this class: - - 1. visitFields - - visitFields visits the fields of an object, traversing up the class hierarchy to visit superclass fields. - - 2. visitXYZ, where XYZ is the name of an ELM class - - The visitXYZ methods come in two flavors: - - A. visits on abstract or base classes forward to the correct visit method for the concrete or derived class. - B. visits on concrete or derived classes visit the fields of its base class using visitFields, and then visits the fields itself. - - TypeSpecifiers are considered to be terminal nodes in the ELM graph. TypeSpecifiers themselves are Elements and thus - have recursive TypeSpecifiers, but these are not visited. -*/ - -/** - * Provides the base implementation for an ElmVisitor. - * - * @param The return type of the visit operation. Use {@link Void} for no return value. - * @param The type of context passed to each visit method - * operations with no return type. - */ -public abstract class BaseElmVisitor implements ElmVisitor { - - /** - * Provides the default result of a visit - * - * @return - */ - protected T defaultResult(Trackable elm, C context) { - return null; - } - - /** - * Provides for aggregation behavior of the results of a visit. - * Default behavior returns the next result, ignoring the current - * aggregate. - * - * @param aggregate Current aggregate result - * @param nextResult Next result to be aggregated - * @return The result of aggregating the nextResult into aggregate - */ - protected T aggregateResult(T aggregate, T nextResult) { - return nextResult; - } - - /** - * Visit an Element in an ELM tree. This method will be called for - * every node in the tree that is a descendant of the Element type. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitElement(Element elm, C context) { - if (elm instanceof Expression) return visitExpression((Expression) elm, context); - else if (elm instanceof CaseItem) return visitCaseItem((CaseItem) elm, context); - else if (elm instanceof LetClause) return visitLetClause((LetClause) elm, context); - else if (elm instanceof OperandDef) return visitOperandDef((OperandDef) elm, context); - else if (elm instanceof ParameterDef) return visitParameterDef((ParameterDef) elm, context); - else if (elm instanceof SortByItem) return visitSortByItem((SortByItem) elm, context); - else if (elm instanceof SortClause) return visitSortClause((SortClause) elm, context); - else if (elm instanceof TupleElementDefinition) - return visitTupleElementDefinition((TupleElementDefinition) elm, context); - else if (elm instanceof TypeSpecifier) return visitTypeSpecifier((TypeSpecifier) elm, context); - else - throw new IllegalArgumentException( - "Unknown Element type: " + elm.getClass().getName()); - } - - /** - * Visit a TypeSpecifier. This method will be called for every - * node in the tree that is a descendant of the TypeSpecifier type. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitTypeSpecifier(TypeSpecifier elm, C context) { - if (elm instanceof NamedTypeSpecifier) return visitNamedTypeSpecifier((NamedTypeSpecifier) elm, context); - else if (elm instanceof IntervalTypeSpecifier) - return visitIntervalTypeSpecifier((IntervalTypeSpecifier) elm, context); - else if (elm instanceof ListTypeSpecifier) return visitListTypeSpecifier((ListTypeSpecifier) elm, context); - else if (elm instanceof TupleTypeSpecifier) return visitTupleTypeSpecifier((TupleTypeSpecifier) elm, context); - else if (elm instanceof ChoiceTypeSpecifier) - return visitChoiceTypeSpecifier((ChoiceTypeSpecifier) elm, context); - else if (elm instanceof ParameterTypeSpecifier) - return visitParameterTypeSpecifier((ParameterTypeSpecifier) elm, context); - else - throw new IllegalArgumentException( - "Unknown TypeSpecifier type: " + elm.getClass().getName()); - } - - /** - * Visit a ParameterTypeSpecifier. This method will be called for - * every node in the tree that is a ParameterTypeSpecifier. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitParameterTypeSpecifier(ParameterTypeSpecifier elm, C context) { - return defaultResult(elm, context); - } - - /** - * Visit a NamedTypeSpecifier. This method will be called for - * every node in the tree that is a NamedTypeSpecifier. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitNamedTypeSpecifier(NamedTypeSpecifier elm, C context) { - return defaultResult(elm, context); - } - - /** - * Visit a IntervalTypeSpecifier. This method will be called for - * every node in the tree that is a IntervalTypeSpecifier. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitIntervalTypeSpecifier(IntervalTypeSpecifier elm, C context) { - T result = defaultResult(elm, context); - - if (elm.getPointType() != null) { - T childResult = visitTypeSpecifier(elm.getPointType(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a ListTypeSpecifier. This method will be called for - * every node in the tree that is a ListTypeSpecifier. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitListTypeSpecifier(ListTypeSpecifier elm, C context) { - T result = defaultResult(elm, context); - - if (elm.getElementType() != null) { - T childResult = visitTypeSpecifier(elm.getElementType(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a TupleElementDefinition. This method will be called for - * every node in the tree that is a TupleElementDefinition. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitTupleElementDefinition(TupleElementDefinition elm, C context) { - T result = visitFields(elm, context); - - if (elm.getElementType() != null) { - T childResult = visitTypeSpecifier(elm.getElementType(), context); - result = aggregateResult(result, childResult); - } - - if (elm.getType() != null) { - T childResult = visitTypeSpecifier(elm.getType(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a TupleTypeSpecifier. This method will be called for - * every node in the tree that is a TupleTypeSpecifier. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitTupleTypeSpecifier(TupleTypeSpecifier elm, C context) { - T result = defaultResult(elm, context); - - for (TupleElementDefinition element : elm.getElement()) { - T childResult = visitTupleElementDefinition(element, context); - result = aggregateResult(result, childResult); - } - return result; - } - - /** - * Visit a ChoiceTypeSpecifier. This method will be called for - * every node in the tree that is a ChoiceTypeSpecifier. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitChoiceTypeSpecifier(ChoiceTypeSpecifier elm, C context) { - T result = defaultResult(elm, context); - - for (var choice : elm.getChoice()) { - T childResult = visitTypeSpecifier(choice, context); - result = aggregateResult(result, childResult); - } - - for (var type : elm.getType()) { - T childResult = visitTypeSpecifier(type, context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit an Expression. This method will be called for - * every node in the tree that is an Expression. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitExpression(Expression elm, C context) { - if (elm instanceof AliasRef) return visitAliasRef((AliasRef) elm, context); - else if (elm instanceof Case) return visitCase((Case) elm, context); - else if (elm instanceof Current) return visitCurrent((Current) elm, context); - else if (elm instanceof ExpressionRef) return visitExpressionRef((ExpressionRef) elm, context); - else if (elm instanceof Filter) return visitFilter((Filter) elm, context); - else if (elm instanceof ForEach) return visitForEach((ForEach) elm, context); - else if (elm instanceof IdentifierRef) return visitIdentifierRef((IdentifierRef) elm, context); - else if (elm instanceof If) return visitIf((If) elm, context); - else if (elm instanceof Instance) return visitInstance((Instance) elm, context); - else if (elm instanceof Interval) return visitInterval((Interval) elm, context); - else if (elm instanceof Iteration) return visitIteration((Iteration) elm, context); - else if (elm instanceof List) return visitList((List) elm, context); - else if (elm instanceof Literal) return visitLiteral((Literal) elm, context); - else if (elm instanceof MaxValue) return visitMaxValue((MaxValue) elm, context); - else if (elm instanceof MinValue) return visitMinValue((MinValue) elm, context); - else if (elm instanceof Null) return visitNull((Null) elm, context); - else if (elm instanceof OperandRef) return visitOperandRef((OperandRef) elm, context); - else if (elm instanceof ParameterRef) return visitParameterRef((ParameterRef) elm, context); - else if (elm instanceof Property) return visitProperty((Property) elm, context); - else if (elm instanceof Query) return visitQuery((Query) elm, context); - else if (elm instanceof QueryLetRef) return visitQueryLetRef((QueryLetRef) elm, context); - else if (elm instanceof Repeat) return visitRepeat((Repeat) elm, context); - else if (elm instanceof Sort) return visitSort((Sort) elm, context); - else if (elm instanceof Total) return visitTotal((Total) elm, context); - else if (elm instanceof Tuple) return visitTuple((Tuple) elm, context); - else if (elm instanceof AggregateExpression) - return visitAggregateExpression((AggregateExpression) elm, context); - else if (elm instanceof OperatorExpression) return visitOperatorExpression((OperatorExpression) elm, context); - else - throw new IllegalArgumentException( - "Unknown Expression type: " + elm.getClass().getName()); - } - - /** - * Visit an OperatorExpression. This method will be called for - * every node in the tree that is an OperatorExpression. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitOperatorExpression(OperatorExpression elm, C context) { - if (elm instanceof Round) return visitRound((Round) elm, context); - else if (elm instanceof Combine) return visitCombine((Combine) elm, context); - else if (elm instanceof Split) return visitSplit((Split) elm, context); - else if (elm instanceof SplitOnMatches) return visitSplitOnMatches((SplitOnMatches) elm, context); - else if (elm instanceof PositionOf) return visitPositionOf((PositionOf) elm, context); - else if (elm instanceof LastPositionOf) return visitLastPositionOf((LastPositionOf) elm, context); - else if (elm instanceof Substring) return visitSubstring((Substring) elm, context); - else if (elm instanceof TimeOfDay) return visitTimeOfDay((TimeOfDay) elm, context); - else if (elm instanceof Today) return visitToday((Today) elm, context); - else if (elm instanceof Now) return visitNow((Now) elm, context); - else if (elm instanceof Time) return visitTime((Time) elm, context); - else if (elm instanceof Date) return visitDate((Date) elm, context); - else if (elm instanceof DateTime) return visitDateTime((DateTime) elm, context); - else if (elm instanceof First) return visitFirst((First) elm, context); - else if (elm instanceof Last) return visitLast((Last) elm, context); - else if (elm instanceof IndexOf) return visitIndexOf((IndexOf) elm, context); - else if (elm instanceof Slice) return visitSlice((Slice) elm, context); - else if (elm instanceof Children) return visitChildren((Children) elm, context); - else if (elm instanceof Descendents) return visitDescendents((Descendents) elm, context); - else if (elm instanceof Message) return visitMessage((Message) elm, context); - else if (elm instanceof UnaryExpression) return visitUnaryExpression((UnaryExpression) elm, context); - else if (elm instanceof BinaryExpression) return visitBinaryExpression((BinaryExpression) elm, context); - else if (elm instanceof TernaryExpression) return visitTernaryExpression((TernaryExpression) elm, context); - else if (elm instanceof NaryExpression) return visitNaryExpression((NaryExpression) elm, context); - else - throw new IllegalArgumentException( - "Unknown OperatorExpression type: " + elm.getClass().getName()); - } - - /** - * Visit a UnaryExpression. This method will be called for - * every node in the tree that is a UnaryExpression. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitUnaryExpression(UnaryExpression elm, C context) { - if (elm instanceof Abs) return visitAbs((Abs) elm, context); - else if (elm instanceof As) return visitAs((As) elm, context); - else if (elm instanceof Ceiling) return visitCeiling((Ceiling) elm, context); - else if (elm instanceof CanConvert) return visitCanConvert((CanConvert) elm, context); - else if (elm instanceof Convert) return visitConvert((Convert) elm, context); - else if (elm instanceof ConvertsToBoolean) return visitConvertsToBoolean((ConvertsToBoolean) elm, context); - else if (elm instanceof ConvertsToDate) return visitConvertsToDate((ConvertsToDate) elm, context); - else if (elm instanceof ConvertsToDateTime) return visitConvertsToDateTime((ConvertsToDateTime) elm, context); - else if (elm instanceof ConvertsToDecimal) return visitConvertsToDecimal((ConvertsToDecimal) elm, context); - else if (elm instanceof ConvertsToInteger) return visitConvertsToInteger((ConvertsToInteger) elm, context); - else if (elm instanceof ConvertsToLong) return visitConvertsToLong((ConvertsToLong) elm, context); - else if (elm instanceof ConvertsToQuantity) return visitConvertsToQuantity((ConvertsToQuantity) elm, context); - else if (elm instanceof ConvertsToRatio) return visitConvertsToRatio((ConvertsToRatio) elm, context); - else if (elm instanceof ConvertsToString) return visitConvertsToString((ConvertsToString) elm, context); - else if (elm instanceof ConvertsToTime) return visitConvertsToTime((ConvertsToTime) elm, context); - else if (elm instanceof DateFrom) return visitDateFrom((DateFrom) elm, context); - else if (elm instanceof DateTimeComponentFrom) - return visitDateTimeComponentFrom((DateTimeComponentFrom) elm, context); - else if (elm instanceof Distinct) return visitDistinct((Distinct) elm, context); - else if (elm instanceof End) return visitEnd((End) elm, context); - else if (elm instanceof Exists) return visitExists((Exists) elm, context); - else if (elm instanceof Exp) return visitExp((Exp) elm, context); - else if (elm instanceof Flatten) return visitFlatten((Flatten) elm, context); - else if (elm instanceof Floor) return visitFloor((Floor) elm, context); - else if (elm instanceof Is) return visitIs((Is) elm, context); - else if (elm instanceof IsFalse) return visitIsFalse((IsFalse) elm, context); - else if (elm instanceof IsNull) return visitIsNull((IsNull) elm, context); - else if (elm instanceof IsTrue) return visitIsTrue((IsTrue) elm, context); - else if (elm instanceof Length) return visitLength((Length) elm, context); - else if (elm instanceof Ln) return visitLn((Ln) elm, context); - else if (elm instanceof Lower) return visitLower((Lower) elm, context); - else if (elm instanceof Negate) return visitNegate((Negate) elm, context); - else if (elm instanceof Not) return visitNot((Not) elm, context); - else if (elm instanceof PointFrom) return visitPointFrom((PointFrom) elm, context); - else if (elm instanceof Precision) return visitPrecision((Precision) elm, context); - else if (elm instanceof Predecessor) return visitPredecessor((Predecessor) elm, context); - else if (elm instanceof SingletonFrom) return visitSingletonFrom((SingletonFrom) elm, context); - else if (elm instanceof Size) return visitSize((Size) elm, context); - else if (elm instanceof Start) return visitStart((Start) elm, context); - else if (elm instanceof Successor) return visitSuccessor((Successor) elm, context); - else if (elm instanceof TimeFrom) return visitTimeFrom((TimeFrom) elm, context); - else if (elm instanceof TimezoneFrom) return visitTimezoneFrom((TimezoneFrom) elm, context); - else if (elm instanceof TimezoneOffsetFrom) return visitTimezoneOffsetFrom((TimezoneOffsetFrom) elm, context); - else if (elm instanceof ToBoolean) return visitToBoolean((ToBoolean) elm, context); - else if (elm instanceof ToConcept) return visitToConcept((ToConcept) elm, context); - else if (elm instanceof ToChars) return visitToChars((ToChars) elm, context); - else if (elm instanceof ToDate) return visitToDate((ToDate) elm, context); - else if (elm instanceof ToDateTime) return visitToDateTime((ToDateTime) elm, context); - else if (elm instanceof ToDecimal) return visitToDecimal((ToDecimal) elm, context); - else if (elm instanceof ToInteger) return visitToInteger((ToInteger) elm, context); - else if (elm instanceof ToLong) return visitToLong((ToLong) elm, context); - else if (elm instanceof ToList) return visitToList((ToList) elm, context); - else if (elm instanceof ToQuantity) return visitToQuantity((ToQuantity) elm, context); - else if (elm instanceof ToRatio) return visitToRatio((ToRatio) elm, context); - else if (elm instanceof ToString) return visitToString((ToString) elm, context); - else if (elm instanceof ToTime) return visitToTime((ToTime) elm, context); - else if (elm instanceof Truncate) return visitTruncate((Truncate) elm, context); - else if (elm instanceof Upper) return visitUpper((Upper) elm, context); - else if (elm instanceof Width) return visitWidth((Width) elm, context); - else - throw new IllegalArgumentException( - "Unknown UnaryExpression type: " + elm.getClass().getName()); - } - - /** - * Visit a BinaryExpression. This method will be called for - * every node in the tree that is a BinaryExpression. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitBinaryExpression(BinaryExpression elm, C context) { - if (elm instanceof Add) return visitAdd((Add) elm, context); - else if (elm instanceof After) return visitAfter((After) elm, context); - else if (elm instanceof And) return visitAnd((And) elm, context); - else if (elm instanceof Before) return visitBefore((Before) elm, context); - else if (elm instanceof CanConvertQuantity) return visitCanConvertQuantity((CanConvertQuantity) elm, context); - else if (elm instanceof Contains) return visitContains((Contains) elm, context); - else if (elm instanceof ConvertQuantity) return visitConvertQuantity((ConvertQuantity) elm, context); - else if (elm instanceof Collapse) return visitCollapse((Collapse) elm, context); - else if (elm instanceof DifferenceBetween) return visitDifferenceBetween((DifferenceBetween) elm, context); - else if (elm instanceof Divide) return visitDivide((Divide) elm, context); - else if (elm instanceof DurationBetween) return visitDurationBetween((DurationBetween) elm, context); - else if (elm instanceof Ends) return visitEnds((Ends) elm, context); - else if (elm instanceof EndsWith) return visitEndsWith((EndsWith) elm, context); - else if (elm instanceof Equal) return visitEqual((Equal) elm, context); - else if (elm instanceof Equivalent) return visitEquivalent((Equivalent) elm, context); - else if (elm instanceof Expand) return visitExpand((Expand) elm, context); - else if (elm instanceof Greater) return visitGreater((Greater) elm, context); - else if (elm instanceof GreaterOrEqual) return visitGreaterOrEqual((GreaterOrEqual) elm, context); - else if (elm instanceof HighBoundary) return visitHighBoundary((HighBoundary) elm, context); - else if (elm instanceof Implies) return visitImplies((Implies) elm, context); - else if (elm instanceof In) return visitIn((In) elm, context); - else if (elm instanceof IncludedIn) return visitIncludedIn((IncludedIn) elm, context); - else if (elm instanceof Includes) return visitIncludes((Includes) elm, context); - else if (elm instanceof Indexer) return visitIndexer((Indexer) elm, context); - else if (elm instanceof Less) return visitLess((Less) elm, context); - else if (elm instanceof LessOrEqual) return visitLessOrEqual((LessOrEqual) elm, context); - else if (elm instanceof Log) return visitLog((Log) elm, context); - else if (elm instanceof LowBoundary) return visitLowBoundary((LowBoundary) elm, context); - else if (elm instanceof Matches) return visitMatches((Matches) elm, context); - else if (elm instanceof Meets) return visitMeets((Meets) elm, context); - else if (elm instanceof MeetsAfter) return visitMeetsAfter((MeetsAfter) elm, context); - else if (elm instanceof MeetsBefore) return visitMeetsBefore((MeetsBefore) elm, context); - else if (elm instanceof Modulo) return visitModulo((Modulo) elm, context); - else if (elm instanceof Multiply) return visitMultiply((Multiply) elm, context); - else if (elm instanceof NotEqual) return visitNotEqual((NotEqual) elm, context); - else if (elm instanceof Or) return visitOr((Or) elm, context); - else if (elm instanceof Overlaps) return visitOverlaps((Overlaps) elm, context); - else if (elm instanceof OverlapsAfter) return visitOverlapsAfter((OverlapsAfter) elm, context); - else if (elm instanceof OverlapsBefore) return visitOverlapsBefore((OverlapsBefore) elm, context); - else if (elm instanceof Power) return visitPower((Power) elm, context); - else if (elm instanceof ProperContains) return visitProperContains((ProperContains) elm, context); - else if (elm instanceof ProperIn) return visitProperIn((ProperIn) elm, context); - else if (elm instanceof ProperIncludedIn) return visitProperIncludedIn((ProperIncludedIn) elm, context); - else if (elm instanceof ProperIncludes) return visitProperIncludes((ProperIncludes) elm, context); - else if (elm instanceof SameAs) return visitSameAs((SameAs) elm, context); - else if (elm instanceof SameOrAfter) return visitSameOrAfter((SameOrAfter) elm, context); - else if (elm instanceof SameOrBefore) return visitSameOrBefore((SameOrBefore) elm, context); - else if (elm instanceof Starts) return visitStarts((Starts) elm, context); - else if (elm instanceof StartsWith) return visitStartsWith((StartsWith) elm, context); - else if (elm instanceof Subtract) return visitSubtract((Subtract) elm, context); - else if (elm instanceof Times) return visitTimes((Times) elm, context); - else if (elm instanceof TruncatedDivide) return visitTruncatedDivide((TruncatedDivide) elm, context); - else if (elm instanceof Xor) return visitXor((Xor) elm, context); - else - throw new IllegalArgumentException( - "Unknown BinaryExpression type: " + elm.getClass().getName()); - } - - /** - * Visit a TernaryExpression. This method will be called for - * every node in the tree that is a TernaryExpression. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitTernaryExpression(TernaryExpression elm, C context) { - if (elm instanceof ReplaceMatches) return visitReplaceMatches((ReplaceMatches) elm, context); - else - throw new IllegalArgumentException( - "Unknown TernaryExpression type: " + elm.getClass().getName()); - } - - /** - * Visit a NaryExpression. This method will be called for - * every node in the tree that is a NaryExpression. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitNaryExpression(NaryExpression elm, C context) { - if (elm instanceof Coalesce) return visitCoalesce((Coalesce) elm, context); - else if (elm instanceof Concatenate) return visitConcatenate((Concatenate) elm, context); - else if (elm instanceof Except) return visitExcept((Except) elm, context); - else if (elm instanceof Intersect) return visitIntersect((Intersect) elm, context); - else if (elm instanceof Union) return visitUnion((Union) elm, context); - else - throw new IllegalArgumentException( - "Unknown NaryExpression type: " + elm.getClass().getName()); - } - - /** - * Visit a ExpressionDef. This method will be called for - * every node in the tree that is a ExpressionDef. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitExpressionDef(ExpressionDef elm, C context) { - if (elm instanceof FunctionDef) { - return visitFunctionDef((FunctionDef) elm, context); - } - - return visitFields(elm, context); - } - - /** - * Visit a FunctionDef. This method will be called for - * every node in the tree that is a FunctionDef. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitFunctionDef(FunctionDef elm, C context) { - T result = visitFields(elm, context); - - for (var operand : elm.getOperand()) { - T childResult = visitOperandDef(operand, context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit AccessModifier. This method will be called for - * every node in the tree that is a AccessModifier. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitAccessModifier(AccessModifier elm, C context) { - // NOTE: AccessModifier isn't trackable? - return defaultResult(null, context); - } - - /** - * Visit a ExpressionRef. This method will be called for - * every node in the tree that is a ExpressionRef. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitExpressionRef(ExpressionRef elm, C context) { - if (elm instanceof FunctionRef) { - return visitFunctionRef((FunctionRef) elm, context); - } - - return visitFields(elm, context); - } - - /** - * Visit a FunctionRef. This method will be called for - * every node in the tree that is a FunctionRef. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitFunctionRef(FunctionRef elm, C context) { - T result = visitFields(elm, context); - - for (var element : elm.getOperand()) { - T childResult = visitExpression(element, context); - result = aggregateResult(result, childResult); - } - - for (var s : elm.getSignature()) { - T childResult = visitTypeSpecifier(s, context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a ParameterDef. This method will be called for - * every node in the tree that is a ParameterDef. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitParameterDef(ParameterDef elm, C context) { - T result = visitFields(elm, context); - - if (elm.getParameterTypeSpecifier() != null) { - T childResult = visitTypeSpecifier(elm.getParameterTypeSpecifier(), context); - result = aggregateResult(result, childResult); - } - - if (elm.getDefault() != null) { - T childResult = visitExpression(elm.getDefault(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a ParameterRef. This method will be called for - * every node in the tree that is a ParameterRef. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitParameterRef(ParameterRef elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a OperandDef. This method will be called for - * every node in the tree that is a OperandDef. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitOperandDef(OperandDef elm, C context) { - T result = visitFields(elm, context); - - if (elm.getOperandTypeSpecifier() != null) { - T childResult = visitTypeSpecifier(elm.getOperandTypeSpecifier(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a OperandRef. This method will be called for - * every node in the tree that is a OperandRef. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitOperandRef(OperandRef elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a IdentifierRef. This method will be called for - * every node in the tree that is a IdentifierRef. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitIdentifierRef(IdentifierRef elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Literal. This method will be called for - * every node in the tree that is a Literal. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitLiteral(Literal elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a TupleElement. This method will be called for - * every node in the tree that is a TupleElement. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitTupleElement(TupleElement elm, C context) { - T result = defaultResult(elm, context); - - if (elm.getValue() != null) { - T childResult = visitExpression(elm.getValue(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a Tuple. This method will be called for - * every node in the tree that is a Tuple. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitTuple(Tuple elm, C context) { - T result = visitFields(elm, context); - - for (TupleElement element : elm.getElement()) { - T childResult = visitTupleElement(element, context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a InstanceElement. This method will be called for - * every node in the tree that is a InstanceElement. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitInstanceElement(InstanceElement elm, C context) { - T result = defaultResult(elm, context); - - if (elm.getValue() != null) { - T childResult = visitExpression(elm.getValue(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a Instance. This method will be called for - * every node in the tree that is a Instance. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitInstance(Instance elm, C context) { - T result = visitFields(elm, context); - - for (InstanceElement element : elm.getElement()) { - T childResult = visitInstanceElement(element, context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a Interval. This method will be called for - * every node in the tree that is a Interval. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitInterval(Interval elm, C context) { - T result = visitFields(elm, context); - - if (elm.getLow() != null) { - T childResult = visitExpression(elm.getLow(), context); - result = aggregateResult(result, childResult); - } - if (elm.getLowClosedExpression() != null) { - T childResult = visitExpression(elm.getLowClosedExpression(), context); - result = aggregateResult(result, childResult); - } - if (elm.getHigh() != null) { - T childResult = visitExpression(elm.getHigh(), context); - result = aggregateResult(result, childResult); - } - if (elm.getHighClosedExpression() != null) { - T childResult = visitExpression(elm.getHighClosedExpression(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a List. This method will be called for - * every node in the tree that is a List. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitList(List elm, C context) { - T result = visitFields(elm, context); - - if (elm.getTypeSpecifier() != null) { - T childResult = visitTypeSpecifier(elm.getTypeSpecifier(), context); - result = aggregateResult(result, childResult); - } - - for (Expression element : elm.getElement()) { - T childResult = visitExpression(element, context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a And. This method will be called for - * every node in the tree that is a And. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitAnd(And elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Or. This method will be called for - * every node in the tree that is a Or. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitOr(Or elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Xor. This method will be called for - * every node in the tree that is a Xor. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitXor(Xor elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Implies. This method will be called for - * every node in the tree that is a Implies. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitImplies(Implies elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Not. This method will be called for - * every node in the tree that is a Not. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitNot(Not elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a If. This method will be called for - * every node in the tree that is a If. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitIf(If elm, C context) { - T result = visitFields(elm, context); - - if (elm.getCondition() != null) { - T childResult = visitExpression(elm.getCondition(), context); - result = aggregateResult(result, childResult); - } - if (elm.getThen() != null) { - T childResult = visitExpression(elm.getThen(), context); - result = aggregateResult(result, childResult); - } - if (elm.getElse() != null) { - T childResult = visitExpression(elm.getElse(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a CaseItem. This method will be called for - * every node in the tree that is a CaseItem. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitCaseItem(CaseItem elm, C context) { - T result = visitFields(elm, context); - - if (elm.getWhen() != null) { - T childResult = visitExpression(elm.getWhen(), context); - result = aggregateResult(result, childResult); - } - if (elm.getThen() != null) { - T childResult = visitExpression(elm.getThen(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a Case. This method will be called for - * every node in the tree that is a Case. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitCase(Case elm, C context) { - T result = visitFields(elm, context); - - if (elm.getComparand() != null) { - T childResult = visitExpression(elm.getComparand(), context); - result = aggregateResult(result, childResult); - } - - for (CaseItem ci : elm.getCaseItem()) { - T childResult = visitCaseItem(ci, context); - result = aggregateResult(result, childResult); - } - - if (elm.getElse() != null) { - T childResult = visitExpression(elm.getElse(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a Null. This method will be called for - * every node in the tree that is a Null. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitNull(Null elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a IsNull. This method will be called for - * every node in the tree that is a IsNull. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitIsNull(IsNull elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a IsTrue. This method will be called for - * every node in the tree that is a IsTrue. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitIsTrue(IsTrue elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a IsFalse. This method will be called for - * every node in the tree that is a IsFalse. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitIsFalse(IsFalse elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Coalesce. This method will be called for - * every node in the tree that is a Coalesce. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitCoalesce(Coalesce elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Is. This method will be called for - * every node in the tree that is a Is. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitIs(Is elm, C context) { - T result = visitFields(elm, context); - - if (elm.getIsTypeSpecifier() != null) { - T childResult = visitTypeSpecifier(elm.getIsTypeSpecifier(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a As. This method will be called for - * every node in the tree that is a As. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitAs(As elm, C context) { - T result = visitFields(elm, context); - - if (elm.getAsTypeSpecifier() != null) { - T childResult = visitTypeSpecifier(elm.getAsTypeSpecifier(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a Convert. This method will be called for - * every node in the tree that is a Convert. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitConvert(Convert elm, C context) { - T result = visitFields(elm, context); - - if (elm.getToTypeSpecifier() != null) { - T childResult = visitTypeSpecifier(elm.getToTypeSpecifier(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a CanConvert. This method will be called for - * every node in the tree that is a CanConvert. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitCanConvert(CanConvert elm, C context) { - T result = visitFields(elm, context); - - if (elm.getToTypeSpecifier() != null) { - T childResult = visitTypeSpecifier(elm.getToTypeSpecifier(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a ConvertsToBoolean. This method will be called for - * every node in the tree that is a ConvertsToBoolean. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitConvertsToBoolean(ConvertsToBoolean elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a ToBoolean. This method will be called for - * every node in the tree that is a ToBoolean. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitToBoolean(ToBoolean elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a ToChars. This method will be called for - * every node in the tree that is a ToChars. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitToChars(ToChars elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a ToConcept. This method will be called for - * every node in the tree that is a ToConcept. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitToConcept(ToConcept elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a ConvertsToDate. This method will be called for - * every node in the tree that is a ConvertsToDate. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitConvertsToDate(ConvertsToDate elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a ToDate. This method will be called for - * every node in the tree that is a ToDate. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitToDate(ToDate elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a ConvertsToDateTime. This method will be called for - * every node in the tree that is a ConvertsToDateTime. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitConvertsToDateTime(ConvertsToDateTime elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a ToDateTime. This method will be called for - * every node in the tree that is a ToDateTime. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitToDateTime(ToDateTime elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a ConvertsToLong. This method will be called for - * every node in the tree that is a ConvertsToLong. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitConvertsToLong(ConvertsToLong elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a ToLong. This method will be called for - * every node in the tree that is a ToLong. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitToLong(ToLong elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a ConvertsToDecimal. This method will be called for - * every node in the tree that is a ConvertsToDecimal. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitConvertsToDecimal(ConvertsToDecimal elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a ToDecimal. This method will be called for - * every node in the tree that is a ToDecimal. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitToDecimal(ToDecimal elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a ConvertsToInteger. This method will be called for - * every node in the tree that is a ConvertsToInteger. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitConvertsToInteger(ConvertsToInteger elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a ToInteger. This method will be called for - * every node in the tree that is a ToInteger. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitToInteger(ToInteger elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a ToList. This method will be called for - * every node in the tree that is a ToList. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitToList(ToList elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a ConvertQuantity. This method will be called for - * every node in the tree that is a ConvertQuantity. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitConvertQuantity(ConvertQuantity elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a CanConvertQuantity. This method will be called for - * every node in the tree that is a CanConvertQuantity. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitCanConvertQuantity(CanConvertQuantity elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a ConvertsToQuantity. This method will be called for - * every node in the tree that is a ConvertsToQuantity. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitConvertsToQuantity(ConvertsToQuantity elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a ToQuantity. This method will be called for - * every node in the tree that is a ToQuantity. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitToQuantity(ToQuantity elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a ConvertsToRatio. This method will be called for - * every node in the tree that is a ConvertsToRatio. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitConvertsToRatio(ConvertsToRatio elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Ratio. This method will be called for - * every node in the tree that is a Ratio. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitToRatio(ToRatio elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a ConvertsToString. This method will be called for - * every node in the tree that is a ConvertsToString. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitConvertsToString(ConvertsToString elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a ToString. This method will be called for - * every node in the tree that is a ToString. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitToString(ToString elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a ConvertsToTime. This method will be called for - * every node in the tree that is a ConvertsToTime. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitConvertsToTime(ConvertsToTime elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a ToTime. This method will be called for - * every node in the tree that is a ToTime. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitToTime(ToTime elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Equal. This method will be called for - * every node in the tree that is a Equal. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitEqual(Equal elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Equivalent. This method will be called for - * every node in the tree that is a Equivalent. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitEquivalent(Equivalent elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a NotEqual. This method will be called for - * every node in the tree that is a NotEqual. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitNotEqual(NotEqual elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Less. This method will be called for - * every node in the tree that is a Less. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitLess(Less elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Greater. This method will be called for - * every node in the tree that is a Greater. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitGreater(Greater elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a LessOrEqual. This method will be called for - * every node in the tree that is a LessOrEqual. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitLessOrEqual(LessOrEqual elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a GreaterOrEqual. This method will be called for - * every node in the tree that is a GreaterOrEqual. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitGreaterOrEqual(GreaterOrEqual elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Add. This method will be called for - * every node in the tree that is a Add. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitAdd(Add elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Subtract. This method will be called for - * every node in the tree that is a Subtract. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitSubtract(Subtract elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Multiply. This method will be called for - * every node in the tree that is a Multiply. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitMultiply(Multiply elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Divide. This method will be called for - * every node in the tree that is a Divide. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitDivide(Divide elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a TruncatedDivide. This method will be called for - * every node in the tree that is a TruncatedDivide. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitTruncatedDivide(TruncatedDivide elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Modulo. This method will be called for - * every node in the tree that is a Modulo. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitModulo(Modulo elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Ceiling. This method will be called for - * every node in the tree that is a Ceiling. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitCeiling(Ceiling elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Floor. This method will be called for - * every node in the tree that is a Floor. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitFloor(Floor elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Truncate. This method will be called for - * every node in the tree that is a Truncate. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitTruncate(Truncate elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Abs. This method will be called for - * every node in the tree that is a Abs. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitAbs(Abs elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Negate. This method will be called for - * every node in the tree that is a Negate. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitNegate(Negate elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Round. This method will be called for - * every node in the tree that is a Round. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitRound(Round elm, C context) { - T result = visitFields(elm, context); - if (elm.getOperand() != null) { - T childResult = visitExpression(elm.getOperand(), context); - result = aggregateResult(result, childResult); - } - - if (elm.getPrecision() != null) { - T childResult = visitExpression(elm.getPrecision(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a Ln. This method will be called for - * every node in the tree that is a Ln. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitLn(Ln elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Exp. This method will be called for - * every node in the tree that is a Exp. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitExp(Exp elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Log. This method will be called for - * every node in the tree that is a Log. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitLog(Log elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Power. This method will be called for - * every node in the tree that is a Power. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitPower(Power elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Successor. This method will be called for - * every node in the tree that is a Successor. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitSuccessor(Successor elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Predecessor. This method will be called for - * every node in the tree that is a Predecessor. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitPredecessor(Predecessor elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a MinValue. This method will be called for - * every node in the tree that is a MinValue. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitMinValue(MinValue elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a MaxValue. This method will be called for - * every node in the tree that is a MaxValue. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitMaxValue(MaxValue elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Precision. This method will be called for - * every node in the tree that is a Precision. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitPrecision(Precision elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a LowBoundary. This method will be called for - * every node in the tree that is a LowBoundary. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitLowBoundary(LowBoundary elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a HighBoundary. This method will be called for - * every node in the tree that is a HighBoundary. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitHighBoundary(HighBoundary elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Concatenate. This method will be called for - * every node in the tree that is a Concatenate. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitConcatenate(Concatenate elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Combine. This method will be called for - * every node in the tree that is a Combine. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitCombine(Combine elm, C context) { - T result = visitFields(elm, context); - - if (elm.getSource() != null) { - T childResult = visitExpression(elm.getSource(), context); - result = aggregateResult(result, childResult); - } - if (elm.getSeparator() != null) { - T childResult = visitExpression(elm.getSeparator(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a Split. This method will be called for - * every node in the tree that is a Split. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitSplit(Split elm, C context) { - T result = visitFields(elm, context); - - if (elm.getStringToSplit() != null) { - T childResult = visitExpression(elm.getStringToSplit(), context); - result = aggregateResult(result, childResult); - } - if (elm.getSeparator() != null) { - T childResult = visitExpression(elm.getSeparator(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a SplitOnMatches. This method will be called for - * every node in the tree that is a SplitOnMatches. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitSplitOnMatches(SplitOnMatches elm, C context) { - T result = visitFields(elm, context); - - if (elm.getStringToSplit() != null) { - T childResult = visitExpression(elm.getStringToSplit(), context); - result = aggregateResult(result, childResult); - } - if (elm.getSeparatorPattern() != null) { - T childResult = visitExpression(elm.getSeparatorPattern(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a Length. This method will be called for - * every node in the tree that is a Length. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitLength(Length elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Upper. This method will be called for - * every node in the tree that is a Upper. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitUpper(Upper elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Lower. This method will be called for - * every node in the tree that is a Lower. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitLower(Lower elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Indexer. This method will be called for - * every node in the tree that is a Indexer. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitIndexer(Indexer elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a PositionOf. This method will be called for - * every node in the tree that is a PositionOf. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitPositionOf(PositionOf elm, C context) { - T result = visitFields(elm, context); - - if (elm.getPattern() != null) { - T childResult = visitExpression(elm.getPattern(), context); - result = aggregateResult(result, childResult); - } - if (elm.getString() != null) { - T childResult = visitExpression(elm.getString(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a LastPositionOf. This method will be called for - * every node in the tree that is a LastPositionOf. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitLastPositionOf(LastPositionOf elm, C context) { - T result = visitFields(elm, context); - - if (elm.getPattern() != null) { - T childResult = visitExpression(elm.getPattern(), context); - result = aggregateResult(result, childResult); - } - if (elm.getString() != null) { - T childResult = visitExpression(elm.getString(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a Substring. This method will be called for - * every node in the tree that is a Substring. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitSubstring(Substring elm, C context) { - T result = visitFields(elm, context); - - if (elm.getStringToSub() != null) { - T childResult = visitExpression(elm.getStringToSub(), context); - result = aggregateResult(result, childResult); - } - if (elm.getStartIndex() != null) { - T childResult = visitExpression(elm.getStartIndex(), context); - result = aggregateResult(result, childResult); - } - if (elm.getLength() != null) { - T childResult = visitExpression(elm.getLength(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a StartsWith. This method will be called for - * every node in the tree that is a StartsWith. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitStartsWith(StartsWith elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a EndsWith. This method will be called for - * every node in the tree that is a EndsWith. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitEndsWith(EndsWith elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Matches. This method will be called for - * every node in the tree that is a Matches. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitMatches(Matches elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a ReplaceMatches. This method will be called for - * every node in the tree that is a ReplaceMatches. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitReplaceMatches(ReplaceMatches elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a DurationBetween. This method will be called for - * every node in the tree that is a DurationBetween. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitDurationBetween(DurationBetween elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a DifferenceBetween. This method will be called for - * every node in the tree that is a DifferenceBetween. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitDifferenceBetween(DifferenceBetween elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a DateFrom. This method will be called for - * every node in the tree that is a DateFrom. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitDateFrom(DateFrom elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a TimeFrom. This method will be called for - * every node in the tree that is a TimeFrom. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitTimeFrom(TimeFrom elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a TimezoneFrom. This method will be called for - * every node in the tree that is a TimezoneFrom. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitTimezoneFrom(TimezoneFrom elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a TimezoneOffsetFrom. This method will be called for - * every node in the tree that is a TimezoneOffsetFrom. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitTimezoneOffsetFrom(TimezoneOffsetFrom elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a DateTimeComponentFrom. This method will be called for - * every node in the tree that is a DateTimeComponentFrom. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitDateTimeComponentFrom(DateTimeComponentFrom elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a TimeOfDay. This method will be called for - * every node in the tree that is a TimeOfDay. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitTimeOfDay(TimeOfDay elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Today. This method will be called for - * every node in the tree that is a Today. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitToday(Today elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Now. This method will be called for - * every node in the tree that is a Now. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitNow(Now elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a DateTime. This method will be called for - * every node in the tree that is a DateTime. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitDateTime(DateTime elm, C context) { - T result = visitFields(elm, context); - - if (elm.getYear() != null) { - T childResult = visitExpression(elm.getYear(), context); - result = aggregateResult(result, childResult); - } - if (elm.getMonth() != null) { - T childResult = visitExpression(elm.getMonth(), context); - result = aggregateResult(result, childResult); - } - if (elm.getDay() != null) { - T childResult = visitExpression(elm.getDay(), context); - result = aggregateResult(result, childResult); - } - if (elm.getHour() != null) { - T childResult = visitExpression(elm.getHour(), context); - result = aggregateResult(result, childResult); - } - if (elm.getMinute() != null) { - T childResult = visitExpression(elm.getMinute(), context); - result = aggregateResult(result, childResult); - } - if (elm.getSecond() != null) { - T childResult = visitExpression(elm.getSecond(), context); - result = aggregateResult(result, childResult); - } - if (elm.getMillisecond() != null) { - T childResult = visitExpression(elm.getMillisecond(), context); - result = aggregateResult(result, childResult); - } - if (elm.getTimezoneOffset() != null) { - T childResult = visitExpression(elm.getTimezoneOffset(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a Date. This method will be called for - * every node in the tree that is a Date. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitDate(Date elm, C context) { - T result = visitFields(elm, context); - - if (elm.getYear() != null) { - T childResult = visitExpression(elm.getYear(), context); - result = aggregateResult(result, childResult); - } - if (elm.getMonth() != null) { - T childResult = visitExpression(elm.getMonth(), context); - result = aggregateResult(result, childResult); - } - if (elm.getDay() != null) { - T childResult = visitExpression(elm.getDay(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a Time. This method will be called for - * every node in the tree that is a Time. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitTime(Time elm, C context) { - T result = visitFields(elm, context); - - if (elm.getHour() != null) { - T childResult = visitExpression(elm.getHour(), context); - result = aggregateResult(result, childResult); - } - if (elm.getMinute() != null) { - T childResult = visitExpression(elm.getMinute(), context); - result = aggregateResult(result, childResult); - } - if (elm.getSecond() != null) { - T childResult = visitExpression(elm.getSecond(), context); - result = aggregateResult(result, childResult); - } - if (elm.getMillisecond() != null) { - T childResult = visitExpression(elm.getMillisecond(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a SameAs. This method will be called for - * every node in the tree that is a SameAs. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitSameAs(SameAs elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a SameOrBefore. This method will be called for - * every node in the tree that is a SameOrBefore. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitSameOrBefore(SameOrBefore elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a SameOrAfter. This method will be called for - * every node in the tree that is a SameOrAfter. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitSameOrAfter(SameOrAfter elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Width. This method will be called for - * every node in the tree that is a Width. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitWidth(Width elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Size. This method will be called for - * every node in the tree that is a Size. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitSize(Size elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a PointFrom. This method will be called for - * every node in the tree that is a PointFrom. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitPointFrom(PointFrom elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Start. This method will be called for - * every node in the tree that is a Start. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitStart(Start elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a End. This method will be called for - * every node in the tree that is a End. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitEnd(End elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Contains. This method will be called for - * every node in the tree that is a Contains. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitContains(Contains elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a ProperContains. This method will be called for - * every node in the tree that is a ProperContains. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitProperContains(ProperContains elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a In. This method will be called for - * every node in the tree that is a In. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitIn(In elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a ProperIn. This method will be called for - * every node in the tree that is a ProperIn. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitProperIn(ProperIn elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Includes. This method will be called for - * every node in the tree that is a Includes. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitIncludes(Includes elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a IncludedIn. This method will be called for - * every node in the tree that is a IncludedIn. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitIncludedIn(IncludedIn elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a ProperIncludes. This method will be called for - * every node in the tree that is a ProperIncludes. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitProperIncludes(ProperIncludes elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a ProperIncludedIn. This method will be called for - * every node in the tree that is a ProperIncludedIn. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitProperIncludedIn(ProperIncludedIn elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Before. This method will be called for - * every node in the tree that is a Before. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitBefore(Before elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a After. This method will be called for - * every node in the tree that is a After. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitAfter(After elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Meets. This method will be called for - * every node in the tree that is a Meets. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitMeets(Meets elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a MeetsBefore. This method will be called for - * every node in the tree that is a MeetsBefore. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitMeetsBefore(MeetsBefore elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a MeetsAfter. This method will be called for - * every node in the tree that is a MeetsAfter. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitMeetsAfter(MeetsAfter elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Overlaps. This method will be called for - * every node in the tree that is a Overlaps. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitOverlaps(Overlaps elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a OverlapsBefore. This method will be called for - * every node in the tree that is a OverlapsBefore. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitOverlapsBefore(OverlapsBefore elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a OverlapsAfter. This method will be called for - * every node in the tree that is a OverlapsAfter. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitOverlapsAfter(OverlapsAfter elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Starts. This method will be called for - * every node in the tree that is a Starts. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitStarts(Starts elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Ends. This method will be called for - * every node in the tree that is a Ends. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitEnds(Ends elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Collapse. This method will be called for - * every node in the tree that is a Collapse. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitCollapse(Collapse elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Expand. This method will be called for - * every node in the tree that is a Expand. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitExpand(Expand elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Union. This method will be called for - * every node in the tree that is a Union. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitUnion(Union elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Intersect. This method will be called for - * every node in the tree that is a Intersect. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitIntersect(Intersect elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Except. This method will be called for - * every node in the tree that is a Except. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitExcept(Except elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Exists. This method will be called for - * every node in the tree that is a Exists. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitExists(Exists elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Times. This method will be called for - * every node in the tree that is a Times. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitTimes(Times elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Filter. This method will be called for - * every node in the tree that is a Filter. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitFilter(Filter elm, C context) { - T result = visitFields(elm, context); - - if (elm.getSource() != null) { - T childResult = visitExpression(elm.getSource(), context); - result = aggregateResult(result, childResult); - } - if (elm.getCondition() != null) { - T childResult = visitExpression(elm.getCondition(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a First. This method will be called for - * every node in the tree that is a First. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitFirst(First elm, C context) { - T result = visitFields(elm, context); - - if (elm.getSource() != null) { - T childResult = visitExpression(elm.getSource(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a Last. This method will be called for - * every node in the tree that is a Last. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitLast(Last elm, C context) { - T result = visitFields(elm, context); - - if (elm.getSource() != null) { - T childResult = visitExpression(elm.getSource(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a Slice. This method will be called for - * every node in the tree that is a Slice. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitSlice(Slice elm, C context) { - T result = visitFields(elm, context); - - if (elm.getSource() != null) { - T childResult = visitExpression(elm.getSource(), context); - result = aggregateResult(result, childResult); - } - if (elm.getStartIndex() != null) { - T childResult = visitExpression(elm.getStartIndex(), context); - result = aggregateResult(result, childResult); - } - if (elm.getEndIndex() != null) { - T childResult = visitExpression(elm.getEndIndex(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a Children. This method will be called for - * every node in the tree that is a Children. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitChildren(Children elm, C context) { - T result = visitFields(elm, context); - - if (elm.getSource() != null) { - T childResult = visitExpression(elm.getSource(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a Descendents. This method will be called for - * every node in the tree that is a Descendents. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitDescendents(Descendents elm, C context) { - T result = visitFields(elm, context); - - if (elm.getSource() != null) { - T childResult = visitExpression(elm.getSource(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a Message. This method will be called for - * every node in the tree that is a Message. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitMessage(Message elm, C context) { - T result = visitFields(elm, context); - - if (elm.getSource() != null) { - T childResult = visitExpression(elm.getSource(), context); - result = aggregateResult(result, childResult); - } - if (elm.getCondition() != null) { - T childResult = visitExpression(elm.getCondition(), context); - result = aggregateResult(result, childResult); - } - if (elm.getCode() != null) { - T childResult = visitExpression(elm.getCode(), context); - result = aggregateResult(result, childResult); - } - if (elm.getSeverity() != null) { - T childResult = visitExpression(elm.getSeverity(), context); - result = aggregateResult(result, childResult); - } - if (elm.getMessage() != null) { - T childResult = visitExpression(elm.getMessage(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a IndexOf. This method will be called for - * every node in the tree that is a IndexOf. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitIndexOf(IndexOf elm, C context) { - T result = visitFields(elm, context); - - if (elm.getSource() != null) { - T childResult = visitExpression(elm.getSource(), context); - result = aggregateResult(result, childResult); - } - if (elm.getElement() != null) { - T childResult = visitExpression(elm.getElement(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a Flatten. This method will be called for - * every node in the tree that is a Flatten. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitFlatten(Flatten elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Sort. This method will be called for - * every node in the tree that is a Sort. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitSort(Sort elm, C context) { - T result = visitFields(elm, context); - - if (elm.getSource() != null) { - T childResult = visitExpression(elm.getSource(), context); - result = aggregateResult(result, childResult); - } - for (SortByItem sbi : elm.getBy()) { - T childResult = visitSortByItem(sbi, context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a ForEach. This method will be called for - * every node in the tree that is a ForEach. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitForEach(ForEach elm, C context) { - T result = visitFields(elm, context); - - if (elm.getSource() != null) { - T childResult = visitExpression(elm.getSource(), context); - result = aggregateResult(result, childResult); - } - if (elm.getElement() != null) { - T childResult = visitExpression(elm.getElement(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a Repeat. This method will be called for - * every node in the tree that is a Repeat. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitRepeat(Repeat elm, C context) { - T result = visitFields(elm, context); - - if (elm.getSource() != null) { - T childResult = visitExpression(elm.getSource(), context); - result = aggregateResult(result, childResult); - } - if (elm.getElement() != null) { - T childResult = visitExpression(elm.getElement(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a Distinct. This method will be called for - * every node in the tree that is a Distinct. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitDistinct(Distinct elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Current. This method will be called for - * every node in the tree that is a Current. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitCurrent(Current elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit an Iteration. This method will be called for - * every node in the tree that is an Iteration. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitIteration(Iteration elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Total. This method will be called for - * every node in the tree that is a Total. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitTotal(Total elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a SingletonFrom. This method will be called for - * every node in the tree that is a SingletonFrom. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitSingletonFrom(SingletonFrom elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a AggregateExpression. This method will be called for - * every node in the tree that is a AggregateExpression. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitAggregateExpression(AggregateExpression elm, C context) { - if (elm instanceof Aggregate) return visitAggregate((Aggregate) elm, context); - else if (elm instanceof Count) return visitCount((Count) elm, context); - else if (elm instanceof Sum) return visitSum((Sum) elm, context); - else if (elm instanceof Product) return visitProduct((Product) elm, context); - else if (elm instanceof Min) return visitMin((Min) elm, context); - else if (elm instanceof Max) return visitMax((Max) elm, context); - else if (elm instanceof Avg) return visitAvg((Avg) elm, context); - else if (elm instanceof GeometricMean) return visitGeometricMean((GeometricMean) elm, context); - else if (elm instanceof Median) return visitMedian((Median) elm, context); - else if (elm instanceof Mode) return visitMode((Mode) elm, context); - else if (elm instanceof Variance) return visitVariance((Variance) elm, context); - else if (elm instanceof StdDev) return visitStdDev((StdDev) elm, context); - else if (elm instanceof PopulationVariance) return visitPopulationVariance((PopulationVariance) elm, context); - else if (elm instanceof PopulationStdDev) return visitPopulationStdDev((PopulationStdDev) elm, context); - else if (elm instanceof AllTrue) return visitAllTrue((AllTrue) elm, context); - else if (elm instanceof AnyTrue) return visitAnyTrue((AnyTrue) elm, context); - else - throw new IllegalArgumentException( - "Unsupported AggregateExpression type: " + elm.getClass().getName()); - } - - /** - * Visit an Aggregate. This method will be called for - * every node in the tree that is an Aggregate. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitAggregate(Aggregate elm, C context) { - T result = visitFields((AggregateExpression) elm, context); - - if (elm.getInitialValue() != null) { - T childResult = visitExpression(elm.getInitialValue(), context); - result = aggregateResult(result, childResult); - } - if (elm.getIteration() != null) { - T childResult = visitExpression(elm.getIteration(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a Count. This method will be called for - * every node in the tree that is a Count. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitCount(Count elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Sum. This method will be called for - * every node in the tree that is a Sum. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitSum(Sum elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Product. This method will be called for - * every node in the tree that is a Product. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitProduct(Product elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a GeometricMean. This method will be called for - * every node in the tree that is a GeometricMean. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitGeometricMean(GeometricMean elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Min. This method will be called for - * every node in the tree that is a Min. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitMin(Min elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Max. This method will be called for - * every node in the tree that is a Max. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitMax(Max elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Avg. This method will be called for - * every node in the tree that is a Avg. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitAvg(Avg elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Median. This method will be called for - * every node in the tree that is a Median. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitMedian(Median elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Mode. This method will be called for - * every node in the tree that is a Mode. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitMode(Mode elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Variance. This method will be called for - * every node in the tree that is a Variance. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitVariance(Variance elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a PopulationVariance. This method will be called for - * every node in the tree that is a PopulationVariance. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitPopulationVariance(PopulationVariance elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a StdDev. This method will be called for - * every node in the tree that is a StdDev. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitStdDev(StdDev elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a PopulationStdDev. This method will be called for - * every node in the tree that is a PopulationStdDev. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitPopulationStdDev(PopulationStdDev elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a AllTrue. This method will be called for - * every node in the tree that is a AllTrue. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitAllTrue(AllTrue elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a AnyTrue. This method will be called for - * every node in the tree that is a AnyTrue. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitAnyTrue(AnyTrue elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Property. This method will be called for - * every node in the tree that is a Property. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitProperty(Property elm, C context) { - T result = visitFields(elm, context); - - if (elm.getSource() != null) { - T childResult = visitExpression(elm.getSource(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a AliasedQuerySource. This method will be called for - * every node in the tree that is a AliasedQuerySource. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitAliasedQuerySource(AliasedQuerySource elm, C context) { - if (elm instanceof RelationshipClause) { - return visitRelationshipClause((RelationshipClause) elm, context); - } - - return visitFields(elm, context); - } - - /** - * Visit a LetClause. This method will be called for - * every node in the tree that is a LetClause. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitLetClause(LetClause elm, C context) { - T result = visitFields(elm, context); - - if (elm.getExpression() != null) { - T childResult = visitExpression(elm.getExpression(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a RelationshipClause. This method will be called for - * every node in the tree that is a RelationshipClause. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitRelationshipClause(RelationshipClause elm, C context) { - if (elm instanceof With) { - return visitWith((With) elm, context); - } else if (elm instanceof Without) { - return visitWithout((Without) elm, context); - } else { - throw new IllegalArgumentException( - "Unknown RelationshipClause type: " + elm.getClass().getName()); - } - } - - /** - * Visit a With. This method will be called for - * every node in the tree that is a With. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitWith(With elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a Without. This method will be called for - * every node in the tree that is a Without. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitWithout(Without elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a SortByItem. This method will be called for - * every node in the tree that is a SortByItem. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitSortByItem(SortByItem elm, C context) { - if (elm instanceof ByDirection) { - return visitByDirection((ByDirection) elm, context); - } else if (elm instanceof ByColumn) { - return visitByColumn((ByColumn) elm, context); - } else if (elm instanceof ByExpression) { - return visitByExpression((ByExpression) elm, context); - } else - throw new IllegalArgumentException( - "Unknown SortByItem type: " + elm.getClass().getName()); - } - - /** - * Visit a ByDirection. This method will be called for - * every node in the tree that is a ByDirection. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitByDirection(ByDirection elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a ByColumn. This method will be called for - * every node in the tree that is a ByColumn. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitByColumn(ByColumn elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a ByExpression. This method will be called for - * every node in the tree that is a ByExpression. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitByExpression(ByExpression elm, C context) { - T result = visitFields(elm, context); - - if (elm.getExpression() != null) { - T childResult = visitExpression(elm.getExpression(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a SortClause. This method will be called for - * every node in the tree that is a SortClause. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitSortClause(SortClause elm, C context) { - T result = visitFields(elm, context); - - for (SortByItem sbi : elm.getBy()) { - T childResult = visitSortByItem(sbi, context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a AggregateClause. This method will be called for - * every node in the tree that is an AggregateClause. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitAggregateClause(AggregateClause elm, C context) { - T result = visitFields(elm, context); - - if (elm.getExpression() != null) { - T childResult = visitExpression(elm.getExpression(), context); - result = aggregateResult(result, childResult); - } - if (elm.getStarting() != null) { - T childResult = visitExpression(elm.getStarting(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a ReturnClause. This method will be called for - * every node in the tree that is a ReturnClause. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitReturnClause(ReturnClause elm, C context) { - T result = visitFields(elm, context); - - if (elm.getExpression() != null) { - T childResult = visitExpression(elm.getExpression(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a Query. This method will be called for - * every node in the tree that is a Query. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitQuery(Query elm, C context) { - T result = visitFields(elm, context); - - for (var source : elm.getSource()) { - T childResult = visitAliasedQuerySource(source, context); - result = aggregateResult(result, childResult); - } - for (var let : elm.getLet()) { - T childResult = visitLetClause(let, context); - result = aggregateResult(result, childResult); - } - - for (var r : elm.getRelationship()) { - T childResult = visitRelationshipClause(r, context); - result = aggregateResult(result, childResult); - } - - if (elm.getWhere() != null) { - T childResult = visitExpression(elm.getWhere(), context); - result = aggregateResult(result, childResult); - } - if (elm.getReturn() != null) { - T childResult = visitReturnClause(elm.getReturn(), context); - result = aggregateResult(result, childResult); - } - - if (elm.getAggregate() != null) { - T childResult = visitAggregateClause(elm.getAggregate(), context); - result = aggregateResult(result, childResult); - } - - if (elm.getSort() != null) { - T childResult = visitSortClause(elm.getSort(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit a AliasRef. This method will be called for - * every node in the tree that is a AliasRef. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitAliasRef(AliasRef elm, C context) { - return visitFields(elm, context); - } - - /** - * Visit a QueryLetRef. This method will be called for - * every node in the tree that is a QueryLetRef. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitQueryLetRef(QueryLetRef elm, C context) { - return visitFields(elm, context); - } - - protected T visitFields(Element elm, C context) { - T result = defaultResult(elm, context); - - if (elm.getResultTypeSpecifier() != null) { - T childResult = visitTypeSpecifier(elm.getResultTypeSpecifier(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - protected T visitFields(Expression elm, C context) { - return visitFields((Element) elm, context); - } - - protected T visitFields(RelationshipClause elm, C context) { - T result = visitFields((AliasedQuerySource) elm, context); - - if (elm.getSuchThat() != null) { - T childResult = visitExpression(elm.getSuchThat(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * visits the fields of an AggregateExpression - * - * @param elm - * @param context - * @return - */ - protected T visitFields(AggregateExpression elm, C context) { - T result = visitFields((Expression) elm, context); - - if (elm.getSource() != null) { - T childResult = visitExpression(elm.getSource(), context); - result = aggregateResult(result, childResult); - } - - for (var s : elm.getSignature()) { - T childResult = visitTypeSpecifier(s, context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visit the fields of an ExpressionDef - * @param elm - * @param context - * @return - */ - protected T visitFields(ExpressionDef elm, C context) { - T result = visitFields((Element) elm, context); - - if (elm.getAccessLevel() != null) { - T childResult = visitAccessModifier(elm.getAccessLevel(), context); - result = aggregateResult(result, childResult); - } - if (elm.getExpression() != null) { - T childResult = visitExpression(elm.getExpression(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visits the fields of a UnaryExpression - * - * @param elm - * @param context - * @return - */ - protected T visitFields(UnaryExpression elm, C context) { - T result = visitFields((OperatorExpression) elm, context); - - if (elm.getOperand() != null) { - T childResult = visitExpression(elm.getOperand(), context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * visits the fields of an NaryExpression - * - * @param elm - * @param context - * @return - */ - protected T visitFields(NaryExpression elm, C context) { - T result = visitFields((OperatorExpression) elm, context); - - for (Expression e : elm.getOperand()) { - T childResult = visitExpression(e, context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visits the fields of a TernaryExpression - * - * @param elm - * @param context - * @return - */ - protected T visitFields(TernaryExpression elm, C context) { - T result = visitFields((OperatorExpression) elm, context); - - for (var s : elm.getOperand()) { - T childResult = visitExpression(s, context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * Visits the fields of an OperatorExpression - * - * @param elm - * @param context - * @return - */ - protected T visitFields(OperatorExpression elm, C context) { - T result = visitFields((Expression) elm, context); - - for (var s : elm.getSignature()) { - T childResult = visitTypeSpecifier(s, context); - result = aggregateResult(result, childResult); - } - - return result; - } - - /** - * visits the fields of a BinaryExpression - * - * @param elm - * @param context - * @return - */ - protected T visitFields(BinaryExpression elm, C context) { - T result = visitFields((OperatorExpression) elm, context); - - for (Expression e : elm.getOperand()) { - T childResult = visitExpression(e, context); - result = aggregateResult(result, childResult); - } - - return result; - } - - protected T visitFields(AliasedQuerySource elm, C context) { - T result = visitFields((Element) elm, context); - - if (elm.getExpression() != null) { - T childResult = visitExpression(elm.getExpression(), context); - result = aggregateResult(result, childResult); - } - - return result; - } -} diff --git a/Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/BaseElmVisitor.kt b/Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/BaseElmVisitor.kt new file mode 100644 index 000000000..15bb06f74 --- /dev/null +++ b/Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/BaseElmVisitor.kt @@ -0,0 +1,3734 @@ +package org.cqframework.cql.elm.visiting + +import org.cqframework.cql.elm.tracking.Trackable +import org.hl7.elm.r1.Abs +import org.hl7.elm.r1.AccessModifier +import org.hl7.elm.r1.Add +import org.hl7.elm.r1.After +import org.hl7.elm.r1.Aggregate +import org.hl7.elm.r1.AggregateClause +import org.hl7.elm.r1.AggregateExpression +import org.hl7.elm.r1.AliasRef +import org.hl7.elm.r1.AliasedQuerySource +import org.hl7.elm.r1.AllTrue +import org.hl7.elm.r1.And +import org.hl7.elm.r1.AnyTrue +import org.hl7.elm.r1.As +import org.hl7.elm.r1.Avg +import org.hl7.elm.r1.Before +import org.hl7.elm.r1.BinaryExpression +import org.hl7.elm.r1.ByColumn +import org.hl7.elm.r1.ByDirection +import org.hl7.elm.r1.ByExpression +import org.hl7.elm.r1.CanConvert +import org.hl7.elm.r1.CanConvertQuantity +import org.hl7.elm.r1.Case +import org.hl7.elm.r1.CaseItem +import org.hl7.elm.r1.Ceiling +import org.hl7.elm.r1.Children +import org.hl7.elm.r1.ChoiceTypeSpecifier +import org.hl7.elm.r1.Coalesce +import org.hl7.elm.r1.Collapse +import org.hl7.elm.r1.Combine +import org.hl7.elm.r1.Concatenate +import org.hl7.elm.r1.Contains +import org.hl7.elm.r1.Convert +import org.hl7.elm.r1.ConvertQuantity +import org.hl7.elm.r1.ConvertsToBoolean +import org.hl7.elm.r1.ConvertsToDate +import org.hl7.elm.r1.ConvertsToDateTime +import org.hl7.elm.r1.ConvertsToDecimal +import org.hl7.elm.r1.ConvertsToInteger +import org.hl7.elm.r1.ConvertsToLong +import org.hl7.elm.r1.ConvertsToQuantity +import org.hl7.elm.r1.ConvertsToRatio +import org.hl7.elm.r1.ConvertsToString +import org.hl7.elm.r1.ConvertsToTime +import org.hl7.elm.r1.Count +import org.hl7.elm.r1.Current +import org.hl7.elm.r1.Date +import org.hl7.elm.r1.DateFrom +import org.hl7.elm.r1.DateTime +import org.hl7.elm.r1.DateTimeComponentFrom +import org.hl7.elm.r1.Descendents +import org.hl7.elm.r1.DifferenceBetween +import org.hl7.elm.r1.Distinct +import org.hl7.elm.r1.Divide +import org.hl7.elm.r1.DurationBetween +import org.hl7.elm.r1.Element +import org.hl7.elm.r1.End +import org.hl7.elm.r1.Ends +import org.hl7.elm.r1.EndsWith +import org.hl7.elm.r1.Equal +import org.hl7.elm.r1.Equivalent +import org.hl7.elm.r1.Except +import org.hl7.elm.r1.Exists +import org.hl7.elm.r1.Exp +import org.hl7.elm.r1.Expand +import org.hl7.elm.r1.Expression +import org.hl7.elm.r1.ExpressionDef +import org.hl7.elm.r1.ExpressionRef +import org.hl7.elm.r1.Filter +import org.hl7.elm.r1.First +import org.hl7.elm.r1.Flatten +import org.hl7.elm.r1.Floor +import org.hl7.elm.r1.ForEach +import org.hl7.elm.r1.FunctionDef +import org.hl7.elm.r1.FunctionRef +import org.hl7.elm.r1.GeometricMean +import org.hl7.elm.r1.Greater +import org.hl7.elm.r1.GreaterOrEqual +import org.hl7.elm.r1.HighBoundary +import org.hl7.elm.r1.IdentifierRef +import org.hl7.elm.r1.If +import org.hl7.elm.r1.Implies +import org.hl7.elm.r1.In +import org.hl7.elm.r1.IncludedIn +import org.hl7.elm.r1.Includes +import org.hl7.elm.r1.IndexOf +import org.hl7.elm.r1.Indexer +import org.hl7.elm.r1.Instance +import org.hl7.elm.r1.InstanceElement +import org.hl7.elm.r1.Intersect +import org.hl7.elm.r1.Interval +import org.hl7.elm.r1.IntervalTypeSpecifier +import org.hl7.elm.r1.Is +import org.hl7.elm.r1.IsFalse +import org.hl7.elm.r1.IsNull +import org.hl7.elm.r1.IsTrue +import org.hl7.elm.r1.Iteration +import org.hl7.elm.r1.Last +import org.hl7.elm.r1.LastPositionOf +import org.hl7.elm.r1.Length +import org.hl7.elm.r1.Less +import org.hl7.elm.r1.LessOrEqual +import org.hl7.elm.r1.LetClause +import org.hl7.elm.r1.List +import org.hl7.elm.r1.ListTypeSpecifier +import org.hl7.elm.r1.Literal +import org.hl7.elm.r1.Ln +import org.hl7.elm.r1.Log +import org.hl7.elm.r1.LowBoundary +import org.hl7.elm.r1.Lower +import org.hl7.elm.r1.Matches +import org.hl7.elm.r1.Max +import org.hl7.elm.r1.MaxValue +import org.hl7.elm.r1.Median +import org.hl7.elm.r1.Meets +import org.hl7.elm.r1.MeetsAfter +import org.hl7.elm.r1.MeetsBefore +import org.hl7.elm.r1.Message +import org.hl7.elm.r1.Min +import org.hl7.elm.r1.MinValue +import org.hl7.elm.r1.Mode +import org.hl7.elm.r1.Modulo +import org.hl7.elm.r1.Multiply +import org.hl7.elm.r1.NamedTypeSpecifier +import org.hl7.elm.r1.NaryExpression +import org.hl7.elm.r1.Negate +import org.hl7.elm.r1.Not +import org.hl7.elm.r1.NotEqual +import org.hl7.elm.r1.Now +import org.hl7.elm.r1.Null +import org.hl7.elm.r1.OperandDef +import org.hl7.elm.r1.OperandRef +import org.hl7.elm.r1.OperatorExpression +import org.hl7.elm.r1.Or +import org.hl7.elm.r1.Overlaps +import org.hl7.elm.r1.OverlapsAfter +import org.hl7.elm.r1.OverlapsBefore +import org.hl7.elm.r1.ParameterDef +import org.hl7.elm.r1.ParameterRef +import org.hl7.elm.r1.ParameterTypeSpecifier +import org.hl7.elm.r1.PointFrom +import org.hl7.elm.r1.PopulationStdDev +import org.hl7.elm.r1.PopulationVariance +import org.hl7.elm.r1.PositionOf +import org.hl7.elm.r1.Power +import org.hl7.elm.r1.Precision +import org.hl7.elm.r1.Predecessor +import org.hl7.elm.r1.Product +import org.hl7.elm.r1.ProperContains +import org.hl7.elm.r1.ProperIn +import org.hl7.elm.r1.ProperIncludedIn +import org.hl7.elm.r1.ProperIncludes +import org.hl7.elm.r1.Property +import org.hl7.elm.r1.Query +import org.hl7.elm.r1.QueryLetRef +import org.hl7.elm.r1.RelationshipClause +import org.hl7.elm.r1.Repeat +import org.hl7.elm.r1.ReplaceMatches +import org.hl7.elm.r1.ReturnClause +import org.hl7.elm.r1.Round +import org.hl7.elm.r1.SameAs +import org.hl7.elm.r1.SameOrAfter +import org.hl7.elm.r1.SameOrBefore +import org.hl7.elm.r1.SingletonFrom +import org.hl7.elm.r1.Size +import org.hl7.elm.r1.Slice +import org.hl7.elm.r1.Sort +import org.hl7.elm.r1.SortByItem +import org.hl7.elm.r1.SortClause +import org.hl7.elm.r1.Split +import org.hl7.elm.r1.SplitOnMatches +import org.hl7.elm.r1.Start +import org.hl7.elm.r1.Starts +import org.hl7.elm.r1.StartsWith +import org.hl7.elm.r1.StdDev +import org.hl7.elm.r1.Substring +import org.hl7.elm.r1.Subtract +import org.hl7.elm.r1.Successor +import org.hl7.elm.r1.Sum +import org.hl7.elm.r1.TernaryExpression +import org.hl7.elm.r1.Time +import org.hl7.elm.r1.TimeFrom +import org.hl7.elm.r1.TimeOfDay +import org.hl7.elm.r1.Times +import org.hl7.elm.r1.TimezoneFrom +import org.hl7.elm.r1.TimezoneOffsetFrom +import org.hl7.elm.r1.ToBoolean +import org.hl7.elm.r1.ToChars +import org.hl7.elm.r1.ToConcept +import org.hl7.elm.r1.ToDate +import org.hl7.elm.r1.ToDateTime +import org.hl7.elm.r1.ToDecimal +import org.hl7.elm.r1.ToInteger +import org.hl7.elm.r1.ToList +import org.hl7.elm.r1.ToLong +import org.hl7.elm.r1.ToQuantity +import org.hl7.elm.r1.ToRatio +import org.hl7.elm.r1.ToString +import org.hl7.elm.r1.ToTime +import org.hl7.elm.r1.Today +import org.hl7.elm.r1.Total +import org.hl7.elm.r1.Truncate +import org.hl7.elm.r1.TruncatedDivide +import org.hl7.elm.r1.Tuple +import org.hl7.elm.r1.TupleElement +import org.hl7.elm.r1.TupleElementDefinition +import org.hl7.elm.r1.TupleTypeSpecifier +import org.hl7.elm.r1.TypeSpecifier +import org.hl7.elm.r1.UnaryExpression +import org.hl7.elm.r1.Union +import org.hl7.elm.r1.Upper +import org.hl7.elm.r1.Variance +import org.hl7.elm.r1.Width +import org.hl7.elm.r1.With +import org.hl7.elm.r1.Without +import org.hl7.elm.r1.Xor + +/* +Design notes: +There are two types of methods in this class: + + 1. visitFields + + visitFields visits the fields of an object, traversing up the class hierarchy to visit superclass fields. + + 2. visitXYZ, where XYZ is the name of an ELM class + + The visitXYZ methods come in two flavors: + + A. visits on abstract or base classes forward to the correct visit method for the concrete or derived class. + B. visits on concrete or derived classes visit the fields of its base class using visitFields, + and then visits the fields itself. + + TypeSpecifiers are considered to be terminal nodes in the ELM graph. TypeSpecifiers themselves are Elements and thus + have recursive TypeSpecifiers, but these are not visited. +*/ +/** + * Provides the base implementation for an ElmVisitor. + * + * @param The return type of the visit operation. Use [Void] for no return value. + * @param The type of context passed to each visit method operations with no return type. + * + */ +@Suppress("LargeClass", "LongMethod", "CyclomaticComplexMethod", "TooManyFunctions") +abstract class BaseElmVisitor : ElmVisitor { + /** + * Provides the default result of a visit + * + * @return + */ + protected open fun defaultResult(elm: Trackable?, context: C): T? { + return null + } + + /** + * Provides for aggregation behavior of the results of a visit. Default behavior returns the + * next result, ignoring the current aggregate. + * + * @param aggregate Current aggregate result + * @param nextResult Next result to be aggregated + * @return The result of aggregating the nextResult into aggregate + */ + protected open fun aggregateResult(aggregate: T?, nextResult: T?): T? { + return nextResult + } + + /** + * Visit an Element in an ELM tree. This method will be called for every node in the tree that + * is a descendant of the Element type. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitElement(elm: Element, context: C): T? { + return when (elm) { + is Expression -> visitExpression(elm, context) + is CaseItem -> visitCaseItem(elm, context) + is LetClause -> visitLetClause(elm, context) + is OperandDef -> visitOperandDef(elm, context) + is ParameterDef -> visitParameterDef(elm, context) + is SortByItem -> visitSortByItem(elm, context) + is SortClause -> visitSortClause(elm, context) + is TupleElementDefinition -> visitTupleElementDefinition(elm, context) + is TypeSpecifier -> visitTypeSpecifier(elm, context) + else -> throw IllegalArgumentException("Unknown Element type: " + elm.javaClass.name) + } + } + + /** + * Visit a TypeSpecifier. This method will be called for every node in the tree that is a + * descendant of the TypeSpecifier type. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitTypeSpecifier(elm: TypeSpecifier, context: C): T? { + return when (elm) { + is NamedTypeSpecifier -> visitNamedTypeSpecifier(elm, context) + is IntervalTypeSpecifier -> visitIntervalTypeSpecifier(elm, context) + is ListTypeSpecifier -> visitListTypeSpecifier(elm, context) + is TupleTypeSpecifier -> visitTupleTypeSpecifier(elm, context) + is ChoiceTypeSpecifier -> visitChoiceTypeSpecifier(elm, context) + is ParameterTypeSpecifier -> visitParameterTypeSpecifier(elm, context) + else -> + throw IllegalArgumentException("Unknown TypeSpecifier type: " + elm.javaClass.name) + } + } + + /** + * Visit a ParameterTypeSpecifier. This method will be called for every node in the tree that is + * a ParameterTypeSpecifier. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitParameterTypeSpecifier(elm: ParameterTypeSpecifier?, context: C): T? { + return defaultResult(elm, context) + } + + /** + * Visit a NamedTypeSpecifier. This method will be called for every node in the tree that is a + * NamedTypeSpecifier. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitNamedTypeSpecifier(elm: NamedTypeSpecifier, context: C): T? { + return defaultResult(elm, context) + } + + /** + * Visit an IntervalTypeSpecifier. This method will be called for every node in the tree that is + * an IntervalTypeSpecifier. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitIntervalTypeSpecifier(elm: IntervalTypeSpecifier, context: C): T? { + var result = defaultResult(elm, context) + + if (elm.pointType != null) { + val childResult = visitTypeSpecifier(elm.pointType, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a ListTypeSpecifier. This method will be called for every node in the tree that is a + * ListTypeSpecifier. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitListTypeSpecifier(elm: ListTypeSpecifier, context: C): T? { + var result = defaultResult(elm, context) + + if (elm.elementType != null) { + val childResult = visitTypeSpecifier(elm.elementType, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a TupleElementDefinition. This method will be called for every node in the tree that is + * a TupleElementDefinition. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitTupleElementDefinition(elm: TupleElementDefinition, context: C): T? { + var result = visitFields(elm, context) + + if (elm.elementType != null) { + val childResult = visitTypeSpecifier(elm.elementType, context) + result = aggregateResult(result, childResult) + } + + if (elm.type != null) { + val childResult = visitTypeSpecifier(elm.type, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a TupleTypeSpecifier. This method will be called for every node in the tree that is a + * TupleTypeSpecifier. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitTupleTypeSpecifier(elm: TupleTypeSpecifier, context: C): T? { + var result = defaultResult(elm, context) + + for (element in elm.element) { + val childResult = visitTupleElementDefinition(element, context) + result = aggregateResult(result, childResult) + } + return result + } + + /** + * Visit a ChoiceTypeSpecifier. This method will be called for every node in the tree that is a + * ChoiceTypeSpecifier. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitChoiceTypeSpecifier(elm: ChoiceTypeSpecifier, context: C): T? { + var result = defaultResult(elm, context) + + for (choice in elm.choice) { + val childResult = visitTypeSpecifier(choice, context) + result = aggregateResult(result, childResult) + } + + for (type in elm.type) { + val childResult = visitTypeSpecifier(type, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit an Expression. This method will be called for every node in the tree that is an + * Expression. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitExpression(elm: Expression, context: C): T? { + return when (elm) { + is AliasRef -> visitAliasRef(elm, context) + is Case -> visitCase(elm, context) + is Current -> visitCurrent(elm, context) + is ExpressionRef -> visitExpressionRef(elm, context) + is Filter -> visitFilter(elm, context) + is ForEach -> visitForEach(elm, context) + is IdentifierRef -> visitIdentifierRef(elm, context) + is If -> visitIf(elm, context) + is Instance -> visitInstance(elm, context) + is Interval -> visitInterval(elm, context) + is Iteration -> visitIteration(elm, context) + is List -> visitList(elm, context) + is Literal -> visitLiteral(elm, context) + is MaxValue -> visitMaxValue(elm, context) + is MinValue -> visitMinValue(elm, context) + is Null -> visitNull(elm, context) + is OperandRef -> visitOperandRef(elm, context) + is ParameterRef -> visitParameterRef(elm, context) + is Property -> visitProperty(elm, context) + is Query -> visitQuery(elm, context) + is QueryLetRef -> visitQueryLetRef(elm, context) + is Repeat -> visitRepeat(elm, context) + is Sort -> visitSort(elm, context) + is Total -> visitTotal(elm, context) + is Tuple -> visitTuple(elm, context) + is AggregateExpression -> visitAggregateExpression(elm, context) + is OperatorExpression -> visitOperatorExpression(elm, context) + else -> throw IllegalArgumentException("Unknown Expression type: " + elm.javaClass.name) + } + } + + /** + * Visit an OperatorExpression. This method will be called for every node in the tree that is an + * OperatorExpression. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitOperatorExpression(elm: OperatorExpression, context: C): T? { + return when (elm) { + is Round -> visitRound(elm, context) + is Combine -> visitCombine(elm, context) + is Split -> visitSplit(elm, context) + is SplitOnMatches -> visitSplitOnMatches(elm, context) + is PositionOf -> visitPositionOf(elm, context) + is LastPositionOf -> visitLastPositionOf(elm, context) + is Substring -> visitSubstring(elm, context) + is TimeOfDay -> visitTimeOfDay(elm, context) + is Today -> visitToday(elm, context) + is Now -> visitNow(elm, context) + is Time -> visitTime(elm, context) + is Date -> visitDate(elm, context) + is DateTime -> visitDateTime(elm, context) + is First -> visitFirst(elm, context) + is Last -> visitLast(elm, context) + is IndexOf -> visitIndexOf(elm, context) + is Slice -> visitSlice(elm, context) + is Children -> visitChildren(elm, context) + is Descendents -> visitDescendents(elm, context) + is Message -> visitMessage(elm, context) + is UnaryExpression -> visitUnaryExpression(elm, context) + is BinaryExpression -> visitBinaryExpression(elm, context) + is TernaryExpression -> visitTernaryExpression(elm, context) + is NaryExpression -> visitNaryExpression(elm, context) + else -> + throw IllegalArgumentException( + "Unknown OperatorExpression type: " + elm.javaClass.name + ) + } + } + + /** + * Visit an UnaryExpression. This method will be called for every node in the tree that is an + * UnaryExpression. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitUnaryExpression(elm: UnaryExpression, context: C): T? { + return when (elm) { + is Abs -> visitAbs(elm, context) + is As -> visitAs(elm, context) + is Ceiling -> visitCeiling(elm, context) + is CanConvert -> visitCanConvert(elm, context) + is Convert -> visitConvert(elm, context) + is ConvertsToBoolean -> visitConvertsToBoolean(elm, context) + is ConvertsToDate -> visitConvertsToDate(elm, context) + is ConvertsToDateTime -> visitConvertsToDateTime(elm, context) + is ConvertsToDecimal -> visitConvertsToDecimal(elm, context) + is ConvertsToInteger -> visitConvertsToInteger(elm, context) + is ConvertsToLong -> visitConvertsToLong(elm, context) + is ConvertsToQuantity -> visitConvertsToQuantity(elm, context) + is ConvertsToRatio -> visitConvertsToRatio(elm, context) + is ConvertsToString -> visitConvertsToString(elm, context) + is ConvertsToTime -> visitConvertsToTime(elm, context) + is DateFrom -> visitDateFrom(elm, context) + is DateTimeComponentFrom -> visitDateTimeComponentFrom(elm, context) + is Distinct -> visitDistinct(elm, context) + is End -> visitEnd(elm, context) + is Exists -> visitExists(elm, context) + is Exp -> visitExp(elm, context) + is Flatten -> visitFlatten(elm, context) + is Floor -> visitFloor(elm, context) + is Is -> visitIs(elm, context) + is IsFalse -> visitIsFalse(elm, context) + is IsNull -> visitIsNull(elm, context) + is IsTrue -> visitIsTrue(elm, context) + is Length -> visitLength(elm, context) + is Ln -> visitLn(elm, context) + is Lower -> visitLower(elm, context) + is Negate -> visitNegate(elm, context) + is Not -> visitNot(elm, context) + is PointFrom -> visitPointFrom(elm, context) + is Precision -> visitPrecision(elm, context) + is Predecessor -> visitPredecessor(elm, context) + is SingletonFrom -> visitSingletonFrom(elm, context) + is Size -> visitSize(elm, context) + is Start -> visitStart(elm, context) + is Successor -> visitSuccessor(elm, context) + is TimeFrom -> visitTimeFrom(elm, context) + is TimezoneFrom -> visitTimezoneFrom(elm, context) + is TimezoneOffsetFrom -> visitTimezoneOffsetFrom(elm, context) + is ToBoolean -> visitToBoolean(elm, context) + is ToConcept -> visitToConcept(elm, context) + is ToChars -> visitToChars(elm, context) + is ToDate -> visitToDate(elm, context) + is ToDateTime -> visitToDateTime(elm, context) + is ToDecimal -> visitToDecimal(elm, context) + is ToInteger -> visitToInteger(elm, context) + is ToLong -> visitToLong(elm, context) + is ToList -> visitToList(elm, context) + is ToQuantity -> visitToQuantity(elm, context) + is ToRatio -> visitToRatio(elm, context) + is ToString -> visitToString(elm, context) + is ToTime -> visitToTime(elm, context) + is Truncate -> visitTruncate(elm, context) + is Upper -> visitUpper(elm, context) + is Width -> visitWidth(elm, context) + else -> + throw IllegalArgumentException( + "Unknown UnaryExpression type: " + elm.javaClass.name + ) + } + } + + /** + * Visit a BinaryExpression. This method will be called for every node in the tree that is a + * BinaryExpression. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitBinaryExpression(elm: BinaryExpression, context: C): T? { + return when (elm) { + is Add -> visitAdd(elm, context) + is After -> visitAfter(elm, context) + is And -> visitAnd(elm, context) + is Before -> visitBefore(elm, context) + is CanConvertQuantity -> visitCanConvertQuantity(elm, context) + is Contains -> visitContains(elm, context) + is ConvertQuantity -> visitConvertQuantity(elm, context) + is Collapse -> visitCollapse(elm, context) + is DifferenceBetween -> visitDifferenceBetween(elm, context) + is Divide -> visitDivide(elm, context) + is DurationBetween -> visitDurationBetween(elm, context) + is Ends -> visitEnds(elm, context) + is EndsWith -> visitEndsWith(elm, context) + is Equal -> visitEqual(elm, context) + is Equivalent -> visitEquivalent(elm, context) + is Expand -> visitExpand(elm, context) + is Greater -> visitGreater(elm, context) + is GreaterOrEqual -> visitGreaterOrEqual(elm, context) + is HighBoundary -> visitHighBoundary(elm, context) + is Implies -> visitImplies(elm, context) + is In -> visitIn(elm, context) + is IncludedIn -> visitIncludedIn(elm, context) + is Includes -> visitIncludes(elm, context) + is Indexer -> visitIndexer(elm, context) + is Less -> visitLess(elm, context) + is LessOrEqual -> visitLessOrEqual(elm, context) + is Log -> visitLog(elm, context) + is LowBoundary -> visitLowBoundary(elm, context) + is Matches -> visitMatches(elm, context) + is Meets -> visitMeets(elm, context) + is MeetsAfter -> visitMeetsAfter(elm, context) + is MeetsBefore -> visitMeetsBefore(elm, context) + is Modulo -> visitModulo(elm, context) + is Multiply -> visitMultiply(elm, context) + is NotEqual -> visitNotEqual(elm, context) + is Or -> visitOr(elm, context) + is Overlaps -> visitOverlaps(elm, context) + is OverlapsAfter -> visitOverlapsAfter(elm, context) + is OverlapsBefore -> visitOverlapsBefore(elm, context) + is Power -> visitPower(elm, context) + is ProperContains -> visitProperContains(elm, context) + is ProperIn -> visitProperIn(elm, context) + is ProperIncludedIn -> visitProperIncludedIn(elm, context) + is ProperIncludes -> visitProperIncludes(elm, context) + is SameAs -> visitSameAs(elm, context) + is SameOrAfter -> visitSameOrAfter(elm, context) + is SameOrBefore -> visitSameOrBefore(elm, context) + is Starts -> visitStarts(elm, context) + is StartsWith -> visitStartsWith(elm, context) + is Subtract -> visitSubtract(elm, context) + is Times -> visitTimes(elm, context) + is TruncatedDivide -> visitTruncatedDivide(elm, context) + is Xor -> visitXor(elm, context) + else -> + throw IllegalArgumentException( + "Unknown BinaryExpression type: " + elm.javaClass.name + ) + } + } + + /** + * Visit a TernaryExpression. This method will be called for every node in the tree that is a + * TernaryExpression. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitTernaryExpression(elm: TernaryExpression, context: C): T? { + if (elm is ReplaceMatches) return visitReplaceMatches(elm, context) + else throw IllegalArgumentException("Unknown TernaryExpression type: " + elm.javaClass.name) + } + + /** + * Visit a NaryExpression. This method will be called for every node in the tree that is a + * NaryExpression. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitNaryExpression(elm: NaryExpression, context: C): T? { + return when (elm) { + is Coalesce -> visitCoalesce(elm, context) + is Concatenate -> visitConcatenate(elm, context) + is Except -> visitExcept(elm, context) + is Intersect -> visitIntersect(elm, context) + is Union -> visitUnion(elm, context) + else -> + throw IllegalArgumentException("Unknown NaryExpression type: " + elm.javaClass.name) + } + } + + /** + * Visit an ExpressionDef. This method will be called for every node in the tree that is an + * ExpressionDef. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitExpressionDef(elm: ExpressionDef, context: C): T? { + if (elm is FunctionDef) { + return visitFunctionDef(elm, context) + } + + return visitFields(elm, context) + } + + /** + * Visit a FunctionDef. This method will be called for every node in the tree that is a + * FunctionDef. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitFunctionDef(elm: FunctionDef, context: C): T? { + var result = visitFields(elm, context) + + for (operand in elm.operand) { + val childResult = visitOperandDef(operand, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit AccessModifier. This method will be called for every node in the tree that is an + * AccessModifier. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + @Suppress("UnusedParameter") + fun visitAccessModifier(elm: AccessModifier?, context: C): T? { + // NOTE: AccessModifier isn't trackable? + return defaultResult(null, context) + } + + /** + * Visit an ExpressionRef. This method will be called for every node in the tree that is an + * ExpressionRef. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitExpressionRef(elm: ExpressionRef, context: C): T? { + if (elm is FunctionRef) { + return visitFunctionRef(elm, context) + } + + return visitFields(elm, context) + } + + /** + * Visit a FunctionRef. This method will be called for every node in the tree that is a + * FunctionRef. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitFunctionRef(elm: FunctionRef, context: C): T? { + var result = visitFields(elm, context) + + for (element in elm.operand) { + val childResult = visitExpression(element, context) + result = aggregateResult(result, childResult) + } + + for (s in elm.signature) { + val childResult = visitTypeSpecifier(s, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a ParameterDef. This method will be called for every node in the tree that is a + * ParameterDef. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitParameterDef(elm: ParameterDef, context: C): T? { + var result = visitFields(elm, context) + + if (elm.parameterTypeSpecifier != null) { + val childResult = visitTypeSpecifier(elm.parameterTypeSpecifier, context) + result = aggregateResult(result, childResult) + } + + if (elm.default != null) { + val childResult = visitExpression(elm.default, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a ParameterRef. This method will be called for every node in the tree that is a + * ParameterRef. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitParameterRef(elm: ParameterRef, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit an OperandDef. This method will be called for every node in the tree that is an + * OperandDef. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitOperandDef(elm: OperandDef, context: C): T? { + var result = visitFields(elm, context) + + if (elm.operandTypeSpecifier != null) { + val childResult = visitTypeSpecifier(elm.operandTypeSpecifier, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit an OperandRef. This method will be called for every node in the tree that is an + * OperandRef. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitOperandRef(elm: OperandRef, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit an IdentifierRef. This method will be called for every node in the tree that is an + * IdentifierRef. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitIdentifierRef(elm: IdentifierRef, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Literal. This method will be called for every node in the tree that is a Literal. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitLiteral(elm: Literal, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a TupleElement. This method will be called for every node in the tree that is a + * TupleElement. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitTupleElement(elm: TupleElement, context: C): T? { + var result = defaultResult(elm, context) + + if (elm.value != null) { + val childResult = visitExpression(elm.value, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a Tuple. This method will be called for every node in the tree that is a Tuple. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitTuple(elm: Tuple, context: C): T? { + var result = visitFields(elm, context) + + for (element in elm.element) { + val childResult = visitTupleElement(element, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit an InstanceElement. This method will be called for every node in the tree that is an + * InstanceElement. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitInstanceElement(elm: InstanceElement, context: C): T? { + var result = defaultResult(elm, context) + + if (elm.value != null) { + val childResult = visitExpression(elm.value, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit an Instance. This method will be called for every node in the tree that is an Instance. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitInstance(elm: Instance, context: C): T? { + var result = visitFields(elm, context) + + for (element in elm.element) { + val childResult = visitInstanceElement(element, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit an Interval. This method will be called for every node in the tree that is an Interval. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitInterval(elm: Interval, context: C): T? { + var result = visitFields(elm, context) + + if (elm.low != null) { + val childResult = visitExpression(elm.low, context) + result = aggregateResult(result, childResult) + } + if (elm.lowClosedExpression != null) { + val childResult = visitExpression(elm.lowClosedExpression, context) + result = aggregateResult(result, childResult) + } + if (elm.high != null) { + val childResult = visitExpression(elm.high, context) + result = aggregateResult(result, childResult) + } + if (elm.highClosedExpression != null) { + val childResult = visitExpression(elm.highClosedExpression, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a List. This method will be called for every node in the tree that is a List. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitList(elm: List, context: C): T? { + var result = visitFields(elm, context) + + if (elm.typeSpecifier != null) { + val childResult = visitTypeSpecifier(elm.typeSpecifier, context) + result = aggregateResult(result, childResult) + } + + for (element in elm.element) { + val childResult = visitExpression(element, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit an And. This method will be called for every node in the tree that is an And. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitAnd(elm: And, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit an Or. This method will be called for every node in the tree that is an Or. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitOr(elm: Or, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Xor. This method will be called for every node in the tree that is a Xor. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitXor(elm: Xor, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit an Implies. This method will be called for every node in the tree that is an Implies. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitImplies(elm: Implies, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Not. This method will be called for every node in the tree that is a Not. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitNot(elm: Not, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit an If. This method will be called for every node in the tree that is an If. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitIf(elm: If, context: C): T? { + var result = visitFields(elm, context) + + if (elm.condition != null) { + val childResult = visitExpression(elm.condition, context) + result = aggregateResult(result, childResult) + } + if (elm.then != null) { + val childResult = visitExpression(elm.then, context) + result = aggregateResult(result, childResult) + } + if (elm.getElse() != null) { + val childResult = visitExpression(elm.getElse(), context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a CaseItem. This method will be called for every node in the tree that is a CaseItem. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitCaseItem(elm: CaseItem, context: C): T? { + var result = visitFields(elm, context) + + if (elm.getWhen() != null) { + val childResult = visitExpression(elm.getWhen(), context) + result = aggregateResult(result, childResult) + } + if (elm.then != null) { + val childResult = visitExpression(elm.then, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a Case. This method will be called for every node in the tree that is a Case. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitCase(elm: Case, context: C): T? { + var result = visitFields(elm, context) + + if (elm.comparand != null) { + val childResult = visitExpression(elm.comparand, context) + result = aggregateResult(result, childResult) + } + + for (ci in elm.caseItem) { + val childResult = visitCaseItem(ci, context) + result = aggregateResult(result, childResult) + } + + if (elm.getElse() != null) { + val childResult = visitExpression(elm.getElse(), context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a Null. This method will be called for every node in the tree that is a Null. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitNull(elm: Null, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit an IsNull. This method will be called for every node in the tree that is an IsNull. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitIsNull(elm: IsNull, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit an IsTrue. This method will be called for every node in the tree that is an IsTrue. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitIsTrue(elm: IsTrue, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit an IsFalse. This method will be called for every node in the tree that is an IsFalse. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitIsFalse(elm: IsFalse, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Coalesce. This method will be called for every node in the tree that is a Coalesce. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitCoalesce(elm: Coalesce, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit an Is. This method will be called for every node in the tree that is an Is. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitIs(elm: Is, context: C): T? { + var result = visitFields(elm, context) + + if (elm.isTypeSpecifier != null) { + val childResult = visitTypeSpecifier(elm.isTypeSpecifier, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit an As. This method will be called for every node in the tree that is an As. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitAs(elm: As, context: C): T? { + var result = visitFields(elm, context) + + if (elm.asTypeSpecifier != null) { + val childResult = visitTypeSpecifier(elm.asTypeSpecifier, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a Convert. This method will be called for every node in the tree that is a Convert. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitConvert(elm: Convert, context: C): T? { + var result = visitFields(elm, context) + + if (elm.toTypeSpecifier != null) { + val childResult = visitTypeSpecifier(elm.toTypeSpecifier, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a CanConvert. This method will be called for every node in the tree that is a + * CanConvert. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitCanConvert(elm: CanConvert, context: C): T? { + var result = visitFields(elm, context) + + if (elm.toTypeSpecifier != null) { + val childResult = visitTypeSpecifier(elm.toTypeSpecifier, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a ConvertsToBoolean. This method will be called for every node in the tree that is a + * ConvertsToBoolean. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitConvertsToBoolean(elm: ConvertsToBoolean, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a ToBoolean. This method will be called for every node in the tree that is a ToBoolean. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitToBoolean(elm: ToBoolean, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a ToChars. This method will be called for every node in the tree that is a ToChars. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitToChars(elm: ToChars, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a ToConcept. This method will be called for every node in the tree that is a ToConcept. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitToConcept(elm: ToConcept, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a ConvertsToDate. This method will be called for every node in the tree that is a + * ConvertsToDate. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitConvertsToDate(elm: ConvertsToDate, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a ToDate. This method will be called for every node in the tree that is a ToDate. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitToDate(elm: ToDate, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a ConvertsToDateTime. This method will be called for every node in the tree that is a + * ConvertsToDateTime. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitConvertsToDateTime(elm: ConvertsToDateTime, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a ToDateTime. This method will be called for every node in the tree that is a + * ToDateTime. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitToDateTime(elm: ToDateTime, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a ConvertsToLong. This method will be called for every node in the tree that is a + * ConvertsToLong. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitConvertsToLong(elm: ConvertsToLong, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a ToLong. This method will be called for every node in the tree that is a ToLong. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitToLong(elm: ToLong, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a ConvertsToDecimal. This method will be called for every node in the tree that is a + * ConvertsToDecimal. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitConvertsToDecimal(elm: ConvertsToDecimal, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a ToDecimal. This method will be called for every node in the tree that is a ToDecimal. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitToDecimal(elm: ToDecimal, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a ConvertsToInteger. This method will be called for every node in the tree that is a + * ConvertsToInteger. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitConvertsToInteger(elm: ConvertsToInteger, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a ToInteger. This method will be called for every node in the tree that is a ToInteger. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitToInteger(elm: ToInteger, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a ToList. This method will be called for every node in the tree that is a ToList. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitToList(elm: ToList, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a ConvertQuantity. This method will be called for every node in the tree that is a + * ConvertQuantity. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitConvertQuantity(elm: ConvertQuantity, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a CanConvertQuantity. This method will be called for every node in the tree that is a + * CanConvertQuantity. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitCanConvertQuantity(elm: CanConvertQuantity, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a ConvertsToQuantity. This method will be called for every node in the tree that is a + * ConvertsToQuantity. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitConvertsToQuantity(elm: ConvertsToQuantity, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a ToQuantity. This method will be called for every node in the tree that is a + * ToQuantity. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitToQuantity(elm: ToQuantity, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a ConvertsToRatio. This method will be called for every node in the tree that is a + * ConvertsToRatio. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitConvertsToRatio(elm: ConvertsToRatio, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Ratio. This method will be called for every node in the tree that is a Ratio. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitToRatio(elm: ToRatio, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a ConvertsToString. This method will be called for every node in the tree that is a + * ConvertsToString. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitConvertsToString(elm: ConvertsToString, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a ToString. This method will be called for every node in the tree that is a ToString. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitToString(elm: ToString, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a ConvertsToTime. This method will be called for every node in the tree that is a + * ConvertsToTime. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitConvertsToTime(elm: ConvertsToTime, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a ToTime. This method will be called for every node in the tree that is a ToTime. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitToTime(elm: ToTime, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit an Equal. This method will be called for every node in the tree that is an Equal. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitEqual(elm: Equal, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit an Equivalent. This method will be called for every node in the tree that is an + * Equivalent. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitEquivalent(elm: Equivalent, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a NotEqual. This method will be called for every node in the tree that is a NotEqual. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitNotEqual(elm: NotEqual, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Less. This method will be called for every node in the tree that is a Less. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitLess(elm: Less, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Greater. This method will be called for every node in the tree that is a Greater. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitGreater(elm: Greater, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a LessOrEqual. This method will be called for every node in the tree that is a + * LessOrEqual. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitLessOrEqual(elm: LessOrEqual, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a GreaterOrEqual. This method will be called for every node in the tree that is a + * GreaterOrEqual. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitGreaterOrEqual(elm: GreaterOrEqual, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit an Add. This method will be called for every node in the tree that is an Add. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitAdd(elm: Add, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Subtract. This method will be called for every node in the tree that is a Subtract. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitSubtract(elm: Subtract, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Multiply. This method will be called for every node in the tree that is a Multiply. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitMultiply(elm: Multiply, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Divide. This method will be called for every node in the tree that is a Divide. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitDivide(elm: Divide, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a TruncatedDivide. This method will be called for every node in the tree that is a + * TruncatedDivide. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitTruncatedDivide(elm: TruncatedDivide, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Modulo. This method will be called for every node in the tree that is a Modulo. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitModulo(elm: Modulo, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Ceiling. This method will be called for every node in the tree that is a Ceiling. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitCeiling(elm: Ceiling, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Floor. This method will be called for every node in the tree that is a Floor. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitFloor(elm: Floor, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Truncate. This method will be called for every node in the tree that is a Truncate. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitTruncate(elm: Truncate, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit an Abs. This method will be called for every node in the tree that is an Abs. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitAbs(elm: Abs, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Negate. This method will be called for every node in the tree that is a Negate. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitNegate(elm: Negate, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Round. This method will be called for every node in the tree that is a Round. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitRound(elm: Round, context: C): T? { + var result = visitFields(elm, context) + if (elm.operand != null) { + val childResult = visitExpression(elm.operand, context) + result = aggregateResult(result, childResult) + } + + if (elm.precision != null) { + val childResult = visitExpression(elm.precision, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a Ln. This method will be called for every node in the tree that is a Ln. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitLn(elm: Ln, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit an Exp. This method will be called for every node in the tree that is an Exp. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitExp(elm: Exp, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Log. This method will be called for every node in the tree that is a Log. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitLog(elm: Log, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Power. This method will be called for every node in the tree that is a Power. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitPower(elm: Power, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Successor. This method will be called for every node in the tree that is a Successor. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitSuccessor(elm: Successor, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Predecessor. This method will be called for every node in the tree that is a + * Predecessor. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitPredecessor(elm: Predecessor, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a MinValue. This method will be called for every node in the tree that is a MinValue. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitMinValue(elm: MinValue, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a MaxValue. This method will be called for every node in the tree that is a MaxValue. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitMaxValue(elm: MaxValue, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Precision. This method will be called for every node in the tree that is a Precision. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitPrecision(elm: Precision, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a LowBoundary. This method will be called for every node in the tree that is a + * LowBoundary. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitLowBoundary(elm: LowBoundary, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a HighBoundary. This method will be called for every node in the tree that is a + * HighBoundary. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitHighBoundary(elm: HighBoundary, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Concatenate. This method will be called for every node in the tree that is a + * Concatenate. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitConcatenate(elm: Concatenate, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Combine. This method will be called for every node in the tree that is a Combine. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitCombine(elm: Combine, context: C): T? { + var result = visitFields(elm, context) + + if (elm.source != null) { + val childResult = visitExpression(elm.source, context) + result = aggregateResult(result, childResult) + } + if (elm.separator != null) { + val childResult = visitExpression(elm.separator, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a Split. This method will be called for every node in the tree that is a Split. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitSplit(elm: Split, context: C): T? { + var result = visitFields(elm, context) + + if (elm.stringToSplit != null) { + val childResult = visitExpression(elm.stringToSplit, context) + result = aggregateResult(result, childResult) + } + if (elm.separator != null) { + val childResult = visitExpression(elm.separator, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a SplitOnMatches. This method will be called for every node in the tree that is a + * SplitOnMatches. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitSplitOnMatches(elm: SplitOnMatches, context: C): T? { + var result = visitFields(elm, context) + + if (elm.stringToSplit != null) { + val childResult = visitExpression(elm.stringToSplit, context) + result = aggregateResult(result, childResult) + } + if (elm.separatorPattern != null) { + val childResult = visitExpression(elm.separatorPattern, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a Length. This method will be called for every node in the tree that is a Length. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitLength(elm: Length, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit an Upper. This method will be called for every node in the tree that is an Upper. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitUpper(elm: Upper, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Lower. This method will be called for every node in the tree that is a Lower. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitLower(elm: Lower, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit an Indexer. This method will be called for every node in the tree that is an Indexer. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitIndexer(elm: Indexer, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a PositionOf. This method will be called for every node in the tree that is a + * PositionOf. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitPositionOf(elm: PositionOf, context: C): T? { + var result = visitFields(elm, context) + + if (elm.pattern != null) { + val childResult = visitExpression(elm.pattern, context) + result = aggregateResult(result, childResult) + } + if (elm.string != null) { + val childResult = visitExpression(elm.string, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a LastPositionOf. This method will be called for every node in the tree that is a + * LastPositionOf. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitLastPositionOf(elm: LastPositionOf, context: C): T? { + var result = visitFields(elm, context) + + if (elm.pattern != null) { + val childResult = visitExpression(elm.pattern, context) + result = aggregateResult(result, childResult) + } + if (elm.string != null) { + val childResult = visitExpression(elm.string, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a Substring. This method will be called for every node in the tree that is a Substring. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitSubstring(elm: Substring, context: C): T? { + var result = visitFields(elm, context) + + if (elm.stringToSub != null) { + val childResult = visitExpression(elm.stringToSub, context) + result = aggregateResult(result, childResult) + } + if (elm.startIndex != null) { + val childResult = visitExpression(elm.startIndex, context) + result = aggregateResult(result, childResult) + } + if (elm.length != null) { + val childResult = visitExpression(elm.length, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a StartsWith. This method will be called for every node in the tree that is a + * StartsWith. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitStartsWith(elm: StartsWith, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit an EndsWith. This method will be called for every node in the tree that is an EndsWith. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitEndsWith(elm: EndsWith, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Matches. This method will be called for every node in the tree that is a Matches. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitMatches(elm: Matches, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a ReplaceMatches. This method will be called for every node in the tree that is a + * ReplaceMatches. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitReplaceMatches(elm: ReplaceMatches, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a DurationBetween. This method will be called for every node in the tree that is a + * DurationBetween. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitDurationBetween(elm: DurationBetween, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a DifferenceBetween. This method will be called for every node in the tree that is a + * DifferenceBetween. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitDifferenceBetween(elm: DifferenceBetween, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a DateFrom. This method will be called for every node in the tree that is a DateFrom. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitDateFrom(elm: DateFrom, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a TimeFrom. This method will be called for every node in the tree that is a TimeFrom. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitTimeFrom(elm: TimeFrom, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a TimezoneFrom. This method will be called for every node in the tree that is a + * TimezoneFrom. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitTimezoneFrom(elm: TimezoneFrom, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a TimezoneOffsetFrom. This method will be called for every node in the tree that is a + * TimezoneOffsetFrom. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitTimezoneOffsetFrom(elm: TimezoneOffsetFrom, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a DateTimeComponentFrom. This method will be called for every node in the tree that is + * a DateTimeComponentFrom. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitDateTimeComponentFrom(elm: DateTimeComponentFrom, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a TimeOfDay. This method will be called for every node in the tree that is a TimeOfDay. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitTimeOfDay(elm: TimeOfDay, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Today. This method will be called for every node in the tree that is a Today. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitToday(elm: Today, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Now. This method will be called for every node in the tree that is a Now. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitNow(elm: Now, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a DateTime. This method will be called for every node in the tree that is a DateTime. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitDateTime(elm: DateTime, context: C): T? { + var result = visitFields(elm, context) + + if (elm.year != null) { + val childResult = visitExpression(elm.year, context) + result = aggregateResult(result, childResult) + } + if (elm.month != null) { + val childResult = visitExpression(elm.month, context) + result = aggregateResult(result, childResult) + } + if (elm.day != null) { + val childResult = visitExpression(elm.day, context) + result = aggregateResult(result, childResult) + } + if (elm.hour != null) { + val childResult = visitExpression(elm.hour, context) + result = aggregateResult(result, childResult) + } + if (elm.minute != null) { + val childResult = visitExpression(elm.minute, context) + result = aggregateResult(result, childResult) + } + if (elm.second != null) { + val childResult = visitExpression(elm.second, context) + result = aggregateResult(result, childResult) + } + if (elm.millisecond != null) { + val childResult = visitExpression(elm.millisecond, context) + result = aggregateResult(result, childResult) + } + if (elm.timezoneOffset != null) { + val childResult = visitExpression(elm.timezoneOffset, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a Date. This method will be called for every node in the tree that is a Date. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitDate(elm: Date, context: C): T? { + var result = visitFields(elm, context) + + if (elm.year != null) { + val childResult = visitExpression(elm.year, context) + result = aggregateResult(result, childResult) + } + if (elm.month != null) { + val childResult = visitExpression(elm.month, context) + result = aggregateResult(result, childResult) + } + if (elm.day != null) { + val childResult = visitExpression(elm.day, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a Time. This method will be called for every node in the tree that is a Time. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitTime(elm: Time, context: C): T? { + var result = visitFields(elm, context) + + if (elm.hour != null) { + val childResult = visitExpression(elm.hour, context) + result = aggregateResult(result, childResult) + } + if (elm.minute != null) { + val childResult = visitExpression(elm.minute, context) + result = aggregateResult(result, childResult) + } + if (elm.second != null) { + val childResult = visitExpression(elm.second, context) + result = aggregateResult(result, childResult) + } + if (elm.millisecond != null) { + val childResult = visitExpression(elm.millisecond, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a SameAs. This method will be called for every node in the tree that is a SameAs. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitSameAs(elm: SameAs, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a SameOrBefore. This method will be called for every node in the tree that is a + * SameOrBefore. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitSameOrBefore(elm: SameOrBefore, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a SameOrAfter. This method will be called for every node in the tree that is a + * SameOrAfter. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitSameOrAfter(elm: SameOrAfter, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Width. This method will be called for every node in the tree that is a Width. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitWidth(elm: Width, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Size. This method will be called for every node in the tree that is a Size. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitSize(elm: Size, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a PointFrom. This method will be called for every node in the tree that is a PointFrom. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitPointFrom(elm: PointFrom, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Start. This method will be called for every node in the tree that is a Start. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitStart(elm: Start, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit an End. This method will be called for every node in the tree that is an End. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitEnd(elm: End, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Contains. This method will be called for every node in the tree that is a Contains. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitContains(elm: Contains, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a ProperContains. This method will be called for every node in the tree that is a + * ProperContains. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitProperContains(elm: ProperContains, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit an In. This method will be called for every node in the tree that is an In. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitIn(elm: In, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a ProperIn. This method will be called for every node in the tree that is a ProperIn. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitProperIn(elm: ProperIn, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit an Includes. This method will be called for every node in the tree that is an Includes. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitIncludes(elm: Includes, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit an IncludedIn. This method will be called for every node in the tree that is an + * IncludedIn. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitIncludedIn(elm: IncludedIn, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a ProperIncludes. This method will be called for every node in the tree that is a + * ProperIncludes. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitProperIncludes(elm: ProperIncludes, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a ProperIncludedIn. This method will be called for every node in the tree that is a + * ProperIncludedIn. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitProperIncludedIn(elm: ProperIncludedIn, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Before. This method will be called for every node in the tree that is a Before. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitBefore(elm: Before, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit an After. This method will be called for every node in the tree that is an After. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitAfter(elm: After, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Meets. This method will be called for every node in the tree that is a Meets. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitMeets(elm: Meets, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a MeetsBefore. This method will be called for every node in the tree that is a + * MeetsBefore. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitMeetsBefore(elm: MeetsBefore, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a MeetsAfter. This method will be called for every node in the tree that is a + * MeetsAfter. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitMeetsAfter(elm: MeetsAfter, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit an Overlaps. This method will be called for every node in the tree that is an Overlaps. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitOverlaps(elm: Overlaps, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit an OverlapsBefore. This method will be called for every node in the tree that is an + * OverlapsBefore. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitOverlapsBefore(elm: OverlapsBefore, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit an OverlapsAfter. This method will be called for every node in the tree that is an + * OverlapsAfter. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitOverlapsAfter(elm: OverlapsAfter, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Starts. This method will be called for every node in the tree that is a Starts. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitStarts(elm: Starts, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit an Ends. This method will be called for every node in the tree that is an Ends. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitEnds(elm: Ends, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Collapse. This method will be called for every node in the tree that is a Collapse. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitCollapse(elm: Collapse, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit an Expand. This method will be called for every node in the tree that is an Expand. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitExpand(elm: Expand, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Union. This method will be called for every node in the tree that is a Union. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitUnion(elm: Union, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit an Intersect. This method will be called for every node in the tree that is an + * Intersect. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitIntersect(elm: Intersect, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit an Except. This method will be called for every node in the tree that is an Except. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitExcept(elm: Except, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit an Exists. This method will be called for every node in the tree that is an Exists. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitExists(elm: Exists, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Times. This method will be called for every node in the tree that is a Times. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitTimes(elm: Times, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Filter. This method will be called for every node in the tree that is a Filter. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitFilter(elm: Filter, context: C): T? { + var result = visitFields(elm, context) + + if (elm.source != null) { + val childResult = visitExpression(elm.source, context) + result = aggregateResult(result, childResult) + } + if (elm.condition != null) { + val childResult = visitExpression(elm.condition, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a First. This method will be called for every node in the tree that is a First. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitFirst(elm: First, context: C): T? { + var result = visitFields(elm, context) + + if (elm.source != null) { + val childResult = visitExpression(elm.source, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a Last. This method will be called for every node in the tree that is a Last. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitLast(elm: Last, context: C): T? { + var result = visitFields(elm, context) + + if (elm.source != null) { + val childResult = visitExpression(elm.source, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a Slice. This method will be called for every node in the tree that is a Slice. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitSlice(elm: Slice, context: C): T? { + var result = visitFields(elm, context) + + if (elm.source != null) { + val childResult = visitExpression(elm.source, context) + result = aggregateResult(result, childResult) + } + if (elm.startIndex != null) { + val childResult = visitExpression(elm.startIndex, context) + result = aggregateResult(result, childResult) + } + if (elm.endIndex != null) { + val childResult = visitExpression(elm.endIndex, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a Children. This method will be called for every node in the tree that is a Children. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitChildren(elm: Children, context: C): T? { + var result = visitFields(elm, context) + + if (elm.source != null) { + val childResult = visitExpression(elm.source, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a Descendents. This method will be called for every node in the tree that is a + * Descendents. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitDescendents(elm: Descendents, context: C): T? { + var result = visitFields(elm, context) + + if (elm.source != null) { + val childResult = visitExpression(elm.source, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a Message. This method will be called for every node in the tree that is a Message. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitMessage(elm: Message, context: C): T? { + var result = visitFields(elm, context) + + if (elm.source != null) { + val childResult = visitExpression(elm.source, context) + result = aggregateResult(result, childResult) + } + if (elm.condition != null) { + val childResult = visitExpression(elm.condition, context) + result = aggregateResult(result, childResult) + } + if (elm.code != null) { + val childResult = visitExpression(elm.code, context) + result = aggregateResult(result, childResult) + } + if (elm.severity != null) { + val childResult = visitExpression(elm.severity, context) + result = aggregateResult(result, childResult) + } + if (elm.message != null) { + val childResult = visitExpression(elm.message, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit an IndexOf. This method will be called for every node in the tree that is an IndexOf. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitIndexOf(elm: IndexOf, context: C): T? { + var result = visitFields(elm, context) + + if (elm.source != null) { + val childResult = visitExpression(elm.source, context) + result = aggregateResult(result, childResult) + } + if (elm.element != null) { + val childResult = visitExpression(elm.element, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a Flatten. This method will be called for every node in the tree that is a Flatten. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitFlatten(elm: Flatten, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Sort. This method will be called for every node in the tree that is a Sort. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitSort(elm: Sort, context: C): T? { + var result = visitFields(elm, context) + + if (elm.source != null) { + val childResult = visitExpression(elm.source, context) + result = aggregateResult(result, childResult) + } + for (sbi in elm.by) { + val childResult = visitSortByItem(sbi, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a ForEach. This method will be called for every node in the tree that is a ForEach. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitForEach(elm: ForEach, context: C): T? { + var result = visitFields(elm, context) + + if (elm.source != null) { + val childResult = visitExpression(elm.source, context) + result = aggregateResult(result, childResult) + } + if (elm.element != null) { + val childResult = visitExpression(elm.element, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a Repeat. This method will be called for every node in the tree that is a Repeat. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitRepeat(elm: Repeat, context: C): T? { + var result = visitFields(elm, context) + + if (elm.source != null) { + val childResult = visitExpression(elm.source, context) + result = aggregateResult(result, childResult) + } + if (elm.element != null) { + val childResult = visitExpression(elm.element, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a Distinct. This method will be called for every node in the tree that is a Distinct. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitDistinct(elm: Distinct, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Current. This method will be called for every node in the tree that is a Current. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitCurrent(elm: Current, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit an Iteration. This method will be called for every node in the tree that is an + * Iteration. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitIteration(elm: Iteration, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Total. This method will be called for every node in the tree that is a Total. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitTotal(elm: Total, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a SingletonFrom. This method will be called for every node in the tree that is a + * SingletonFrom. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitSingletonFrom(elm: SingletonFrom, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit an AggregateExpression. This method will be called for every node in the tree that is + * an AggregateExpression. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitAggregateExpression(elm: AggregateExpression, context: C): T? { + return when (elm) { + is Aggregate -> visitAggregate(elm, context) + is Count -> visitCount(elm, context) + is Sum -> visitSum(elm, context) + is Product -> visitProduct(elm, context) + is Min -> visitMin(elm, context) + is Max -> visitMax(elm, context) + is Avg -> visitAvg(elm, context) + is GeometricMean -> visitGeometricMean(elm, context) + is Median -> visitMedian(elm, context) + is Mode -> visitMode(elm, context) + is Variance -> visitVariance(elm, context) + is StdDev -> visitStdDev(elm, context) + is PopulationVariance -> visitPopulationVariance(elm, context) + is PopulationStdDev -> visitPopulationStdDev(elm, context) + is AllTrue -> visitAllTrue(elm, context) + is AnyTrue -> visitAnyTrue(elm, context) + else -> + throw IllegalArgumentException( + "Unsupported AggregateExpression type: " + elm.javaClass.name + ) + } + } + + /** + * Visit an Aggregate. This method will be called for every node in the tree that is an + * Aggregate. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitAggregate(elm: Aggregate, context: C): T? { + var result = visitFields(elm as AggregateExpression, context) + + if (elm.initialValue != null) { + val childResult = visitExpression(elm.initialValue, context) + result = aggregateResult(result, childResult) + } + if (elm.iteration != null) { + val childResult = visitExpression(elm.iteration, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a Count. This method will be called for every node in the tree that is a Count. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitCount(elm: Count, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Sum. This method will be called for every node in the tree that is a Sum. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitSum(elm: Sum, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Product. This method will be called for every node in the tree that is a Product. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitProduct(elm: Product, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a GeometricMean. This method will be called for every node in the tree that is a + * GeometricMean. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitGeometricMean(elm: GeometricMean, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Min. This method will be called for every node in the tree that is a Min. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitMin(elm: Min, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Max. This method will be called for every node in the tree that is a Max. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitMax(elm: Max, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit an Avg. This method will be called for every node in the tree that is an Avg. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitAvg(elm: Avg, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Median. This method will be called for every node in the tree that is a Median. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitMedian(elm: Median, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Mode. This method will be called for every node in the tree that is a Mode. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitMode(elm: Mode, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Variance. This method will be called for every node in the tree that is a Variance. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitVariance(elm: Variance, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a PopulationVariance. This method will be called for every node in the tree that is a + * PopulationVariance. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitPopulationVariance(elm: PopulationVariance, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a StdDev. This method will be called for every node in the tree that is a StdDev. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitStdDev(elm: StdDev, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a PopulationStdDev. This method will be called for every node in the tree that is a + * PopulationStdDev. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitPopulationStdDev(elm: PopulationStdDev, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit an AllTrue. This method will be called for every node in the tree that is an AllTrue. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitAllTrue(elm: AllTrue, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit an AnyTrue. This method will be called for every node in the tree that is an AnyTrue. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitAnyTrue(elm: AnyTrue, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Property. This method will be called for every node in the tree that is a Property. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitProperty(elm: Property, context: C): T? { + var result = visitFields(elm, context) + + if (elm.source != null) { + val childResult = visitExpression(elm.source, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit an AliasedQuerySource. This method will be called for every node in the tree that is an + * AliasedQuerySource. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitAliasedQuerySource(elm: AliasedQuerySource, context: C): T? { + if (elm is RelationshipClause) { + return visitRelationshipClause(elm, context) + } + + return visitFields(elm, context) + } + + /** + * Visit a LetClause. This method will be called for every node in the tree that is a LetClause. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitLetClause(elm: LetClause, context: C): T? { + var result = visitFields(elm, context) + + if (elm.expression != null) { + val childResult = visitExpression(elm.expression, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a RelationshipClause. This method will be called for every node in the tree that is a + * RelationshipClause. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitRelationshipClause(elm: RelationshipClause, context: C): T? { + return when (elm) { + is With -> { + visitWith(elm, context) + } + is Without -> { + visitWithout(elm, context) + } + else -> { + throw IllegalArgumentException( + "Unknown RelationshipClause type: " + elm.javaClass.name + ) + } + } + } + + /** + * Visit a With. This method will be called for every node in the tree that is a With. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitWith(elm: With, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a Without. This method will be called for every node in the tree that is a Without. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitWithout(elm: Without, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a SortByItem. This method will be called for every node in the tree that is a + * SortByItem. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitSortByItem(elm: SortByItem, context: C): T? { + return when (elm) { + is ByDirection -> { + visitByDirection(elm, context) + } + is ByColumn -> { + visitByColumn(elm, context) + } + is ByExpression -> { + visitByExpression(elm, context) + } + else -> throw IllegalArgumentException("Unknown SortByItem type: " + elm.javaClass.name) + } + } + + /** + * Visit a ByDirection. This method will be called for every node in the tree that is a + * ByDirection. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitByDirection(elm: ByDirection, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a ByColumn. This method will be called for every node in the tree that is a ByColumn. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitByColumn(elm: ByColumn, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a ByExpression. This method will be called for every node in the tree that is a + * ByExpression. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitByExpression(elm: ByExpression, context: C): T? { + var result = visitFields(elm, context) + + if (elm.expression != null) { + val childResult = visitExpression(elm.expression, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a SortClause. This method will be called for every node in the tree that is a + * SortClause. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitSortClause(elm: SortClause, context: C): T? { + var result = visitFields(elm, context) + + for (sbi in elm.by) { + val childResult = visitSortByItem(sbi, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit an AggregateClause. This method will be called for every node in the tree that is an + * AggregateClause. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitAggregateClause(elm: AggregateClause, context: C): T? { + var result = visitFields(elm, context) + + if (elm.expression != null) { + val childResult = visitExpression(elm.expression, context) + result = aggregateResult(result, childResult) + } + if (elm.starting != null) { + val childResult = visitExpression(elm.starting, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a ReturnClause. This method will be called for every node in the tree that is a + * ReturnClause. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitReturnClause(elm: ReturnClause, context: C): T? { + var result = visitFields(elm, context) + + if (elm.expression != null) { + val childResult = visitExpression(elm.expression, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit a Query. This method will be called for every node in the tree that is a Query. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitQuery(elm: Query, context: C): T? { + var result = visitFields(elm, context) + + for (source in elm.source) { + val childResult = visitAliasedQuerySource(source, context) + result = aggregateResult(result, childResult) + } + for (let in elm.let) { + val childResult = visitLetClause(let, context) + result = aggregateResult(result, childResult) + } + + for (r in elm.relationship) { + val childResult = visitRelationshipClause(r, context) + result = aggregateResult(result, childResult) + } + + if (elm.where != null) { + val childResult = visitExpression(elm.where, context) + result = aggregateResult(result, childResult) + } + if (elm.getReturn() != null) { + val childResult = visitReturnClause(elm.getReturn(), context) + result = aggregateResult(result, childResult) + } + + if (elm.aggregate != null) { + val childResult = visitAggregateClause(elm.aggregate, context) + result = aggregateResult(result, childResult) + } + + if (elm.sort != null) { + val childResult = visitSortClause(elm.sort, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit an AliasRef. This method will be called for every node in the tree that is an AliasRef. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitAliasRef(elm: AliasRef, context: C): T? { + return visitFields(elm, context) + } + + /** + * Visit a QueryLetRef. This method will be called for every node in the tree that is a + * QueryLetRef. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + override fun visitQueryLetRef(elm: QueryLetRef, context: C): T? { + return visitFields(elm, context) + } + + protected fun visitFields(elm: Element, context: C): T? { + var result = defaultResult(elm, context) + + if (elm.resultTypeSpecifier != null) { + val childResult = visitTypeSpecifier(elm.resultTypeSpecifier, context) + result = aggregateResult(result, childResult) + } + + return result + } + + protected fun visitFields(elm: Expression, context: C): T? { + return visitFields(elm as Element, context) + } + + protected fun visitFields(elm: RelationshipClause, context: C): T? { + var result = visitFields(elm as AliasedQuerySource, context) + + if (elm.suchThat != null) { + val childResult = visitExpression(elm.suchThat, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * visits the fields of an AggregateExpression + * + * @param elm + * @param context + * @return + */ + protected fun visitFields(elm: AggregateExpression, context: C): T? { + var result = visitFields(elm as Expression, context) + + if (elm.source != null) { + val childResult = visitExpression(elm.source, context) + result = aggregateResult(result, childResult) + } + + for (s in elm.signature) { + val childResult = visitTypeSpecifier(s, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visit the fields of an ExpressionDef + * + * @param elm + * @param context + * @return + */ + protected fun visitFields(elm: ExpressionDef, context: C): T? { + var result = visitFields(elm as Element, context) + + if (elm.accessLevel != null) { + val childResult = visitAccessModifier(elm.accessLevel, context) + result = aggregateResult(result, childResult) + } + if (elm.expression != null) { + val childResult = visitExpression(elm.expression, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visits the fields of an UnaryExpression + * + * @param elm + * @param context + * @return + */ + protected fun visitFields(elm: UnaryExpression, context: C): T? { + var result = visitFields(elm as OperatorExpression, context) + + if (elm.operand != null) { + val childResult = visitExpression(elm.operand, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * visits the fields of an NaryExpression + * + * @param elm + * @param context + * @return + */ + protected fun visitFields(elm: NaryExpression, context: C): T? { + var result = visitFields(elm as OperatorExpression, context) + + for (e in elm.operand) { + val childResult = visitExpression(e, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visits the fields of a TernaryExpression + * + * @param elm + * @param context + * @return + */ + protected fun visitFields(elm: TernaryExpression, context: C): T? { + var result = visitFields(elm as OperatorExpression, context) + + for (s in elm.operand) { + val childResult = visitExpression(s, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * Visits the fields of an OperatorExpression + * + * @param elm + * @param context + * @return + */ + protected fun visitFields(elm: OperatorExpression, context: C): T? { + var result = visitFields(elm as Expression, context) + + for (s in elm.signature) { + val childResult = visitTypeSpecifier(s, context) + result = aggregateResult(result, childResult) + } + + return result + } + + /** + * visits the fields of a BinaryExpression + * + * @param elm + * @param context + * @return + */ + protected open fun visitFields(elm: BinaryExpression, context: C): T? { + var result = visitFields(elm as OperatorExpression, context) + + for (e in elm.operand) { + val childResult = visitExpression(e, context) + result = aggregateResult(result, childResult) + } + + return result + } + + protected open fun visitFields(elm: AliasedQuerySource, context: C): T? { + var result = visitFields(elm as Element, context) + + if (elm.expression != null) { + val childResult = visitExpression(elm.expression, context) + result = aggregateResult(result, childResult) + } + + return result + } +} diff --git a/Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/ElmClinicalVisitor.java b/Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/ElmClinicalVisitor.java deleted file mode 100644 index 37bb1a5e0..000000000 --- a/Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/ElmClinicalVisitor.java +++ /dev/null @@ -1,273 +0,0 @@ -package org.cqframework.cql.elm.visiting; - -import org.hl7.elm.r1.*; - -/** - * This interface defines a complete generic visitor for an Elm tree - * - * @param The return type of the visit operation. Use {@link Void} for - * @param The type of context passed to each visit method - * operations with no return type. - */ -public interface ElmClinicalVisitor extends ElmVisitor { - - /** - * Visit a CodeFilterElement. This method will be called for - * every node in the tree that is a CodeFilterElement. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitCodeFilterElement(CodeFilterElement elm, C context); - - /** - * Visit a DateFilterElement. This method will be called for - * every node in the tree that is a DateFilterElement. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitDateFilterElement(DateFilterElement elm, C context); - - /** - * Visit an OtherFilterElement. This method will be called for - * every node in the tree that is an OtherFilterElement. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitOtherFilterElement(OtherFilterElement elm, C context); - - /** - * Visit an IncludeElement. This method will be called for - * every node in the tree that is an IncludeElement. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitIncludeElement(IncludeElement elm, C context); - - /** - * Visit a Retrieve. This method will be called for - * every node in the tree that is a Retrieve. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitRetrieve(Retrieve elm, C context); - - /** - * Visit a Search. This method will be called for - * every node in the tree that is a Search. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitSearch(Search elm, C context); - - /** - * Visit a CodeSystemDef. This method will be called for - * every node in the tree that is a CodeSystemDef. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitCodeSystemDef(CodeSystemDef elm, C context); - - /** - * Visit a ValueSetDef. This method will be called for - * every node in the tree that is a ValueSetDef. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitValueSetDef(ValueSetDef elm, C context); - - /** - * Visit a CodeDef. This method will be called for - * every node in the tree that is a CodeDef. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitCodeDef(CodeDef elm, C context); - - /** - * Visit an ConceptDef. This method will be called for - * every node in the tree that is an ConceptDef. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitConceptDef(ConceptDef elm, C context); - - /** - * Visit a CodeSystemRef. This method will be called for - * every node in the tree that is a CodeSystemRef. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitCodeSystemRef(CodeSystemRef elm, C context); - - /** - * Visit a ValueSetRef. This method will be called for - * every node in the tree that is a ValueSetRef. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitValueSetRef(ValueSetRef elm, C context); - - /** - * Visit a CodeRef. This method will be called for - * every node in the tree that is a CodeRef. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitCodeRef(CodeRef elm, C context); - - /** - * Visit a ConceptRef. This method will be called for - * every node in the tree that is a ConceptRef. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitConceptRef(ConceptRef elm, C context); - - /** - * Visit a Code. This method will be called for - * every node in the tree that is a Code. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitCode(Code elm, C context); - - /** - * Visit a Concept. This method will be called for - * every node in the tree that is a Concept. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitConcept(Concept elm, C context); - - /** - * Visit a InCodeSystem. This method will be called for - * every node in the tree that is a InCodeSystem. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitInCodeSystem(InCodeSystem elm, C context); - - /** - * Visit an AnyInCodeSystem. This method will be called for - * every node in the tree that is an AnyInCodeSystem. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitAnyInCodeSystem(AnyInCodeSystem elm, C context); - - /** - * Visit a InValueSet. This method will be called for - * every node in the tree that is a InValueSet. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitInValueSet(InValueSet elm, C context); - - /** - * Visit an AnyInValueSet. This method will be called for - * every node in the tree that is an AnyInValueSet. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitAnyInValueSet(AnyInValueSet elm, C context); - - /** - * Visit an Subsumes. This method will be called for - * every node in the tree that is an Subsumes. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitSubsumes(Subsumes elm, C context); - - /** - * Visit an SubsumedBy. This method will be called for - * every node in the tree that is an SubsumedBy. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitSubsumedBy(SubsumedBy elm, C context); - - /** - * Visit a Quantity. This method will be called for - * every node in the tree that is a Quantity. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitQuantity(Quantity elm, C context); - - /** - * Visit a Ratio. This method will be called for - * every node in the tree that is a Ratio. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitRatio(Ratio elm, C context); - - /** - * Visit a CalculateAge. This method will be called for - * every node in the tree that is a CalculateAge. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitCalculateAge(CalculateAge elm, C context); - - /** - * Visit a CalculateAgeAt. This method will be called for - * every node in the tree that is a CalculateAgeAt. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitCalculateAgeAt(CalculateAgeAt elm, C context); -} diff --git a/Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/ElmClinicalVisitor.kt b/Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/ElmClinicalVisitor.kt new file mode 100644 index 000000000..1e2648461 --- /dev/null +++ b/Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/ElmClinicalVisitor.kt @@ -0,0 +1,289 @@ +package org.cqframework.cql.elm.visiting + +import org.hl7.elm.r1.AnyInCodeSystem +import org.hl7.elm.r1.AnyInValueSet +import org.hl7.elm.r1.CalculateAge +import org.hl7.elm.r1.CalculateAgeAt +import org.hl7.elm.r1.Code +import org.hl7.elm.r1.CodeDef +import org.hl7.elm.r1.CodeFilterElement +import org.hl7.elm.r1.CodeRef +import org.hl7.elm.r1.CodeSystemDef +import org.hl7.elm.r1.CodeSystemRef +import org.hl7.elm.r1.Concept +import org.hl7.elm.r1.ConceptDef +import org.hl7.elm.r1.ConceptRef +import org.hl7.elm.r1.DateFilterElement +import org.hl7.elm.r1.InCodeSystem +import org.hl7.elm.r1.InValueSet +import org.hl7.elm.r1.IncludeElement +import org.hl7.elm.r1.OtherFilterElement +import org.hl7.elm.r1.Quantity +import org.hl7.elm.r1.Ratio +import org.hl7.elm.r1.Retrieve +import org.hl7.elm.r1.Search +import org.hl7.elm.r1.SubsumedBy +import org.hl7.elm.r1.Subsumes +import org.hl7.elm.r1.ValueSetDef +import org.hl7.elm.r1.ValueSetRef + +/** + * This interface defines a complete generic visitor for an Elm tree + * + * @param The return type of the visit operation. Use [Void] for + * @param The type of context passed to each visit method operations with no return type. + * + */ +@Suppress("TooManyFunctions") +interface ElmClinicalVisitor : ElmVisitor { + /** + * Visit a CodeFilterElement. This method will be called for every node in the tree that is a + * CodeFilterElement. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitCodeFilterElement(elm: CodeFilterElement, context: C): T? + + /** + * Visit a DateFilterElement. This method will be called for every node in the tree that is a + * DateFilterElement. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitDateFilterElement(elm: DateFilterElement, context: C): T? + + /** + * Visit an OtherFilterElement. This method will be called for every node in the tree that is an + * OtherFilterElement. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitOtherFilterElement(elm: OtherFilterElement, context: C): T? + + /** + * Visit an IncludeElement. This method will be called for every node in the tree that is an + * IncludeElement. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitIncludeElement(elm: IncludeElement, context: C): T? + + /** + * Visit a Retrieve. This method will be called for every node in the tree that is a Retrieve. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitRetrieve(elm: Retrieve, context: C): T? + + /** + * Visit a Search. This method will be called for every node in the tree that is a Search. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitSearch(elm: Search, context: C): T? + + /** + * Visit a CodeSystemDef. This method will be called for every node in the tree that is a + * CodeSystemDef. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitCodeSystemDef(elm: CodeSystemDef, context: C): T? + + /** + * Visit a ValueSetDef. This method will be called for every node in the tree that is a + * ValueSetDef. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitValueSetDef(elm: ValueSetDef, context: C): T? + + /** + * Visit a CodeDef. This method will be called for every node in the tree that is a CodeDef. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitCodeDef(elm: CodeDef, context: C): T? + + /** + * Visit an ConceptDef. This method will be called for every node in the tree that is an + * ConceptDef. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitConceptDef(elm: ConceptDef, context: C): T? + + /** + * Visit a CodeSystemRef. This method will be called for every node in the tree that is a + * CodeSystemRef. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitCodeSystemRef(elm: CodeSystemRef, context: C): T? + + /** + * Visit a ValueSetRef. This method will be called for every node in the tree that is a + * ValueSetRef. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitValueSetRef(elm: ValueSetRef, context: C): T? + + /** + * Visit a CodeRef. This method will be called for every node in the tree that is a CodeRef. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitCodeRef(elm: CodeRef, context: C): T? + + /** + * Visit a ConceptRef. This method will be called for every node in the tree that is a + * ConceptRef. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitConceptRef(elm: ConceptRef, context: C): T? + + /** + * Visit a Code. This method will be called for every node in the tree that is a Code. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitCode(elm: Code, context: C): T? + + /** + * Visit a Concept. This method will be called for every node in the tree that is a Concept. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitConcept(elm: Concept, context: C): T? + + /** + * Visit a InCodeSystem. This method will be called for every node in the tree that is a + * InCodeSystem. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitInCodeSystem(elm: InCodeSystem, context: C): T? + + /** + * Visit an AnyInCodeSystem. This method will be called for every node in the tree that is an + * AnyInCodeSystem. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitAnyInCodeSystem(elm: AnyInCodeSystem, context: C): T? + + /** + * Visit a InValueSet. This method will be called for every node in the tree that is a + * InValueSet. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitInValueSet(elm: InValueSet, context: C): T? + + /** + * Visit an AnyInValueSet. This method will be called for every node in the tree that is an + * AnyInValueSet. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitAnyInValueSet(elm: AnyInValueSet, context: C): T? + + /** + * Visit a Subsumes. This method will be called for every node in the tree that is a Subsumes. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitSubsumes(elm: Subsumes, context: C): T? + + /** + * Visit an SubsumedBy. This method will be called for every node in the tree that is an + * SubsumedBy. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitSubsumedBy(elm: SubsumedBy, context: C): T? + + /** + * Visit a Quantity. This method will be called for every node in the tree that is a Quantity. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitQuantity(elm: Quantity, context: C): T? + + /** + * Visit a Ratio. This method will be called for every node in the tree that is a Ratio. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitRatio(elm: Ratio, context: C): T? + + /** + * Visit a CalculateAge. This method will be called for every node in the tree that is a + * CalculateAge. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitCalculateAge(elm: CalculateAge, context: C): T? + + /** + * Visit a CalculateAgeAt. This method will be called for every node in the tree that is a + * CalculateAgeAt. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitCalculateAgeAt(elm: CalculateAgeAt, context: C): T? +} diff --git a/Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/ElmLibraryVisitor.java b/Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/ElmLibraryVisitor.java deleted file mode 100644 index 7059704a0..000000000 --- a/Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/ElmLibraryVisitor.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.cqframework.cql.elm.visiting; - -import org.hl7.elm.r1.*; - -/** - * This interface defines a complete generic visitor for an Elm tree - * - * @param The return type of the visit operation. Use {@link Void} for - * @param The type of context passed to each visit method - * operations with no return type. - */ -public interface ElmLibraryVisitor extends ElmClinicalVisitor { - /** - * Visit a Library. This method will be called for - * every node in the tree that is a Library. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitLibrary(Library elm, C context); - - /** - * Visit a UsingDef. This method will be called for - * every node in the tree that is a UsingDef. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitUsingDef(UsingDef elm, C context); - - /** - * Visit a IncludeDef. This method will be called for - * every node in the tree that is a IncludeDef. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitIncludeDef(IncludeDef elm, C context); - - /** - * Visit a ContextDef. This method will be called for - * every node in the tree that is a ContextDef. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitContextDef(ContextDef elm, C context); -} diff --git a/Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/ElmLibraryVisitor.kt b/Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/ElmLibraryVisitor.kt new file mode 100644 index 000000000..43a2cf443 --- /dev/null +++ b/Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/ElmLibraryVisitor.kt @@ -0,0 +1,54 @@ +package org.cqframework.cql.elm.visiting + +import org.hl7.elm.r1.ContextDef +import org.hl7.elm.r1.IncludeDef +import org.hl7.elm.r1.Library +import org.hl7.elm.r1.UsingDef + +/** + * This interface defines a complete generic visitor for an Elm tree + * + * @param The return type of the visit operation. Use [Void] for + * @param The type of context passed to each visit method operations with no return type. + * + */ +@Suppress("TooManyFunctions") +interface ElmLibraryVisitor : ElmClinicalVisitor { + /** + * Visit a Library. This method will be called for every node in the tree that is a Library. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitLibrary(elm: Library, context: C): T? + + /** + * Visit a UsingDef. This method will be called for every node in the tree that is a UsingDef. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitUsingDef(elm: UsingDef, context: C): T? + + /** + * Visit a IncludeDef. This method will be called for every node in the tree that is a + * IncludeDef. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitIncludeDef(elm: IncludeDef, context: C): T? + + /** + * Visit a ContextDef. This method will be called for every node in the tree that is a + * ContextDef. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitContextDef(elm: ContextDef, context: C): T? +} diff --git a/Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/ElmVisitor.java b/Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/ElmVisitor.java deleted file mode 100644 index 3257634ad..000000000 --- a/Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/ElmVisitor.java +++ /dev/null @@ -1,2142 +0,0 @@ -package org.cqframework.cql.elm.visiting; - -import org.hl7.elm.r1.*; - -/** - * This interface defines a complete generic visitor for an Elm tree - * - * @param The return type of the visit operation. Use {@link Void} for - * @param The type of context passed to each visit method - * operations with no return type. - */ -public interface ElmVisitor { - /** - * Visit an Element in an ELM tree. This method will be called for - * every node in the tree that is a descendant of the Element type. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitElement(Element elm, C context); - - /** - * Visit a TypeSpecifier. This method will be called for every - * node in the tree that is a descendant of the TypeSpecifier type. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitTypeSpecifier(TypeSpecifier elm, C context); - - /** - * Visit a NamedTypeSpecifier. This method will be called for - * every node in the tree that is a NamedTypeSpecifier. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitNamedTypeSpecifier(NamedTypeSpecifier elm, C context); - - /** - * Visit a IntervalTypeSpecifier. This method will be called for - * every node in the tree that is a IntervalTypeSpecifier. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitIntervalTypeSpecifier(IntervalTypeSpecifier elm, C context); - - /** - * Visit a ListTypeSpecifier. This method will be called for - * every node in the tree that is a ListTypeSpecifier. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitListTypeSpecifier(ListTypeSpecifier elm, C context); - - /** - * Visit a TupleElementDefinition. This method will be called for - * every node in the tree that is a TupleElementDefinition. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitTupleElementDefinition(TupleElementDefinition elm, C context); - - /** - * Visit a TupleTypeSpecifier. This method will be called for - * every node in the tree that is a TupleTypeSpecifier. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitTupleTypeSpecifier(TupleTypeSpecifier elm, C context); - - /** - * Visit a ChoiceTypeSpecifier. This method will be called for - * every node in the tree that is a ChoiceTypeSpecifier. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitChoiceTypeSpecifier(ChoiceTypeSpecifier elm, C context); - - /** - * Visit an Expression. This method will be called for - * every node in the tree that is an Expression. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitExpression(Expression elm, C context); - - /** - * Visit a UnaryExpression. This method will be called for - * every node in the tree that is a UnaryExpression. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitUnaryExpression(UnaryExpression elm, C context); - - /** - * Visit an OperatorExpression. This method will be called for - * every node in the tree that is an OperatorExpression. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitOperatorExpression(OperatorExpression elm, C context); - - /** - * Visit a BinaryExpression. This method will be called for - * every node in the tree that is a BinaryExpression. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitBinaryExpression(BinaryExpression elm, C context); - - /** - * Visit a TernaryExpression. This method will be called for - * every node in the tree that is a TernaryExpression. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitTernaryExpression(TernaryExpression elm, C context); - - /** - * Visit a NaryExpression. This method will be called for - * every node in the tree that is a NaryExpression. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitNaryExpression(NaryExpression elm, C context); - - /** - * Visit a ExpressionDef. This method will be called for - * every node in the tree that is a ExpressionDef. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitExpressionDef(ExpressionDef elm, C context); - - /** - * Visit a FunctionDef. This method will be called for - * every node in the tree that is a FunctionDef. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitFunctionDef(FunctionDef elm, C context); - - /** - * Visit a ExpressionRef. This method will be called for - * every node in the tree that is a ExpressionRef. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitExpressionRef(ExpressionRef elm, C context); - - /** - * Visit a FunctionRef. This method will be called for - * every node in the tree that is a FunctionRef. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitFunctionRef(FunctionRef elm, C context); - - /** - * Visit a ParameterDef. This method will be called for - * every node in the tree that is a ParameterDef. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitParameterDef(ParameterDef elm, C context); - - /** - * Visit a ParameterRef. This method will be called for - * every node in the tree that is a ParameterRef. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitParameterRef(ParameterRef elm, C context); - - /** - * Visit a OperandDef. This method will be called for - * every node in the tree that is a OperandDef. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitOperandDef(OperandDef elm, C context); - - /** - * Visit a OperandRef. This method will be called for - * every node in the tree that is a OperandRef. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitOperandRef(OperandRef elm, C context); - - /** - * Visit a IdentifierRef. This method will be called for - * every node in the tree that is a IdentifierRef. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitIdentifierRef(IdentifierRef elm, C context); - - /** - * Visit a Literal. This method will be called for - * every node in the tree that is a Literal. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitLiteral(Literal elm, C context); - - /** - * Visit a TupleElement. This method will be called for - * every node in the tree that is a TupleElement. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitTupleElement(TupleElement elm, C context); - - /** - * Visit a Tuple. This method will be called for - * every node in the tree that is a Tuple. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitTuple(Tuple elm, C context); - - /** - * Visit a InstanceElement. This method will be called for - * every node in the tree that is a InstanceElement. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitInstanceElement(InstanceElement elm, C context); - - /** - * Visit a Instance. This method will be called for - * every node in the tree that is a Instance. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitInstance(Instance elm, C context); - - /** - * Visit a Interval. This method will be called for - * every node in the tree that is a Interval. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitInterval(Interval elm, C context); - - /** - * Visit a List. This method will be called for - * every node in the tree that is a List. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitList(List elm, C context); - - /** - * Visit a And. This method will be called for - * every node in the tree that is a And. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitAnd(And elm, C context); - - /** - * Visit a Or. This method will be called for - * every node in the tree that is a Or. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitOr(Or elm, C context); - - /** - * Visit a Xor. This method will be called for - * every node in the tree that is a Xor. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitXor(Xor elm, C context); - - /** - * Visit a Implies. This method will be called for - * every node in the tree that is a Implies. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitImplies(Implies elm, C context); - - /** - * Visit a Not. This method will be called for - * every node in the tree that is a Not. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitNot(Not elm, C context); - - /** - * Visit a If. This method will be called for - * every node in the tree that is a If. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitIf(If elm, C context); - - /** - * Visit a CaseItem. This method will be called for - * every node in the tree that is a CaseItem. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitCaseItem(CaseItem elm, C context); - - /** - * Visit a Case. This method will be called for - * every node in the tree that is a Case. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitCase(Case elm, C context); - - /** - * Visit a Null. This method will be called for - * every node in the tree that is a Null. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitNull(Null elm, C context); - - /** - * Visit a IsNull. This method will be called for - * every node in the tree that is a IsNull. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitIsNull(IsNull elm, C context); - - /** - * Visit a IsTrue. This method will be called for - * every node in the tree that is a IsTrue. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitIsTrue(IsTrue elm, C context); - - /** - * Visit a IsFalse. This method will be called for - * every node in the tree that is a IsFalse. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitIsFalse(IsFalse elm, C context); - - /** - * Visit a Coalesce. This method will be called for - * every node in the tree that is a Coalesce. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitCoalesce(Coalesce elm, C context); - - /** - * Visit a Is. This method will be called for - * every node in the tree that is a Is. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitIs(Is elm, C context); - - /** - * Visit a As. This method will be called for - * every node in the tree that is a As. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitAs(As elm, C context); - - /** - * Visit a Convert. This method will be called for - * every node in the tree that is a Convert. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitConvert(Convert elm, C context); - - /** - * Visit a CanConvert. This method will be called for - * every node in the tree that is a CanConvert. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitCanConvert(CanConvert elm, C context); - - /** - * Visit a ConvertsToBoolean. This method will be called for - * every node in the tree that is a ConvertsToBoolean. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitConvertsToBoolean(ConvertsToBoolean elm, C context); - - /** - * Visit a ToBoolean. This method will be called for - * every node in the tree that is a ToBoolean. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitToBoolean(ToBoolean elm, C context); - - /** - * Visit a ToChars. This method will be called for - * every node in the tree that is a ToChars. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitToChars(ToChars elm, C context); - - /** - * Visit a ToConcept. This method will be called for - * every node in the tree that is a ToConcept. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitToConcept(ToConcept elm, C context); - - /** - * Visit a ConvertsToDate. This method will be called for - * every node in the tree that is a ConvertsToDate. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitConvertsToDate(ConvertsToDate elm, C context); - - /** - * Visit a ToDate. This method will be called for - * every node in the tree that is a ToDate. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitToDate(ToDate elm, C context); - - /** - * Visit a ConvertsToDateTime. This method will be called for - * every node in the tree that is a ConvertsToDateTime. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitConvertsToDateTime(ConvertsToDateTime elm, C context); - - /** - * Visit a ToDateTime. This method will be called for - * every node in the tree that is a ToDateTime. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitToDateTime(ToDateTime elm, C context); - - /** - * Visit a ConvertsToLong. This method will be called for - * every node in the tree that is a ConvertsToLong. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitConvertsToLong(ConvertsToLong elm, C context); - - /** - * Visit a ToLong. This method will be called for - * every node in the tree that is a ToLong. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitToLong(ToLong elm, C context); - - /** - * Visit a ConvertsToDecimal. This method will be called for - * every node in the tree that is a ConvertsToDecimal. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitConvertsToDecimal(ConvertsToDecimal elm, C context); - - /** - * Visit a ToDecimal. This method will be called for - * every node in the tree that is a ToDecimal. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitToDecimal(ToDecimal elm, C context); - - /** - * Visit a ConvertsToInteger. This method will be called for - * every node in the tree that is a ConvertsToInteger. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitConvertsToInteger(ConvertsToInteger elm, C context); - - /** - * Visit a ToInteger. This method will be called for - * every node in the tree that is a ToInteger. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitToInteger(ToInteger elm, C context); - - /** - * Visit a ToList. This method will be called for - * every node in the tree that is a ToList. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitToList(ToList elm, C context); - - /** - * Visit a ConvertQuantity. This method will be called for - * every node in the tree that is a ConvertQuantity. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitConvertQuantity(ConvertQuantity elm, C context); - - /** - * Visit a CanConvertQuantity. This method will be called for - * every node in the tree that is a CanConvertQuantity. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitCanConvertQuantity(CanConvertQuantity elm, C context); - - /** - * Visit a ConvertsToQuantity. This method will be called for - * every node in the tree that is a ConvertsToQuantity. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitConvertsToQuantity(ConvertsToQuantity elm, C context); - - /** - * Visit a ToQuantity. This method will be called for - * every node in the tree that is a ToQuantity. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitToQuantity(ToQuantity elm, C context); - - /** - * Visit a ConvertsToRatio. This method will be called for - * every node in the tree that is a ConvertsToRatio. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitConvertsToRatio(ConvertsToRatio elm, C context); - - /** - * Visit a Ratio. This method will be called for - * every node in the tree that is a Ratio. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitToRatio(ToRatio elm, C context); - - /** - * Visit a ConvertsToString. This method will be called for - * every node in the tree that is a ConvertsToString. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitConvertsToString(ConvertsToString elm, C context); - - /** - * Visit a ToString. This method will be called for - * every node in the tree that is a ToString. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitToString(ToString elm, C context); - - /** - * Visit a ConvertsToTime. This method will be called for - * every node in the tree that is a ConvertsToTime. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitConvertsToTime(ConvertsToTime elm, C context); - - /** - * Visit a ToTime. This method will be called for - * every node in the tree that is a ToTime. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitToTime(ToTime elm, C context); - - /** - * Visit a Equal. This method will be called for - * every node in the tree that is a Equal. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitEqual(Equal elm, C context); - - /** - * Visit a Equivalent. This method will be called for - * every node in the tree that is a Equivalent. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitEquivalent(Equivalent elm, C context); - - /** - * Visit a NotEqual. This method will be called for - * every node in the tree that is a NotEqual. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitNotEqual(NotEqual elm, C context); - - /** - * Visit a Less. This method will be called for - * every node in the tree that is a Less. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitLess(Less elm, C context); - - /** - * Visit a Greater. This method will be called for - * every node in the tree that is a Greater. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitGreater(Greater elm, C context); - - /** - * Visit a LessOrEqual. This method will be called for - * every node in the tree that is a LessOrEqual. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitLessOrEqual(LessOrEqual elm, C context); - - /** - * Visit a GreaterOrEqual. This method will be called for - * every node in the tree that is a GreaterOrEqual. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitGreaterOrEqual(GreaterOrEqual elm, C context); - - /** - * Visit a Add. This method will be called for - * every node in the tree that is a Add. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitAdd(Add elm, C context); - - /** - * Visit a Subtract. This method will be called for - * every node in the tree that is a Subtract. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitSubtract(Subtract elm, C context); - - /** - * Visit a Multiply. This method will be called for - * every node in the tree that is a Multiply. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitMultiply(Multiply elm, C context); - - /** - * Visit a Divide. This method will be called for - * every node in the tree that is a Divide. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitDivide(Divide elm, C context); - - /** - * Visit a TruncatedDivide. This method will be called for - * every node in the tree that is a TruncatedDivide. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitTruncatedDivide(TruncatedDivide elm, C context); - - /** - * Visit a Modulo. This method will be called for - * every node in the tree that is a Modulo. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitModulo(Modulo elm, C context); - - /** - * Visit a Ceiling. This method will be called for - * every node in the tree that is a Ceiling. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitCeiling(Ceiling elm, C context); - - /** - * Visit a Floor. This method will be called for - * every node in the tree that is a Floor. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitFloor(Floor elm, C context); - - /** - * Visit a Truncate. This method will be called for - * every node in the tree that is a Truncate. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitTruncate(Truncate elm, C context); - - /** - * Visit a Abs. This method will be called for - * every node in the tree that is a Abs. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitAbs(Abs elm, C context); - - /** - * Visit a Negate. This method will be called for - * every node in the tree that is a Negate. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitNegate(Negate elm, C context); - - /** - * Visit a Round. This method will be called for - * every node in the tree that is a Round. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitRound(Round elm, C context); - - /** - * Visit a Ln. This method will be called for - * every node in the tree that is a Ln. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitLn(Ln elm, C context); - - /** - * Visit a Exp. This method will be called for - * every node in the tree that is a Exp. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitExp(Exp elm, C context); - - /** - * Visit a Log. This method will be called for - * every node in the tree that is a Log. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitLog(Log elm, C context); - - /** - * Visit a Power. This method will be called for - * every node in the tree that is a Power. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitPower(Power elm, C context); - - /** - * Visit a Successor. This method will be called for - * every node in the tree that is a Successor. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitSuccessor(Successor elm, C context); - - /** - * Visit a Predecessor. This method will be called for - * every node in the tree that is a Predecessor. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitPredecessor(Predecessor elm, C context); - - /** - * Visit a MinValue. This method will be called for - * every node in the tree that is a MinValue. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitMinValue(MinValue elm, C context); - - /** - * Visit a MaxValue. This method will be called for - * every node in the tree that is a MaxValue. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitMaxValue(MaxValue elm, C context); - - /** - * Visit a Precision. This method will be called for - * every node in the tree that is a Precision. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitPrecision(Precision elm, C context); - - /** - * Visit a LowBoundary. This method will be called for - * every node in the tree that is a LowBoundary. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitLowBoundary(LowBoundary elm, C context); - - /** - * Visit a HighBoundary. This method will be called for - * every node in the tree that is a HighBoundary. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitHighBoundary(HighBoundary elm, C context); - - /** - * Visit a Concatenate. This method will be called for - * every node in the tree that is a Concatenate. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitConcatenate(Concatenate elm, C context); - - /** - * Visit a Combine. This method will be called for - * every node in the tree that is a Combine. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitCombine(Combine elm, C context); - - /** - * Visit a Split. This method will be called for - * every node in the tree that is a Split. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitSplit(Split elm, C context); - - /** - * Visit a SplitOnMatches. This method will be called for - * every node in the tree that is a SplitOnMatches. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitSplitOnMatches(SplitOnMatches elm, C context); - - /** - * Visit a Length. This method will be called for - * every node in the tree that is a Length. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitLength(Length elm, C context); - - /** - * Visit a Upper. This method will be called for - * every node in the tree that is a Upper. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitUpper(Upper elm, C context); - - /** - * Visit a Lower. This method will be called for - * every node in the tree that is a Lower. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitLower(Lower elm, C context); - - /** - * Visit a Indexer. This method will be called for - * every node in the tree that is a Indexer. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitIndexer(Indexer elm, C context); - - /** - * Visit a PositionOf. This method will be called for - * every node in the tree that is a PositionOf. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitPositionOf(PositionOf elm, C context); - - /** - * Visit a LastPositionOf. This method will be called for - * every node in the tree that is a LastPositionOf. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitLastPositionOf(LastPositionOf elm, C context); - - /** - * Visit a Substring. This method will be called for - * every node in the tree that is a Substring. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitSubstring(Substring elm, C context); - - /** - * Visit a StartsWith. This method will be called for - * every node in the tree that is a StartsWith. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitStartsWith(StartsWith elm, C context); - - /** - * Visit a EndsWith. This method will be called for - * every node in the tree that is a EndsWith. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitEndsWith(EndsWith elm, C context); - - /** - * Visit a Matches. This method will be called for - * every node in the tree that is a Matches. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitMatches(Matches elm, C context); - - /** - * Visit a ReplaceMatches. This method will be called for - * every node in the tree that is a ReplaceMatches. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitReplaceMatches(ReplaceMatches elm, C context); - - /** - * Visit a DurationBetween. This method will be called for - * every node in the tree that is a DurationBetween. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitDurationBetween(DurationBetween elm, C context); - - /** - * Visit a DifferenceBetween. This method will be called for - * every node in the tree that is a DifferenceBetween. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitDifferenceBetween(DifferenceBetween elm, C context); - - /** - * Visit a DateFrom. This method will be called for - * every node in the tree that is a DateFrom. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitDateFrom(DateFrom elm, C context); - - /** - * Visit a TimeFrom. This method will be called for - * every node in the tree that is a TimeFrom. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitTimeFrom(TimeFrom elm, C context); - - /** - * Visit a TimezoneFrom. This method will be called for - * every node in the tree that is a TimezoneFrom. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitTimezoneFrom(TimezoneFrom elm, C context); - - /** - * Visit a TimezoneOffsetFrom. This method will be called for - * every node in the tree that is a TimezoneOffsetFrom. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitTimezoneOffsetFrom(TimezoneOffsetFrom elm, C context); - - /** - * Visit a DateTimeComponentFrom. This method will be called for - * every node in the tree that is a DateTimeComponentFrom. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitDateTimeComponentFrom(DateTimeComponentFrom elm, C context); - - /** - * Visit a TimeOfDay. This method will be called for - * every node in the tree that is a TimeOfDay. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitTimeOfDay(TimeOfDay elm, C context); - - /** - * Visit a Today. This method will be called for - * every node in the tree that is a Today. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitToday(Today elm, C context); - - /** - * Visit a Now. This method will be called for - * every node in the tree that is a Now. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitNow(Now elm, C context); - - /** - * Visit a DateTime. This method will be called for - * every node in the tree that is a DateTime. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitDateTime(DateTime elm, C context); - - /** - * Visit a Date. This method will be called for - * every node in the tree that is a Date. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitDate(Date elm, C context); - - /** - * Visit a Time. This method will be called for - * every node in the tree that is a Time. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitTime(Time elm, C context); - - /** - * Visit a SameAs. This method will be called for - * every node in the tree that is a SameAs. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitSameAs(SameAs elm, C context); - - /** - * Visit a SameOrBefore. This method will be called for - * every node in the tree that is a SameOrBefore. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitSameOrBefore(SameOrBefore elm, C context); - - /** - * Visit a SameOrAfter. This method will be called for - * every node in the tree that is a SameOrAfter. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitSameOrAfter(SameOrAfter elm, C context); - - /** - * Visit a Width. This method will be called for - * every node in the tree that is a Width. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitWidth(Width elm, C context); - - /** - * Visit a Size. This method will be called for - * every node in the tree that is a Size. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitSize(Size elm, C context); - - /** - * Visit a PointFrom. This method will be called for - * every node in the tree that is a PointFrom. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - public T visitPointFrom(PointFrom elm, C context); - - /** - * Visit a Start. This method will be called for - * every node in the tree that is a Start. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitStart(Start elm, C context); - - /** - * Visit a End. This method will be called for - * every node in the tree that is a End. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitEnd(End elm, C context); - - /** - * Visit a Contains. This method will be called for - * every node in the tree that is a Contains. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitContains(Contains elm, C context); - - /** - * Visit a ProperContains. This method will be called for - * every node in the tree that is a ProperContains. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitProperContains(ProperContains elm, C context); - - /** - * Visit a In. This method will be called for - * every node in the tree that is a In. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitIn(In elm, C context); - - /** - * Visit a ProperIn. This method will be called for - * every node in the tree that is a ProperIn. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitProperIn(ProperIn elm, C context); - - /** - * Visit a Includes. This method will be called for - * every node in the tree that is a Includes. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitIncludes(Includes elm, C context); - - /** - * Visit a IncludedIn. This method will be called for - * every node in the tree that is a IncludedIn. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitIncludedIn(IncludedIn elm, C context); - - /** - * Visit a ProperIncludes. This method will be called for - * every node in the tree that is a ProperIncludes. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitProperIncludes(ProperIncludes elm, C context); - - /** - * Visit a ProperIncludedIn. This method will be called for - * every node in the tree that is a ProperIncludedIn. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitProperIncludedIn(ProperIncludedIn elm, C context); - - /** - * Visit a Before. This method will be called for - * every node in the tree that is a Before. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitBefore(Before elm, C context); - - /** - * Visit a After. This method will be called for - * every node in the tree that is a After. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitAfter(After elm, C context); - - /** - * Visit a Meets. This method will be called for - * every node in the tree that is a Meets. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitMeets(Meets elm, C context); - - /** - * Visit a MeetsBefore. This method will be called for - * every node in the tree that is a MeetsBefore. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitMeetsBefore(MeetsBefore elm, C context); - - /** - * Visit a MeetsAfter. This method will be called for - * every node in the tree that is a MeetsAfter. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitMeetsAfter(MeetsAfter elm, C context); - - /** - * Visit a Overlaps. This method will be called for - * every node in the tree that is a Overlaps. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitOverlaps(Overlaps elm, C context); - - /** - * Visit a OverlapsBefore. This method will be called for - * every node in the tree that is a OverlapsBefore. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitOverlapsBefore(OverlapsBefore elm, C context); - - /** - * Visit a OverlapsAfter. This method will be called for - * every node in the tree that is a OverlapsAfter. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitOverlapsAfter(OverlapsAfter elm, C context); - - /** - * Visit a Starts. This method will be called for - * every node in the tree that is a Starts. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitStarts(Starts elm, C context); - - /** - * Visit a Ends. This method will be called for - * every node in the tree that is a Ends. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitEnds(Ends elm, C context); - - /** - * Visit a Collapse. This method will be called for - * every node in the tree that is a Collapse. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitCollapse(Collapse elm, C context); - - /** - * Visit a Expand. This method will be called for - * every node in the tree that is a Expand. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitExpand(Expand elm, C context); - - /** - * Visit a Union. This method will be called for - * every node in the tree that is a Union. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitUnion(Union elm, C context); - - /** - * Visit a Intersect. This method will be called for - * every node in the tree that is a Intersect. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitIntersect(Intersect elm, C context); - - /** - * Visit a Except. This method will be called for - * every node in the tree that is a Except. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitExcept(Except elm, C context); - - /** - * Visit a Literal. This method will be called for - * every node in the tree that is a Literal. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitExists(Exists elm, C context); - - /** - * Visit a Times. This method will be called for - * every node in the tree that is a Times. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitTimes(Times elm, C context); - - /** - * Visit a Filter. This method will be called for - * every node in the tree that is a Filter. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitFilter(Filter elm, C context); - - /** - * Visit a First. This method will be called for - * every node in the tree that is a First. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitFirst(First elm, C context); - - /** - * Visit a Last. This method will be called for - * every node in the tree that is a Last. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitLast(Last elm, C context); - - /** - * Visit a Slice. This method will be called for - * every node in the tree that is a Slice. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitSlice(Slice elm, C context); - - /** - * Visit a Children. This method will be called for - * every node in the tree that is a Children. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitChildren(Children elm, C context); - - /** - * Visit a Descendents. This method will be called for - * every node in the tree that is a Descendents. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitDescendents(Descendents elm, C context); - - /** - * Visit a Message. This method will be called for - * every node in the tree that is a Message. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitMessage(Message elm, C context); - - /** - * Visit a IndexOf. This method will be called for - * every node in the tree that is a IndexOf. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitIndexOf(IndexOf elm, C context); - - /** - * Visit a Flatten. This method will be called for - * every node in the tree that is a Flatten. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitFlatten(Flatten elm, C context); - - /** - * Visit a Sort. This method will be called for - * every node in the tree that is a Sort. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitSort(Sort elm, C context); - - /** - * Visit a ForEach. This method will be called for - * every node in the tree that is a ForEach. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitForEach(ForEach elm, C context); - - /** - * Visit a Repeat. This method will be called for - * every node in the tree that is a Repeat. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitRepeat(Repeat elm, C context); - - /** - * Visit a Distinct. This method will be called for - * every node in the tree that is a Distinct. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitDistinct(Distinct elm, C context); - - /** - * Visit a Current. This method will be called for - * every node in the tree that is a Current. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitCurrent(Current elm, C context); - - /** - * Visit an Iteration. This method will be called for - * every node in the tree that is an Iteration. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitIteration(Iteration elm, C context); - - /** - * Visit a Total. This method will be called for - * every node in the tree that is a Total. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitTotal(Total elm, C context); - - /** - * Visit a SingletonFrom. This method will be called for - * every node in the tree that is a SingletonFrom. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitSingletonFrom(SingletonFrom elm, C context); - - /** - * Visit a AggregateExpression. This method will be called for - * every node in the tree that is a AggregateExpression. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitAggregateExpression(AggregateExpression elm, C context); - - /** - * Visit an Aggregate. This method will be called for - * every node in the tree that is an Aggregate. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitAggregate(Aggregate elm, C context); - - /** - * Visit a Count. This method will be called for - * every node in the tree that is a Count. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitCount(Count elm, C context); - - /** - * Visit a Sum. This method will be called for - * every node in the tree that is a Sum. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitSum(Sum elm, C context); - - /** - * Visit a Product. This method will be called for - * every node in the tree that is a Product. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitProduct(Product elm, C context); - - /** - * Visit a GeometricMean. This method will be called for - * every node in the tree that is a GeometricMean. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitGeometricMean(GeometricMean elm, C context); - - /** - * Visit a Min. This method will be called for - * every node in the tree that is a Min. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitMin(Min elm, C context); - - /** - * Visit a Max. This method will be called for - * every node in the tree that is a Max. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitMax(Max elm, C context); - - /** - * Visit a Avg. This method will be called for - * every node in the tree that is a Avg. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitAvg(Avg elm, C context); - - /** - * Visit a Median. This method will be called for - * every node in the tree that is a Median. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitMedian(Median elm, C context); - - /** - * Visit a Mode. This method will be called for - * every node in the tree that is a Mode. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitMode(Mode elm, C context); - - /** - * Visit a Variance. This method will be called for - * every node in the tree that is a Variance. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitVariance(Variance elm, C context); - - /** - * Visit a PopulationVariance. This method will be called for - * every node in the tree that is a PopulationVariance. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitPopulationVariance(PopulationVariance elm, C context); - - /** - * Visit a StdDev. This method will be called for - * every node in the tree that is a StdDev. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitStdDev(StdDev elm, C context); - - /** - * Visit a PopulationStdDev. This method will be called for - * every node in the tree that is a PopulationStdDev. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitPopulationStdDev(PopulationStdDev elm, C context); - - /** - * Visit a AllTrue. This method will be called for - * every node in the tree that is a AllTrue. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitAllTrue(AllTrue elm, C context); - - /** - * Visit a AnyTrue. This method will be called for - * every node in the tree that is a AnyTrue. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitAnyTrue(AnyTrue elm, C context); - - /** - * Visit a Property. This method will be called for - * every node in the tree that is a Property. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitProperty(Property elm, C context); - - /** - * Visit a AliasedQuerySource. This method will be called for - * every node in the tree that is a AliasedQuerySource. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitAliasedQuerySource(AliasedQuerySource elm, C context); - - /** - * Visit a LetClause. This method will be called for - * every node in the tree that is a LetClause. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitLetClause(LetClause elm, C context); - - /** - * Visit a RelationshipClause. This method will be called for - * every node in the tree that is a RelationshipClause. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitRelationshipClause(RelationshipClause elm, C context); - - /** - * Visit a With. This method will be called for - * every node in the tree that is a With. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitWith(With elm, C context); - - /** - * Visit a Without. This method will be called for - * every node in the tree that is a Without. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitWithout(Without elm, C context); - - /** - * Visit a SortByItem. This method will be called for - * every node in the tree that is a SortByItem. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitSortByItem(SortByItem elm, C context); - - /** - * Visit a ByDirection. This method will be called for - * every node in the tree that is a ByDirection. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitByDirection(ByDirection elm, C context); - - /** - * Visit a ByColumn. This method will be called for - * every node in the tree that is a ByColumn. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitByColumn(ByColumn elm, C context); - - /** - * Visit a ByExpression. This method will be called for - * every node in the tree that is a ByExpression. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitByExpression(ByExpression elm, C context); - - /** - * Visit a SortClause. This method will be called for - * every node in the tree that is a SortClause. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitSortClause(SortClause elm, C context); - - /** - * Visit a AggregateClause. This method will be called for - * every node in the tree that is an AggregateClause. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitAggregateClause(AggregateClause elm, C context); - - /** - * Visit a ReturnClause. This method will be called for - * every node in the tree that is a ReturnClause. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitReturnClause(ReturnClause elm, C context); - - /** - * Visit a Query. This method will be called for - * every node in the tree that is a Query. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitQuery(Query elm, C context); - - /** - * Visit a AliasRef. This method will be called for - * every node in the tree that is a AliasRef. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitAliasRef(AliasRef elm, C context); - - /** - * Visit a QueryLetRef. This method will be called for - * every node in the tree that is a QueryLetRef. - * - * @param elm the ELM tree - * @param context the context passed to the visitor - * @return the visitor result - */ - T visitQueryLetRef(QueryLetRef elm, C context); -} diff --git a/Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/ElmVisitor.kt b/Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/ElmVisitor.kt new file mode 100644 index 000000000..77012ec73 --- /dev/null +++ b/Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/ElmVisitor.kt @@ -0,0 +1,2228 @@ +package org.cqframework.cql.elm.visiting + +import org.hl7.elm.r1.Abs +import org.hl7.elm.r1.Add +import org.hl7.elm.r1.After +import org.hl7.elm.r1.Aggregate +import org.hl7.elm.r1.AggregateClause +import org.hl7.elm.r1.AggregateExpression +import org.hl7.elm.r1.AliasRef +import org.hl7.elm.r1.AliasedQuerySource +import org.hl7.elm.r1.AllTrue +import org.hl7.elm.r1.And +import org.hl7.elm.r1.AnyTrue +import org.hl7.elm.r1.As +import org.hl7.elm.r1.Avg +import org.hl7.elm.r1.Before +import org.hl7.elm.r1.BinaryExpression +import org.hl7.elm.r1.ByColumn +import org.hl7.elm.r1.ByDirection +import org.hl7.elm.r1.ByExpression +import org.hl7.elm.r1.CanConvert +import org.hl7.elm.r1.CanConvertQuantity +import org.hl7.elm.r1.Case +import org.hl7.elm.r1.CaseItem +import org.hl7.elm.r1.Ceiling +import org.hl7.elm.r1.Children +import org.hl7.elm.r1.ChoiceTypeSpecifier +import org.hl7.elm.r1.Coalesce +import org.hl7.elm.r1.Collapse +import org.hl7.elm.r1.Combine +import org.hl7.elm.r1.Concatenate +import org.hl7.elm.r1.Contains +import org.hl7.elm.r1.Convert +import org.hl7.elm.r1.ConvertQuantity +import org.hl7.elm.r1.ConvertsToBoolean +import org.hl7.elm.r1.ConvertsToDate +import org.hl7.elm.r1.ConvertsToDateTime +import org.hl7.elm.r1.ConvertsToDecimal +import org.hl7.elm.r1.ConvertsToInteger +import org.hl7.elm.r1.ConvertsToLong +import org.hl7.elm.r1.ConvertsToQuantity +import org.hl7.elm.r1.ConvertsToRatio +import org.hl7.elm.r1.ConvertsToString +import org.hl7.elm.r1.ConvertsToTime +import org.hl7.elm.r1.Count +import org.hl7.elm.r1.Current +import org.hl7.elm.r1.Date +import org.hl7.elm.r1.DateFrom +import org.hl7.elm.r1.DateTime +import org.hl7.elm.r1.DateTimeComponentFrom +import org.hl7.elm.r1.Descendents +import org.hl7.elm.r1.DifferenceBetween +import org.hl7.elm.r1.Distinct +import org.hl7.elm.r1.Divide +import org.hl7.elm.r1.DurationBetween +import org.hl7.elm.r1.Element +import org.hl7.elm.r1.End +import org.hl7.elm.r1.Ends +import org.hl7.elm.r1.EndsWith +import org.hl7.elm.r1.Equal +import org.hl7.elm.r1.Equivalent +import org.hl7.elm.r1.Except +import org.hl7.elm.r1.Exists +import org.hl7.elm.r1.Exp +import org.hl7.elm.r1.Expand +import org.hl7.elm.r1.Expression +import org.hl7.elm.r1.ExpressionDef +import org.hl7.elm.r1.ExpressionRef +import org.hl7.elm.r1.Filter +import org.hl7.elm.r1.First +import org.hl7.elm.r1.Flatten +import org.hl7.elm.r1.Floor +import org.hl7.elm.r1.ForEach +import org.hl7.elm.r1.FunctionDef +import org.hl7.elm.r1.FunctionRef +import org.hl7.elm.r1.GeometricMean +import org.hl7.elm.r1.Greater +import org.hl7.elm.r1.GreaterOrEqual +import org.hl7.elm.r1.HighBoundary +import org.hl7.elm.r1.IdentifierRef +import org.hl7.elm.r1.If +import org.hl7.elm.r1.Implies +import org.hl7.elm.r1.In +import org.hl7.elm.r1.IncludedIn +import org.hl7.elm.r1.Includes +import org.hl7.elm.r1.IndexOf +import org.hl7.elm.r1.Indexer +import org.hl7.elm.r1.Instance +import org.hl7.elm.r1.InstanceElement +import org.hl7.elm.r1.Intersect +import org.hl7.elm.r1.Interval +import org.hl7.elm.r1.IntervalTypeSpecifier +import org.hl7.elm.r1.Is +import org.hl7.elm.r1.IsFalse +import org.hl7.elm.r1.IsNull +import org.hl7.elm.r1.IsTrue +import org.hl7.elm.r1.Iteration +import org.hl7.elm.r1.Last +import org.hl7.elm.r1.LastPositionOf +import org.hl7.elm.r1.Length +import org.hl7.elm.r1.Less +import org.hl7.elm.r1.LessOrEqual +import org.hl7.elm.r1.LetClause +import org.hl7.elm.r1.List +import org.hl7.elm.r1.ListTypeSpecifier +import org.hl7.elm.r1.Literal +import org.hl7.elm.r1.Ln +import org.hl7.elm.r1.Log +import org.hl7.elm.r1.LowBoundary +import org.hl7.elm.r1.Lower +import org.hl7.elm.r1.Matches +import org.hl7.elm.r1.Max +import org.hl7.elm.r1.MaxValue +import org.hl7.elm.r1.Median +import org.hl7.elm.r1.Meets +import org.hl7.elm.r1.MeetsAfter +import org.hl7.elm.r1.MeetsBefore +import org.hl7.elm.r1.Message +import org.hl7.elm.r1.Min +import org.hl7.elm.r1.MinValue +import org.hl7.elm.r1.Mode +import org.hl7.elm.r1.Modulo +import org.hl7.elm.r1.Multiply +import org.hl7.elm.r1.NamedTypeSpecifier +import org.hl7.elm.r1.NaryExpression +import org.hl7.elm.r1.Negate +import org.hl7.elm.r1.Not +import org.hl7.elm.r1.NotEqual +import org.hl7.elm.r1.Now +import org.hl7.elm.r1.Null +import org.hl7.elm.r1.OperandDef +import org.hl7.elm.r1.OperandRef +import org.hl7.elm.r1.OperatorExpression +import org.hl7.elm.r1.Or +import org.hl7.elm.r1.Overlaps +import org.hl7.elm.r1.OverlapsAfter +import org.hl7.elm.r1.OverlapsBefore +import org.hl7.elm.r1.ParameterDef +import org.hl7.elm.r1.ParameterRef +import org.hl7.elm.r1.PointFrom +import org.hl7.elm.r1.PopulationStdDev +import org.hl7.elm.r1.PopulationVariance +import org.hl7.elm.r1.PositionOf +import org.hl7.elm.r1.Power +import org.hl7.elm.r1.Precision +import org.hl7.elm.r1.Predecessor +import org.hl7.elm.r1.Product +import org.hl7.elm.r1.ProperContains +import org.hl7.elm.r1.ProperIn +import org.hl7.elm.r1.ProperIncludedIn +import org.hl7.elm.r1.ProperIncludes +import org.hl7.elm.r1.Property +import org.hl7.elm.r1.Query +import org.hl7.elm.r1.QueryLetRef +import org.hl7.elm.r1.RelationshipClause +import org.hl7.elm.r1.Repeat +import org.hl7.elm.r1.ReplaceMatches +import org.hl7.elm.r1.ReturnClause +import org.hl7.elm.r1.Round +import org.hl7.elm.r1.SameAs +import org.hl7.elm.r1.SameOrAfter +import org.hl7.elm.r1.SameOrBefore +import org.hl7.elm.r1.SingletonFrom +import org.hl7.elm.r1.Size +import org.hl7.elm.r1.Slice +import org.hl7.elm.r1.Sort +import org.hl7.elm.r1.SortByItem +import org.hl7.elm.r1.SortClause +import org.hl7.elm.r1.Split +import org.hl7.elm.r1.SplitOnMatches +import org.hl7.elm.r1.Start +import org.hl7.elm.r1.Starts +import org.hl7.elm.r1.StartsWith +import org.hl7.elm.r1.StdDev +import org.hl7.elm.r1.Substring +import org.hl7.elm.r1.Subtract +import org.hl7.elm.r1.Successor +import org.hl7.elm.r1.Sum +import org.hl7.elm.r1.TernaryExpression +import org.hl7.elm.r1.Time +import org.hl7.elm.r1.TimeFrom +import org.hl7.elm.r1.TimeOfDay +import org.hl7.elm.r1.Times +import org.hl7.elm.r1.TimezoneFrom +import org.hl7.elm.r1.TimezoneOffsetFrom +import org.hl7.elm.r1.ToBoolean +import org.hl7.elm.r1.ToChars +import org.hl7.elm.r1.ToConcept +import org.hl7.elm.r1.ToDate +import org.hl7.elm.r1.ToDateTime +import org.hl7.elm.r1.ToDecimal +import org.hl7.elm.r1.ToInteger +import org.hl7.elm.r1.ToList +import org.hl7.elm.r1.ToLong +import org.hl7.elm.r1.ToQuantity +import org.hl7.elm.r1.ToRatio +import org.hl7.elm.r1.ToString +import org.hl7.elm.r1.ToTime +import org.hl7.elm.r1.Today +import org.hl7.elm.r1.Total +import org.hl7.elm.r1.Truncate +import org.hl7.elm.r1.TruncatedDivide +import org.hl7.elm.r1.Tuple +import org.hl7.elm.r1.TupleElement +import org.hl7.elm.r1.TupleElementDefinition +import org.hl7.elm.r1.TupleTypeSpecifier +import org.hl7.elm.r1.TypeSpecifier +import org.hl7.elm.r1.UnaryExpression +import org.hl7.elm.r1.Union +import org.hl7.elm.r1.Upper +import org.hl7.elm.r1.Variance +import org.hl7.elm.r1.Width +import org.hl7.elm.r1.With +import org.hl7.elm.r1.Without +import org.hl7.elm.r1.Xor + +/** + * This interface defines a complete generic visitor for an Elm tree + * + * @param The return type of the visit operation. Use [Void] for + * @param The type of context passed to each visit method operations with no return type. + * + */ +@Suppress("TooManyFunctions") +interface ElmVisitor { + /** + * Visit an Element in an ELM tree. This method will be called for every node in the tree that + * is a descendant of the Element type. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitElement(elm: Element, context: C): T? + + /** + * Visit a TypeSpecifier. This method will be called for every node in the tree that is a + * descendant of the TypeSpecifier type. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitTypeSpecifier(elm: TypeSpecifier, context: C): T? + + /** + * Visit a NamedTypeSpecifier. This method will be called for every node in the tree that is a + * NamedTypeSpecifier. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitNamedTypeSpecifier(elm: NamedTypeSpecifier, context: C): T? + + /** + * Visit an IntervalTypeSpecifier. This method will be called for every node in the tree that is + * an IntervalTypeSpecifier. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitIntervalTypeSpecifier(elm: IntervalTypeSpecifier, context: C): T? + + /** + * Visit a ListTypeSpecifier. This method will be called for every node in the tree that is a + * ListTypeSpecifier. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitListTypeSpecifier(elm: ListTypeSpecifier, context: C): T? + + /** + * Visit a TupleElementDefinition. This method will be called for every node in the tree that is + * a TupleElementDefinition. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitTupleElementDefinition(elm: TupleElementDefinition, context: C): T? + + /** + * Visit a TupleTypeSpecifier. This method will be called for every node in the tree that is a + * TupleTypeSpecifier. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitTupleTypeSpecifier(elm: TupleTypeSpecifier, context: C): T? + + /** + * Visit a ChoiceTypeSpecifier. This method will be called for every node in the tree that is a + * ChoiceTypeSpecifier. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitChoiceTypeSpecifier(elm: ChoiceTypeSpecifier, context: C): T? + + /** + * Visit an Expression. This method will be called for every node in the tree that is an + * Expression. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitExpression(elm: Expression, context: C): T? + + /** + * Visit an UnaryExpression. This method will be called for every node in the tree that is a + * UnaryExpression. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitUnaryExpression(elm: UnaryExpression, context: C): T? + + /** + * Visit an OperatorExpression. This method will be called for every node in the tree that is an + * OperatorExpression. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitOperatorExpression(elm: OperatorExpression, context: C): T? + + /** + * Visit a BinaryExpression. This method will be called for every node in the tree that is a + * BinaryExpression. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitBinaryExpression(elm: BinaryExpression, context: C): T? + + /** + * Visit a TernaryExpression. This method will be called for every node in the tree that is a + * TernaryExpression. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitTernaryExpression(elm: TernaryExpression, context: C): T? + + /** + * Visit a NaryExpression. This method will be called for every node in the tree that is a + * NaryExpression. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitNaryExpression(elm: NaryExpression, context: C): T? + + /** + * Visit an ExpressionDef. This method will be called for every node in the tree that is a + * ExpressionDef. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitExpressionDef(elm: ExpressionDef, context: C): T? + + /** + * Visit a FunctionDef. This method will be called for every node in the tree that is a + * FunctionDef. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitFunctionDef(elm: FunctionDef, context: C): T? + + /** + * Visit an ExpressionRef. This method will be called for every node in the tree that is a + * ExpressionRef. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitExpressionRef(elm: ExpressionRef, context: C): T? + + /** + * Visit a FunctionRef. This method will be called for every node in the tree that is a + * FunctionRef. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitFunctionRef(elm: FunctionRef, context: C): T? + + /** + * Visit a ParameterDef. This method will be called for every node in the tree that is a + * ParameterDef. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitParameterDef(elm: ParameterDef, context: C): T? + + /** + * Visit a ParameterRef. This method will be called for every node in the tree that is a + * ParameterRef. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitParameterRef(elm: ParameterRef, context: C): T? + + /** + * Visit an OperandDef. This method will be called for every node in the tree that is a + * OperandDef. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitOperandDef(elm: OperandDef, context: C): T? + + /** + * Visit an OperandRef. This method will be called for every node in the tree that is a + * OperandRef. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitOperandRef(elm: OperandRef, context: C): T? + + /** + * Visit an IdentifierRef. This method will be called for every node in the tree that is a + * IdentifierRef. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitIdentifierRef(elm: IdentifierRef, context: C): T? + + /** + * Visit a Literal. This method will be called for every node in the tree that is a Literal. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitLiteral(elm: Literal, context: C): T? + + /** + * Visit a TupleElement. This method will be called for every node in the tree that is a + * TupleElement. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitTupleElement(elm: TupleElement, context: C): T? + + /** + * Visit a Tuple. This method will be called for every node in the tree that is a Tuple. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitTuple(elm: Tuple, context: C): T? + + /** + * Visit an InstanceElement. This method will be called for every node in the tree that is a + * InstanceElement. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitInstanceElement(elm: InstanceElement, context: C): T? + + /** + * Visit an Instance. This method will be called for every node in the tree that is an Instance. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitInstance(elm: Instance, context: C): T? + + /** + * Visit an Interval. This method will be called for every node in the tree that is an Interval. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitInterval(elm: Interval, context: C): T? + + /** + * Visit a List. This method will be called for every node in the tree that is a List. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitList(elm: List, context: C): T? + + /** + * Visit an And. This method will be called for every node in the tree that is an And. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitAnd(elm: And, context: C): T? + + /** + * Visit an Or. This method will be called for every node in the tree that is an Or. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitOr(elm: Or, context: C): T? + + /** + * Visit a Xor. This method will be called for every node in the tree that is a Xor. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitXor(elm: Xor, context: C): T? + + /** + * Visit an Implies. This method will be called for every node in the tree that is an Implies. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitImplies(elm: Implies, context: C): T? + + /** + * Visit a Not. This method will be called for every node in the tree that is a Not. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitNot(elm: Not, context: C): T? + + /** + * Visit an If. This method will be called for every node in the tree that is an If. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitIf(elm: If, context: C): T? + + /** + * Visit a CaseItem. This method will be called for every node in the tree that is a CaseItem. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitCaseItem(elm: CaseItem, context: C): T? + + /** + * Visit a Case. This method will be called for every node in the tree that is a Case. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitCase(elm: Case, context: C): T? + + /** + * Visit a Null. This method will be called for every node in the tree that is a Null. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitNull(elm: Null, context: C): T? + + /** + * Visit an IsNull. This method will be called for every node in the tree that is an IsNull. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitIsNull(elm: IsNull, context: C): T? + + /** + * Visit an IsTrue. This method will be called for every node in the tree that is an IsTrue. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitIsTrue(elm: IsTrue, context: C): T? + + /** + * Visit an IsFalse. This method will be called for every node in the tree that is an IsFalse. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitIsFalse(elm: IsFalse, context: C): T? + + /** + * Visit a Coalesce. This method will be called for every node in the tree that is a Coalesce. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitCoalesce(elm: Coalesce, context: C): T? + + /** + * Visit an Is. This method will be called for every node in the tree that is an Is. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitIs(elm: Is, context: C): T? + + /** + * Visit an As. This method will be called for every node in the tree that is an As. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitAs(elm: As, context: C): T? + + /** + * Visit a Convert. This method will be called for every node in the tree that is a Convert. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitConvert(elm: Convert, context: C): T? + + /** + * Visit a CanConvert. This method will be called for every node in the tree that is a + * CanConvert. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitCanConvert(elm: CanConvert, context: C): T? + + /** + * Visit a ConvertsToBoolean. This method will be called for every node in the tree that is a + * ConvertsToBoolean. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitConvertsToBoolean(elm: ConvertsToBoolean, context: C): T? + + /** + * Visit a ToBoolean. This method will be called for every node in the tree that is a ToBoolean. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitToBoolean(elm: ToBoolean, context: C): T? + + /** + * Visit a ToChars. This method will be called for every node in the tree that is a ToChars. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitToChars(elm: ToChars, context: C): T? + + /** + * Visit a ToConcept. This method will be called for every node in the tree that is a ToConcept. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitToConcept(elm: ToConcept, context: C): T? + + /** + * Visit a ConvertsToDate. This method will be called for every node in the tree that is a + * ConvertsToDate. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitConvertsToDate(elm: ConvertsToDate, context: C): T? + + /** + * Visit a ToDate. This method will be called for every node in the tree that is a ToDate. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitToDate(elm: ToDate, context: C): T? + + /** + * Visit a ConvertsToDateTime. This method will be called for every node in the tree that is a + * ConvertsToDateTime. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitConvertsToDateTime(elm: ConvertsToDateTime, context: C): T? + + /** + * Visit a ToDateTime. This method will be called for every node in the tree that is a + * ToDateTime. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitToDateTime(elm: ToDateTime, context: C): T? + + /** + * Visit a ConvertsToLong. This method will be called for every node in the tree that is a + * ConvertsToLong. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitConvertsToLong(elm: ConvertsToLong, context: C): T? + + /** + * Visit a ToLong. This method will be called for every node in the tree that is a ToLong. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitToLong(elm: ToLong, context: C): T? + + /** + * Visit a ConvertsToDecimal. This method will be called for every node in the tree that is a + * ConvertsToDecimal. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitConvertsToDecimal(elm: ConvertsToDecimal, context: C): T? + + /** + * Visit a ToDecimal. This method will be called for every node in the tree that is a ToDecimal. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitToDecimal(elm: ToDecimal, context: C): T? + + /** + * Visit a ConvertsToInteger. This method will be called for every node in the tree that is a + * ConvertsToInteger. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitConvertsToInteger(elm: ConvertsToInteger, context: C): T? + + /** + * Visit a ToInteger. This method will be called for every node in the tree that is a ToInteger. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitToInteger(elm: ToInteger, context: C): T? + + /** + * Visit a ToList. This method will be called for every node in the tree that is a ToList. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitToList(elm: ToList, context: C): T? + + /** + * Visit a ConvertQuantity. This method will be called for every node in the tree that is a + * ConvertQuantity. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitConvertQuantity(elm: ConvertQuantity, context: C): T? + + /** + * Visit a CanConvertQuantity. This method will be called for every node in the tree that is a + * CanConvertQuantity. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitCanConvertQuantity(elm: CanConvertQuantity, context: C): T? + + /** + * Visit a ConvertsToQuantity. This method will be called for every node in the tree that is a + * ConvertsToQuantity. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitConvertsToQuantity(elm: ConvertsToQuantity, context: C): T? + + /** + * Visit a ToQuantity. This method will be called for every node in the tree that is a + * ToQuantity. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitToQuantity(elm: ToQuantity, context: C): T? + + /** + * Visit a ConvertsToRatio. This method will be called for every node in the tree that is a + * ConvertsToRatio. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitConvertsToRatio(elm: ConvertsToRatio, context: C): T? + + /** + * Visit a Ratio. This method will be called for every node in the tree that is a Ratio. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitToRatio(elm: ToRatio, context: C): T? + + /** + * Visit a ConvertsToString. This method will be called for every node in the tree that is a + * ConvertsToString. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitConvertsToString(elm: ConvertsToString, context: C): T? + + /** + * Visit a ToString. This method will be called for every node in the tree that is a ToString. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitToString(elm: ToString, context: C): T? + + /** + * Visit a ConvertsToTime. This method will be called for every node in the tree that is a + * ConvertsToTime. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitConvertsToTime(elm: ConvertsToTime, context: C): T? + + /** + * Visit a ToTime. This method will be called for every node in the tree that is a ToTime. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitToTime(elm: ToTime, context: C): T? + + /** + * Visit an Equal. This method will be called for every node in the tree that is an Equal. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitEqual(elm: Equal, context: C): T? + + /** + * Visit an Equivalent. This method will be called for every node in the tree that is an + * Equivalent. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitEquivalent(elm: Equivalent, context: C): T? + + /** + * Visit a NotEqual. This method will be called for every node in the tree that is a NotEqual. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitNotEqual(elm: NotEqual, context: C): T? + + /** + * Visit a Less. This method will be called for every node in the tree that is a Less. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitLess(elm: Less, context: C): T? + + /** + * Visit a Greater. This method will be called for every node in the tree that is a Greater. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitGreater(elm: Greater, context: C): T? + + /** + * Visit a LessOrEqual. This method will be called for every node in the tree that is a + * LessOrEqual. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitLessOrEqual(elm: LessOrEqual, context: C): T? + + /** + * Visit a GreaterOrEqual. This method will be called for every node in the tree that is a + * GreaterOrEqual. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitGreaterOrEqual(elm: GreaterOrEqual, context: C): T? + + /** + * Visit an Add. This method will be called for every node in the tree that is an Add. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitAdd(elm: Add, context: C): T? + + /** + * Visit a Subtract. This method will be called for every node in the tree that is a Subtract. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitSubtract(elm: Subtract, context: C): T? + + /** + * Visit a Multiply. This method will be called for every node in the tree that is a Multiply. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitMultiply(elm: Multiply, context: C): T? + + /** + * Visit a Divide. This method will be called for every node in the tree that is a Divide. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitDivide(elm: Divide, context: C): T? + + /** + * Visit a TruncatedDivide. This method will be called for every node in the tree that is a + * TruncatedDivide. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitTruncatedDivide(elm: TruncatedDivide, context: C): T? + + /** + * Visit a Modulo. This method will be called for every node in the tree that is a Modulo. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitModulo(elm: Modulo, context: C): T? + + /** + * Visit a Ceiling. This method will be called for every node in the tree that is a Ceiling. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitCeiling(elm: Ceiling, context: C): T? + + /** + * Visit a Floor. This method will be called for every node in the tree that is a Floor. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitFloor(elm: Floor, context: C): T? + + /** + * Visit a Truncate. This method will be called for every node in the tree that is a Truncate. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitTruncate(elm: Truncate, context: C): T? + + /** + * Visit an Abs. This method will be called for every node in the tree that is an Abs. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitAbs(elm: Abs, context: C): T? + + /** + * Visit a Negate. This method will be called for every node in the tree that is a Negate. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitNegate(elm: Negate, context: C): T? + + /** + * Visit a Round. This method will be called for every node in the tree that is a Round. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitRound(elm: Round, context: C): T? + + /** + * Visit a Ln. This method will be called for every node in the tree that is a Ln. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitLn(elm: Ln, context: C): T? + + /** + * Visit an Exp. This method will be called for every node in the tree that is an Exp. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitExp(elm: Exp, context: C): T? + + /** + * Visit a Log. This method will be called for every node in the tree that is a Log. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitLog(elm: Log, context: C): T? + + /** + * Visit a Power. This method will be called for every node in the tree that is a Power. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitPower(elm: Power, context: C): T? + + /** + * Visit a Successor. This method will be called for every node in the tree that is a Successor. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitSuccessor(elm: Successor, context: C): T? + + /** + * Visit a Predecessor. This method will be called for every node in the tree that is a + * Predecessor. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitPredecessor(elm: Predecessor, context: C): T? + + /** + * Visit a MinValue. This method will be called for every node in the tree that is a MinValue. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitMinValue(elm: MinValue, context: C): T? + + /** + * Visit a MaxValue. This method will be called for every node in the tree that is a MaxValue. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitMaxValue(elm: MaxValue, context: C): T? + + /** + * Visit a Precision. This method will be called for every node in the tree that is a Precision. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitPrecision(elm: Precision, context: C): T? + + /** + * Visit a LowBoundary. This method will be called for every node in the tree that is a + * LowBoundary. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitLowBoundary(elm: LowBoundary, context: C): T? + + /** + * Visit a HighBoundary. This method will be called for every node in the tree that is a + * HighBoundary. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitHighBoundary(elm: HighBoundary, context: C): T? + + /** + * Visit a Concatenate. This method will be called for every node in the tree that is a + * Concatenate. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitConcatenate(elm: Concatenate, context: C): T? + + /** + * Visit a Combine. This method will be called for every node in the tree that is a Combine. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitCombine(elm: Combine, context: C): T? + + /** + * Visit a Split. This method will be called for every node in the tree that is a Split. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitSplit(elm: Split, context: C): T? + + /** + * Visit a SplitOnMatches. This method will be called for every node in the tree that is a + * SplitOnMatches. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitSplitOnMatches(elm: SplitOnMatches, context: C): T? + + /** + * Visit a Length. This method will be called for every node in the tree that is a Length. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitLength(elm: Length, context: C): T? + + /** + * Visit an Upper. This method will be called for every node in the tree that is an Upper. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitUpper(elm: Upper, context: C): T? + + /** + * Visit a Lower. This method will be called for every node in the tree that is a Lower. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitLower(elm: Lower, context: C): T? + + /** + * Visit an Indexer. This method will be called for every node in the tree that is an Indexer. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitIndexer(elm: Indexer, context: C): T? + + /** + * Visit a PositionOf. This method will be called for every node in the tree that is a + * PositionOf. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitPositionOf(elm: PositionOf, context: C): T? + + /** + * Visit a LastPositionOf. This method will be called for every node in the tree that is a + * LastPositionOf. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitLastPositionOf(elm: LastPositionOf, context: C): T? + + /** + * Visit a Substring. This method will be called for every node in the tree that is a Substring. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitSubstring(elm: Substring, context: C): T? + + /** + * Visit a StartsWith. This method will be called for every node in the tree that is a + * StartsWith. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitStartsWith(elm: StartsWith, context: C): T? + + /** + * Visit an EndsWith. This method will be called for every node in the tree that is an EndsWith. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitEndsWith(elm: EndsWith, context: C): T? + + /** + * Visit a Matches. This method will be called for every node in the tree that is a Matches. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitMatches(elm: Matches, context: C): T? + + /** + * Visit a ReplaceMatches. This method will be called for every node in the tree that is a + * ReplaceMatches. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitReplaceMatches(elm: ReplaceMatches, context: C): T? + + /** + * Visit a DurationBetween. This method will be called for every node in the tree that is a + * DurationBetween. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitDurationBetween(elm: DurationBetween, context: C): T? + + /** + * Visit a DifferenceBetween. This method will be called for every node in the tree that is a + * DifferenceBetween. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitDifferenceBetween(elm: DifferenceBetween, context: C): T? + + /** + * Visit a DateFrom. This method will be called for every node in the tree that is a DateFrom. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitDateFrom(elm: DateFrom, context: C): T? + + /** + * Visit a TimeFrom. This method will be called for every node in the tree that is a TimeFrom. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitTimeFrom(elm: TimeFrom, context: C): T? + + /** + * Visit a TimezoneFrom. This method will be called for every node in the tree that is a + * TimezoneFrom. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitTimezoneFrom(elm: TimezoneFrom, context: C): T? + + /** + * Visit a TimezoneOffsetFrom. This method will be called for every node in the tree that is a + * TimezoneOffsetFrom. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitTimezoneOffsetFrom(elm: TimezoneOffsetFrom, context: C): T? + + /** + * Visit a DateTimeComponentFrom. This method will be called for every node in the tree that is + * a DateTimeComponentFrom. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitDateTimeComponentFrom(elm: DateTimeComponentFrom, context: C): T? + + /** + * Visit a TimeOfDay. This method will be called for every node in the tree that is a TimeOfDay. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitTimeOfDay(elm: TimeOfDay, context: C): T? + + /** + * Visit a Today. This method will be called for every node in the tree that is a Today. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitToday(elm: Today, context: C): T? + + /** + * Visit a Now. This method will be called for every node in the tree that is a Now. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitNow(elm: Now, context: C): T? + + /** + * Visit a DateTime. This method will be called for every node in the tree that is a DateTime. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitDateTime(elm: DateTime, context: C): T? + + /** + * Visit a Date. This method will be called for every node in the tree that is a Date. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitDate(elm: Date, context: C): T? + + /** + * Visit a Time. This method will be called for every node in the tree that is a Time. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitTime(elm: Time, context: C): T? + + /** + * Visit a SameAs. This method will be called for every node in the tree that is a SameAs. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitSameAs(elm: SameAs, context: C): T? + + /** + * Visit a SameOrBefore. This method will be called for every node in the tree that is a + * SameOrBefore. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitSameOrBefore(elm: SameOrBefore, context: C): T? + + /** + * Visit a SameOrAfter. This method will be called for every node in the tree that is a + * SameOrAfter. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitSameOrAfter(elm: SameOrAfter, context: C): T? + + /** + * Visit a Width. This method will be called for every node in the tree that is a Width. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitWidth(elm: Width, context: C): T? + + /** + * Visit a Size. This method will be called for every node in the tree that is a Size. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitSize(elm: Size, context: C): T? + + /** + * Visit a PointFrom. This method will be called for every node in the tree that is a PointFrom. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitPointFrom(elm: PointFrom, context: C): T? + + /** + * Visit a Start. This method will be called for every node in the tree that is a Start. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitStart(elm: Start, context: C): T? + + /** + * Visit an End. This method will be called for every node in the tree that is an End. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitEnd(elm: End, context: C): T? + + /** + * Visit a Contains. This method will be called for every node in the tree that is a Contains. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitContains(elm: Contains, context: C): T? + + /** + * Visit a ProperContains. This method will be called for every node in the tree that is a + * ProperContains. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitProperContains(elm: ProperContains, context: C): T? + + /** + * Visit an In. This method will be called for every node in the tree that is an In. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitIn(elm: In, context: C): T? + + /** + * Visit a ProperIn. This method will be called for every node in the tree that is a ProperIn. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitProperIn(elm: ProperIn, context: C): T? + + /** + * Visit an Includes. This method will be called for every node in the tree that is an Includes. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitIncludes(elm: Includes, context: C): T? + + /** + * Visit an IncludedIn. This method will be called for every node in the tree that is a + * IncludedIn. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitIncludedIn(elm: IncludedIn, context: C): T? + + /** + * Visit a ProperIncludes. This method will be called for every node in the tree that is a + * ProperIncludes. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitProperIncludes(elm: ProperIncludes, context: C): T? + + /** + * Visit a ProperIncludedIn. This method will be called for every node in the tree that is a + * ProperIncludedIn. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitProperIncludedIn(elm: ProperIncludedIn, context: C): T? + + /** + * Visit a Before. This method will be called for every node in the tree that is a Before. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitBefore(elm: Before, context: C): T? + + /** + * Visit an After. This method will be called for every node in the tree that is an After. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitAfter(elm: After, context: C): T? + + /** + * Visit a Meets. This method will be called for every node in the tree that is a Meets. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitMeets(elm: Meets, context: C): T? + + /** + * Visit a MeetsBefore. This method will be called for every node in the tree that is a + * MeetsBefore. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitMeetsBefore(elm: MeetsBefore, context: C): T? + + /** + * Visit a MeetsAfter. This method will be called for every node in the tree that is a + * MeetsAfter. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitMeetsAfter(elm: MeetsAfter, context: C): T? + + /** + * Visit an Overlaps. This method will be called for every node in the tree that is an Overlaps. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitOverlaps(elm: Overlaps, context: C): T? + + /** + * Visit an OverlapsBefore. This method will be called for every node in the tree that is a + * OverlapsBefore. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitOverlapsBefore(elm: OverlapsBefore, context: C): T? + + /** + * Visit an OverlapsAfter. This method will be called for every node in the tree that is a + * OverlapsAfter. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitOverlapsAfter(elm: OverlapsAfter, context: C): T? + + /** + * Visit a Starts. This method will be called for every node in the tree that is a Starts. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitStarts(elm: Starts, context: C): T? + + /** + * Visit an Ends. This method will be called for every node in the tree that is an Ends. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitEnds(elm: Ends, context: C): T? + + /** + * Visit a Collapse. This method will be called for every node in the tree that is a Collapse. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitCollapse(elm: Collapse, context: C): T? + + /** + * Visit an Expand. This method will be called for every node in the tree that is an Expand. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitExpand(elm: Expand, context: C): T? + + /** + * Visit a Union. This method will be called for every node in the tree that is a Union. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitUnion(elm: Union, context: C): T? + + /** + * Visit an Intersect. This method will be called for every node in the tree that is an + * Intersect. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitIntersect(elm: Intersect, context: C): T? + + /** + * Visit an Except. This method will be called for every node in the tree that is an Except. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitExcept(elm: Except, context: C): T? + + /** + * Visit a Literal. This method will be called for every node in the tree that is a Literal. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitExists(elm: Exists, context: C): T? + + /** + * Visit a Times. This method will be called for every node in the tree that is a Times. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitTimes(elm: Times, context: C): T? + + /** + * Visit a Filter. This method will be called for every node in the tree that is a Filter. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitFilter(elm: Filter, context: C): T? + + /** + * Visit a First. This method will be called for every node in the tree that is a First. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitFirst(elm: First, context: C): T? + + /** + * Visit a Last. This method will be called for every node in the tree that is a Last. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitLast(elm: Last, context: C): T? + + /** + * Visit a Slice. This method will be called for every node in the tree that is a Slice. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitSlice(elm: Slice, context: C): T? + + /** + * Visit a Children. This method will be called for every node in the tree that is a Children. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitChildren(elm: Children, context: C): T? + + /** + * Visit a Descendents. This method will be called for every node in the tree that is a + * Descendents. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitDescendents(elm: Descendents, context: C): T? + + /** + * Visit a Message. This method will be called for every node in the tree that is a Message. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitMessage(elm: Message, context: C): T? + + /** + * Visit an IndexOf. This method will be called for every node in the tree that is an IndexOf. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitIndexOf(elm: IndexOf, context: C): T? + + /** + * Visit a Flatten. This method will be called for every node in the tree that is a Flatten. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitFlatten(elm: Flatten, context: C): T? + + /** + * Visit a Sort. This method will be called for every node in the tree that is a Sort. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitSort(elm: Sort, context: C): T? + + /** + * Visit a ForEach. This method will be called for every node in the tree that is a ForEach. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitForEach(elm: ForEach, context: C): T? + + /** + * Visit a Repeat. This method will be called for every node in the tree that is a Repeat. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitRepeat(elm: Repeat, context: C): T? + + /** + * Visit a Distinct. This method will be called for every node in the tree that is a Distinct. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitDistinct(elm: Distinct, context: C): T? + + /** + * Visit a Current. This method will be called for every node in the tree that is a Current. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitCurrent(elm: Current, context: C): T? + + /** + * Visit an Iteration. This method will be called for every node in the tree that is an + * Iteration. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitIteration(elm: Iteration, context: C): T? + + /** + * Visit a Total. This method will be called for every node in the tree that is a Total. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitTotal(elm: Total, context: C): T? + + /** + * Visit a SingletonFrom. This method will be called for every node in the tree that is a + * SingletonFrom. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitSingletonFrom(elm: SingletonFrom, context: C): T? + + /** + * Visit an AggregateExpression. This method will be called for every node in the tree that is a + * AggregateExpression. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitAggregateExpression(elm: AggregateExpression, context: C): T? + + /** + * Visit an Aggregate. This method will be called for every node in the tree that is an + * Aggregate. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitAggregate(elm: Aggregate, context: C): T? + + /** + * Visit a Count. This method will be called for every node in the tree that is a Count. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitCount(elm: Count, context: C): T? + + /** + * Visit a Sum. This method will be called for every node in the tree that is a Sum. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitSum(elm: Sum, context: C): T? + + /** + * Visit a Product. This method will be called for every node in the tree that is a Product. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitProduct(elm: Product, context: C): T? + + /** + * Visit a GeometricMean. This method will be called for every node in the tree that is a + * GeometricMean. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitGeometricMean(elm: GeometricMean, context: C): T? + + /** + * Visit a Min. This method will be called for every node in the tree that is a Min. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitMin(elm: Min, context: C): T? + + /** + * Visit a Max. This method will be called for every node in the tree that is a Max. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitMax(elm: Max, context: C): T? + + /** + * Visit an Avg. This method will be called for every node in the tree that is an Avg. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitAvg(elm: Avg, context: C): T? + + /** + * Visit a Median. This method will be called for every node in the tree that is a Median. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitMedian(elm: Median, context: C): T? + + /** + * Visit a Mode. This method will be called for every node in the tree that is a Mode. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitMode(elm: Mode, context: C): T? + + /** + * Visit a Variance. This method will be called for every node in the tree that is a Variance. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitVariance(elm: Variance, context: C): T? + + /** + * Visit a PopulationVariance. This method will be called for every node in the tree that is a + * PopulationVariance. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitPopulationVariance(elm: PopulationVariance, context: C): T? + + /** + * Visit a StdDev. This method will be called for every node in the tree that is a StdDev. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitStdDev(elm: StdDev, context: C): T? + + /** + * Visit a PopulationStdDev. This method will be called for every node in the tree that is a + * PopulationStdDev. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitPopulationStdDev(elm: PopulationStdDev, context: C): T? + + /** + * Visit an AllTrue. This method will be called for every node in the tree that is an AllTrue. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitAllTrue(elm: AllTrue, context: C): T? + + /** + * Visit an AnyTrue. This method will be called for every node in the tree that is an AnyTrue. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitAnyTrue(elm: AnyTrue, context: C): T? + + /** + * Visit a Property. This method will be called for every node in the tree that is a Property. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitProperty(elm: Property, context: C): T? + + /** + * Visit an AliasedQuerySource. This method will be called for every node in the tree that is a + * AliasedQuerySource. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitAliasedQuerySource(elm: AliasedQuerySource, context: C): T? + + /** + * Visit a LetClause. This method will be called for every node in the tree that is a LetClause. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitLetClause(elm: LetClause, context: C): T? + + /** + * Visit a RelationshipClause. This method will be called for every node in the tree that is a + * RelationshipClause. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitRelationshipClause(elm: RelationshipClause, context: C): T? + + /** + * Visit a With. This method will be called for every node in the tree that is a With. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitWith(elm: With, context: C): T? + + /** + * Visit a Without. This method will be called for every node in the tree that is a Without. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitWithout(elm: Without, context: C): T? + + /** + * Visit a SortByItem. This method will be called for every node in the tree that is a + * SortByItem. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitSortByItem(elm: SortByItem, context: C): T? + + /** + * Visit a ByDirection. This method will be called for every node in the tree that is a + * ByDirection. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitByDirection(elm: ByDirection, context: C): T? + + /** + * Visit a ByColumn. This method will be called for every node in the tree that is a ByColumn. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitByColumn(elm: ByColumn, context: C): T? + + /** + * Visit a ByExpression. This method will be called for every node in the tree that is a + * ByExpression. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitByExpression(elm: ByExpression, context: C): T? + + /** + * Visit a SortClause. This method will be called for every node in the tree that is a + * SortClause. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitSortClause(elm: SortClause, context: C): T? + + /** + * Visit an AggregateClause. This method will be called for every node in the tree that is an + * AggregateClause. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitAggregateClause(elm: AggregateClause, context: C): T? + + /** + * Visit a ReturnClause. This method will be called for every node in the tree that is a + * ReturnClause. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitReturnClause(elm: ReturnClause, context: C): T? + + /** + * Visit a Query. This method will be called for every node in the tree that is a Query. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitQuery(elm: Query, context: C): T? + + /** + * Visit an AliasRef. This method will be called for every node in the tree that is an AliasRef. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitAliasRef(elm: AliasRef, context: C): T? + + /** + * Visit a QueryLetRef. This method will be called for every node in the tree that is a + * QueryLetRef. + * + * @param elm the ELM tree + * @param context the context passed to the visitor + * @return the visitor result + */ + fun visitQueryLetRef(elm: QueryLetRef, context: C): T? +} diff --git a/Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/FunctionalElmVisitor.kt b/Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/FunctionalElmVisitor.kt index acac76355..77199658d 100644 --- a/Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/FunctionalElmVisitor.kt +++ b/Src/java/elm/src/main/java/org/cqframework/cql/elm/visiting/FunctionalElmVisitor.kt @@ -9,15 +9,15 @@ import org.cqframework.cql.elm.tracking.Trackable * type. */ class FunctionalElmVisitor( - private val defaultResult: BiFunction, - private val aggregateResult: BiFunction + private val defaultResult: BiFunction, + private val aggregateResult: BiFunction ) : BaseElmLibraryVisitor() { - public override fun defaultResult(elm: Trackable?, context: C): T { + public override fun defaultResult(elm: Trackable?, context: C): T? { return defaultResult.apply(elm, context) } - public override fun aggregateResult(aggregate: T, nextResult: T): T { + public override fun aggregateResult(aggregate: T?, nextResult: T?): T? { return aggregateResult.apply(aggregate, nextResult) } } diff --git a/Src/java/elm/src/test/java/org/cqframework/cql/elm/visiting/RandomElmGraphTest.kt b/Src/java/elm/src/test/java/org/cqframework/cql/elm/visiting/RandomElmGraphTest.kt index 3441d3e34..442a2a994 100644 --- a/Src/java/elm/src/test/java/org/cqframework/cql/elm/visiting/RandomElmGraphTest.kt +++ b/Src/java/elm/src/test/java/org/cqframework/cql/elm/visiting/RandomElmGraphTest.kt @@ -77,9 +77,9 @@ class RandomElmGraphTest { val elementsDuplicated = HashMap() val countingVisitor = FunctionalElmVisitor( - BiFunction, Int> { + BiFunction, Int?> { x: Trackable?, - y: HashMap? -> + _: HashMap? -> if (x is Element) { val hash = System.identityHashCode(x) if (!elementsVisited.containsKey(hash)) { diff --git a/Src/java/engine-fhir/src/test/java/org/hl7/fhirpath/TestLibrarySourceProvider.java b/Src/java/engine-fhir/src/test/java/org/hl7/fhirpath/TestLibrarySourceProvider.java index f0e4db66b..ae34fe5cd 100644 --- a/Src/java/engine-fhir/src/test/java/org/hl7/fhirpath/TestLibrarySourceProvider.java +++ b/Src/java/engine-fhir/src/test/java/org/hl7/fhirpath/TestLibrarySourceProvider.java @@ -1,6 +1,7 @@ package org.hl7.fhirpath; import java.io.InputStream; +import org.cqframework.cql.cql2elm.LibraryContentType; import org.cqframework.cql.cql2elm.LibrarySourceProvider; import org.hl7.elm.r1.VersionedIdentifier; @@ -13,4 +14,13 @@ public InputStream getLibrarySource(VersionedIdentifier libraryIdentifier) { libraryIdentifier.getVersion() != null ? ("-" + libraryIdentifier.getVersion()) : ""); return TestLibrarySourceProvider.class.getResourceAsStream(libraryFileName); } + + @Override + public InputStream getLibraryContent(VersionedIdentifier libraryIdentifier, LibraryContentType type) { + if (LibraryContentType.CQL == type) { + return getLibrarySource(libraryIdentifier); + } + + return null; + } } diff --git a/Src/java/engine-fhir/src/test/java/org/opencds/cqf/cql/engine/fhir/data/TestLibrarySourceProvider.java b/Src/java/engine-fhir/src/test/java/org/opencds/cqf/cql/engine/fhir/data/TestLibrarySourceProvider.java index f2de89f96..54ff35642 100644 --- a/Src/java/engine-fhir/src/test/java/org/opencds/cqf/cql/engine/fhir/data/TestLibrarySourceProvider.java +++ b/Src/java/engine-fhir/src/test/java/org/opencds/cqf/cql/engine/fhir/data/TestLibrarySourceProvider.java @@ -1,6 +1,7 @@ package org.opencds.cqf.cql.engine.fhir.data; import java.io.InputStream; +import org.cqframework.cql.cql2elm.LibraryContentType; import org.cqframework.cql.cql2elm.LibrarySourceProvider; import org.hl7.elm.r1.VersionedIdentifier; @@ -14,4 +15,13 @@ public InputStream getLibrarySource(VersionedIdentifier libraryIdentifier) { // : ""); return TestLibrarySourceProvider.class.getResourceAsStream(libraryFileName); } + + @Override + public InputStream getLibraryContent(VersionedIdentifier libraryIdentifier, LibraryContentType type) { + if (LibraryContentType.CQL == type) { + return getLibrarySource(libraryIdentifier); + } + + return null; + } } diff --git a/Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/execution/MapLibrarySourceProvider.java b/Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/execution/MapLibrarySourceProvider.java index 12383edb2..b55bba567 100644 --- a/Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/execution/MapLibrarySourceProvider.java +++ b/Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/execution/MapLibrarySourceProvider.java @@ -3,7 +3,9 @@ import java.io.ByteArrayInputStream; import java.io.InputStream; import java.util.Map; +import org.cqframework.cql.cql2elm.LibraryContentType; import org.cqframework.cql.cql2elm.LibrarySourceProvider; +import org.hl7.elm.r1.VersionedIdentifier; /** * This class provides CQL content for a given VersionedIdentifier based on a @@ -22,4 +24,13 @@ public InputStream getLibrarySource(org.hl7.elm.r1.VersionedIdentifier libraryId String text = this.libraries.get(libraryIdentifier); return new ByteArrayInputStream(text.getBytes()); } + + @Override + public InputStream getLibraryContent(VersionedIdentifier libraryIdentifier, LibraryContentType type) { + if (LibraryContentType.CQL == type) { + return getLibrarySource(libraryIdentifier); + } + + return null; + } } diff --git a/Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/execution/TestLibrarySourceProvider.java b/Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/execution/TestLibrarySourceProvider.java index 84f691ed9..0ff2f4fff 100644 --- a/Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/execution/TestLibrarySourceProvider.java +++ b/Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/execution/TestLibrarySourceProvider.java @@ -1,6 +1,7 @@ package org.opencds.cqf.cql.engine.execution; import java.io.InputStream; +import org.cqframework.cql.cql2elm.LibraryContentType; import org.cqframework.cql.cql2elm.LibrarySourceProvider; import org.hl7.elm.r1.VersionedIdentifier; @@ -10,4 +11,13 @@ public InputStream getLibrarySource(VersionedIdentifier libraryIdentifier) { String libraryFileName = String.format("%s%s.cql", libraryIdentifier.getId(), ""); return TestLibrarySourceProvider.class.getResourceAsStream(libraryFileName); } + + @Override + public InputStream getLibraryContent(VersionedIdentifier libraryIdentifier, LibraryContentType type) { + if (LibraryContentType.CQL == type) { + return getLibrarySource(libraryIdentifier); + } + + return null; + } } diff --git a/Src/java/quick/src/main/java/org/cqframework/cql/cql2elm/quick/FhirLibrarySourceProvider.java b/Src/java/quick/src/main/java/org/cqframework/cql/cql2elm/quick/FhirLibrarySourceProvider.java index af79c7c5b..c80974528 100644 --- a/Src/java/quick/src/main/java/org/cqframework/cql/cql2elm/quick/FhirLibrarySourceProvider.java +++ b/Src/java/quick/src/main/java/org/cqframework/cql/cql2elm/quick/FhirLibrarySourceProvider.java @@ -1,6 +1,7 @@ package org.cqframework.cql.cql2elm.quick; import java.io.InputStream; +import org.cqframework.cql.cql2elm.LibraryContentType; import org.cqframework.cql.cql2elm.LibrarySourceProvider; import org.hl7.cql.model.NamespaceAware; import org.hl7.cql.model.NamespaceInfo; @@ -39,4 +40,13 @@ public InputStream getLibrarySource(VersionedIdentifier libraryIdentifier) { public void setNamespaceManager(NamespaceManager namespaceManager) { this.namespaceManager = namespaceManager; } + + @Override + public InputStream getLibraryContent(VersionedIdentifier libraryIdentifier, LibraryContentType type) { + if (LibraryContentType.CQL == type) { + return getLibrarySource(libraryIdentifier); + } + + return null; + } }