diff --git a/byte-buddy-dep/src/main/java/net/bytebuddy/description/annotation/AnnotationList.java b/byte-buddy-dep/src/main/java/net/bytebuddy/description/annotation/AnnotationList.java index 2c6805800a2..94c352c8692 100644 --- a/byte-buddy-dep/src/main/java/net/bytebuddy/description/annotation/AnnotationList.java +++ b/byte-buddy-dep/src/main/java/net/bytebuddy/description/annotation/AnnotationList.java @@ -26,6 +26,7 @@ import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Set; @@ -92,6 +93,14 @@ public interface AnnotationList extends FilterableList asTypeNames(); + /** * An abstract base implementation of an annotation list. */ @@ -185,6 +194,17 @@ public TypeList asTypeList() { return new TypeList.Explicit(annotationTypes); } + /** + * {@inheritDoc} + */ + public List asTypeNames() { + List typeNames = new ArrayList(size()); + for (AnnotationDescription annotation : this) { + typeNames.add(annotation.getAnnotationType().getName()); + } + return typeNames; + } + @Override protected AnnotationList wrap(List values) { return new Explicit(values); @@ -375,5 +395,12 @@ public AnnotationList visibility(ElementMatcher matcher public TypeList asTypeList() { return new TypeList.Empty(); } + + /** + * {@inheritDoc} + */ + public List asTypeNames() { + return Collections.emptyList(); + } } } diff --git a/byte-buddy-dep/src/main/java/net/bytebuddy/pool/TypePool.java b/byte-buddy-dep/src/main/java/net/bytebuddy/pool/TypePool.java index ad5fd2c2e45..c0c55375554 100644 --- a/byte-buddy-dep/src/main/java/net/bytebuddy/pool/TypePool.java +++ b/byte-buddy-dep/src/main/java/net/bytebuddy/pool/TypePool.java @@ -6189,7 +6189,7 @@ protected static AnnotationList asListOfNullable(TypePool typePool, @MaybeNull L * * @param typePool The type pool to be used for looking up linked types. * @param tokens The tokens to represent in the list. - * @return A list of the loadable annotations. + * @return A list of the represented annotations. */ protected static AnnotationList asList(TypePool typePool, List tokens) { List annotationDescriptions = new ArrayList(tokens.size()); @@ -6199,7 +6199,7 @@ protected static AnnotationList asList(TypePool typePool, List tokens; + + /** + * Creates a list of unresolved annotations. + * + * @param annotationDescriptions The list of represented annotation descriptions. + * @param tokens The list of represented annotation tokens. + */ + private UnresolvedAnnotationList(List annotationDescriptions, List tokens) { + super(annotationDescriptions); + this.tokens = tokens; + } + + @Override + public List asTypeNames() { + List typeNames = new ArrayList(tokens.size()); + for (AnnotationToken token : tokens) { + typeNames.add(token.getBinaryName()); + } + return typeNames; + } + } } /** diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/description/annotation/AbstractAnnotationListTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/description/annotation/AbstractAnnotationListTest.java index 464d1b1e179..5a473ae6b08 100644 --- a/byte-buddy-dep/src/test/java/net/bytebuddy/description/annotation/AbstractAnnotationListTest.java +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/description/annotation/AbstractAnnotationListTest.java @@ -88,6 +88,11 @@ public void testAsTypeList() throws Exception { assertThat(asList(getFirst()).asTypeList(), is(Collections.singletonList(asElement(getFirst()).getAnnotationType()))); } + @Test + public void testAsTypeNames() throws Exception { + assertThat(asList(getFirst()).asTypeNames(), is(Collections.singletonList(asElement(getFirst()).getAnnotationType().getName()))); + } + @Retention(RetentionPolicy.RUNTIME) @Inherited protected @interface Foo { diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/description/annotation/AnnotationListEmptyTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/description/annotation/AnnotationListEmptyTest.java index 2b3dd0d002c..5cc24bfb25e 100644 --- a/byte-buddy-dep/src/test/java/net/bytebuddy/description/annotation/AnnotationListEmptyTest.java +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/description/annotation/AnnotationListEmptyTest.java @@ -42,4 +42,9 @@ public void testAnnotationVisibility() throws Exception { public void testAsTypeList() throws Exception { assertThat(new AnnotationList.Empty().asTypeList().size(), is(0)); } + + @Test + public void testAsTypeNames() throws Exception { + assertThat(new AnnotationList.Empty().asTypeNames().size(), is(0)); + } }