-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Functional interfaces should not include a method if it's not used (#334
) This PR fixes an issue present with na-791a where, even though a functional interface's method is not used, it is still being included in the output, causing compilation errors. Since the `@FunctionalInterface` annotation is removed, we should treat all interfaces equally.
- Loading branch information
1 parent
3e836d3
commit ac79474
Showing
10 changed files
with
86 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/test/java/org/checkerframework/specimin/UnusedFuncInterfaceMethodTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.checkerframework.specimin; | ||
|
||
import java.io.IOException; | ||
import org.junit.Test; | ||
|
||
/** | ||
* This test checks that if a functional interface has an unused method, it is removed, and if a | ||
* synthetic functional interface method is generated, it is preserved. | ||
*/ | ||
public class UnusedFuncInterfaceMethodTest { | ||
@Test | ||
public void runTest() throws IOException { | ||
SpeciminTestExecutor.runTestWithoutJarPaths( | ||
"unusedfuncinterfacemethod", | ||
new String[] {"com/example/Simple.java"}, | ||
new String[] {"com.example.Simple#foo()"}); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/test/resources/unusedfuncinterfacemethod/expected/com/example/Bar.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.example; | ||
|
||
public class Bar { | ||
|
||
public static ComExampleBarUseReturnType use(SyntheticFunction4<?, ?, ?, ?, ?> parameter0) { | ||
throw new Error(); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
.../resources/unusedfuncinterfacemethod/expected/com/example/ComExampleBarUseReturnType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.example; | ||
|
||
public class ComExampleBarUseReturnType { | ||
} |
4 changes: 4 additions & 0 deletions
4
src/test/resources/unusedfuncinterfacemethod/expected/com/example/FuncInterfaceUnused.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.example; | ||
|
||
public interface FuncInterfaceUnused { | ||
} |
8 changes: 8 additions & 0 deletions
8
src/test/resources/unusedfuncinterfacemethod/expected/com/example/Simple.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.example; | ||
|
||
public class Simple implements FuncInterfaceUnused { | ||
|
||
public void foo() { | ||
Bar.use((a, b, c, d) -> 0); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/test/resources/unusedfuncinterfacemethod/expected/com/example/SyntheticFunction4.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.example; | ||
|
||
public interface SyntheticFunction4<T, T1, T2, T3, T4> { | ||
|
||
public T4 apply(T parameter0, T1 parameter1, T2 parameter2, T3 parameter3); | ||
} |
6 changes: 6 additions & 0 deletions
6
src/test/resources/unusedfuncinterfacemethod/input/com/example/FuncInterfaceUnused.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.example; | ||
|
||
@FunctionalInterface | ||
public interface FuncInterfaceUnused { | ||
void shouldBeRemoved(); | ||
} |
11 changes: 11 additions & 0 deletions
11
src/test/resources/unusedfuncinterfacemethod/input/com/example/Simple.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.example; | ||
|
||
public class Simple implements FuncInterfaceUnused { | ||
public void foo() { | ||
Bar.use((a, b, c, d) -> 0); | ||
} | ||
|
||
public void shouldBeRemoved() { | ||
|
||
} | ||
} |