@@ -504,8 +504,8 @@ class B { class B {
504
504
methodName = method .getName ();
505
505
} else {
506
506
// Method name might be in quotes
507
- char openingQuote = source .charAt (cursor );
508
- methodName = openingQuote + method . getName ( ) + openingQuote ;
507
+ String delim = source .charAt (cursor ) + "" ;
508
+ methodName = sourceSubstring ( cursor , delim ) + delim ;
509
509
}
510
510
cursor += methodName .length ();
511
511
J .Identifier name = new J .Identifier (randomId (),
@@ -1739,25 +1739,26 @@ public void visitMethodCallExpression(MethodCallExpression call) {
1739
1739
// So the "select" that was just parsed _may_ have actually been the method name
1740
1740
J .Identifier name ;
1741
1741
1742
- String methodNameExpression = call .getMethodAsString ();
1742
+ String methodName = call .getMethodAsString ();
1743
+ // Check for escaped method name, often used in tests (def 'description'() {}) or to avoid clashing with Groovy keywords
1743
1744
if (source .charAt (cursor ) == '"' || source .charAt (cursor ) == '\'' ) {
1744
- // we have an escaped groovy method name, commonly used for test `def 'some scenario description'() {}`
1745
- // or to workaround names that are also keywords in groovy
1746
- methodNameExpression = source . charAt (cursor ) + methodNameExpression + source . charAt ( cursor ) ;
1745
+ // TODO: Methods with string interpolation are parsed as just one method name instead of multiple LST elements
1746
+ String delim = source . charAt ( cursor ) + "" ;
1747
+ methodName = sourceSubstring (cursor , delim ) + delim ;
1747
1748
}
1748
1749
1749
1750
Space prefix = whitespace ();
1750
- boolean implicitCall = (methodNameExpression != null && cursor < source .length () &&
1751
- source .charAt (cursor ) == '(' && (cursor + methodNameExpression .length () > source .length () ||
1752
- !methodNameExpression .equals (source .substring (cursor , cursor + methodNameExpression .length ())))
1751
+ boolean implicitCall = (methodName != null && cursor < source .length () &&
1752
+ source .charAt (cursor ) == '(' && (cursor + methodName .length () > source .length () ||
1753
+ !methodName .equals (source .substring (cursor , cursor + methodName .length ())))
1753
1754
);
1754
1755
if (implicitCall ) {
1755
1756
// This is an implicit call() method - create identifier but it doesn't get printed
1756
1757
name = new J .Identifier (randomId (), prefix , Markers .EMPTY , emptyList (), "" , null , null );
1757
1758
} else {
1758
- if (methodNameExpression .equals (source .substring (cursor , cursor + methodNameExpression .length ()))) {
1759
- skip (methodNameExpression );
1760
- name = new J .Identifier (randomId (), prefix , Markers .EMPTY , emptyList (), methodNameExpression , null , null );
1759
+ if (methodName .equals (source .substring (cursor , cursor + methodName .length ()))) {
1760
+ skip (methodName );
1761
+ name = new J .Identifier (randomId (), prefix , Markers .EMPTY , emptyList (), methodName , null , null );
1761
1762
} else if (select != null && select .getElement () instanceof J .Identifier ) {
1762
1763
name = (J .Identifier ) select .getElement ();
1763
1764
select = null ;
0 commit comments