gnodet-bot commented on code in PR #27612:
URL: https://github.com/apache/camel/pull/27612#discussion_r4228273877
##########
components/camel-dataweave/src/main/java/org/apache/camel/component/dataweave/DataWeaveConverter.java:
##########
@@ -987,17 +1156,23 @@ private List<String> freshNames(List<String> params) {
return names;
}
- // Whether a function argument reads an attribute of its (first)
parameter: (e) -> e.@id, or $.@id
+ // Whether a function argument reads the attributes of its (first)
parameter: (e) -> e.@id, $.@id or $.@
private static boolean readsItemAttributes(DataWeaveAst fn) {
+ Predicate<DataWeaveAst> item;
+ DataWeaveAst body;
if (fn instanceof Lambda lam) {
if (lam.params().isEmpty()) {
return false;
}
String name = lam.params().get(0).name();
- return anyNode(lam.body(), n -> n instanceof AttributeAccess aa &&
aa.object() instanceof Identifier id
- && id.name().equals(name));
+ item = n -> n instanceof Identifier id && id.name().equals(name);
+ body = lam.body();
+ } else {
+ item = n -> n instanceof Dollar d && d.level() == 1;
+ body = fn;
}
- return anyNode(fn, n -> n instanceof AttributeAccess aa && aa.object()
instanceof Dollar d && d.level() == 1);
+ return anyNode(body, n -> n instanceof AttributeAccess aa &&
item.test(aa.object())
+ || n instanceof AllAttributes all && item.test(all.object()));
Review Comment:
💡 **Style:** The mixed `&&` / `||` without parentheses across a line break
makes precedence non-obvious at a glance. Since `&&` binds tighter than `||`,
this is `(A && B) || (C && D)`, which is the intended meaning — but adding
parens makes it unambiguous:
```suggestion
return anyNode(body, n -> (n instanceof AttributeAccess aa &&
item.test(aa.object()))
|| (n instanceof AllAttributes all &&
item.test(all.object())));
```
##########
docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_23.adoc:
##########
@@ -4993,8 +4993,10 @@ DataSonnet directly, or moved to a `.ds` file.
The conversion also follows the DataWeave semantics more closely, which
changes the result of some
scripts that were converted before. For example, a selector on a missing field
now gives `null` (as
in DataWeave) instead of failing, `default` applies to missing fields, and a
field selector on an array
-selects the field of every element. Unknown functions and variables are no
longer passed through
-unchanged, but fail the conversion. The converted scripts use the new
`camel-dataweave.libsonnet` library of
+selects the field of every element. With an XML input, a selector matches an
element by its local name
+(whatever its namespace prefix), an empty element is `null`, and an element
written to another format than XML
+no longer includes the attributes, namespace declarations and positions of the
DataSonnet XML model. Unknown
+functions and variables are no longer passed through unchanged, but fail the
conversion. The converted scripts use the new `camel-dataweave.libsonnet`
library of
Review Comment:
💡 **Style:** This line is ~161 characters after a sentence was merged into
it. Consider splitting it at a natural break (e.g. before `The converted
scripts`) to keep lines within a readable width and consistent with the
surrounding doc style.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]