void () { options.setToShortenFQN(false); String in = """ import java.util.ArrayList; import java.util.List; class X { List<String> list = new java.util.LinkedList<String>(); List<Integer> list2 = new java.util.ArrayList<Integer>(); List<Double> list3 = new ArrayList<>(); }"""; assertEquals("should properly replace with diamond", """ import java.util.ArrayList; import java.util.List; class X { List<String> list = new java.util.LinkedList<>(); List<Integer> list2 = new ArrayList<>(); List<Double> list3 = new ArrayList<>(); }""", replace(in, "new '_X<'_p+>()", "new $X$<>()", true)); assertEquals("should keep generics when matching without", """ import java.util.ArrayList; import java.util.List; class X { List<String> list = new /*1*/java.util.LinkedList<String>(); List<Integer> list2 = new /*1*/ArrayList<Integer>(); List<Double> list3 = new /*1*/ArrayList<>(); }""", replace(in, "new '_X()", "new /*1*/$X$()", true)); assertEquals("should not duplicate generic parameters", """ import java.util.ArrayList; import java.util.List; class X { List<String> list = new java.util.LinkedList</*0*/String>(); List<Integer> list2 = new ArrayList</*0*/Integer>(); List<Double> list3 = new ArrayList<>(); }""", replace(in, "new '_X<'_p+>()", "new $X$</*0*/$p$>()", true)); String in2 = """ import java.util.Map; import java.util.List; import java.util.concurrent.ConcurrentHashMap; class X<A, B>{ void x() { Map<String, List<String>> myVar = new ConcurrentHashMap<>(10, 2); } } """; assertEquals("replace multiple generic parameters correctly", """ import java.util.Map; import java.util.List; import java.util.concurrent.ConcurrentHashMap; class X<A, B>{ void x() { var myVar = new ConcurrentHashMap<String, List<String>>(10, 2); } } """, replace(in2, "'_Type<'_GenericArgument+> '_Var = new '_Ctor<>('_Params*);", "var $Var$ = new $Ctor$<$GenericArgument$>($Params$);", true)); assertEquals("replace multiple class type parameters correctly", """ import java.util.Map; import java.util.List; import java.util.concurrent.ConcurrentHashMap; class X<A, B> { void x() { Map<String, List<String>> myVar = new ConcurrentHashMap<>(10, 2); } } """, replace(in2, "class '_C<'_P+> {}", "class $C$<$P$> {}", true)); }