-
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.
Fully qualify types in generic synthetic method return types (#341)
Previously, when a synthetic method with a generic return type had a type parameter in the same package as the target method, it would not keep its fully qualified name in its synthetic definition, leading to compilation errors seen in na-791b. For example, `ImmutableSet.copyOf` returned an `ImmutableSet<Feature>`, but in its synthetic definition, `copyOf` returned `com.google.common.collect.ImmutableSet<Feature>` instead of `com.google.common.collect.ImmutableSet<com.github.benmanes.caffeine.cache.Feature>`.
- Loading branch information
1 parent
5ca6b72
commit 229a5b5
Showing
17 changed files
with
222 additions
and
17 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,5 +28,5 @@ | |
"na-389": "PASS", | ||
"na-705": "PASS", | ||
"na-791a": "PASS", | ||
"na-791b": "FAIL" | ||
"na-791b": "PASS" | ||
} |
21 changes: 21 additions & 0 deletions
21
src/test/java/org/checkerframework/specimin/MethodReturnFullyQualifiedGenericTest.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,21 @@ | ||
package org.checkerframework.specimin; | ||
|
||
import java.io.IOException; | ||
import org.junit.Test; | ||
|
||
/** | ||
* This test checks that Specimin includes the fully qualified class name in generics when | ||
* generating a synthetic method. For example, if a return type is Bar<com.foo.Foo>, the actual | ||
* synthetic return type should be com.qualified.Bar<com.foo.Foo>. This test encodes Specimin's | ||
* current behavior, which doesn't produce compilable output. If you break this test, it might | ||
* not be a bad thing. | ||
*/ | ||
public class MethodReturnFullyQualifiedGenericTest { | ||
@Test | ||
public void runTest() throws IOException { | ||
SpeciminTestExecutor.runTestWithoutJarPaths( | ||
"methodreturnfullyqualifiedgeneric", | ||
new String[] {"com/example/Simple.java"}, | ||
new String[] {"com.example.Simple#alreadyQualified()"}); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/test/java/org/checkerframework/specimin/MethodReturnGenericTest.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,23 @@ | ||
package org.checkerframework.specimin; | ||
|
||
import java.io.IOException; | ||
import org.junit.Test; | ||
|
||
/** | ||
* This test checks that Specimin includes the fully qualified class name in generics when | ||
* generating a synthetic method. For example, if a return type is Foo<Bar>, Specimin should always | ||
* generate the synthetic method return type as com.example.Foo<com.other.Bar>. | ||
*/ | ||
public class MethodReturnGenericTest { | ||
@Test | ||
public void runTest() throws IOException { | ||
SpeciminTestExecutor.runTestWithoutJarPaths( | ||
"methodreturngeneric", | ||
new String[] {"com/example/Simple.java"}, | ||
new String[] { | ||
"com.example.Simple#foo()", | ||
"com.example.Simple#bar()", | ||
"com.example.Simple#baz()" | ||
}); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/test/resources/methodreturnfullyqualifiedgeneric/expected/com/bar/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.bar; | ||
|
||
public class Bar<T> { | ||
|
||
public static com.bar.Bar<com.example.InOtherPackage2> getOtherPackage2() { | ||
throw new Error(); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/test/resources/methodreturnfullyqualifiedgeneric/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,10 @@ | ||
package com.example; | ||
|
||
import com.bar.Bar; | ||
|
||
public class Simple { | ||
|
||
public Bar<com.foo.InOtherPackage2> alreadyQualified() { | ||
return Bar.getOtherPackage2(); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/test/resources/methodreturnfullyqualifiedgeneric/expected/com/foo/InOtherPackage2.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.foo; | ||
|
||
public class InOtherPackage2 { | ||
} |
9 changes: 9 additions & 0 deletions
9
src/test/resources/methodreturnfullyqualifiedgeneric/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,9 @@ | ||
package com.example; | ||
|
||
import com.bar.Bar; | ||
|
||
public class Simple { | ||
public Bar<com.foo.InOtherPackage2> alreadyQualified() { | ||
return Bar.getOtherPackage2(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/test/resources/methodreturngeneric/expected/com/bar/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,16 @@ | ||
package com.bar; | ||
|
||
public class Bar<T> { | ||
|
||
public static com.bar.Bar<com.foo.InOtherPackage> getOtherPackage() { | ||
throw new Error(); | ||
} | ||
|
||
public static com.bar.Bar<com.example.InSamePackage> getSamePackage() { | ||
throw new Error(); | ||
} | ||
|
||
public static com.bar.Bar<Integer> getJavaLang() { | ||
throw new Error(); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/test/resources/methodreturngeneric/expected/com/example/InSamePackage.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 InSamePackage { | ||
} |
19 changes: 19 additions & 0 deletions
19
src/test/resources/methodreturngeneric/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,19 @@ | ||
package com.example; | ||
|
||
import com.bar.Bar; | ||
import com.foo.InOtherPackage; | ||
|
||
public class Simple { | ||
|
||
public Bar<InOtherPackage> foo() { | ||
return Bar.getOtherPackage(); | ||
} | ||
|
||
public Bar<InSamePackage> bar() { | ||
return Bar.getSamePackage(); | ||
} | ||
|
||
public Bar<Integer> baz() { | ||
return Bar.getJavaLang(); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/test/resources/methodreturngeneric/expected/com/foo/InOtherPackage.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.foo; | ||
|
||
public class InOtherPackage { | ||
} |
18 changes: 18 additions & 0 deletions
18
src/test/resources/methodreturngeneric/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,18 @@ | ||
package com.example; | ||
|
||
import com.bar.Bar; | ||
import com.foo.InOtherPackage; | ||
|
||
public class Simple { | ||
public Bar<InOtherPackage> foo() { | ||
return Bar.getOtherPackage(); | ||
} | ||
|
||
public Bar<InSamePackage> bar() { | ||
return Bar.getSamePackage(); | ||
} | ||
|
||
public Bar<Integer> baz() { | ||
return Bar.getJavaLang(); | ||
} | ||
} |
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