Skip to content

Commit

Permalink
Fix lambda cleanup to not generate if interface method is generic (#1199
Browse files Browse the repository at this point in the history
)

- fixes #1198
- add new test to CleanUpTest1d8
  • Loading branch information
jjohnstn authored Mar 9, 2024
1 parent 16ca3ea commit cb1cc46
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1292,7 +1292,7 @@ public static boolean isFunctionalAnonymous(ClassInstanceCreation node) {
if (interfaces.length != 1) {
return false;
}
if (interfaces[0].getFunctionalInterfaceMethod() == null) {
if (interfaces[0].getFunctionalInterfaceMethod() == null || interfaces[0].getFunctionalInterfaceMethod().isGenericMethod()) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2261,6 +2261,41 @@ public void testDoNotConvertLocalRecursiveClass() throws Exception {
assertRefactoringHasNoChange(new ICompilationUnit[] { cu });
}

@Test
public void testDoNotConvertGenericInterface() throws Exception {
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
String sample= "" //
+ "package test1;\n" //
+ "\n" //
+ "public class C2 {\n" //
+ "\n" //
+ " public interface IInteractionContext {\n" //
+ " }\n" //
+ "\n" //
+ " public interface IAdaptable {\n" //
+ " public <T> T getAdapter(Class<T> adapter);\n" //
+ " }\n" //
+ "\n" //
+ " @SuppressWarnings(\"unchecked\")\n" //
+ " public IAdaptable asAdaptable(final IInteractionContext result) {\n" //
+ " return new IAdaptable() {\n" //
+ " public Object getAdapter(Class adapter) {\n" //
+ " if (adapter == IInteractionContext.class) {\n" //
+ " return result;\n" //
+ " }\n" //
+ " return null;\n" //
+ " }\n" //
+ " };\n" //
+ " }\n" //
+ "}\n"; //
ICompilationUnit cu= pack1.createCompilationUnit("C2.java", sample, false, null);

enable(CleanUpConstants.CONVERT_FUNCTIONAL_INTERFACES);
enable(CleanUpConstants.USE_LAMBDA);

assertRefactoringHasNoChange(new ICompilationUnit[] { cu });
}

@Test
public void testComparingOnCriteria() throws Exception {
// Given
Expand Down

0 comments on commit cb1cc46

Please sign in to comment.