Skip to content

Commit

Permalink
More idiomatic parentheses handling in Groovy parser
Browse files Browse the repository at this point in the history
  • Loading branch information
knutwannheden committed Nov 21, 2023
1 parent 4f64ad3 commit bc98ea0
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1470,8 +1470,7 @@ public void visitMethodCallExpression(MethodCallExpression call) {
ImplicitDot implicitDot = null;
JRightPadded<Expression> select = null;
if (!call.isImplicitThis()) {
Expression selectExpr = insideParentheses(call.getObjectExpression(),
prefix -> this.<Expression>visit(call.getObjectExpression()).withPrefix(prefix));
Expression selectExpr = visit(call.getObjectExpression());
int saveCursor = cursor;
Space afterSelect = whitespace();
if (source.charAt(cursor) == '.' || source.charAt(cursor) == '?' || source.charAt(cursor) == '*') {
Expand Down Expand Up @@ -1691,10 +1690,10 @@ public void visitPropertyExpression(PropertyExpression prop) {

@Override
public void visitRangeExpression(RangeExpression range) {
queue.add(new G.Range(randomId(), whitespace(), Markers.EMPTY,
queue.add(insideParentheses(range, fmt -> new G.Range(randomId(), fmt, Markers.EMPTY,
visit(range.getFrom()),
JLeftPadded.build(range.isInclusive()).withBefore(sourceBefore(range.isInclusive() ? ".." : "..>")),
visit(range.getTo())));
visit(range.getTo()))));
}

@Override
Expand Down Expand Up @@ -2314,10 +2313,11 @@ private <G2 extends J> JRightPadded<G2> maybeSemicolon(G2 g) {

private String name() {
int i = cursor;
char c = source.charAt(i);
while (Character.isJavaIdentifierPart(c) || c == '.' || c == '*') {
i++;
c = source.charAt(i);
for (; i < source.length(); i++) {
char c = source.charAt(i);
if (!(Character.isJavaIdentifierPart(c) || c == '.' || c == '*')) {
break;
}
}
String result = source.substring(cursor, i);
cursor += i - cursor;
Expand Down

0 comments on commit bc98ea0

Please sign in to comment.