Adding blank case for ExpressionNode.toString() in r4 and r5. (#609)

This commit is contained in:
Mark Iantorno 2021-09-27 14:52:55 -04:00 committed by GitHub
parent ad18e131d8
commit 72b7300700
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 102 additions and 95 deletions

View File

@ -1 +1,2 @@
* https://github.com/hapifhir/org.hl7.fhir.core/issues/499
* https://github.com/hapifhir/org.hl7.fhir.core/issues/602 * https://github.com/hapifhir/org.hl7.fhir.core/issues/602

View File

@ -331,43 +331,46 @@ public class ExpressionNode {
public String toString() { public String toString() {
StringBuilder b = new StringBuilder(); StringBuilder b = new StringBuilder();
switch (kind) { switch (kind) {
case Name: case Name:
b.append(name); b.append(name);
break; break;
case Function: case Function:
if (function == Function.Item) if (function == Function.Item)
b.append("["); b.append("[");
else { else {
b.append(name); b.append(name);
b.append("("); b.append("(");
} }
boolean first = true; boolean first = true;
for (ExpressionNode n : parameters) { for (ExpressionNode n : parameters) {
if (first) if (first)
first = false; first = false;
else else
b.append(", "); b.append(", ");
b.append(n.toString()); b.append(n.toString());
} }
if (function == Function.Item) if (function == Function.Item) {
b.append("]"); b.append("]");
else { } else {
b.append(")"); b.append(")");
} }
break; break;
case Constant: case Constant:
if (constant instanceof StringType) if (constant == null) {
b.append("'"+Utilities.escapeJson(constant.primitiveValue())+"'"); b.append("{}");
else if (constant instanceof Quantity) { } else if (constant instanceof StringType) {
b.append("'" + Utilities.escapeJson(constant.primitiveValue()) + "'");
} else if (constant instanceof Quantity) {
Quantity q = (Quantity) constant; Quantity q = (Quantity) constant;
b.append(Utilities.escapeJson(q.getValue().toPlainString())); b.append(Utilities.escapeJson(q.getValue().toPlainString()));
b.append(" '"); b.append(" '");
b.append(Utilities.escapeJson(q.getUnit())); b.append(Utilities.escapeJson(q.getUnit()));
b.append("'"); b.append("'");
} else if (constant.primitiveValue() != null) } else if (constant.primitiveValue() != null) {
b.append(Utilities.escapeJson(constant.primitiveValue())); b.append(Utilities.escapeJson(constant.primitiveValue()));
else } else {
b.append(Utilities.escapeJson(constant.toString())); b.append(Utilities.escapeJson(constant.toString()));
}
break; break;
case Group: case Group:
b.append("("); b.append("(");

View File

@ -395,25 +395,28 @@ public class ExpressionNode {
b.append(", "); b.append(", ");
b.append(n.toString()); b.append(n.toString());
} }
if (function == Function.Item) if (function == Function.Item) {
b.append("]"); b.append("]");
else { } else {
b.append(")"); b.append(")");
} }
break; break;
case Constant: case Constant:
if (constant instanceof StringType) if (constant == null) {
b.append("'"+Utilities.escapeJson(constant.primitiveValue())+"'"); b.append("{}");
else if (constant instanceof Quantity) { } else if (constant instanceof StringType) {
b.append("'" + Utilities.escapeJson(constant.primitiveValue()) + "'");
} else if (constant instanceof Quantity) {
Quantity q = (Quantity) constant; Quantity q = (Quantity) constant;
b.append(Utilities.escapeJson(q.getValue().toPlainString())); b.append(Utilities.escapeJson(q.getValue().toPlainString()));
b.append(" '"); b.append(" '");
b.append(Utilities.escapeJson(q.getUnit())); b.append(Utilities.escapeJson(q.getUnit()));
b.append("'"); b.append("'");
} else if (constant.primitiveValue() != null) } else if (constant.primitiveValue() != null) {
b.append(Utilities.escapeJson(constant.primitiveValue())); b.append(Utilities.escapeJson(constant.primitiveValue()));
else } else {
b.append(Utilities.escapeJson(constant.toString())); b.append(Utilities.escapeJson(constant.toString()));
}
break; break;
case Group: case Group:
b.append("("); b.append("(");