Skip to content

Commit

Permalink
Remove type from TupleTypeElement and ChoiceType, which were deprecat…
Browse files Browse the repository at this point in the history
…ed (#1482)
  • Loading branch information
JPercival authored Dec 20, 2024
1 parent 545e77e commit 12f59f3
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 102 deletions.
10 changes: 0 additions & 10 deletions Src/cql-lm/schema/elm/expression.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,6 @@
<xs:complexContent>
<xs:extension base="Element">
<xs:sequence>
<xs:element name="type" type="TypeSpecifier" minOccurs="0" maxOccurs="1">
<xs:annotation>
<xs:documentation>This element is deprecated. New implementations should use the new elementType element.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="elementType" type="TypeSpecifier" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required"/>
Expand All @@ -118,11 +113,6 @@
<xs:complexContent>
<xs:extension base="TypeSpecifier">
<xs:sequence>
<xs:element name="type" type="TypeSpecifier" minOccurs="0" maxOccurs="unbounded">
<xs:annotation>
<xs:documentation>This element is deprecated. New implementations should use the new choice element.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="choice" type="TypeSpecifier" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:extension>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,6 @@ public TupleElementDefinition visitTupleElementDefinition(cqlParser.TupleElement
.withName(parseString(ctx.referentialIdentifier()))
.withElementType(parseTypeSpecifier(ctx.typeSpecifier()));

if (getIncludeDeprecatedElements()) {
result.setType(result.getElementType());
}

return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,7 @@ public Library run(CharStream is) {
var edits = allNonNull(
!options.contains(EnableAnnotations) ? ElmEdit.REMOVE_ANNOTATION : null,
!options.contains(EnableResultTypes) ? ElmEdit.REMOVE_RESULT_TYPE : null,
!options.contains(EnableLocators) ? ElmEdit.REMOVE_LOCATOR : null,
ElmEdit.REMOVE_CHOICE_TYPE_SPECIFIER_TYPE_IF_EMPTY);
!options.contains(EnableLocators) ? ElmEdit.REMOVE_LOCATOR : null);

new ElmEditor(edits).edit(library);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.cqframework.cql.cql2elm.elm;

import org.hl7.cql_annotations.r1.Annotation;
import org.hl7.elm.r1.ChoiceTypeSpecifier;
import org.hl7.elm.r1.Element;

public enum ElmEdit implements IElmEdit {
Expand Down Expand Up @@ -39,24 +38,5 @@ public void edit(Element element) {
element.setResultTypeName(null);
element.setResultTypeSpecifier(null);
}
},
REMOVE_CHOICE_TYPE_SPECIFIER_TYPE_IF_EMPTY {
// The ChoiceTypeSpecifier ELM node has a deprecated `type` element which, if not null, clashes with the
// `"type" : "ChoiceTypeSpecifier"` field in the JSON serialization of the node. This does not happen in the XML
// serialization which nests <type> tags inside <ChoiceTypeSpecifier>.
// Because the `type` element is deprecated, it is not normally populated by the compiler anymore and
// stays null in the ChoiceTypeSpecifier instance. It is however set to an empty list if you just call
// ChoiceTypeSpecifier.getType() (which we do during the ELM optimization stage in the compiler), so
// this edit is needed to "protect" the downstream JSON serialization if it can be done without data loss.

@Override
public void edit(Element element) {
if (element instanceof ChoiceTypeSpecifier) {
var choice = (ChoiceTypeSpecifier) element;
if (choice.getType().isEmpty()) {
choice.setType(null);
}
}
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public class CqlPreprocessorElmCommonVisitor extends cqlBaseVisitor<Object> {
private boolean fromKeywordRequired = false;

private final List<Expression> expressions = new ArrayList<>();
private boolean includeDeprecatedElements = false;

public CqlPreprocessorElmCommonVisitor(LibraryBuilder libraryBuilder, TokenStream tokenStream) {
this.libraryBuilder = Objects.requireNonNull(libraryBuilder, "libraryBuilder required");
Expand Down Expand Up @@ -152,10 +151,6 @@ public TupleElementDefinition visitTupleElementDefinition(cqlParser.TupleElement
.withName(parseString(ctx.referentialIdentifier()))
.withElementType(parseTypeSpecifier(ctx.typeSpecifier()));

if (includeDeprecatedElements) {
result.setType(result.getElementType());
}

return result;
}

Expand Down Expand Up @@ -185,9 +180,6 @@ public ChoiceTypeSpecifier visitChoiceTypeSpecifier(cqlParser.ChoiceTypeSpecifie
types.add(typeSpecifier.getResultType());
}
ChoiceTypeSpecifier result = of.createChoiceTypeSpecifier().withChoice(typeSpecifiers);
if (includeDeprecatedElements) {
result.getType().addAll(typeSpecifiers);
}
ChoiceType choiceType = new ChoiceType(types);
result.setResultType(choiceType);
return result;
Expand Down Expand Up @@ -884,14 +876,6 @@ public void disableFromKeywordRequired() {
fromKeywordRequired = false;
}

public boolean getIncludeDeprecatedElements() {
return includeDeprecatedElements;
}

public void setIncludeDeprecatedElements(boolean includeDeprecatedElements) {
this.includeDeprecatedElements = includeDeprecatedElements;
}

private void setCompilerOptions(CqlCompilerOptions options) {
if (options.getOptions().contains(CqlCompilerOptions.Options.EnableDateRangeOptimization)) {
this.enableDateRangeOptimization();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ public boolean typeSpecifiersEqual(TypeSpecifier left, TypeSpecifier right) {
leftArg.getElement().get(i);
TupleElementDefinition rightElement =
rightArg.getElement().get(i);
if (!typeSpecifiersEqual(leftElement.getType(), rightElement.getType())
|| !typeSpecifiersEqual(leftElement.getElementType(), rightElement.getElementType())
if (!typeSpecifiersEqual(leftElement.getElementType(), rightElement.getElementType())
|| !stringsEqual(leftElement.getName(), rightElement.getName())) {
return false;
}
Expand All @@ -181,12 +180,12 @@ public boolean typeSpecifiersEqual(TypeSpecifier left, TypeSpecifier right) {
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 (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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,6 @@ public T visitTupleElementDefinition(TupleElementDefinition elm, C context) {
result = aggregateResult(result, childResult);
}

if (elm.getType() != null) {
T childResult = visitTypeSpecifier(elm.getType(), context);
result = aggregateResult(result, childResult);
}

return result;
}

Expand Down Expand Up @@ -220,11 +215,6 @@ public T visitChoiceTypeSpecifier(ChoiceTypeSpecifier elm, C context) {
result = aggregateResult(result, childResult);
}

for (var type : elm.getType()) {
T childResult = visitTypeSpecifier(type, context);
result = aggregateResult(result, childResult);
}

return result;
}

Expand Down

0 comments on commit 12f59f3

Please sign in to comment.