forked from oracle/graal
-
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.
Add regression test for record annotations
This adds a JDK 17+ test project and adds a regression test for the fix described in issue oracle#3984
- Loading branch information
Showing
6 changed files
with
217 additions
and
0 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
31 changes: 31 additions & 0 deletions
31
...tevm/src/com.oracle.svm.test.jdk17/src/com/oracle/svm/test/jdk17/recordannotations/F.java
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,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) { | ||
} |
38 changes: 38 additions & 0 deletions
38
...vm/src/com.oracle.svm.test.jdk17/src/com/oracle/svm/test/jdk17/recordannotations/RCA.java
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,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 | ||
} | ||
|
37 changes: 37 additions & 0 deletions
37
...m/src/com.oracle.svm.test.jdk17/src/com/oracle/svm/test/jdk17/recordannotations/RCA2.java
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,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 | ||
} |
81 changes: 81 additions & 0 deletions
81
...svm.test.jdk17/src/com/oracle/svm/test/jdk17/recordannotations/RecordAnnotationsTest.java
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,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<Annotation> 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<Annotation> 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()); | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
substratevm/src/com.oracle.svm.test/src/META-INF/native-image/reflect-config.json
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,11 @@ | ||
[ | ||
{ | ||
"name" : "com.oracle.svm.test.jdk17.recordannotations.F", | ||
"allDeclaredConstructors" : true, | ||
"allPublicConstructors" : true, | ||
"allDeclaredMethods" : true, | ||
"allPublicMethods" : true, | ||
"allDeclaredClasses" : true, | ||
"allPublicClasses" : true | ||
} | ||
] |