Class HashCodeAndEqualsPlugin

java.lang.Object
net.bytebuddy.build.HashCodeAndEqualsPlugin
All Implemented Interfaces:
Closeable, AutoCloseable, Plugin, Plugin.Factory, MethodAttributeAppender, MethodAttributeAppender.Factory, ElementMatcher<TypeDescription>
Direct Known Subclasses:
HashCodeAndEqualsPlugin.WithNonNullableFields

@Enhance public class HashCodeAndEqualsPlugin extends Object implements Plugin, Plugin.Factory, MethodAttributeAppender.Factory, MethodAttributeAppender
A build tool plugin that adds Object.hashCode() and Object.equals(Object) methods to a class if the HashCodeAndEqualsPlugin.Enhance annotation is present and no explicit method declaration was added. This plugin does not need to be closed.
  • Constructor Details

    • HashCodeAndEqualsPlugin

      public HashCodeAndEqualsPlugin()
      Creates a new hash code equals plugin.
    • HashCodeAndEqualsPlugin

      public HashCodeAndEqualsPlugin(@MaybeNull String annotationType)
      Creates a new hash code equals plugin.
      Parameters:
      annotationType - Defines the binary name of a runtime-visible annotation type that should be added to the parameter of the Object.equals(Object) method, or null if no such name should be defined.
  • Method Details

    • make

      public Plugin make()
      Returns a plugin that can be used for a transformation and which is subsequently closed.
      Specified by:
      make in interface Plugin.Factory
      Returns:
      The plugin to use for type transformations.
    • matches

      public boolean matches(@MaybeNull TypeDescription target)
      Matches a target against this element matcher.
      Specified by:
      matches in interface ElementMatcher<TypeDescription>
      Parameters:
      target - The instance to be matched or null.
      Returns:
      true if the given element is matched by this matcher or false otherwise.
    • apply

      public DynamicType.Builder<?> apply(DynamicType.Builder<?> builder, TypeDescription typeDescription, ClassFileLocator classFileLocator)
      Applies this plugin.
      Specified by:
      apply in interface Plugin
      Parameters:
      builder - The builder to use as a basis for the applied transformation.
      typeDescription - The type being transformed.
      classFileLocator - A class file locator that can locate other types in the scope of the project.
      Returns:
      The supplied builder with additional transformations registered.
    • nonNullable

      Resolves the matcher to identify non-nullable fields.
      Parameters:
      matcher - The matcher that identifies fields that are either nullable or non-nullable.
      Returns:
      The actual matcher to identify non-nullable fields.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • make

      public MethodAttributeAppender make(TypeDescription typeDescription)
      Returns a method attribute appender that is applicable for a given type description.
      Specified by:
      make in interface MethodAttributeAppender.Factory
      Parameters:
      typeDescription - The type for which a method attribute appender is to be applied for.
      Returns:
      The method attribute appender which should be applied for the given type.
    • apply

      public void apply(org.objectweb.asm.MethodVisitor methodVisitor, MethodDescription methodDescription, AnnotationValueFilter annotationValueFilter)
      Applies this attribute appender to a given method visitor.
      Specified by:
      apply in interface MethodAttributeAppender
      Parameters:
      methodVisitor - The method visitor to which the attributes that are represented by this attribute appender are written to.
      methodDescription - The description of the method for which the given method visitor creates an instrumentation for.
      annotationValueFilter - The annotation value filter to apply when the annotations are written.