From 40a07844c095d4b43d5a0876b600a4c118542ca7 Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Mon, 20 Dec 2021 11:07:20 +0100 Subject: [PATCH] [release] Release new version. --- .../description/type/TypeDescription.java | 17 +++++++++++++++++ .../build/HashCodeAndEqualsPluginTest.java | 16 +++++++++++----- .../type/AbstractTypeDescriptionTest.java | 16 ++++++++++++++-- 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/byte-buddy-dep/src/main/java/net/bytebuddy/description/type/TypeDescription.java b/byte-buddy-dep/src/main/java/net/bytebuddy/description/type/TypeDescription.java index 6eddfe79552..828c4ec7fa0 100644 --- a/byte-buddy-dep/src/main/java/net/bytebuddy/description/type/TypeDescription.java +++ b/byte-buddy-dep/src/main/java/net/bytebuddy/description/type/TypeDescription.java @@ -241,6 +241,13 @@ public interface TypeDescription extends TypeDefinition, ByteCodeElement, TypeVa */ String getSimpleName(); + /** + * Returns a form of a type's simple name which only shortens the package name but not the names of outer classes. + * + * @return The long form of the simple name of this type. + */ + String getLongSimpleName(); + /** * Returns the canonical name of this type if it exists. * @@ -7964,6 +7971,16 @@ public String getActualName() { } } + /** + * {@inheritDoc} + */ + public String getLongSimpleName() { + TypeDescription declaringType = getDeclaringType(); + return declaringType == null + ? getSimpleName() + : declaringType.getLongSimpleName() + "." + getSimpleName(); + } + /** * {@inheritDoc} */ diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/build/HashCodeAndEqualsPluginTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/build/HashCodeAndEqualsPluginTest.java index 48e63f9f7ce..dd9a7c5277e 100644 --- a/byte-buddy-dep/src/test/java/net/bytebuddy/build/HashCodeAndEqualsPluginTest.java +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/build/HashCodeAndEqualsPluginTest.java @@ -8,11 +8,12 @@ import net.bytebuddy.dynamic.ClassFileLocator; import net.bytebuddy.dynamic.loading.ClassLoadingStrategy; import net.bytebuddy.implementation.EqualsMethod; -import net.bytebuddy.utility.nullability.MaybeNull; import org.hamcrest.CoreMatchers; import org.junit.Test; import java.lang.annotation.Annotation; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; import java.lang.reflect.Method; import java.util.Comparator; @@ -209,15 +210,15 @@ public void testAnnotationComparatorEqualsRightBiggerAnnotations() { } @Test - public void testPluginEnhanceJsr305() throws Exception { - Class type = new HashCodeAndEqualsPlugin(MaybeNull.class.getName()) + public void testPluginEnhanceWithAnnotation() throws Exception { + Class type = new HashCodeAndEqualsPlugin(SampleAnnotation.class.getName()) .apply(new ByteBuddy().redefine(SimpleSample.class), TypeDescription.ForLoadedType.of(SimpleSample.class), ClassFileLocator.ForClassLoader.of(SimpleSample.class.getClassLoader())) .make() - .load(MaybeNull.class.getClassLoader(), ClassLoadingStrategy.Default.CHILD_FIRST) + .load(SampleAnnotation.class.getClassLoader(), ClassLoadingStrategy.Default.CHILD_FIRST) .getLoaded(); Method method = type.getMethod("equals", Object.class); assertThat(method.getParameterAnnotations()[0].length, is(1)); - assertThat(method.getParameterAnnotations()[0][0], CoreMatchers.instanceOf(MaybeNull.class)); + assertThat(method.getParameterAnnotations()[0][0], CoreMatchers.instanceOf(SampleAnnotation.class)); assertThat(type.getDeclaredConstructor().newInstance().hashCode(), is(type.getDeclaredConstructor().newInstance().hashCode())); assertThat(type.getDeclaredConstructor().newInstance(), is(type.getDeclaredConstructor().newInstance())); } @@ -290,4 +291,9 @@ public static class FieldSortOrderSample { @HashCodeAndEqualsPlugin.Sorted(1) public String qux; } + + @Retention(RetentionPolicy.RUNTIME) + public @interface SampleAnnotation { + /* empty */ + } } \ No newline at end of file diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/description/type/AbstractTypeDescriptionTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/description/type/AbstractTypeDescriptionTest.java index 49c48ce5f1d..6b39873c6f5 100644 --- a/byte-buddy-dep/src/test/java/net/bytebuddy/description/type/AbstractTypeDescriptionTest.java +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/description/type/AbstractTypeDescriptionTest.java @@ -213,8 +213,20 @@ public void testCanonicalName() throws Exception { @Test public void testSimpleName() throws Exception { for (Class type : standardTypes) { - if (type.getName().equals("net.bytebuddy.test.scope.EnclosingType$1Foo")) - assertThat(describe(type).getSimpleName(), is(type.getSimpleName())); + assertThat(describe(type).getSimpleName(), is(type.getSimpleName())); + } + } + + @Test + public void getLongSimpleName() throws Exception { + for (Class type : standardTypes) { + if (type.getDeclaringClass() == null) { + assertThat(describe(type).getLongSimpleName(), is(type.getSimpleName())); + } else { + assertThat(describe(type).getLongSimpleName(), is(type.getDeclaringClass().getSimpleName() + + "." + + type.getSimpleName())); + } } }