Skip to content

Commit 0e0cf2c

Browse files
committed
HHH-19733 Extracting some more reusable constants in the ByteBuddy Enhancer
1 parent 39c0806 commit 0e0cf2c

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

hibernate-core/src/main/java/org/hibernate/bytecode/enhance/internal/bytebuddy/EnhancerImpl.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969
import java.util.Set;
7070
import java.util.function.Supplier;
7171

72-
import static net.bytebuddy.matcher.ElementMatchers.isDefaultFinalizer;
7372
import static net.bytebuddy.matcher.ElementMatchers.isGetter;
7473
import static net.bytebuddy.matcher.ElementMatchers.isSetter;
7574
import static net.bytebuddy.matcher.ElementMatchers.isStatic;
@@ -85,7 +84,7 @@ public class EnhancerImpl implements Enhancer {
8584
private final ByteBuddyState byteBuddyState;
8685
private final EnhancerClassLocator typePool;
8786
private final EnhancerImplConstants constants;
88-
private final List<? extends Annotation> infoAnnotationList;
87+
private final AnnotationList.ForLoadedAnnotations infoAnnotationList;
8988

9089
/**
9190
* Constructs the Enhancer, using the given context.
@@ -111,7 +110,7 @@ public EnhancerImpl(final EnhancementContext enhancementContext, final ByteBuddy
111110
this.typePool = Objects.requireNonNull( classLocator );
112111
this.constants = byteBuddyState.getEnhancerConstants();
113112

114-
this.infoAnnotationList = List.of( createInfoAnnotation( enhancementContext ) );
113+
this.infoAnnotationList = new AnnotationList.ForLoadedAnnotations( List.of( createInfoAnnotation( enhancementContext ) ) );
115114
}
116115

117116

@@ -135,7 +134,7 @@ public byte[] enhance(String className, byte[] originalBytes) throws Enhancement
135134
final TypeDescription typeDescription = typePool.describe( safeClassName ).resolve();
136135

137136
return byteBuddyState.rewrite( typePool, safeClassName, byteBuddy -> doEnhance(
138-
() -> byteBuddy.ignore( isDefaultFinalizer() )
137+
() -> byteBuddy.ignore( constants.defaultFinalizer() )
139138
.redefine( typeDescription, typePool.asClassFileLocator() )
140139
.annotateType( infoAnnotationList ),
141140
typeDescription

hibernate-core/src/main/java/org/hibernate/bytecode/enhance/internal/bytebuddy/EnhancerImplConstants.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import jakarta.persistence.Transient;
88
import net.bytebuddy.asm.Advice;
99
import net.bytebuddy.description.annotation.AnnotationDescription;
10+
import net.bytebuddy.description.method.MethodDescription;
1011
import net.bytebuddy.description.modifier.FieldPersistence;
1112
import net.bytebuddy.description.modifier.ModifierContributor;
1213
import net.bytebuddy.description.modifier.Visibility;
@@ -19,11 +20,14 @@
1920
import java.util.Collection;
2021
import java.util.List;
2122

23+
import net.bytebuddy.matcher.ElementMatcher;
2224
import org.hibernate.bytecode.enhance.spi.CollectionTracker;
2325
import org.hibernate.engine.spi.EntityEntry;
2426
import org.hibernate.engine.spi.ManagedEntity;
2527
import org.hibernate.engine.spi.PersistentAttributeInterceptor;
2628

29+
import static net.bytebuddy.matcher.ElementMatchers.isDefaultFinalizer;
30+
2731
/**
2832
* Extracts constants used by EnhancerImpl.
2933
* This allows integrators to choose reusing this state for multiple enhancement processes,
@@ -69,6 +73,9 @@ public final class EnhancerImplConstants {
6973
final TypeDefinition Type_Array_String = TypeDescription.ForLoadedType.of( String[].class );
7074
final TypeDefinition TypeCollectionTracker = TypeDescription.ForLoadedType.of( CollectionTracker.class );
7175

76+
//Frequently used ElementMatchers:
77+
final ElementMatcher.Junction<MethodDescription> DEFAULT_FINALIZER = isDefaultFinalizer();
78+
7279
public EnhancerImplConstants() {
7380
this.adviceLocator = ClassFileLocator.ForClassLoader.of( CodeTemplates.class.getClassLoader() );
7481
this.implementationTrackChange = Advice.to( CodeTemplates.TrackChange.class, adviceLocator )
@@ -110,4 +117,8 @@ public EnhancerImplConstants() {
110117
.wrap( StubMethod.INSTANCE );
111118
}
112119

120+
public ElementMatcher<? super MethodDescription> defaultFinalizer() {
121+
return DEFAULT_FINALIZER;
122+
}
123+
113124
}

0 commit comments

Comments
 (0)