Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing of nested generics in Groovy #4707

Merged
merged 3 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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