diff --git a/substratevm/mx.substratevm/suite.py b/substratevm/mx.substratevm/suite.py index 50dfa55cdcdf..7d1d3260238a 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/META-INF/native-image/com.oracle.svm.test.jdk17/reflect-config.json b/substratevm/src/com.oracle.svm.test.jdk17/src/META-INF/native-image/com.oracle.svm.test.jdk17/reflect-config.json new file mode 100644 index 000000000000..4cff54a9803e --- /dev/null +++ b/substratevm/src/com.oracle.svm.test.jdk17/src/META-INF/native-image/com.oracle.svm.test.jdk17/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 + } +] 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 000000000000..07159409c9e6 --- /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 000000000000..536d62dee057 --- /dev/null +++ b/substratevm/src/com.oracle.svm.test.jdk17/src/com/oracle/svm/test/jdk17/recordannotations/RCA.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}) +@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 000000000000..81d05f21cb8f --- /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 000000000000..5666c8314d54 --- /dev/null +++ b/substratevm/src/com.oracle.svm.test.jdk17/src/com/oracle/svm/test/jdk17/recordannotations/RecordAnnotationsTest.java @@ -0,0 +1,91 @@ +/* + * 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 + // + // Checkstyle: stop + List stringCompAnnot = Arrays.asList(stringComp.getAnnotations()); + // Checkstyle: resume + 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()); + // Checkstyle: stop + Annotation rcaAnnotation = stringComp.getAnnotation(RCA.class); + // Checkstyle: resume + Assert.assertNotNull("expected RCA annotation to be present", rcaAnnotation); + Assert.assertEquals(String.class.getTypeName(), stringComp.getGenericType().getTypeName()); + + // Verify int component annotations + // + // Checkstyle: stop + List intCompAnnot = Arrays.asList(intComp.getAnnotations()); + // Checkstyle: resume + 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()); + // Checkstyle: stop + Assert.assertNull(intComp.getAnnotation(RCA.class)); + Assert.assertNotNull(intComp.getAnnotation(RCA2.class)); + // Checkstyle: resume + Assert.assertEquals(int.class.getTypeName(), intComp.getGenericType().getTypeName()); + + Assert.assertEquals(1, x.i()); + Assert.assertEquals("x", x.name()); + } + +}