Package net.bytebuddy.build
Class HashCodeAndEqualsPlugin
- java.lang.Object
-
- net.bytebuddy.build.HashCodeAndEqualsPlugin
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,Plugin,Plugin.Factory,ElementMatcher<TypeDescription>
- Direct Known Subclasses:
HashCodeAndEqualsPlugin.WithNonNullableFields
@Enhance public class HashCodeAndEqualsPlugin extends java.lang.Object implements Plugin, Plugin.Factory
A build tool plugin that addsObject.hashCode()andObject.equals(Object)methods to a class if theHashCodeAndEqualsPlugin.Enhanceannotation is present and no explicit method declaration was added. This plugin does not need to be closed.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classHashCodeAndEqualsPlugin.AnnotationOrderComparatorA comparator that arranges fields in the order ofHashCodeAndEqualsPlugin.Sorted.static interfaceHashCodeAndEqualsPlugin.EnhanceInstructs theHashCodeAndEqualsPluginto generateObject.hashCode()andObject.equals(Object)for the annotated class unless these methods are already declared explicitly.static interfaceHashCodeAndEqualsPlugin.SortedDetermines the sort order of fields for the equality check when implementing theObject.equals(Object)method.static interfaceHashCodeAndEqualsPlugin.ValueHandlingDetermines how a field should be used within generated hash code and equality methods.protected static classHashCodeAndEqualsPlugin.ValueMatcherAn element matcher for aHashCodeAndEqualsPlugin.ValueHandlingannotation.static classHashCodeAndEqualsPlugin.WithNonNullableFieldsA version of theHashCodeAndEqualsPluginthat assumes that all fields are non-nullable unless they are explicitly marked.-
Nested classes/interfaces inherited from interface net.bytebuddy.matcher.ElementMatcher
ElementMatcher.Junction<S>
-
Nested classes/interfaces inherited from interface net.bytebuddy.build.Plugin
Plugin.Engine, Plugin.Factory, Plugin.ForElementMatcher, Plugin.NoOp, Plugin.WithPreprocessor
-
Nested classes/interfaces inherited from interface net.bytebuddy.build.Plugin.Factory
Plugin.Factory.Simple, Plugin.Factory.UsingReflection
-
-
Constructor Summary
Constructors Constructor Description HashCodeAndEqualsPlugin()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DynamicType.Builder<?>apply(DynamicType.Builder<?> builder, TypeDescription typeDescription, ClassFileLocator classFileLocator)Applies this plugin.voidclose()Pluginmake()Returns a plugin that can be used for a transformation and which is subsequently closed.booleanmatches(TypeDescription target)Matches a target against this element matcher.protected ElementMatcher<FieldDescription>nonNullable(ElementMatcher<FieldDescription> matcher)Resolves the matcher to identify non-nullable fields.
-
-
-
Method Detail
-
make
public Plugin make()
Returns a plugin that can be used for a transformation and which is subsequently closed.- Specified by:
makein interfacePlugin.Factory- Returns:
- The plugin to use for type transformations.
-
matches
public boolean matches(TypeDescription target)
Matches a target against this element matcher.- Specified by:
matchesin interfaceElementMatcher<TypeDescription>- Parameters:
target- The instance to be matched.- Returns:
trueif the given element is matched by this matcher orfalseotherwise.
-
apply
public DynamicType.Builder<?> apply(DynamicType.Builder<?> builder, TypeDescription typeDescription, ClassFileLocator classFileLocator)
Applies this plugin.- Specified by:
applyin interfacePlugin- 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
protected ElementMatcher<FieldDescription> nonNullable(ElementMatcher<FieldDescription> matcher)
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:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable
-
-