Skip to content
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 @@ -75,8 +75,8 @@ public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx)
.build()
.apply(getCursor(), method.getCoordinates().replace(), method.getArguments().get(0));
}
// Skip Iterable-only cases to avoid generating broken code
if (TypeUtils.isAssignableTo("java.lang.Iterable", method.getArguments().get(0).getType())) {
// Skip Iterable-only and Iterator-only cases to avoid generating broken code
if (TypeUtils.isAssignableTo("java.lang.Iterable", method.getArguments().get(0).getType()) || TypeUtils.isAssignableTo("java.util.Iterator", method.getArguments().get(0).getType())) {
return method;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,28 @@ void test() {
);
}

@Test
void setsNewHashSetWithIteratorsFilter() {
//language=java
rewriteRun(
java(
"""
import java.util.Collection;
import java.util.Iterator;

import com.google.common.collect.Iterators;
import com.google.common.collect.Sets;

class Test {
public Collection<String> collectExistingRepresentations(Iterator<Object> iterator) {
return Sets.newHashSet(Iterators.filter(iterator, String.class));
}
}
"""
)
);
}

@Test
void setsNewHashSetWithCustomIterable() {
//language=java
Expand Down