forked from openjdk/jdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
84 additions
and
43 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
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* @test | ||
* @enablePreview | ||
* @compile -parameters Points.java | ||
* @run main Points | ||
*/ | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
import java.lang.invoke.MethodType; | ||
import java.lang.template.Carriers; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public record Points(Collection<Integer> is) { | ||
public static void main(String... args) { | ||
assertEquals(List.of(1), test(new Points(List.of(1)))); | ||
} | ||
|
||
public static List<Integer> test(Object o) { | ||
if (o instanceof Points(List<Integer> ss)) { | ||
return ss; | ||
} | ||
return List.of(-1); | ||
} | ||
|
||
public __matcher Points(@Foo Collection<Integer> is) throws Throwable { | ||
// is = this.is; | ||
|
||
MethodType returnType = MethodType.methodType(Object.class, Collection.class); | ||
return Carriers.factory(returnType).invoke(this.is); | ||
} | ||
|
||
@Target(ElementType.PARAMETER) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface Foo { } | ||
|
||
private static <T> void assertEquals(T expected, T actual) { | ||
if (!Objects.equals(expected, actual)) { | ||
throw new AssertionError("Expected: " + expected + ", but got: " + actual); | ||
} | ||
} | ||
} |