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 simple app using record annotations, for which a native image gets generated. This is a regression test for the fix described in issue oracle#3984
- Loading branch information
Showing
9 changed files
with
286 additions
and
1 deletion.
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
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
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
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,53 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>records</groupId> | ||
<artifactId>recordannotations</artifactId> | ||
<version>1</version> | ||
|
||
<name>recordannotations</name> | ||
|
||
<properties> | ||
<maven-jar-plugin.version>3.2.0</maven-jar-plugin.version> | ||
<maven-compiler-plugin.version>3.10.1</maven-compiler-plugin.version> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
</properties> | ||
|
||
<profiles> | ||
<profile> | ||
<id>java-17</id> | ||
<activation> | ||
<jdk>17</jdk> | ||
</activation> | ||
<build> | ||
<finalName>recordannotations</finalName> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>${maven-compiler-plugin.version}</version> | ||
<configuration> | ||
<source>17</source> | ||
<target>17</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<version>${maven-jar-plugin.version}</version> | ||
<configuration> | ||
<archive> | ||
<manifest> | ||
<mainClass>recordannotations.Main</mainClass> | ||
</manifest> | ||
</archive> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
|
||
</project> |
30 changes: 30 additions & 0 deletions
30
substratevm/src/native-image-record-annot-tests/src/main/java/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,30 @@ | ||
/* | ||
* 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 recordannotations; | ||
|
||
// Main record under test. See Main. | ||
@RCA2 | ||
record F(@RCA @RCA2 String name, @RCA2 int i) { | ||
} |
77 changes: 77 additions & 0 deletions
77
substratevm/src/native-image-record-annot-tests/src/main/java/recordannotations/Main.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,77 @@ | ||
/* | ||
* 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 recordannotations; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.lang.reflect.RecordComponent; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class Main { | ||
|
||
public static void main(String[] args) { | ||
failIfAssertionsAreDisabled(); | ||
|
||
F x = new F("x", 1); | ||
|
||
RecordComponent[] recordComponents = x.getClass().getRecordComponents(); | ||
assert recordComponents.length == 2; | ||
|
||
// Verify String component annotations | ||
RecordComponent stringComp = recordComponents[0]; | ||
List<Annotation> stringCompAnnot = Arrays.asList(stringComp.getAnnotations()); | ||
assert stringCompAnnot.size() == 2 : "expected 2 record annotations for string component"; | ||
assert stringCompAnnot.stream().anyMatch(a -> a.annotationType().getName().equals("recordannotations.RCA")); | ||
assert stringCompAnnot.stream().anyMatch(a -> a.annotationType().getName().equals("recordannotations.RCA2")); | ||
assert stringComp.getAnnotatedType().getType().getTypeName().equals(String.class.getTypeName()); | ||
Annotation rcaAnnotation = stringComp.getAnnotation(RCA.class); | ||
assert rcaAnnotation != null : "expected RCA annotation to be present"; | ||
assert String.class.getTypeName().equals(stringComp.getGenericType().getTypeName()); | ||
|
||
// Verify int component annotations | ||
RecordComponent intComp = recordComponents[1]; | ||
List<Annotation> intCompAnnot = Arrays.asList(intComp.getAnnotations()); | ||
assert intCompAnnot.size() == 1 : "expected 1 record annotations for int component"; | ||
assert intCompAnnot.stream().anyMatch(a -> a.annotationType().getName().equals("recordannotations.RCA2")); | ||
assert intComp.getAnnotatedType().getType().getTypeName().equals(int.class.getTypeName()); | ||
assert intComp.getAnnotation(RCA.class) == null; | ||
assert intComp.getAnnotation(RCA2.class) != null; | ||
assert int.class.getTypeName().equals(intComp.getGenericType().getTypeName()); | ||
|
||
assert x.i() == 1; | ||
assert "x".equals(x.name()); | ||
|
||
System.out.println("Record annotation tests passed!"); | ||
} | ||
|
||
private static void failIfAssertionsAreDisabled() { | ||
boolean enabled = false; | ||
assert enabled = true; | ||
if (!enabled) { | ||
throw new AssertionError("This example requires that assertions are enabled (-ea)"); | ||
} | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
substratevm/src/native-image-record-annot-tests/src/main/java/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 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
substratevm/src/native-image-record-annot-tests/src/main/java/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 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 | ||
} |
11 changes: 11 additions & 0 deletions
11
...ive-image-record-annot-tests/src/main/resources/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" : "recordannotations.F", | ||
"allDeclaredConstructors" : true, | ||
"allPublicConstructors" : true, | ||
"allDeclaredMethods" : true, | ||
"allPublicMethods" : true, | ||
"allDeclaredClasses" : true, | ||
"allPublicClasses" : true | ||
} | ||
] |