mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8336934: Clean up JavaLangReflectAccess
Reviewed-by: rriggs, darcy
This commit is contained in:
parent
d72810794b
commit
88ccbb6091
6 changed files with 35 additions and 168 deletions
|
@ -165,6 +165,14 @@ public final class Constructor<T> extends Executable {
|
|||
return res;
|
||||
}
|
||||
|
||||
// Creates a new root constructor with a custom accessor for serialization hooks.
|
||||
Constructor<T> newWithAccessor(ConstructorAccessor accessor) {
|
||||
var res = new Constructor<>(clazz, parameterTypes, exceptionTypes, modifiers, slot,
|
||||
signature, annotations, parameterAnnotations);
|
||||
res.constructorAccessor = accessor;
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
|
|
|
@ -173,21 +173,6 @@ public final class Method extends Executable {
|
|||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a copy of a leaf method.
|
||||
*/
|
||||
Method leafCopy() {
|
||||
if (this.root == null)
|
||||
throw new IllegalArgumentException("Can only leafCopy a non-root Method");
|
||||
|
||||
Method res = new Method(clazz, name, parameterTypes, returnType,
|
||||
exceptionTypes, modifiers, slot, signature,
|
||||
annotations, parameterAnnotations, annotationDefault);
|
||||
res.root = root;
|
||||
res.methodAccessor = methodAccessor;
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InaccessibleObjectException {@inheritDoc}
|
||||
* @throws SecurityException {@inheritDoc}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2001, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2001, 2024, 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,65 +25,15 @@
|
|||
|
||||
package java.lang.reflect;
|
||||
|
||||
import jdk.internal.reflect.MethodAccessor;
|
||||
import jdk.internal.access.JavaLangReflectAccess;
|
||||
import jdk.internal.reflect.ConstructorAccessor;
|
||||
|
||||
/** Package-private class implementing the
|
||||
jdk.internal.access.JavaLangReflectAccess interface, allowing the java.lang
|
||||
package to instantiate objects in this package. */
|
||||
|
||||
class ReflectAccess implements jdk.internal.access.JavaLangReflectAccess {
|
||||
public <T> Constructor<T> newConstructor(Class<T> declaringClass,
|
||||
Class<?>[] parameterTypes,
|
||||
Class<?>[] checkedExceptions,
|
||||
int modifiers,
|
||||
int slot,
|
||||
String signature,
|
||||
byte[] annotations,
|
||||
byte[] parameterAnnotations)
|
||||
{
|
||||
return new Constructor<>(declaringClass,
|
||||
parameterTypes,
|
||||
checkedExceptions,
|
||||
modifiers,
|
||||
slot,
|
||||
signature,
|
||||
annotations,
|
||||
parameterAnnotations);
|
||||
}
|
||||
|
||||
public MethodAccessor getMethodAccessor(Method m) {
|
||||
return m.getMethodAccessor();
|
||||
}
|
||||
|
||||
public void setMethodAccessor(Method m, MethodAccessor accessor) {
|
||||
m.setMethodAccessor(accessor);
|
||||
}
|
||||
|
||||
public ConstructorAccessor getConstructorAccessor(Constructor<?> c) {
|
||||
return c.getConstructorAccessor();
|
||||
}
|
||||
|
||||
public void setConstructorAccessor(Constructor<?> c,
|
||||
ConstructorAccessor accessor)
|
||||
{
|
||||
c.setConstructorAccessor(accessor);
|
||||
}
|
||||
|
||||
public int getConstructorSlot(Constructor<?> c) {
|
||||
return c.getSlot();
|
||||
}
|
||||
|
||||
public String getConstructorSignature(Constructor<?> c) {
|
||||
return c.getSignature();
|
||||
}
|
||||
|
||||
public byte[] getConstructorAnnotations(Constructor<?> c) {
|
||||
return c.getRawAnnotations();
|
||||
}
|
||||
|
||||
public byte[] getConstructorParameterAnnotations(Constructor<?> c) {
|
||||
return c.getRawParameterAnnotations();
|
||||
final class ReflectAccess implements JavaLangReflectAccess {
|
||||
public <T> Constructor<T> newConstructorWithAccessor(Constructor<T> original, ConstructorAccessor accessor) {
|
||||
return original.newWithAccessor(accessor);
|
||||
}
|
||||
|
||||
public byte[] getExecutableTypeAnnotationBytes(Executable ex) {
|
||||
|
@ -105,9 +55,6 @@ class ReflectAccess implements jdk.internal.access.JavaLangReflectAccess {
|
|||
public Method copyMethod(Method arg) {
|
||||
return arg.copy();
|
||||
}
|
||||
public Method leafCopyMethod(Method arg) {
|
||||
return arg.leafCopy();
|
||||
}
|
||||
|
||||
public Field copyField(Field arg) {
|
||||
return arg.copy();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue