gnodet-bot commented on code in PR #28046:
URL: https://github.com/apache/camel/pull/28046#discussion_r4306302504
##########
dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/main/java/org/apache/camel/dsl/yaml/validator/SchemaHints.java:
##########
@@ -129,6 +129,27 @@ static String unquotedBraces(Match m) {
}
/** The text of a scalar property of the error's node, or the fallback
when it is not a scalar. */
Review Comment:
💡 **Javadoc placement:** the `/** The text of a scalar property... */`
Javadoc now documents `SCRIPT_FILE` rather than `valueOf` — the new constant
and method were inserted between the Javadoc and the method it was written for.
Consider moving the new additions before that Javadoc (i.e. between
`unquotedBraces` and the `valueOf` Javadoc), or repeating the `valueOf` Javadoc
after the insertion.
##########
dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/main/java/org/apache/camel/dsl/yaml/validator/SchemaHints.java:
##########
@@ -129,6 +129,27 @@ static String unquotedBraces(Match m) {
}
/** The text of a scalar property of the error's node, or the fallback
when it is not a scalar. */
+ /** A value that names a script file by its scheme, as resource: loads it.
*/
+ private static final Pattern SCRIPT_FILE =
Pattern.compile("(file|classpath|https?):.+", Pattern.DOTALL);
+
+ /**
+ * Where the text of a language goes, for the text written under another
key (groovy: {script: "..."}). A script
+ * file under resource: (groovy: {resource: "file:x.groovy"}) is loaded
with the resource: prefix, which the value
+ * often lacks (CAMEL-25748): the expression "file:x.groovy" would run as
code.
+ */
+ static String languageTextHint(String language, String property, String
value) {
+ String key = property.toLowerCase(Locale.ROOT);
+ String text = value.strip();
+ boolean scriptFile = !text.startsWith("resource:")
+ && (key.contains("resource") || key.startsWith("script") &&
SCRIPT_FILE.matcher(text).matches());
Review Comment:
💡 **Readability:** `&&` binds tighter than `||` in Java so the precedence is
correct, but explicit inner parentheses would make the intent clearer:
```suggestion
boolean scriptFile = !text.startsWith("resource:")
&& (key.contains("resource") || (key.startsWith("script") &&
SCRIPT_FILE.matcher(text).matches()));
```
--
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]