Skip to content

Commit

Permalink
Merge branch 'feature-kotlin' into feature-kotlin-patch
Browse files Browse the repository at this point in the history
  • Loading branch information
JPercival committed Dec 26, 2024
2 parents 59e3270 + 1627ddf commit b349903
Show file tree
Hide file tree
Showing 45 changed files with 1,658 additions and 2,595 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ object CqlTranslatorOptionsMapper {
return fromReader(fr)
} catch (@Suppress("SwallowedException") e: IOException) {
@Suppress("TooGenericExceptionThrown")
throw RuntimeException(
String.format(Locale.US, "Errors occurred reading options: %s", e.message)
)
throw RuntimeException("Errors occurred reading options: ${e.message}", e)
}
}

Expand All @@ -34,9 +32,7 @@ object CqlTranslatorOptionsMapper {
return om.readValue(reader, CqlTranslatorOptions::class.java)
} catch (@Suppress("SwallowedException") e: IOException) {
@Suppress("TooGenericExceptionThrown")
throw RuntimeException(
String.format(Locale.US, "Errors occurred reading options: %s", e.message)
)
throw RuntimeException("Errors occurred reading options: ${e.message}", e)
}
}

Expand All @@ -48,9 +44,7 @@ object CqlTranslatorOptionsMapper {
toWriter(fw, options)
} catch (@Suppress("SwallowedException") e: IOException) {
@Suppress("TooGenericExceptionThrown")
throw RuntimeException(
String.format(Locale.US, "Errors occurred writing options: %s", e.message)
)
throw RuntimeException("Errors occurred writing options: ${e.message}", e)
}
}

Expand All @@ -61,9 +55,7 @@ object CqlTranslatorOptionsMapper {
om.writeValue(writer, options)
} catch (@Suppress("SwallowedException") e: IOException) {
@Suppress("TooGenericExceptionThrown")
throw RuntimeException(
String.format(Locale.US, "Errors occurred writing options: %s", e.message)
)
throw RuntimeException("Errors occurred writing options: ${e.message}", e)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ object CompilerOptions {

/**
* Parses a string representing CQL compiler Options into an EnumSet. The string is expected to
* be a comma delimited list of values from the CqlCompiler.Options enumeration. For example
* be a comma-delimited list of values from the CqlCompiler.Options enumeration. For example
* "EnableListPromotion, EnableListDemotion".
*
* @param compilerOptions the string to parse
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ class CqlCompiler(
return retrieves
}

val compiledLibraries: Map<VersionedIdentifier, CompiledLibrary>
get() = libraryManager.compiledLibraries

val libraries: Map<VersionedIdentifier, Library>
get() {
val result = HashMap<VersionedIdentifier, Library>()
Expand Down Expand Up @@ -129,11 +126,7 @@ class CqlCompiler(
} else {
if (offendingSymbol is CommonToken) {
builder.recordParsingException(
CqlSyntaxException(
String.format(Locale.US, "Syntax error at %s", offendingSymbol.text),
trackback,
e
)
CqlSyntaxException("Syntax error at ${offendingSymbol.text}", trackback, e)
)
} else {
builder.recordParsingException(CqlSyntaxException("Syntax error", trackback, e))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,5 @@ package org.cqframework.cql.cql2elm
import org.cqframework.cql.cql2elm.tracking.TrackBack

/** Created by Bryn on 5/20/2017. */
class CqlInternalException : CqlCompilerException {
constructor(message: String?) : super(message, ErrorSeverity.Error)

constructor(message: String?, cause: Throwable?) : super(message, ErrorSeverity.Error, cause)

constructor(
message: String?,
locator: TrackBack?
) : super(message, ErrorSeverity.Error, locator)

constructor(
message: String?,
locator: TrackBack?,
cause: Throwable?
) : super(message, ErrorSeverity.Error, locator, cause)
}
class CqlInternalException(message: String?, locator: TrackBack? = null, cause: Throwable? = null) :
CqlCompilerException(message, ErrorSeverity.Error, locator, cause)
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,6 @@ import org.cqframework.cql.cql2elm.tracking.TrackBack
class CqlSemanticException : CqlCompilerException {
constructor(message: String?) : super(message)

constructor(message: String?, severity: ErrorSeverity) : super(message, severity)

constructor(message: String?, cause: Throwable?) : super(message, cause)

constructor(
message: String?,
severity: ErrorSeverity,
cause: Throwable?
) : super(message, severity, cause)

constructor(message: String?, locator: TrackBack?) : super(message, locator)

constructor(
message: String?,
severity: ErrorSeverity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,5 @@ package org.cqframework.cql.cql2elm
import org.cqframework.cql.cql2elm.tracking.TrackBack

/** Created by Bryn on 3/27/2017. */
class CqlSyntaxException : CqlCompilerException {
constructor(message: String?) : super(message)

constructor(message: String?, severity: ErrorSeverity) : super(message, severity)

constructor(message: String?, cause: Throwable?) : super(message, cause)

constructor(
message: String?,
severity: ErrorSeverity,
cause: Throwable?
) : super(message, severity, cause)

constructor(message: String?, locator: TrackBack?) : super(message, locator)

constructor(
message: String?,
severity: ErrorSeverity,
locator: TrackBack?
) : super(message, severity, locator)

constructor(
message: String?,
locator: TrackBack?,
cause: Throwable?
) : super(message, locator, cause)

constructor(
message: String?,
severity: ErrorSeverity,
locator: TrackBack?,
cause: Throwable?
) : super(message, severity, locator, cause)
}
class CqlSyntaxException(message: String?, locator: TrackBack?, cause: Throwable?) :
CqlCompilerException(message, locator, cause)
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ class CqlTranslator(
val libraries: Map<VersionedIdentifier, Library?>
get() = compiler.libraries

val translatedLibraries: Map<VersionedIdentifier, CompiledLibrary?>
get() = compiler.compiledLibraries

val exceptions: List<CqlCompilerException?>?
// public Map<String, String> getLibrariesAsXML() {
get() = compiler.exceptions
Expand All @@ -97,35 +94,6 @@ class CqlTranslator(
return CqlTranslator(null, null, CharStreams.fromString(cqlText), libraryManager)
}

@JvmStatic
fun fromText(
namespaceInfo: NamespaceInfo?,
cqlText: String,
libraryManager: LibraryManager
): CqlTranslator {
return CqlTranslator(
namespaceInfo,
null,
CharStreams.fromString(cqlText),
libraryManager
)
}

@JvmStatic
fun fromText(
namespaceInfo: NamespaceInfo?,
sourceInfo: VersionedIdentifier?,
cqlText: String,
libraryManager: LibraryManager
): CqlTranslator {
return CqlTranslator(
namespaceInfo,
sourceInfo,
CharStreams.fromString(cqlText),
libraryManager
)
}

@JvmStatic
@Throws(IOException::class)
fun fromStream(
Expand Down Expand Up @@ -220,7 +188,7 @@ class CqlTranslator(
fun fromFile(
namespaceInfo: NamespaceInfo?,
sourceInfo: VersionedIdentifier?,
cqlFile: File?,
cqlFile: File,
libraryManager: LibraryManager
): CqlTranslator {
return CqlTranslator(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
package org.cqframework.cql.cql2elm

import java.util.*
import org.hl7.cql.model.DataType

private const val UNKNOWN = "<unknown>"

object DataTypes {
@JvmStatic
fun verifyType(actualType: DataType?, expectedType: DataType?) {
require(subTypeOf(actualType, expectedType)) {
// ERROR:
String.format(
Locale.US,
"Expected an expression of type '%s', but found an expression of type '%s'.",
if (expectedType != null) expectedType.toLabel() else "<unknown>",
if (actualType != null) actualType.toLabel() else "<unknown>"
)
"Expected an expression of type '${expectedType?.toLabel() ?: UNKNOWN}'," +
"but found an expression of type '${actualType?.toLabel() ?: UNKNOWN}'."
}
}

@JvmStatic
fun verifyCast(targetType: DataType?, sourceType: DataType?) {
// Casting can be used for compatible types as well as subtypes and supertypes
require(
Expand All @@ -26,30 +21,24 @@ object DataTypes {
compatibleWith(sourceType, targetType)
) {
// ERROR:
String.format(
Locale.US,
"Expression of type '%s' cannot be cast as a value of type '%s'.",
if (sourceType != null) sourceType.toLabel() else "<unknown>",
if (targetType != null) targetType.toLabel() else "<unknown>"
)
"Expression of type '${sourceType?.toLabel() ?: UNKNOWN}'" +
" cannot be cast as a value of type '${targetType?.toLabel() ?: UNKNOWN}'."
}
}

@JvmStatic
fun equal(a: DataType?, b: DataType?): Boolean {
return a != null && b != null && a == b
}

fun compatibleWith(a: DataType?, b: DataType?): Boolean {
private fun compatibleWith(a: DataType?, b: DataType?): Boolean {
return a != null && b != null && a.isCompatibleWith(b)
}

@JvmStatic
fun subTypeOf(a: DataType?, b: DataType?): Boolean {
return a != null && b != null && a.isSubTypeOf(b)
}

fun superTypeOf(a: DataType?, b: DataType?): Boolean {
private fun superTypeOf(a: DataType?, b: DataType?): Boolean {
return a != null && b != null && a.isSuperTypeOf(b)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@ package org.cqframework.cql.cql2elm

import java.io.InputStream
import java.nio.file.Path
import java.util.*
import kotlin.collections.ArrayList
import org.hl7.cql.model.NamespaceAware
import org.hl7.cql.model.NamespaceManager
import org.hl7.elm.r1.VersionedIdentifier

/**
* Used by LibraryManager to manage a set of library source providers that resolve library includes
* within CQL. Package private since its not intended to be used outside the context of the
* within CQL. Package private since it's not intended to be used outside the context of the
* instantiating LibraryManager instance.
*/
internal class DefaultLibrarySourceLoader : LibrarySourceLoader, NamespaceAware, PathAware {
private val providers: MutableList<LibrarySourceProvider> = ArrayList()
var initialized: Boolean = false
private var initialized: Boolean = false

override fun registerProvider(provider: LibrarySourceProvider) {
if (namespaceManager != null && provider is NamespaceAware) {
Expand All @@ -30,9 +29,7 @@ internal class DefaultLibrarySourceLoader : LibrarySourceLoader, NamespaceAware,
private var path: Path? = null

override fun setPath(path: Path) {
require(path.toFile().isDirectory) {
String.format(Locale.US, "path '%s' is not a valid directory", path)
}
require(path.toFile().isDirectory) { "path '$path' is not a valid directory" }

this.path = path
for (provider in getProviders()) {
Expand Down Expand Up @@ -65,25 +62,13 @@ internal class DefaultLibrarySourceLoader : LibrarySourceLoader, NamespaceAware,
val localSource: InputStream? = provider.getLibrarySource(libraryIdentifier)
if (localSource != null) {
require(source == null) {
String.format(
Locale.US,
"Multiple sources found for library %s, version %s.",
libraryIdentifier.id,
libraryIdentifier.version
)
"Multiple sources found for library ${libraryIdentifier.id}, version ${libraryIdentifier.version}."
}
source = localSource
}
}
if (source == null) {
throw IllegalArgumentException(
String.format(
Locale.US,
"Could not load source for library %s, version %s.",
libraryIdentifier.id,
libraryIdentifier.version
)
)
requireNotNull(source) {
"Could not load source for library ${libraryIdentifier.id}, version ${libraryIdentifier.version}."
}
return source
}
Expand Down
Loading

0 comments on commit b349903

Please sign in to comment.