Skip to content

Commit

Permalink
Fix parsing of nested generics in Groovy (#4707)
Browse files Browse the repository at this point in the history
* Fix parsing of nested generics in Groovy

Fixes: #4702

* Polish
  • Loading branch information
knutwannheden authored Nov 23, 2024
1 parent 2b76e9c commit dcc0ec6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2585,7 +2585,7 @@ private Expression visitTypeParameterization(GenericsType genericsType) {
return new J.Empty(randomId(), prefix, Markers.EMPTY);
}
cursor = saveCursor;
return typeTree(null)
return typeTree(genericsType.getType())
.withType(typeMapping.type(genericsType));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,18 +207,18 @@ void stringMultipliedInParentheses() {
void extraParensAroundInfixOperator() {
rewriteRun(
groovy(
"""
def foo(Map map) {
((map.containsKey("foo"))
&& ((map.get("foo")).equals("bar")))
}
def timestamp(int hours, int minutes, int seconds) {
(hours) * 60 * 60 + (minutes * 60) + seconds
}
def differenceInDays(int time) {
return (int) ((time)/(1000*60*60*24))
}
"""
def foo(Map map) {
((map.containsKey("foo"))
&& ((map.get("foo")).equals("bar")))
}
def timestamp(int hours, int minutes, int seconds) {
(hours) * 60 * 60 + (minutes * 60) + seconds
}
def differenceInDays(int time) {
return (int) ((time)/(1000*60*60*24))
}
"""
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ void finalKeyword() {
);
}

@Test
void nestedGenerics() {
rewriteRun(
groovy("final map = new HashMap<String, List<String>>()")
);
}

@Test
void singleVariableDeclaration() {
rewriteRun(
Expand Down

0 comments on commit dcc0ec6

Please sign in to comment.