diff --git a/substratevm/mx.substratevm/suite.py b/substratevm/mx.substratevm/suite.py index 50dfa55cdcdf5..7d1d3260238a8 100644 --- a/substratevm/mx.substratevm/suite.py +++ b/substratevm/mx.substratevm/suite.py @@ -683,6 +683,24 @@ "spotbugs": "false", }, + "com.oracle.svm.test.jdk17": { + "subDir": "src", + "sourceDirs": ["src"], + "dependencies": [ + "mx:JUNIT_TOOL", + "sdk:GRAAL_SDK", + "SVM", + ], + "checkstyle": "com.oracle.svm.test", + "workingSets": "SVM", + "annotationProcessors": [ + "compiler:GRAAL_PROCESSOR", + ], + "javaCompliance": "17+", + "spotbugs": "false", + "testProject": True, + }, + "com.oracle.svm.configure.test": { "subDir": "src", "sourceDirs": ["src"], @@ -1497,6 +1515,7 @@ "relpath" : True, "dependencies" : [ "com.oracle.svm.test", + "com.oracle.svm.test.jdk17", "com.oracle.svm.configure.test", "com.oracle.svm.graal.test", ], diff --git a/substratevm/src/com.oracle.svm.test.jdk17/src/com/oracle/svm/test/jdk17/recordannotations/F.java b/substratevm/src/com.oracle.svm.test.jdk17/src/com/oracle/svm/test/jdk17/recordannotations/F.java new file mode 100644 index 0000000000000..07159409c9e6a --- /dev/null +++ b/substratevm/src/com.oracle.svm.test.jdk17/src/com/oracle/svm/test/jdk17/recordannotations/F.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2022, 2022, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ + +package com.oracle.svm.test.jdk17.recordannotations; + +// Main record under test. See Main. +@RCA2 +record F(@RCA @RCA2 String name, @RCA2 int i) { +} diff --git a/substratevm/src/com.oracle.svm.test.jdk17/src/com/oracle/svm/test/jdk17/recordannotations/RCA.java b/substratevm/src/com.oracle.svm.test.jdk17/src/com/oracle/svm/test/jdk17/recordannotations/RCA.java new file mode 100644 index 0000000000000..31f0e54328d15 --- /dev/null +++ b/substratevm/src/com.oracle.svm.test.jdk17/src/com/oracle/svm/test/jdk17/recordannotations/RCA.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2022, 2022, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ + +package com.oracle.svm.test.jdk17.recordannotations; + +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; +import java.lang.annotation.ElementType; + +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.RECORD_COMPONENT, ElementType.FIELD }) +@interface RCA { + // empty +} + diff --git a/substratevm/src/com.oracle.svm.test.jdk17/src/com/oracle/svm/test/jdk17/recordannotations/RCA2.java b/substratevm/src/com.oracle.svm.test.jdk17/src/com/oracle/svm/test/jdk17/recordannotations/RCA2.java new file mode 100644 index 0000000000000..ad08379c76c24 --- /dev/null +++ b/substratevm/src/com.oracle.svm.test.jdk17/src/com/oracle/svm/test/jdk17/recordannotations/RCA2.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2022, 2022, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ + +package com.oracle.svm.test.jdk17.recordannotations; + +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; +import java.lang.annotation.ElementType; + +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.RECORD_COMPONENT, ElementType.FIELD, ElementType.TYPE }) +@interface RCA2 { + // empty +} diff --git a/substratevm/src/com.oracle.svm.test.jdk17/src/com/oracle/svm/test/jdk17/recordannotations/RecordAnnotationsTest.java b/substratevm/src/com.oracle.svm.test.jdk17/src/com/oracle/svm/test/jdk17/recordannotations/RecordAnnotationsTest.java new file mode 100644 index 0000000000000..fbae166653dec --- /dev/null +++ b/substratevm/src/com.oracle.svm.test.jdk17/src/com/oracle/svm/test/jdk17/recordannotations/RecordAnnotationsTest.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2022, 2022, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ + +package com.oracle.svm.test.jdk17.recordannotations; + +import java.lang.annotation.Annotation; +import java.lang.reflect.RecordComponent; +import java.util.Arrays; +import java.util.List; +import org.junit.Assert; +import org.junit.Test; + +public class RecordAnnotationsTest { + + @Test + public void verifyRecordAnnotations() { + F x = new F("x", 1); + + RecordComponent[] recordComponents = x.getClass().getRecordComponents(); + Assert.assertEquals(2, recordComponents.length); + + // Avoid relying on order of returned record components + RecordComponent intComp = null; + RecordComponent stringComp = null; + for (RecordComponent c: recordComponents) { + if ("name".equals(c.getName())) { + stringComp = c; + } + if ("i".equals(c.getName())) { + intComp = c; + } + } + Assert.assertNotNull(stringComp); + Assert.assertNotNull(intComp); + + // Verify String component annotations + List stringCompAnnot = Arrays.asList(stringComp.getAnnotations()); + Assert.assertEquals("expected 2 record annotations for string component", 2, stringCompAnnot.size()); + Assert.assertTrue("expected RCA component annotation", stringCompAnnot.stream().anyMatch(a -> a.annotationType().getName().equals("com.oracle.svm.test.jdk17.recordannotations.RCA"))); + Assert.assertTrue("expected RCA2 component annotation", stringCompAnnot.stream().anyMatch(a -> a.annotationType().getName().equals("com.oracle.svm.test.jdk17.recordannotations.RCA2"))); + Assert.assertEquals(String.class.getTypeName(), stringComp.getAnnotatedType().getType().getTypeName()); + Annotation rcaAnnotation = stringComp.getAnnotation(RCA.class); + Assert.assertNotNull("expected RCA annotation to be present", rcaAnnotation); + Assert.assertEquals(String.class.getTypeName(), stringComp.getGenericType().getTypeName()); + + // Verify int component annotations + List intCompAnnot = Arrays.asList(intComp.getAnnotations()); + Assert.assertEquals("expected 1 record annotation for int component", 1, intCompAnnot.size()); + Assert.assertTrue("expected RCA2 component annotation", intCompAnnot.stream().anyMatch(a -> a.annotationType().getName().equals("com.oracle.svm.test.jdk17.recordannotations.RCA2"))); + Assert.assertEquals(int.class.getTypeName(), intComp.getAnnotatedType().getType().getTypeName()); + Assert.assertNull(intComp.getAnnotation(RCA.class)); + Assert.assertNotNull(intComp.getAnnotation(RCA2.class)); + Assert.assertEquals(int.class.getTypeName(), intComp.getGenericType().getTypeName()); + + Assert.assertEquals(1, x.i()); + Assert.assertEquals("x", x.name()); + } + +} diff --git a/substratevm/src/com.oracle.svm.test/src/META-INF/native-image/reflect-config.json b/substratevm/src/com.oracle.svm.test/src/META-INF/native-image/reflect-config.json new file mode 100644 index 0000000000000..4cff54a9803e9 --- /dev/null +++ b/substratevm/src/com.oracle.svm.test/src/META-INF/native-image/reflect-config.json @@ -0,0 +1,11 @@ +[ + { + "name" : "com.oracle.svm.test.jdk17.recordannotations.F", + "allDeclaredConstructors" : true, + "allPublicConstructors" : true, + "allDeclaredMethods" : true, + "allPublicMethods" : true, + "allDeclaredClasses" : true, + "allPublicClasses" : true + } +]