changeset 57890:d37da910a3b6 amber-demo-II

Automatic merge with records-and-sealed
author mcimadamore
date Tue, 08 Oct 2019 15:30:57 +0000
parents 1c25d41a2e7f eba93be51780
children fd9176455f5e
files test/hotspot/jtreg/runtime/records/recordAccessorsTest.java
diffstat 2 files changed, 110 insertions(+), 108 deletions(-) [+]
line wrap: on
line diff
--- a/test/hotspot/jtreg/runtime/records/recordAccessorsTest.java	Mon Oct 07 17:01:04 2019 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,108 +0,0 @@
-/*
- * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*
- * @test
- * @compile --enable-preview --source 14 recordAccessorsTest.java
- * @run main/othervm --enable-preview recordAccessorsTest
- */
-
-
-import java.lang.reflect.Method;
-import java.lang.reflect.RecordComponent;
-
-public class recordAccessorsTest {
-
-    record recordNames(int intX, String stringY) {
-        public RecordComponent[] getComponents() throws Throwable {
-            return recordNames.class.getRecordComponents();
-        }
-    }
-
-    class notRecord {
-        public RecordComponent[] getComponents() throws Throwable {
-            return notRecord.class.getRecordComponents();
-        }
-    }
-
-    record recordGeneric<T>(T xx, String yy) {
-        public RecordComponent[] getComponents() throws Throwable {
-            return recordGeneric.class.getRecordComponents();
-        }
-    }
-
-    record recordEmpty() {
-        public RecordComponent[] getComponents() throws Throwable {
-            return recordEmpty.class.getRecordComponents();
-        }
-    }
-
-    notRecord nr = new notRecord();
-
-    public static boolean hasComponent(RecordComponent[] components, String name,
-                                       String type, String method) {
-        for (int x = 0; x < components.length; x++) {
-            RecordComponent component = components[x];
-            if (component.getName() == name &&
-                component.getType().toString().contains(type) &&
-                component.getAccessor().toString().contains(method)) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    public static void main(String... args) throws Throwable {
-        recordNames rn = new recordNames(3, "abc");
-        RecordComponent[] components = rn.getComponents();
-        if (components.length != 2 ||
-            !hasComponent(components, "intX", "int",
-                          "int recordAccessorsTest$recordNames.intX()") ||
-            !hasComponent(components, "stringY", "java.lang.String",
-                          "java.lang.String recordAccessorsTest$recordNames.stringY()")) {
-            throw new RuntimeException("Bad component accessors returned for recordNames");
-        }
-
-        recordAccessorsTest rat = new recordAccessorsTest();
-        components = rat.nr.getComponents();
-        if (components.length != 0) {
-            throw new RuntimeException("Non-empty component accessors returned for notRecord");
-        }
-
-        recordGeneric rg = new recordGeneric(35, "abcd");
-        components = rg.getComponents();
-        if (components.length != 2 ||
-            !hasComponent(components, "xx", "java.lang.Object",
-                          "java.lang.Object recordAccessorsTest$recordGeneric.xx()") ||
-            !hasComponent(components, "yy", "java.lang.String",
-                          "java.lang.String recordAccessorsTest$recordGeneric.yy()")) {
-            throw new RuntimeException("Bad component accessors returned for recordGeneric");
-        }
-
-        recordEmpty re = new recordEmpty();
-        components = re.getComponents();
-        if (components.length != 0) {
-            throw new RuntimeException("Non-empty component accessors returned for recordEmpty");
-        }
-    }
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/runtime/records/recordReflectionTest.java	Tue Oct 08 15:30:57 2019 +0000
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @compile --enable-preview --source 14 recordReflectionTest.java
+ * @run main/othervm --enable-preview recordReflectionTest
+ */
+
+
+import java.lang.reflect.Method;
+import java.lang.reflect.RecordComponent;
+
+public class recordReflectionTest {
+
+    record recordNames(int intX, String stringY) {
+        public RecordComponent[] getComponents() throws Throwable {
+            return recordNames.class.getRecordComponents();
+        }
+    }
+
+    class notRecord {
+        public RecordComponent[] getComponents() throws Throwable {
+            return notRecord.class.getRecordComponents();
+        }
+    }
+
+    record recordGeneric<T>(T xx, String yy) {
+        public RecordComponent[] getComponents() throws Throwable {
+            return recordGeneric.class.getRecordComponents();
+        }
+    }
+
+    record recordEmpty() {
+        public RecordComponent[] getComponents() throws Throwable {
+            return recordEmpty.class.getRecordComponents();
+        }
+    }
+
+    notRecord nr = new notRecord();
+
+    public static boolean hasComponent(RecordComponent[] components, String enclosingClass,
+                                       String name, String type, String method, String genericSig) {
+        for (int x = 0; x < components.length; x++) {
+            RecordComponent component = components[x];
+            if (component.getName() == name &&
+                component.toGenericString().contains(enclosingClass) &&
+                component.getType().toString().contains(type) &&
+                component.getAccessor().toString().contains(method) &&
+                component.getGenericSignature() == genericSig) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public static void main(String... args) throws Throwable {
+        recordNames rn = new recordNames(3, "abc");
+        RecordComponent[] components = rn.getComponents();
+        if (components.length != 2 ||
+            !hasComponent(components, "recordNames", "intX", "int",
+                          "int recordReflectionTest$recordNames.intX()", null) ||
+            !hasComponent(components, "recordNames", "stringY", "java.lang.String",
+                          "java.lang.String recordReflectionTest$recordNames.stringY()", null)) {
+            throw new RuntimeException("Bad component accessors returned for recordNames");
+        }
+
+        recordReflectionTest rft = new recordReflectionTest();
+        components = rft.nr.getComponents();
+        if (components.length != 0) {
+            throw new RuntimeException("Non-empty component accessors returned for notRecord");
+        }
+
+        recordGeneric rg = new recordGeneric(35, "abcd");
+        components = rg.getComponents();
+        if (components.length != 2 ||
+            !hasComponent(components, "recordGeneric", "xx", "java.lang.Object",
+                          "java.lang.Object recordReflectionTest$recordGeneric.xx()", "TT;") ||
+            !hasComponent(components, "recordGeneric", "yy", "java.lang.String",
+                          "java.lang.String recordReflectionTest$recordGeneric.yy()", null)) {
+            throw new RuntimeException("Bad component accessors returned for recordGeneric");
+        }
+
+        recordEmpty re = new recordEmpty();
+        components = re.getComponents();
+        if (components.length != 0) {
+            throw new RuntimeException("Non-empty component accessors returned for recordEmpty");
+        }
+    }
+}