Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #742 from platosha/feature/missing-annotation-api
Add `getTypeAnnotationInfo` to `TypeParameter` and `TypeArgument`
- Loading branch information
Showing
4 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/test/java/io/github/classgraph/issues/issue741/TypeArgumentAnnotationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package io.github.classgraph.issues.issue741; | ||
|
||
import io.github.classgraph.*; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Target; | ||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class TypeArgumentAnnotationTest { | ||
@Target({ElementType.FIELD, ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) | ||
private static @interface A { | ||
} | ||
|
||
@Target({ElementType.FIELD, ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) | ||
private static @interface B { | ||
String value(); | ||
} | ||
|
||
@Target({ElementType.FIELD, ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) | ||
private static @interface C { | ||
Class<?> t(); | ||
} | ||
|
||
@Target({ElementType.FIELD, ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) | ||
private static @interface D { | ||
int n(); | ||
} | ||
|
||
static class U { | ||
} | ||
|
||
void setValueList(List<@A @B("foo") @C(t=U.class) @D(n=50) ?> valueList) { | ||
} | ||
|
||
@Test | ||
void typeArgumentAnnotation() { | ||
try (final ScanResult scanResult = new ClassGraph().acceptPackages(TypeArgumentAnnotationTest.class.getPackage().getName()) | ||
.enableAllInfo().scan()) { | ||
final ClassInfo cls = scanResult.getClassInfo(TypeArgumentAnnotationTest.class.getName()); | ||
final MethodInfo method = cls.getMethodInfo().get("setValueList").get(0); | ||
final MethodParameterInfo parameterInfo = method.getParameterInfo()[0]; | ||
final TypeArgument typeArgument = ((ClassRefTypeSignature) parameterInfo.getTypeSignatureOrTypeDescriptor()).getTypeArguments().get(0); | ||
final AnnotationInfoList annotationInfoList = typeArgument.getTypeAnnotationInfo(); | ||
assertThat(annotationInfoList.get(0).toStringWithSimpleNames()).isEqualTo("@A"); | ||
assertThat(annotationInfoList.get(1).toStringWithSimpleNames()).isEqualTo("@B(\"foo\")"); | ||
assertThat(annotationInfoList.get(2).toStringWithSimpleNames()).isEqualTo("@C(t=U.class)"); | ||
assertThat(annotationInfoList.get(3).toStringWithSimpleNames()).isEqualTo("@D(n=50)"); | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/test/java/io/github/classgraph/issues/issue741/TypeParameterAnnotationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package io.github.classgraph.issues.issue741; | ||
|
||
import io.github.classgraph.*; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Target; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class TypeParameterAnnotationTest { | ||
@Target({ElementType.FIELD, ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) | ||
private static @interface A { | ||
} | ||
|
||
@Target({ElementType.FIELD, ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) | ||
private static @interface B { | ||
String value(); | ||
} | ||
|
||
@Target({ElementType.FIELD, ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) | ||
private static @interface C { | ||
Class<?> t(); | ||
} | ||
|
||
@Target({ElementType.FIELD, ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) | ||
private static @interface D { | ||
int n(); | ||
} | ||
|
||
static class U { | ||
} | ||
|
||
<@A @B("foo") @C(t=U.class) @D(n=50) T> void setValue(T value) { | ||
} | ||
|
||
@Test | ||
void typeParameterAnnotation() { | ||
try (final ScanResult scanResult = new ClassGraph().acceptPackages(TypeParameterAnnotationTest.class.getPackage().getName()) | ||
.enableAllInfo().scan()) { | ||
final ClassInfo cls = scanResult.getClassInfo(TypeParameterAnnotationTest.class.getName()); | ||
final MethodInfo method = cls.getMethodInfo().get("setValue").get(0); | ||
final TypeParameter typeParameter = method.getTypeSignatureOrTypeDescriptor().getTypeParameters().get(0); | ||
final AnnotationInfoList annotationInfoList = typeParameter.getTypeAnnotationInfo(); | ||
assertThat(annotationInfoList.get(0).toStringWithSimpleNames()).isEqualTo("@A"); | ||
assertThat(annotationInfoList.get(1).toStringWithSimpleNames()).isEqualTo("@B(\"foo\")"); | ||
assertThat(annotationInfoList.get(2).toStringWithSimpleNames()).isEqualTo("@C(t=U.class)"); | ||
assertThat(annotationInfoList.get(3).toStringWithSimpleNames()).isEqualTo("@D(n=50)"); | ||
} | ||
} | ||
} |