From 4866823f5f474bd738e5d49b5273bd44786bd2ad Mon Sep 17 00:00:00 2001 From: Bryn Rhodes Date: Tue, 29 Oct 2024 22:51:22 -0600 Subject: [PATCH] Spotless and quality gate fixes --- .../cql/cql2elm/Cql2ElmVisitor.java | 4 ++ .../cql/cql2elm/LibraryBuilder.java | 9 ++-- .../cql/cql2elm/model/OperatorEntry.java | 3 +- .../cql/cql2elm/TranslationTests.java | 44 +++++++++---------- 4 files changed, 32 insertions(+), 28 deletions(-) diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/Cql2ElmVisitor.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/Cql2ElmVisitor.java index c4c1de08e..d5041a294 100755 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/Cql2ElmVisitor.java +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/Cql2ElmVisitor.java @@ -734,6 +734,10 @@ public Object visitListSelector(cqlParser.ListSelectorContext ctx) { for (cqlParser.ExpressionContext elementContext : ctx.expression()) { Expression element = parseExpression(elementContext); + if (element == null) { + throw new RuntimeException("Element failed to parse"); + } + if (elementType != null) { libraryBuilder.verifyType(element.getResultType(), elementType); } else { diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/LibraryBuilder.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/LibraryBuilder.java index 9e66f360d..a4fc5efcf 100644 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/LibraryBuilder.java +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/LibraryBuilder.java @@ -1100,8 +1100,7 @@ public Invocation resolveProperContainsInvocation( private int getTypeScore(OperatorResolution resolution) { int typeScore = ConversionMap.ConversionScore.ExactMatch.score(); - for (DataType operand : - resolution.getOperator().getSignature().getOperandTypes()) { + for (DataType operand : resolution.getOperator().getSignature().getOperandTypes()) { typeScore += ConversionMap.getTypePrecedenceScore(operand); } @@ -1114,10 +1113,12 @@ private Expression lowestScoringInvocation(Invocation primary, Invocation second if (secondary.getResolution().getScore() < primary.getResolution().getScore()) { return secondary.getExpression(); - } else if (primary.getResolution().getScore() < secondary.getResolution().getScore()) { + } else if (primary.getResolution().getScore() + < secondary.getResolution().getScore()) { return primary.getExpression(); } - if (primary.getResolution().getScore() == secondary.getResolution().getScore()) { + if (primary.getResolution().getScore() + == secondary.getResolution().getScore()) { int primaryTypeScore = getTypeScore(primary.getResolution()); int secondaryTypeScore = getTypeScore(secondary.getResolution()); diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/OperatorEntry.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/OperatorEntry.java index 9c8f87d04..ed1a17a34 100644 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/OperatorEntry.java +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/OperatorEntry.java @@ -78,8 +78,7 @@ private OperatorResolution getOperatorResolution( boolean requireConversions) { Conversion[] conversions = getConversions( callSignature, operator.getSignature(), conversionMap, operatorMap, allowPromotionAndDemotion); - OperatorResolution result = new OperatorResolution( - operator, conversions); + OperatorResolution result = new OperatorResolution(operator, conversions); if (requireConversions && conversions == null) { return null; } diff --git a/Src/java/cql-to-elm/src/test/java/org/cqframework/cql/cql2elm/TranslationTests.java b/Src/java/cql-to-elm/src/test/java/org/cqframework/cql/cql2elm/TranslationTests.java index 808511f6d..876205432 100644 --- a/Src/java/cql-to-elm/src/test/java/org/cqframework/cql/cql2elm/TranslationTests.java +++ b/Src/java/cql-to-elm/src/test/java/org/cqframework/cql/cql2elm/TranslationTests.java @@ -341,67 +341,67 @@ void resolutionProperlyIncludesTests() throws IOException { ExpressionDef test = statements.get(0); assertThat(test.getExpression(), instanceOf(ProperContains.class)); - ProperContains properContains = (ProperContains)test.getExpression(); + ProperContains properContains = (ProperContains) test.getExpression(); assertThat(properContains.getOperand().get(0), instanceOf(Interval.class)); - Interval interval = (Interval)properContains.getOperand().get(0); + Interval interval = (Interval) properContains.getOperand().get(0); assertThat(interval.getResultType(), instanceOf(IntervalType.class)); - IntervalType intervalType = (IntervalType)interval.getResultType(); + IntervalType intervalType = (IntervalType) interval.getResultType(); assertThat(intervalType.getPointType(), instanceOf(SimpleType.class)); - SimpleType pointType = (SimpleType)intervalType.getPointType(); + SimpleType pointType = (SimpleType) intervalType.getPointType(); assertThat(pointType.getName(), equalTo("System.Integer")); assertThat(properContains.getOperand().get(1), instanceOf(As.class)); - As _as = (As)properContains.getOperand().get(1); + As _as = (As) properContains.getOperand().get(1); assertThat(_as.getAsType().toString(), equalTo("{urn:hl7-org:elm-types:r1}Integer")); assertThat(_as.getOperand(), instanceOf(Null.class)); test = statements.get(1); assertThat(test.getExpression(), instanceOf(ProperContains.class)); - properContains = (ProperContains)test.getExpression(); + properContains = (ProperContains) test.getExpression(); assertThat(properContains.getOperand().get(0), instanceOf(Interval.class)); - interval = (Interval)properContains.getOperand().get(0); + interval = (Interval) properContains.getOperand().get(0); assertThat(interval.getResultType(), instanceOf(IntervalType.class)); - intervalType = (IntervalType)interval.getResultType(); + intervalType = (IntervalType) interval.getResultType(); assertThat(intervalType.getPointType(), instanceOf(SimpleType.class)); - pointType = (SimpleType)intervalType.getPointType(); + pointType = (SimpleType) intervalType.getPointType(); assertThat(pointType.getName(), equalTo("System.Integer")); assertThat(properContains.getOperand().get(1), instanceOf(As.class)); - _as = (As)properContains.getOperand().get(1); + _as = (As) properContains.getOperand().get(1); assertThat(_as.getAsType().toString(), equalTo("{urn:hl7-org:elm-types:r1}Integer")); assertThat(_as.getOperand(), instanceOf(Null.class)); test = statements.get(2); assertThat(test.getExpression(), instanceOf(ProperContains.class)); - properContains = (ProperContains)test.getExpression(); + properContains = (ProperContains) test.getExpression(); assertThat(properContains.getOperand().get(0), instanceOf(Interval.class)); - interval = (Interval)properContains.getOperand().get(0); + interval = (Interval) properContains.getOperand().get(0); assertThat(interval.getResultType(), instanceOf(IntervalType.class)); - intervalType = (IntervalType)interval.getResultType(); + intervalType = (IntervalType) interval.getResultType(); assertThat(intervalType.getPointType(), instanceOf(SimpleType.class)); - pointType = (SimpleType)intervalType.getPointType(); + pointType = (SimpleType) intervalType.getPointType(); assertThat(pointType.getName(), equalTo("System.Any")); assertThat(properContains.getOperand().get(1), instanceOf(Null.class)); test = statements.get(3); assertThat(test.getExpression(), instanceOf(ProperContains.class)); - properContains = (ProperContains)test.getExpression(); + properContains = (ProperContains) test.getExpression(); assertThat(properContains.getOperand().get(0), instanceOf(Interval.class)); - interval = (Interval)properContains.getOperand().get(0); + interval = (Interval) properContains.getOperand().get(0); assertThat(interval.getResultType(), instanceOf(IntervalType.class)); - intervalType = (IntervalType)interval.getResultType(); + intervalType = (IntervalType) interval.getResultType(); assertThat(intervalType.getPointType(), instanceOf(SimpleType.class)); - pointType = (SimpleType)intervalType.getPointType(); + pointType = (SimpleType) intervalType.getPointType(); assertThat(pointType.getName(), equalTo("System.Any")); assertThat(properContains.getOperand().get(1), instanceOf(Null.class)); test = statements.get(4); assertThat(test.getExpression(), instanceOf(ProperContains.class)); - properContains = (ProperContains)test.getExpression(); + properContains = (ProperContains) test.getExpression(); assertThat(properContains.getOperand().get(0), instanceOf(Interval.class)); - interval = (Interval)properContains.getOperand().get(0); + interval = (Interval) properContains.getOperand().get(0); assertThat(interval.getResultType(), instanceOf(IntervalType.class)); - intervalType = (IntervalType)interval.getResultType(); + intervalType = (IntervalType) interval.getResultType(); assertThat(intervalType.getPointType(), instanceOf(SimpleType.class)); - pointType = (SimpleType)intervalType.getPointType(); + pointType = (SimpleType) intervalType.getPointType(); assertThat(pointType.getName(), equalTo("System.Integer")); assertThat(properContains.getOperand().get(1), instanceOf(As.class)); }