HHH-15634 Extracting constant for @Transient annotation in ByteBuddy Enhancer

This commit is contained in:
Sanne Grinovero 2022-11-03 17:06:54 +00:00 committed by Sanne Grinovero
parent a40fea29c0
commit 93355272fd
1 changed files with 7 additions and 5 deletions

View File

@ -87,6 +87,8 @@ public class EnhancerImpl implements Enhancer {
}; };
} }
private static final AnnotationDescription TRANSIENT_ANNOTATION = AnnotationDescription.Builder.ofType( Transient.class ).build();
protected final ByteBuddyEnhancementContext enhancementContext; protected final ByteBuddyEnhancementContext enhancementContext;
private final ByteBuddyState byteBuddyState; private final ByteBuddyState byteBuddyState;
@ -218,7 +220,7 @@ public class EnhancerImpl implements Enhancer {
if ( collectionFields.isEmpty() ) { if ( collectionFields.isEmpty() ) {
builder = builder.implement( SelfDirtinessTracker.class ) builder = builder.implement( SelfDirtinessTracker.class )
.defineField( EnhancerConstants.TRACKER_FIELD_NAME, DirtyTracker.class, FieldPersistence.TRANSIENT, Visibility.PRIVATE ) .defineField( EnhancerConstants.TRACKER_FIELD_NAME, DirtyTracker.class, FieldPersistence.TRANSIENT, Visibility.PRIVATE )
.annotateField( AnnotationDescription.Builder.ofType( Transient.class ).build() ) .annotateField( TRANSIENT_ANNOTATION )
.defineMethod( EnhancerConstants.TRACKER_CHANGER_NAME, void.class, Visibility.PUBLIC ) .defineMethod( EnhancerConstants.TRACKER_CHANGER_NAME, void.class, Visibility.PUBLIC )
.withParameters( String.class ) .withParameters( String.class )
.intercept( implementationTrackChange ) .intercept( implementationTrackChange )
@ -239,9 +241,9 @@ public class EnhancerImpl implements Enhancer {
//TODO es.enableInterfaceExtendedSelfDirtinessTracker ? Careful with consequences.. //TODO es.enableInterfaceExtendedSelfDirtinessTracker ? Careful with consequences..
builder = builder.implement( ExtendedSelfDirtinessTracker.class ) builder = builder.implement( ExtendedSelfDirtinessTracker.class )
.defineField( EnhancerConstants.TRACKER_FIELD_NAME, DirtyTracker.class, FieldPersistence.TRANSIENT, Visibility.PRIVATE ) .defineField( EnhancerConstants.TRACKER_FIELD_NAME, DirtyTracker.class, FieldPersistence.TRANSIENT, Visibility.PRIVATE )
.annotateField( AnnotationDescription.Builder.ofType( Transient.class ).build() ) .annotateField( TRANSIENT_ANNOTATION )
.defineField( EnhancerConstants.TRACKER_COLLECTION_NAME, CollectionTracker.class, FieldPersistence.TRANSIENT, Visibility.PRIVATE ) .defineField( EnhancerConstants.TRACKER_COLLECTION_NAME, CollectionTracker.class, FieldPersistence.TRANSIENT, Visibility.PRIVATE )
.annotateField( AnnotationDescription.Builder.ofType( Transient.class ).build() ) .annotateField( TRANSIENT_ANNOTATION )
.defineMethod( EnhancerConstants.TRACKER_CHANGER_NAME, void.class, Visibility.PUBLIC ) .defineMethod( EnhancerConstants.TRACKER_CHANGER_NAME, void.class, Visibility.PUBLIC )
.withParameters( String.class ) .withParameters( String.class )
.intercept( implementationTrackChange ) .intercept( implementationTrackChange )
@ -347,7 +349,7 @@ public class EnhancerImpl implements Enhancer {
FieldPersistence.TRANSIENT, FieldPersistence.TRANSIENT,
Visibility.PRIVATE Visibility.PRIVATE
) )
.annotateField( AnnotationDescription.Builder.ofType( Transient.class ).build() ) .annotateField( TRANSIENT_ANNOTATION )
.defineMethod( .defineMethod(
EnhancerConstants.TRACKER_COMPOSITE_SET_OWNER, EnhancerConstants.TRACKER_COMPOSITE_SET_OWNER,
void.class, void.class,
@ -424,7 +426,7 @@ public class EnhancerImpl implements Enhancer {
String setterName) { String setterName) {
return builder return builder
.defineField( fieldName, type, Visibility.PRIVATE, FieldPersistence.TRANSIENT ) .defineField( fieldName, type, Visibility.PRIVATE, FieldPersistence.TRANSIENT )
.annotateField( AnnotationDescription.Builder.ofType( Transient.class ).build() ) .annotateField( TRANSIENT_ANNOTATION )
.defineMethod( getterName, type, Visibility.PUBLIC ) .defineMethod( getterName, type, Visibility.PUBLIC )
.intercept( FieldAccessor.ofField( fieldName ) ) .intercept( FieldAccessor.ofField( fieldName ) )
.defineMethod( setterName, void.class, Visibility.PUBLIC ) .defineMethod( setterName, void.class, Visibility.PUBLIC )