gnodet commented on code in PR #12136:
URL: https://github.com/apache/maven/pull/12136#discussion_r3284328837
##########
impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/ConditionParser.java:
##########
@@ -129,18 +129,30 @@ private List<String> tokenize(String expression) {
}
quoteType = c;
sb.append(c);
- } else if (c == ' ' || c == '(' || c == ')' || c == ',' || c ==
'+' || c == '>' || c == '<' || c == '='
- || c == '!') {
+ } else if (Character.isWhitespace(c)
+ || c == '('
+ || c == ')'
+ || c == ','
+ || c == '+'
+ || c == '>'
+ || c == '<'
+ || c == '='
+ || c == '!'
+ || c == '&'
+ || c == '|') {
if (!sb.isEmpty()) {
tokens.add(sb.toString());
sb.setLength(0);
}
- if (c != ' ') {
+ if (!Character.isWhitespace(c)) {
if ((c == '>' || c == '<' || c == '=' || c == '!')
&& i + 1 < expression.length()
&& expression.charAt(i + 1) == '=') {
tokens.add(c + "=");
i++; // Skip the next character
+ } else if ((c == '&' || c == '|') && i + 1 <
expression.length() && expression.charAt(i + 1) == c) {
+ tokens.add(String.valueOf(c) + c);
+ i++; // Skip the next character
Review Comment:
Minor: if someone writes a lone `&` or `|` (without doubling), it falls
through to the `else` branch and gets added as a single-character token, which
will then cause `parseExpression()` to throw `"Unexpected tokens after end of
expression"`. That error message isn't very helpful for diagnosing a typo. Not
a blocker -- the old code didn't support these characters at all -- but worth
noting for a future improvement.
##########
impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/ConditionParser.java:
##########
@@ -129,18 +129,30 @@ private List<String> tokenize(String expression) {
}
quoteType = c;
sb.append(c);
- } else if (c == ' ' || c == '(' || c == ')' || c == ',' || c ==
'+' || c == '>' || c == '<' || c == '='
- || c == '!') {
+ } else if (Character.isWhitespace(c)
+ || c == '('
+ || c == ')'
+ || c == ','
+ || c == '+'
+ || c == '>'
+ || c == '<'
+ || c == '='
+ || c == '!'
+ || c == '&'
+ || c == '|') {
if (!sb.isEmpty()) {
tokens.add(sb.toString());
sb.setLength(0);
}
- if (c != ' ') {
+ if (!Character.isWhitespace(c)) {
if ((c == '>' || c == '<' || c == '=' || c == '!')
&& i + 1 < expression.length()
&& expression.charAt(i + 1) == '=') {
tokens.add(c + "=");
i++; // Skip the next character
+ } else if ((c == '&' || c == '|') && i + 1 <
expression.length() && expression.charAt(i + 1) == c) {
+ tokens.add(String.valueOf(c) + c);
+ i++; // Skip the next character
Review Comment:
Nit: the existing code on line 151 builds the two-char operator with `c +
"="` (char + String). Here the order is reversed to `String.valueOf(c) + c`,
which works but is inconsistent. Consider aligning the style:
```suggestion
} else if ((c == '&' || c == '|') && i + 1 <
expression.length() && expression.charAt(i + 1) == c) {
tokens.add("" + c + c);
i++; // Skip the next character
```
Or even simpler, use the same `c + ""` pattern that the `>=`/`<=` branch
above uses (`c + "="`). That said, this is purely cosmetic -- feel free to
ignore.
--
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]