Skip to content

Commit 490615d

Browse files
committed
compiler warnings
1 parent c758642 commit 490615d

File tree

1 file changed

+60
-79
lines changed
  • json-java21-jsonpath/src/main/java/json/java21/jsonpath

1 file changed

+60
-79
lines changed

json-java21-jsonpath/src/main/java/json/java21/jsonpath/JsonPath.java

Lines changed: 60 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,14 @@ public static JsonPath parse(String path) {
4444
return new JsonPath(ast);
4545
}
4646

47-
/// Selects matching values from a JSON document.
48-
/// @param json the JSON document to query
49-
/// @return a list of matching JsonValue instances (may be empty)
50-
/// @throws NullPointerException if json is null
51-
/// @deprecated Use `query(JsonValue)` (aligns with Goessner JSONPath terminology).
52-
@Deprecated(forRemoval = false)
53-
public List<JsonValue> select(JsonValue json) {
54-
return query(json);
55-
}
56-
5747
/// Queries matching values from a JSON document.
5848
///
5949
/// This is the preferred instance API: compile once via `parse(String)`, then call `query(JsonValue)`
6050
/// for each already-parsed JSON document.
6151
///
6252
/// @param json the JSON document to query
63-
/// @return a list of matching JsonValue instances (may be empty)
64-
/// @throws NullPointerException if json is null
53+
/// @return a list of matching JsonValue instances (maybe empty)
54+
/// @throws NullPointerException if JSON is null
6555
public List<JsonValue> query(JsonValue json) {
6656
Objects.requireNonNull(json, "json must not be null");
6757
LOG.fine(() -> "Querying document with path: " + this);
@@ -74,21 +64,11 @@ public String toString() {
7464
return reconstruct(ast);
7565
}
7666

77-
/// Returns the parsed AST.
78-
public JsonPathAst.Root ast() {
79-
return ast;
80-
}
81-
82-
/// Returns the original path expression.
83-
public String expression() {
84-
return "Todo";
85-
}
86-
8767
/// Evaluates a compiled JsonPath against a JSON document.
8868
/// @param path a compiled JsonPath (typically cached)
8969
/// @param json the JSON document to query
90-
/// @return a list of matching JsonValue instances (may be empty)
91-
/// @throws NullPointerException if path or json is null
70+
/// @return a list of matching JsonValue instances (maybe empty)
71+
/// @throws NullPointerException if path or JSON is null
9272
public static List<JsonValue> query(JsonPath path, JsonValue json) {
9373
Objects.requireNonNull(path, "path must not be null");
9474
return path.query(json);
@@ -97,7 +77,7 @@ public static List<JsonValue> query(JsonPath path, JsonValue json) {
9777
/// Evaluates a pre-parsed JsonPath AST against a JSON document.
9878
/// @param ast the parsed JsonPath AST
9979
/// @param json the JSON document to query
100-
/// @return a list of matching JsonValue instances (may be empty)
80+
/// @return a list of matching JsonValue instances (maybe empty)
10181
static List<JsonValue> evaluate(JsonPathAst.Root ast, JsonValue json) {
10282
Objects.requireNonNull(ast, "ast must not be null");
10383
Objects.requireNonNull(json, "json must not be null");
@@ -127,7 +107,7 @@ private static void evaluateSegments(
127107
case JsonPathAst.PropertyAccess prop -> evaluatePropertyAccess(prop, segments, index, current, root, results);
128108
case JsonPathAst.ArrayIndex arr -> evaluateArrayIndex(arr, segments, index, current, root, results);
129109
case JsonPathAst.ArraySlice slice -> evaluateArraySlice(slice, segments, index, current, root, results);
130-
case JsonPathAst.Wildcard wildcard -> evaluateWildcard(segments, index, current, root, results);
110+
case JsonPathAst.Wildcard ignored -> evaluateWildcard(segments, index, current, root, results);
131111
case JsonPathAst.RecursiveDescent desc -> evaluateRecursiveDescent(desc, segments, index, current, root, results);
132112
case JsonPathAst.Filter filter -> evaluateFilter(filter, segments, index, current, root, results);
133113
case JsonPathAst.Union union -> evaluateUnion(union, segments, index, current, root, results);
@@ -276,7 +256,7 @@ private static void evaluateTargetSegment(
276256
}
277257
}
278258
}
279-
case JsonPathAst.Wildcard w -> {
259+
case JsonPathAst.Wildcard ignored -> {
280260
if (current instanceof JsonObject obj) {
281261
for (final var value : obj.members().values()) {
282262
evaluateSegments(segments, index + 1, value, root, results);
@@ -297,10 +277,8 @@ private static void evaluateTargetSegment(
297277
}
298278
}
299279
}
300-
default -> {
301-
// Other segment types in recursive descent context
302-
LOG.finer(() -> "Unsupported target in recursive descent: " + target);
303-
}
280+
default -> // Other segment types in recursive descent context
281+
LOG.finer(() -> "Unsupported target in recursive descent: " + target);
304282
}
305283
}
306284

@@ -340,9 +318,9 @@ yield switch (logical.op()) {
340318
case NOT -> !leftMatch;
341319
};
342320
}
343-
case JsonPathAst.CurrentNode cn -> true;
321+
case JsonPathAst.CurrentNode ignored1 -> true;
344322
case JsonPathAst.PropertyPath path -> resolvePropertyPath(path, current) != null;
345-
case JsonPathAst.LiteralValue lv -> true;
323+
case JsonPathAst.LiteralValue ignored -> true;
346324
};
347325
}
348326

@@ -353,7 +331,7 @@ private static Object resolveFilterExpression(JsonPathAst.FilterExpression expr,
353331
yield jsonValueToComparable(value);
354332
}
355333
case JsonPathAst.LiteralValue lit -> lit.value();
356-
case JsonPathAst.CurrentNode cn2 -> jsonValueToComparable(current);
334+
case JsonPathAst.CurrentNode ignored -> jsonValueToComparable(current);
357335
default -> null;
358336
};
359337
}
@@ -379,7 +357,7 @@ private static Object jsonValueToComparable(JsonValue value) {
379357
case JsonString s -> s.string();
380358
case JsonNumber n -> n.toDouble();
381359
case JsonBoolean b -> b.bool();
382-
case JsonNull jn -> null;
360+
case JsonNull ignored -> null;
383361
default -> value;
384362
};
385363
}
@@ -395,40 +373,45 @@ private static boolean compareValues(Object left, JsonPathAst.ComparisonOp op, O
395373
}
396374

397375
// Try numeric comparison
398-
if (left instanceof Number leftNum && right instanceof Number rightNum) {
399-
final double l = leftNum.doubleValue();
400-
final double r = rightNum.doubleValue();
401-
return switch (op) {
402-
case EQ -> l == r;
403-
case NE -> l != r;
404-
case LT -> l < r;
405-
case LE -> l <= r;
406-
case GT -> l > r;
407-
case GE -> l >= r;
408-
};
409-
}
376+
switch (left) {
377+
case Number leftNum when right instanceof Number rightNum -> {
378+
final double l = leftNum.doubleValue();
379+
final double r = rightNum.doubleValue();
380+
return switch (op) {
381+
case EQ -> l == r;
382+
case NE -> l != r;
383+
case LT -> l < r;
384+
case LE -> l <= r;
385+
case GT -> l > r;
386+
case GE -> l >= r;
387+
};
388+
}
410389

411-
// String comparison
412-
if (left instanceof String && right instanceof String) {
413-
@SuppressWarnings("rawtypes")
414-
final int cmp = ((Comparable) left).compareTo(right);
415-
return switch (op) {
416-
case EQ -> cmp == 0;
417-
case NE -> cmp != 0;
418-
case LT -> cmp < 0;
419-
case LE -> cmp <= 0;
420-
case GT -> cmp > 0;
421-
case GE -> cmp >= 0;
422-
};
423-
}
424390

425-
// Boolean comparison
426-
if (left instanceof Boolean && right instanceof Boolean) {
427-
return switch (op) {
428-
case EQ -> left.equals(right);
429-
case NE -> !left.equals(right);
430-
default -> false;
431-
};
391+
// String comparison
392+
case String ignored when right instanceof String -> {
393+
@SuppressWarnings("rawtypes") final int cmp = ((Comparable) left).compareTo(right);
394+
return switch (op) {
395+
case EQ -> cmp == 0;
396+
case NE -> cmp != 0;
397+
case LT -> cmp < 0;
398+
case LE -> cmp <= 0;
399+
case GT -> cmp > 0;
400+
case GE -> cmp >= 0;
401+
};
402+
}
403+
404+
405+
// Boolean comparison
406+
case Boolean ignored when right instanceof Boolean -> {
407+
return switch (op) {
408+
case EQ -> left.equals(right);
409+
case NE -> !left.equals(right);
410+
default -> false;
411+
};
412+
}
413+
default -> {
414+
}
432415
}
433416

434417
// Fallback equality
@@ -504,7 +487,7 @@ private static void appendSegment(StringBuilder sb, JsonPathAst.Segment segment)
504487
if (slice.step() != null) sb.append(":").append(slice.step());
505488
sb.append("]");
506489
}
507-
case JsonPathAst.Wildcard w -> sb.append(".*");
490+
case JsonPathAst.Wildcard ignored -> sb.append(".*");
508491
case JsonPathAst.RecursiveDescent desc -> {
509492
sb.append("..");
510493
// RecursiveDescent target is usually PropertyAccess or Wildcard,
@@ -515,7 +498,7 @@ private static void appendSegment(StringBuilder sb, JsonPathAst.Segment segment)
515498
// We need to handle how it's appended.
516499
// appendSegment prepends "." or "[" usually.
517500
// But ".." replaces the dot.
518-
// Let's special case the target printing.
501+
// Let special case the target printing.
519502
appendRecursiveTarget(sb, desc.target());
520503
}
521504
case JsonPathAst.Filter filter -> {
@@ -537,8 +520,8 @@ private static void appendSegment(StringBuilder sb, JsonPathAst.Segment segment)
537520
}
538521

539522
private static void appendRecursiveTarget(StringBuilder sb, JsonPathAst.Segment target) {
540-
if (target instanceof JsonPathAst.PropertyAccess prop) {
541-
sb.append(prop.name()); // ..name
523+
if (target instanceof JsonPathAst.PropertyAccess(String name)) {
524+
sb.append(name); // ..name
542525
} else if (target instanceof JsonPathAst.Wildcard) {
543526
sb.append("*"); // ..*
544527
} else {
@@ -548,10 +531,10 @@ private static void appendRecursiveTarget(StringBuilder sb, JsonPathAst.Segment
548531
}
549532

550533
private static void appendUnionSelector(StringBuilder sb, JsonPathAst.Segment selector) {
551-
if (selector instanceof JsonPathAst.PropertyAccess prop) {
552-
sb.append("'").append(escape(prop.name())).append("'");
553-
} else if (selector instanceof JsonPathAst.ArrayIndex arr) {
554-
sb.append(arr.index());
534+
if (selector instanceof JsonPathAst.PropertyAccess(String name)) {
535+
sb.append("'").append(escape(name)).append("'");
536+
} else if (selector instanceof JsonPathAst.ArrayIndex(int index)) {
537+
sb.append(index);
555538
} else {
556539
// Fallback
557540
appendSegment(sb, selector);
@@ -560,9 +543,7 @@ private static void appendUnionSelector(StringBuilder sb, JsonPathAst.Segment se
560543

561544
private static void appendFilterExpression(StringBuilder sb, JsonPathAst.FilterExpression expr) {
562545
switch (expr) {
563-
case JsonPathAst.ExistsFilter exists -> {
564-
appendFilterExpression(sb, exists.path()); // Should print the path
565-
}
546+
case JsonPathAst.ExistsFilter exists -> appendFilterExpression(sb, exists.path()); // Should print the path
566547
case JsonPathAst.ComparisonFilter comp -> {
567548
appendFilterExpression(sb, comp.left());
568549
sb.append(comp.op().symbol());
@@ -580,7 +561,7 @@ private static void appendFilterExpression(StringBuilder sb, JsonPathAst.FilterE
580561
sb.append(")");
581562
}
582563
}
583-
case JsonPathAst.CurrentNode cn -> sb.append("@");
564+
case JsonPathAst.CurrentNode ignored -> sb.append("@");
584565
case JsonPathAst.PropertyPath path -> {
585566
sb.append("@");
586567
for (String p : path.properties()) {

0 commit comments

Comments
 (0)