8304161: Add TypeKind.from to derive from TypeDescriptor.OfField
Reviewed-by: jvernee
This commit is contained in:
parent
d4eb395335
commit
7dbab81d3c
src/java.base/share/classes/jdk/internal/classfile
test/jdk/jdk/classfile
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2022, 2023, 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
|
||||
@ -25,6 +25,8 @@
|
||||
|
||||
package jdk.internal.classfile;
|
||||
|
||||
import java.lang.invoke.TypeDescriptor;
|
||||
|
||||
/**
|
||||
* Describes the types that can be part of a field or method descriptor.
|
||||
*/
|
||||
@ -132,4 +134,12 @@ public enum TypeKind {
|
||||
default -> throw new IllegalArgumentException("Bad type: " + s);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the type kind associated with the specified field descriptor}
|
||||
* @param descriptor the field descriptor
|
||||
*/
|
||||
public static TypeKind from(TypeDescriptor.OfField<?> descriptor) {
|
||||
return fromDescriptor(descriptor.descriptorString());
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ public sealed interface CodeLocalsShifter extends CodeTransform {
|
||||
static CodeLocalsShifter of(AccessFlags methodFlags, MethodTypeDesc methodDescriptor) {
|
||||
int fixed = methodFlags.has(AccessFlag.STATIC) ? 0 : 1;
|
||||
for (var param : methodDescriptor.parameterList())
|
||||
fixed += TypeKind.fromDescriptor(param.descriptorString()).slotSize();
|
||||
fixed += TypeKind.from(param).slotSize();
|
||||
return new CodeLocalsShifterImpl(fixed);
|
||||
}
|
||||
|
||||
|
@ -235,13 +235,13 @@ public sealed interface CodeStackTracker extends CodeTransform {
|
||||
case InvokeDynamicInstruction i -> {
|
||||
var type = i.typeSymbol();
|
||||
pop(type.parameterCount());
|
||||
push(TypeKind.fromDescriptor(type.returnType().descriptorString()));
|
||||
push(TypeKind.from(type.returnType()));
|
||||
}
|
||||
case InvokeInstruction i -> {
|
||||
var type = i.typeSymbol();
|
||||
pop(type.parameterCount());
|
||||
if (i.opcode() != Opcode.INVOKESTATIC) pop(1);
|
||||
push(TypeKind.fromDescriptor(type.returnType().descriptorString()));
|
||||
push(TypeKind.from(type.returnType()));
|
||||
}
|
||||
case LoadInstruction i ->
|
||||
push(i.typeKind());
|
||||
|
@ -173,7 +173,7 @@ class PackageSnippets {
|
||||
if (!mm.flags().has(AccessFlag.STATIC))
|
||||
storeStack.push(StoreInstruction.of(TypeKind.ReferenceType, slot++));
|
||||
for (var pt : mm.methodTypeSymbol().parameterList()) {
|
||||
var tk = TypeKind.fromDescriptor(pt.descriptorString());
|
||||
var tk = TypeKind.from(pt);
|
||||
storeStack.push(StoreInstruction.of(tk, slot));
|
||||
slot += tk.slotSize();
|
||||
}
|
||||
|
@ -267,7 +267,7 @@ class PackageSnippets {
|
||||
if (!mm.flags().has(AccessFlag.STATIC))
|
||||
storeStack.add(StoreInstruction.of(TypeKind.ReferenceType, slot++));
|
||||
for (var pt : mm.methodTypeSymbol().parameterList()) {
|
||||
var tk = TypeKind.fromDescriptor(pt.descriptorString());
|
||||
var tk = TypeKind.from(pt);
|
||||
storeStack.addFirst(StoreInstruction.of(tk, slot));
|
||||
slot += tk.slotSize();
|
||||
}
|
||||
|
@ -319,7 +319,7 @@ class AdvancedTransformationsTest {
|
||||
if (!mm.flags().has(AccessFlag.STATIC))
|
||||
storeStack.push(StoreInstruction.of(TypeKind.ReferenceType, slot++));
|
||||
for (var pt : mm.methodTypeSymbol().parameterList()) {
|
||||
var tk = TypeKind.fromDescriptor(pt.descriptorString());
|
||||
var tk = TypeKind.from(pt);
|
||||
storeStack.push(StoreInstruction.of(tk, slot));
|
||||
slot += tk.slotSize();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user