16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @modules jdk.incubator.vector
27 * @run testng CovarOverrideTest
28 *
29 */
30
31 import jdk.incubator.vector.ByteVector;
32 import jdk.incubator.vector.DoubleVector;
33 import jdk.incubator.vector.FloatVector;
34 import jdk.incubator.vector.IntVector;
35 import jdk.incubator.vector.ShortVector;
36 import jdk.incubator.vector.Vector;
37 import org.testng.annotations.DataProvider;
38 import org.testng.annotations.Test;
39
40 import java.lang.reflect.Method;
41 import java.lang.reflect.Modifier;
42 import java.util.ArrayList;
43 import java.util.List;
44 import java.util.Set;
45 import java.util.stream.Stream;
46
47 import static java.util.stream.Collectors.toList;
48 import static org.testng.Assert.assertTrue;
49
50 public class CovarOverrideTest {
51
52 static final Set<String> NON_COVARIENT_RETURNING_METHOD_NAMES_ON_VECTOR =
53 Set.of("cast", "reinterpret", "reshape");
54
55 @DataProvider
56 public static Object[][] classesProvider() {
57 return List.of(
58 ByteVector.class,
59 ShortVector.class,
60 IntVector.class,
61 FloatVector.class,
62 DoubleVector.class).
63 stream().
64 map(c -> new Object[]{c}).
65 toArray(Object[][]::new);
66 }
67
68 @Test(dataProvider = "classesProvider")
69 public void testCovarientOverridesExist(Class<?> c) {
70 Class<?> superClass = c.getSuperclass();
71
72 Class<?> vectorClass = c;
73 if (superClass == Vector.Species.class) {
74 vectorClass = c.getDeclaringClass();
75 }
76
77 List<Method> notFound = new ArrayList<>();
78 List<Method> notCovarientlyOverridden = new ArrayList<>();
79 for (Method superMethod : getVectorReturningMethods(superClass)) {
80 try {
81 Method overrideMethod = c.getDeclaredMethod(superMethod.getName(), superMethod.getParameterTypes());
82 if (vectorClass != overrideMethod.getReturnType()) {
83 notCovarientlyOverridden.add(overrideMethod);
84 }
85 }
86 catch (NoSuchMethodException e) {
87 notFound.add(superMethod);
88 }
89 }
90
91 if (!notFound.isEmpty()) {
92 System.out.println(" Methods not found on sub-type " + c.getName());
93 notFound.forEach(m -> System.out.println(" " + m));
|
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @modules jdk.incubator.vector
27 * @run testng CovarOverrideTest
28 *
29 */
30
31 import jdk.incubator.vector.ByteVector;
32 import jdk.incubator.vector.DoubleVector;
33 import jdk.incubator.vector.FloatVector;
34 import jdk.incubator.vector.IntVector;
35 import jdk.incubator.vector.ShortVector;
36 import jdk.incubator.vector.VectorSpecies;
37 import jdk.incubator.vector.Vector;
38 import org.testng.annotations.DataProvider;
39 import org.testng.annotations.Test;
40
41 import java.lang.reflect.Method;
42 import java.lang.reflect.Modifier;
43 import java.util.ArrayList;
44 import java.util.List;
45 import java.util.Set;
46 import java.util.stream.Stream;
47
48 import static java.util.stream.Collectors.toList;
49 import static org.testng.Assert.assertTrue;
50
51 public class CovarOverrideTest {
52
53 static final Set<String> NON_COVARIENT_RETURNING_METHOD_NAMES_ON_VECTOR =
54 Set.of("cast", "reinterpret", "reshape");
55
56 @DataProvider
57 public static Object[][] classesProvider() {
58 return List.of(
59 ByteVector.class,
60 ShortVector.class,
61 IntVector.class,
62 FloatVector.class,
63 DoubleVector.class).
64 stream().
65 map(c -> new Object[]{c}).
66 toArray(Object[][]::new);
67 }
68
69 @Test(dataProvider = "classesProvider")
70 public void testCovarientOverridesExist(Class<?> c) {
71 Class<?> superClass = c.getSuperclass();
72
73 Class<?> vectorClass = c;
74 if (superClass == VectorSpecies.class) {
75 vectorClass = c.getDeclaringClass();
76 }
77
78 List<Method> notFound = new ArrayList<>();
79 List<Method> notCovarientlyOverridden = new ArrayList<>();
80 for (Method superMethod : getVectorReturningMethods(superClass)) {
81 try {
82 Method overrideMethod = c.getDeclaredMethod(superMethod.getName(), superMethod.getParameterTypes());
83 if (vectorClass != overrideMethod.getReturnType()) {
84 notCovarientlyOverridden.add(overrideMethod);
85 }
86 }
87 catch (NoSuchMethodException e) {
88 notFound.add(superMethod);
89 }
90 }
91
92 if (!notFound.isEmpty()) {
93 System.out.println(" Methods not found on sub-type " + c.getName());
94 notFound.forEach(m -> System.out.println(" " + m));
|