Skip to content

Commit

Permalink
[release] Release new version.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Dec 20, 2021
1 parent 158b70c commit 40a0784
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
Expand Up @@ -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.
*
Expand Down Expand Up @@ -7964,6 +7971,16 @@ public String getActualName() {
}
}

/**
* {@inheritDoc}
*/
public String getLongSimpleName() {
TypeDescription declaringType = getDeclaringType();
return declaringType == null
? getSimpleName()
: declaringType.getLongSimpleName() + "." + getSimpleName();
}

/**
* {@inheritDoc}
*/
Expand Down
Expand Up @@ -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;

Expand Down Expand Up @@ -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.<Annotation>instanceOf(MaybeNull.class));
assertThat(method.getParameterAnnotations()[0][0], CoreMatchers.<Annotation>instanceOf(SampleAnnotation.class));
assertThat(type.getDeclaredConstructor().newInstance().hashCode(), is(type.getDeclaredConstructor().newInstance().hashCode()));
assertThat(type.getDeclaredConstructor().newInstance(), is(type.getDeclaredConstructor().newInstance()));
}
Expand Down Expand Up @@ -290,4 +291,9 @@ public static class FieldSortOrderSample {
@HashCodeAndEqualsPlugin.Sorted(1)
public String qux;
}

@Retention(RetentionPolicy.RUNTIME)
public @interface SampleAnnotation {
/* empty */
}
}
Expand Up @@ -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()));
}
}
}

Expand Down

0 comments on commit 40a0784

Please sign in to comment.