Skip to content

Commit e9b4887

Browse files
JPercivalantvaset
andauthored
Partial conversion of the model package to Kotlin (#1455)
* WIP * WIP * WIP * merge nondeterminism fixes * WIP * Further work on kotlin conversion of model * Signature converted * More Signature updates * Update gradle version, fix deprecations, change XJC task configuration, add foojay resolver to buildSrc * further updates to signature * Move FhirLibrarySourceLoader to correct project * Kotlin for LibraryRef, InstantiationResult * FunctionHeader * Fix usage of spread operator * Version * PropertyResolution, OperatorResolution, Operator * Add Kotlin toolchain back * Small code reduction (#1456) Small suggestions * Fixes for Sonar * QueryContext * Suppress warnings on refactored code * Fixes for Sonar warnings * Make version pattern a constant --------- Co-authored-by: Anton Vasetenkov <[email protected]>
1 parent b80b613 commit e9b4887

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+3722
-4071
lines changed

Src/java/buildSrc/src/main/kotlin/cql.java-conventions.gradle.kts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ kotlin {
1515

1616
java {
1717
toolchain {
18-
languageVersion.set(JavaLanguageVersion.of(17))
18+
languageVersion = JavaLanguageVersion.of(17)
1919
}
2020
}
2121

@@ -30,7 +30,6 @@ repositories {
3030
}
3131
}
3232

33-
3433
spotless {
3534
java {
3635
targetExclude("**/generated/**")

Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/Cql2ElmVisitor.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1905,6 +1905,8 @@ public Expression visitBooleanExpression(cqlParser.BooleanExpressionContext ctx)
19051905
public Object visitTimingExpression(cqlParser.TimingExpressionContext ctx) {
19061906
Expression left = parseExpression(ctx.expression(0));
19071907
Expression right = parseExpression(ctx.expression(1));
1908+
requireNonNull(left, "left expression of timing operator can not be null");
1909+
requireNonNull(right, "right expression of timing operator can not be null");
19081910
TimingOperatorContext timingOperatorContext = new TimingOperatorContext(left, right);
19091911
timingOperators.push(timingOperatorContext);
19101912
try {
@@ -3582,7 +3584,6 @@ private Expression getConversionReference(Expression reference) {
35823584
if (o != null
35833585
&& o.getLibraryName() != null
35843586
&& o.getLibraryName().equals(functionRef.getLibraryName())
3585-
&& o.getName() != null
35863587
&& o.getName().equals(functionRef.getName())) {
35873588
return functionRef.getOperand().get(0);
35883589
}
@@ -4172,7 +4173,7 @@ public Expression resolveFunction(
41724173
.getId()))) {
41734174
Operator op = invocation.getResolution().getOperator();
41744175
FunctionHeader fh = getFunctionHeader(op);
4175-
if (!fh.getIsCompiled()) {
4176+
if (!fh.isCompiled()) {
41764177
cqlParser.FunctionDefinitionContext ctx = getFunctionDefinitionContext(fh);
41774178
String saveContext = saveCurrentContext(fh.getFunctionDef().getContext());
41784179
Stack<Chunk> saveChunks = chunks;
@@ -4440,7 +4441,7 @@ public FunctionDef compileFunctionDefinition(cqlParser.FunctionDefinitionContext
44404441
}
44414442

44424443
fun.setContext(getCurrentContext());
4443-
fh.setIsCompiled();
4444+
fh.setCompiled(true);
44444445

44454446
return fun;
44464447
} finally {

Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/LibraryBuilder.java

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,12 +1280,7 @@ public CallContext buildCallContext(
12801280
}
12811281

12821282
return new CallContext(
1283-
libraryName,
1284-
operatorName,
1285-
allowPromotionAndDemotion,
1286-
allowFluent,
1287-
mustResolve,
1288-
dataTypes.toArray(new DataType[dataTypes.size()]));
1283+
libraryName, operatorName, allowPromotionAndDemotion, allowFluent, mustResolve, dataTypes);
12891284
}
12901285

12911286
public Invocation resolveInvocation(
@@ -1384,7 +1379,7 @@ public Operator resolveFunctionDefinition(FunctionDef fd) {
13841379
false,
13851380
fd.isFluent() != null && fd.isFluent(),
13861381
false,
1387-
dataTypes.toArray(new DataType[dataTypes.size()]));
1382+
dataTypes);
13881383
// Resolve exact, no conversion map
13891384
OperatorResolution resolution = compiledLibrary.resolveCall(callContext, null);
13901385
if (resolution != null) {
@@ -1395,7 +1390,7 @@ public Operator resolveFunctionDefinition(FunctionDef fd) {
13951390

13961391
public OperatorResolution resolveCall(CallContext callContext) {
13971392
OperatorResolution result = null;
1398-
if (callContext.getLibraryName() == null || callContext.getLibraryName().equals("")) {
1393+
if (callContext.getLibraryName() == null || callContext.getLibraryName().isEmpty()) {
13991394
result = compiledLibrary.resolveCall(callContext, conversionMap);
14001395
if (result == null) {
14011396
result = getSystemLibrary().resolveCall(callContext, conversionMap);
@@ -2279,7 +2274,7 @@ public PropertyResolution resolveProperty(DataType sourceType, String identifier
22792274
"Inconsistent target maps %s and %s for choice type %s",
22802275
resultTargetMaps.get(resolution.getType()),
22812276
resolution.getTargetMap(),
2282-
resolution.getType().toString()));
2277+
resolution.getType()));
22832278
}
22842279
} else {
22852280
resultTargetMaps.put(resolution.getType(), resolution.getTargetMap());
@@ -2293,14 +2288,6 @@ public PropertyResolution resolveProperty(DataType sourceType, String identifier
22932288
"Inconsistent property resolution for choice type %s (was %s, is %s)",
22942289
choice.toString(), name, resolution.getName()));
22952290
}
2296-
2297-
if (name == null) {
2298-
name = resolution.getName();
2299-
} else if (!name.equals(resolution.getName())) {
2300-
throw new IllegalArgumentException(String.format(
2301-
"Inconsistent property resolution for choice type %s (was %s, is %s)",
2302-
choice.toString(), name, resolution.getName()));
2303-
}
23042291
}
23052292
}
23062293

@@ -2310,9 +2297,7 @@ public PropertyResolution resolveProperty(DataType sourceType, String identifier
23102297
}
23112298

23122299
if (resultTypes.size() == 1) {
2313-
for (DataType resultType : resultTypes) {
2314-
return new PropertyResolution(resultType, name, resultTargetMaps);
2315-
}
2300+
return new PropertyResolution(resultTypes.iterator().next(), name, resultTargetMaps);
23162301
}
23172302
} else if (currentType instanceof ListType && listTraversal) {
23182303
// NOTE: FHIRPath path traversal support
@@ -2495,10 +2480,7 @@ public Expression resolveIdentifier(String identifier, boolean mustResolve) {
24952480

24962481
if (element instanceof IncludeDef) {
24972482
checkLiteralContext();
2498-
LibraryRef libraryRef = new LibraryRef();
2499-
libraryRef.setLocalId(of.nextId());
2500-
libraryRef.setLibraryName(((IncludeDef) element).getLocalIdentifier());
2501-
return libraryRef;
2483+
return new LibraryRef(of.nextId(), ((IncludeDef) element).getLocalIdentifier());
25022484
}
25032485
}
25042486

@@ -3171,7 +3153,7 @@ private DataType getExpressionDefResultType(ExpressionDef expressionDef) {
31713153
if (inUnfilteredContext()) {
31723154
// If we are in the source clause of a query, indicate that the source references patient context
31733155
if (inQueryContext() && getScope().getQueries().peek().inSourceClause()) {
3174-
getScope().getQueries().peek().referenceSpecificContext();
3156+
getScope().getQueries().peek().setReferencesSpecificContextValue(true);
31753157
}
31763158

31773159
DataType resultType = expressionDef.getResultType();

Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/SystemMethodResolver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ private void checkArgumentCount(cqlParser.ParamListContext ctx, String functionN
5151

5252
private AliasedQuerySource enterQueryContext(Expression target) {
5353
QueryContext queryContext = new QueryContext();
54-
queryContext.setIsImplicit(
55-
true); // Set to an implicit context to allow for implicit resolution of property names
54+
queryContext.setImplicit(true);
55+
// Set to an implicit context to allow for implicit resolution of property names
5656
List<AliasedQuerySource> sources = new ArrayList<>();
5757
AliasedQuerySource source =
5858
of.createAliasedQuerySource().withExpression(target).withAlias("$this");

Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/CallContext.java

Lines changed: 0 additions & 61 deletions
This file was deleted.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.cqframework.cql.cql2elm.model
2+
3+
import org.hl7.cql.model.DataType
4+
5+
class CallContext(
6+
val libraryName: String?,
7+
val operatorName: String,
8+
val allowPromotionAndDemotion: Boolean,
9+
val allowFluent: Boolean,
10+
val mustResolve: Boolean,
11+
operandTypes: List<DataType>
12+
) {
13+
constructor(
14+
libraryName: String?,
15+
operatorName: String,
16+
allowPromotionAndDemotion: Boolean,
17+
allowFluent: Boolean,
18+
mustResolve: Boolean,
19+
vararg operandTypes: DataType
20+
) : this(
21+
libraryName,
22+
operatorName,
23+
allowPromotionAndDemotion,
24+
allowFluent,
25+
mustResolve,
26+
operandTypes.toList()
27+
)
28+
29+
val signature: Signature
30+
31+
init {
32+
require(operatorName.isNotEmpty()) { "operatorName is empty" }
33+
signature = Signature(operandTypes)
34+
}
35+
}

Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/Chunk.java

Lines changed: 0 additions & 131 deletions
This file was deleted.

0 commit comments

Comments
 (0)