Skip to content

Commit

Permalink
Refactor instanceof expressions to use new Java 21 name syntax.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 695816069
Change-Id: Icd911c319f15d4ba2ed58318a51ba368c16bc16c
  • Loading branch information
katre authored and copybara-github committed Nov 12, 2024
1 parent 24ada2c commit 099fcbf
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/main/java/net/starlark/java/lib/json/Json.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ private void encode(Object x) throws EvalException {
return;
}

if (x instanceof String) {
appendQuoted((String) x);
if (x instanceof String s) {
appendQuoted(s);
return;
}

Expand All @@ -120,8 +120,8 @@ private void encode(Object x) throws EvalException {
return;
}

if (x instanceof StarlarkFloat) {
if (!Double.isFinite(((StarlarkFloat) x).toDouble())) {
if (x instanceof StarlarkFloat fl) {
if (!Double.isFinite(fl.toDouble())) {
throw Starlark.errorf("cannot encode non-finite float %s", x);
}
out.append(x.toString()); // always contains a decimal point or exponent
Expand All @@ -136,9 +136,7 @@ private void encode(Object x) throws EvalException {
}

// e.g. dict (must have string keys)
if (x instanceof Map) {
Map<?, ?> m = (Map) x;

if (x instanceof Map<?, ?> m) {
// Sort keys for determinism.
Object[] keys = m.keySet().toArray();
for (Object key : keys) {
Expand Down Expand Up @@ -169,11 +167,11 @@ private void encode(Object x) throws EvalException {
}

// e.g. tuple, list
if (x instanceof StarlarkIterable) {
if (x instanceof StarlarkIterable<?> it) {
out.append('[');
String sep = "";
int i = 0;
for (Object elem : (StarlarkIterable) x) {
for (Object elem : it) {
out.append(sep);
sep = ",";
try {
Expand All @@ -188,9 +186,7 @@ private void encode(Object x) throws EvalException {
}

// e.g. struct
if (x instanceof Structure) {
Structure obj = (Structure) x;

if (x instanceof Structure obj) {
// Sort keys for determinism.
String[] fields = obj.getFieldNames().toArray(new String[0]);
Arrays.sort(fields);
Expand Down

0 comments on commit 099fcbf

Please sign in to comment.