HHH-16711 Ensure static accessor methods for accessing foreign package state use visible types

This commit is contained in:
Christian Beikov 2023-06-20 19:48:30 +02:00
parent d19a6cca03
commit fa3b2e82fb
1 changed files with 22 additions and 35 deletions

View File

@ -324,23 +324,14 @@ public class BytecodeProviderImpl implements BytecodeProvider {
getterType = ( (Method) getter ).getReturnType(); getterType = ( (Method) getter ).getReturnType();
} }
builder = builder.define( builder = builder.defineMethod(
new MethodDescription.InDefinedShape.Latent( "get_" + getter.getName(),
builder.toTypeDescription(), TypeDescription.Generic.OfNonGenericType.ForLoadedType.of(
new MethodDescription.Token( getterType
"get_" + getter.getName(), ),
Opcodes.ACC_PROTECTED | Opcodes.ACC_STATIC, Opcodes.ACC_PROTECTED | Opcodes.ACC_STATIC
TypeDescription.Generic.OfNonGenericType.ForLoadedType.of(
getterType
),
Collections.singletonList(
TypeDescription.Generic.OfNonGenericType.ForLoadedType.of(
clazz
)
)
)
)
) )
.withParameter( foreignPackageClassInfo.clazz )
.intercept( .intercept(
new Implementation.Simple( new Implementation.Simple(
new GetFieldOnArgument( new GetFieldOnArgument(
@ -358,24 +349,13 @@ public class BytecodeProviderImpl implements BytecodeProvider {
setterType = ( (Method) setter ).getParameterTypes()[0]; setterType = ( (Method) setter ).getParameterTypes()[0];
} }
builder = builder.define( builder = builder.defineMethod(
new MethodDescription.InDefinedShape.Latent( "set_" + setter.getName(),
builder.toTypeDescription(), TypeDescription.Generic.VOID,
new MethodDescription.Token( Opcodes.ACC_PROTECTED | Opcodes.ACC_STATIC
"set_" + setter.getName(),
Opcodes.ACC_PROTECTED | Opcodes.ACC_STATIC,
TypeDescription.Generic.VOID,
Arrays.asList(
TypeDescription.Generic.OfNonGenericType.ForLoadedType.of(
clazz
),
TypeDescription.Generic.OfNonGenericType.ForLoadedType.of(
setterType
)
)
)
)
) )
.withParameter( foreignPackageClassInfo.clazz )
.withParameter( setterType )
.intercept( .intercept(
new Implementation.Simple( new Implementation.Simple(
new SetFieldOnArgument( new SetFieldOnArgument(
@ -781,7 +761,10 @@ public class BytecodeProviderImpl implements BytecodeProvider {
Opcodes.INVOKESTATIC, Opcodes.INVOKESTATIC,
Type.getInternalName( foreignPackageMember.getForeignPackageAccessor() ), Type.getInternalName( foreignPackageMember.getForeignPackageAccessor() ),
"get_" + getterMember.getName(), "get_" + getterMember.getName(),
Type.getMethodDescriptor( Type.getType( type ), Type.getType( clazz ) ), Type.getMethodDescriptor(
Type.getType( type ),
Type.getType( underlyingMember.getDeclaringClass() )
),
false false
); );
} }
@ -976,7 +959,11 @@ public class BytecodeProviderImpl implements BytecodeProvider {
Opcodes.INVOKESTATIC, Opcodes.INVOKESTATIC,
Type.getInternalName( foreignPackageMember.getForeignPackageAccessor() ), Type.getInternalName( foreignPackageMember.getForeignPackageAccessor() ),
"set_" + setterMember.getName(), "set_" + setterMember.getName(),
Type.getMethodDescriptor( Type.getType( void.class ), Type.getType( clazz ), Type.getType( type ) ), Type.getMethodDescriptor(
Type.getType( void.class ),
Type.getType( foreignPackageMember.getMember().getDeclaringClass() ),
Type.getType( type )
),
false false
); );
} }