8308753: Class-File API transition to Preview

Reviewed-by: ihse, mchung, vromero
This commit is contained in:
Adam Sotona 2023-12-04 07:07:57 +00:00
parent b9df827adc
commit 2b00ac0d02
681 changed files with 7518 additions and 6502 deletions

View file

@ -25,12 +25,8 @@
* @test
* @bug 8004727
* @summary javac should generate method parameters correctly.
* @modules java.base/jdk.internal.classfile
* java.base/jdk.internal.classfile.attribute
* java.base/jdk.internal.classfile.constantpool
* java.base/jdk.internal.classfile.instruction
* java.base/jdk.internal.classfile.components
* java.base/jdk.internal.classfile.impl
* @enablePreview
* @modules java.base/jdk.internal.classfile.impl
* jdk.compiler/com.sun.tools.javac.code
* jdk.compiler/com.sun.tools.javac.comp
* jdk.compiler/com.sun.tools.javac.file
@ -39,8 +35,8 @@
* jdk.compiler/com.sun.tools.javac.util
*/
// key: opt.arg.parameters
import jdk.internal.classfile.*;
import jdk.internal.classfile.attribute.*;
import java.lang.classfile.*;
import java.lang.classfile.attribute.*;
import com.sun.tools.javac.code.Symtab;
import com.sun.tools.javac.file.JavacFileManager;
import com.sun.tools.javac.main.Main;
@ -171,7 +167,7 @@ public class MethodParametersTest {
void modifyBaz(boolean flip) throws Exception {
final File Baz_class = new File(classesdir, Baz_name + ".class");
final ClassModel baz = Classfile.of().parse(Baz_class.toPath());
final ClassModel baz = ClassFile.of().parse(Baz_class.toPath());
// Find MethodParameters and the Code attributes
if (baz.methods().size() != 1)
@ -188,7 +184,7 @@ public class MethodParametersTest {
// Alter the MethodParameters attribute, changing the name of
// the parameter from i to baz.
byte[] bazBytes = Classfile.of().transform(baz, ClassTransform.transformingMethods((methodBuilder, methodElement) -> {
byte[] bazBytes = ClassFile.of().transform(baz, ClassTransform.transformingMethods((methodBuilder, methodElement) -> {
if (methodElement instanceof MethodParametersAttribute a) {
List<MethodParameterInfo> newParameterInfos = new ArrayList<>();
for (MethodParameterInfo info : a.parameters()) {
@ -204,7 +200,7 @@ public class MethodParametersTest {
// Flip the code and method attributes(). This is for checking
// that order doesn't matter.
if (flip) {
bazBytes = Classfile.of().transform(baz, ClassTransform.transformingMethods((methodBuilder, methodElement) -> {
bazBytes = ClassFile.of().transform(baz, ClassTransform.transformingMethods((methodBuilder, methodElement) -> {
if (methodElement instanceof MethodParametersAttribute) {
methodBuilder.with(cattr);
} else if (methodElement instanceof CodeAttribute){
@ -220,7 +216,7 @@ public class MethodParametersTest {
// Run a bunch of structural tests on foo to make sure it looks right.
void checkFoo() throws Exception {
final File Foo_class = new File(classesdir, Foo_name + ".class");
final ClassModel foo = Classfile.of().parse(Foo_class.toPath());
final ClassModel foo = ClassFile.of().parse(Foo_class.toPath());
for (int i = 0; i < foo.methods().size(); i++) {
System.err.println("Examine method Foo." + foo.methods().get(i).methodName());
if (foo.methods().get(i).methodName().equalsString("foo2")) {
@ -261,7 +257,7 @@ public class MethodParametersTest {
// Run a bunch of structural tests on Bar to make sure it looks right.
void checkBar() throws Exception {
final File Bar_class = new File(classesdir, Bar_name + ".class");
final ClassModel bar = Classfile.of().parse(Bar_class.toPath());
final ClassModel bar = ClassFile.of().parse(Bar_class.toPath());
for (int i = 0; i < bar.methods().size(); i++) {
System.err.println("Examine method Bar." + bar.methods().get(i).methodName());
if (bar.methods().get(i).methodName().equalsString("<init>")) {