本文整理汇总了Java中net.bytebuddy.description.annotation.AnnotationDescription类的典型用法代码示例。如果您正苦于以下问题:Java AnnotationDescription类的具体用法?Java AnnotationDescription怎么用?Java AnnotationDescription使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AnnotationDescription类属于net.bytebuddy.description.annotation包,在下文中一共展示了AnnotationDescription类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: buildApiListingEndpoint
import net.bytebuddy.description.annotation.AnnotationDescription; //导入依赖的package包/类
/**
* Build a Swagger API listing JAX-RS endpoint class, binding it to given <code>path</code> using standard JAX-RS
* {@link Path} annotation.
* @param classLoader ClassLoader to use to create the class proxy
* @param apiGroupId API group id
* @param path Endpoint path
* @param authSchemes Authenticatiob schemes
* @param rolesAllowed Optional security roles for endpoint authorization
* @return The Swagger API listing JAX-RS endpoint class proxy
*/
public static Class<?> buildApiListingEndpoint(ClassLoader classLoader, String apiGroupId, String path,
String[] authSchemes, String[] rolesAllowed) {
String configId = (apiGroupId != null && !apiGroupId.trim().equals("")) ? apiGroupId
: ApiGroupId.DEFAULT_GROUP_ID;
final ClassLoader cl = (classLoader != null) ? classLoader : ClassUtils.getDefaultClassLoader();
DynamicType.Builder<SwaggerApiListingResource> builder = new ByteBuddy()
.subclass(SwaggerApiListingResource.class)
.annotateType(AnnotationDescription.Builder.ofType(Path.class).define("value", path).build())
.annotateType(AnnotationDescription.Builder.ofType(ApiGroupId.class).define("value", configId).build());
if (authSchemes != null && authSchemes.length > 0) {
if (authSchemes.length == 1 && authSchemes[0] != null && authSchemes[0].trim().equals("*")) {
builder = builder.annotateType(AnnotationDescription.Builder.ofType(Authenticate.class).build());
} else {
builder = builder.annotateType(AnnotationDescription.Builder.ofType(Authenticate.class)
.defineArray("schemes", authSchemes).build());
}
}
if (rolesAllowed != null && rolesAllowed.length > 0) {
builder = builder.annotateType(AnnotationDescription.Builder.ofType(RolesAllowed.class)
.defineArray("value", rolesAllowed).build());
}
return builder.make().load(cl, ClassLoadingStrategy.Default.INJECTION).getLoaded();
}
开发者ID:holon-platform,项目名称:holon-jaxrs,代码行数:34,代码来源:SwaggerJaxrsUtils.java
示例2: getAnnotations
import net.bytebuddy.description.annotation.AnnotationDescription; //导入依赖的package包/类
@SuppressWarnings({"unchecked", "rawtypes"})
public static Annotation[] getAnnotations(Collection<AnnotationDescription> annotations)
{
Collection<Annotation> col = new ArrayList<>(annotations.size());
for (AnnotationDescription annotation : annotations)
{
TypeDescription annotationType = annotation.getAnnotationType();
try
{
Class<?> forName = Class.forName(annotationType.getActualName());
if (! forName.isAnnotation())
{
continue;
}
col.add(annotation.prepare((Class) forName).load());
}
catch (ClassNotFoundException ignored)
{
}
}
return col.toArray(new Annotation[col.size()]);
}
开发者ID:Diorite,项目名称:Diorite,代码行数:23,代码来源:AsmUtils.java
示例3: isInjectElement
import net.bytebuddy.description.annotation.AnnotationDescription; //导入依赖的package包/类
@Override
protected boolean isInjectElement(AnnotatedCodeElement element)
{
for (AnnotationDescription annotation : AsmUtils.getAnnotationList(element))
{
TypeDescription annotationType = annotation.getAnnotationType();
if (annotationType.equals(INJECT))
{
return true;
}
if (annotationType.getInheritedAnnotations().isAnnotationPresent(SHORTCUT_INJECT))
{
return true;
}
}
return false;
}
开发者ID:Diorite,项目名称:Diorite,代码行数:18,代码来源:Controller.java
示例4: createConverterClass
import net.bytebuddy.description.annotation.AnnotationDescription; //导入依赖的package包/类
private void createConverterClass(Converter convert, ClassLoader classLoader) {
//create Java Class
Class<?> attributeConverter = new ByteBuddy()
// .subclass(TypeDescription.Generic.Builder.parameterizedType(AttributeConverter.class, String.class, Integer.class).build())
.subclass(AttributeConverter.class)
.name(convert.getClazz())
.annotateType(AnnotationDescription.Builder.ofType(javax.persistence.Converter.class).build())
.make()
.load(classLoader, ClassLoadingStrategy.Default.INJECTION)
.getLoaded();
//create MetadataClass
MetadataClass metadataClass = new MetadataClass(getMetadataFactory(), convert.getClazz());
metadataClass.addInterface(AttributeConverter.class.getName());
metadataClass.addGenericType("");
metadataClass.addGenericType("");
metadataClass.addGenericType(convert.getAttributeType());
metadataClass.addGenericType("");
metadataClass.addGenericType(convert.getFieldType());
getMetadataFactory().addMetadataClass(metadataClass);
}
开发者ID:jeddict,项目名称:jeddict,代码行数:23,代码来源:DBEntityMappings.java
示例5: isMatch
import net.bytebuddy.description.annotation.AnnotationDescription; //导入依赖的package包/类
@Override
public boolean isMatch(TypeDescription typeDescription) {
for (MethodDescription.InDefinedShape methodDescription : typeDescription.getDeclaredMethods()) {
List<String> annotationList = new ArrayList<String>(Arrays.asList(annotations));
AnnotationList declaredAnnotations = methodDescription.getDeclaredAnnotations();
for (AnnotationDescription annotation : declaredAnnotations) {
annotationList.remove(annotation.getAnnotationType().getActualName());
}
if (annotationList.isEmpty()) {
return true;
}
}
return false;
}
开发者ID:apache,项目名称:incubator-skywalking,代码行数:17,代码来源:MethodAnnotationMatch.java
示例6: resolve
import net.bytebuddy.description.annotation.AnnotationDescription; //导入依赖的package包/类
@Override
public Object[] resolve() {
TypeDescription componentTypeDescription = typePool.describe(componentTypeReference.lookup()).resolve();
Class<?> componentType;
if (componentTypeDescription.represents(Class.class)) {
componentType = TypeDescription.class;
} else if (componentTypeDescription.isAssignableTo(Enum.class)) { // Enums can implement annotation interfaces, check this first.
componentType = EnumerationDescription.class;
} else if (componentTypeDescription.isAssignableTo(Annotation.class)) {
componentType = AnnotationDescription.class;
} else if (componentTypeDescription.represents(String.class)) {
componentType = String.class;
} else {
throw new IllegalStateException("Unexpected complex array component type " + componentTypeDescription);
}
Object[] array = (Object[]) Array.newInstance(componentType, values.size());
int index = 0;
for (AnnotationValue<?, ?> annotationValue : values) {
Array.set(array, index++, annotationValue.resolve());
}
return array;
}
开发者ID:raphw,项目名称:byte-buddy,代码行数:23,代码来源:TypePool.java
示例7: testPackageRebasement
import net.bytebuddy.description.annotation.AnnotationDescription; //导入依赖的package包/类
@Test
public void testPackageRebasement() throws Exception {
Class<?> packageType = new ByteBuddy()
.rebase(Sample.class.getPackage(), ClassFileLocator.ForClassLoader.of(getClass().getClassLoader()))
.annotateType(AnnotationDescription.Builder.ofType(Baz.class).build())
.make()
.load(getClass().getClassLoader(), ClassLoadingStrategy.Default.CHILD_FIRST)
.getLoaded();
assertThat(packageType.getSimpleName(), CoreMatchers.is(PackageDescription.PACKAGE_CLASS_NAME));
assertThat(packageType.getName(), CoreMatchers.is(Sample.class.getPackage().getName() + "." + PackageDescription.PACKAGE_CLASS_NAME));
assertThat(packageType.getModifiers(), CoreMatchers.is(PackageDescription.PACKAGE_MODIFIERS));
assertThat(packageType.getDeclaredFields().length, CoreMatchers.is(0));
assertThat(packageType.getDeclaredMethods().length, CoreMatchers.is(0));
assertThat(packageType.getDeclaredAnnotations().length, CoreMatchers.is(2));
assertThat(packageType.getAnnotation(PackageAnnotation.class), notNullValue(PackageAnnotation.class));
assertThat(packageType.getAnnotation(Baz.class), notNullValue(Baz.class));
}
开发者ID:raphw,项目名称:byte-buddy,代码行数:18,代码来源:RebaseDynamicTypeBuilderTest.java
示例8: testImitateSuperClassOpeningStrategy
import net.bytebuddy.description.annotation.AnnotationDescription; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testImitateSuperClassOpeningStrategy() throws Exception {
assertThat(ConstructorStrategy.Default.IMITATE_SUPER_CLASS_OPENING.extractConstructors(instrumentedType), is(Collections.singletonList(new MethodDescription.Token(FOO,
Opcodes.ACC_PUBLIC,
Collections.<TypeVariableToken>emptyList(),
typeDescription,
Collections.<ParameterDescription.Token>emptyList(),
Collections.<TypeDescription.Generic>emptyList(),
Collections.<AnnotationDescription>emptyList(),
defaultValue,
TypeDescription.Generic.UNDEFINED))));
assertThat(ConstructorStrategy.Default.IMITATE_SUPER_CLASS_OPENING.inject(instrumentedType, methodRegistry), is(methodRegistry));
verify(methodRegistry).append(any(LatentMatcher.class),
any(MethodRegistry.Handler.class),
eq(MethodAttributeAppender.NoOp.INSTANCE),
eq(Transformer.NoOp.<MethodDescription>make()));
verifyNoMoreInteractions(methodRegistry);
verify(instrumentedType, atLeastOnce()).getSuperClass();
verifyNoMoreInteractions(instrumentedType);
}
开发者ID:raphw,项目名称:byte-buddy,代码行数:22,代码来源:ConstructorStrategyDefaultTest.java
示例9: make
import net.bytebuddy.description.annotation.AnnotationDescription; //导入依赖的package包/类
@Override
public OffsetMapping make(ParameterDescription.InDefinedShape target,
AnnotationDescription.Loadable<Origin> annotation,
AdviceType adviceType) {
if (target.getType().asErasure().represents(Class.class)) {
return OffsetMapping.ForInstrumentedType.INSTANCE;
} else if (target.getType().asErasure().represents(Method.class)) {
return OffsetMapping.ForInstrumentedMethod.METHOD;
} else if (target.getType().asErasure().represents(Constructor.class)) {
return OffsetMapping.ForInstrumentedMethod.CONSTRUCTOR;
} else if (JavaType.EXECUTABLE.getTypeStub().equals(target.getType().asErasure())) {
return OffsetMapping.ForInstrumentedMethod.EXECUTABLE;
} else if (target.getType().asErasure().isAssignableFrom(String.class)) {
return ForOrigin.parse(annotation.loadSilent().value());
} else {
throw new IllegalStateException("Non-supported type " + target.getType() + " for @Origin annotation");
}
}
开发者ID:raphw,项目名称:byte-buddy,代码行数:19,代码来源:Advice.java
示例10: testMethodDuplicateAnnotation
import net.bytebuddy.description.annotation.AnnotationDescription; //导入依赖的package包/类
@Test(expected = IllegalStateException.class)
public void testMethodDuplicateAnnotation() throws Exception {
makePlainInstrumentedType()
.withMethod(new MethodDescription.Token(FOO,
ModifierContributor.EMPTY_MASK,
Collections.<TypeVariableToken>emptyList(),
TypeDescription.Generic.OBJECT,
Collections.<ParameterDescription.Token>emptyList(),
Collections.<TypeDescription.Generic>emptyList(),
Arrays.asList(
AnnotationDescription.Builder.ofType(SampleAnnotation.class).build(),
AnnotationDescription.Builder.ofType(SampleAnnotation.class).build()
), AnnotationValue.UNDEFINED,
TypeDescription.Generic.UNDEFINED))
.validated();
}
开发者ID:raphw,项目名称:byte-buddy,代码行数:17,代码来源:InstrumentedTypeDefaultTest.java
示例11: testTypeVariableOnTypeAnnotationInterfaceBound
import net.bytebuddy.description.annotation.AnnotationDescription; //导入依赖的package包/类
@Test
@JavaVersionRule.Enforce(8)
@SuppressWarnings("unchecked")
public void testTypeVariableOnTypeAnnotationInterfaceBound() throws Exception {
Class<? extends Annotation> typeAnnotationType = (Class<? extends Annotation>) Class.forName(TYPE_VARIABLE_NAME);
MethodDescription.InDefinedShape value = new TypeDescription.ForLoadedType(typeAnnotationType).getDeclaredMethods().filter(named(VALUE)).getOnly();
Class<?> type = createPlain()
.typeVariable(FOO, TypeDescription.Generic.Builder.rawType(Runnable.class)
.build(AnnotationDescription.Builder.ofType(typeAnnotationType).define(VALUE, INTEGER_VALUE * 2).build()))
.annotateTypeVariable(AnnotationDescription.Builder.ofType(typeAnnotationType).define(VALUE, INTEGER_VALUE).build())
.make()
.load(typeAnnotationType.getClassLoader(), ClassLoadingStrategy.Default.CHILD_FIRST)
.getLoaded();
assertThat(type.getTypeParameters().length, is(1));
assertThat(type.getTypeParameters()[0].getBounds().length, is(1));
assertThat(type.getTypeParameters()[0].getBounds()[0], is((Object) Runnable.class));
assertThat(TypeDescription.Generic.AnnotationReader.DISPATCHER.resolveTypeVariable(type.getTypeParameters()[0]).asList().size(), is(1));
assertThat(TypeDescription.Generic.AnnotationReader.DISPATCHER.resolveTypeVariable(type.getTypeParameters()[0]).asList().ofType(typeAnnotationType)
.getValue(value).resolve(Integer.class), is(INTEGER_VALUE));
assertThat(TypeDescription.Generic.AnnotationReader.DISPATCHER.resolveTypeVariable(type.getTypeParameters()[0]).ofTypeVariableBoundType(0)
.asList().size(), is(1));
assertThat(TypeDescription.Generic.AnnotationReader.DISPATCHER.resolveTypeVariable(type.getTypeParameters()[0]).ofTypeVariableBoundType(0)
.asList().ofType(typeAnnotationType).getValue(value).resolve(Integer.class), is(INTEGER_VALUE * 2));
}
开发者ID:raphw,项目名称:byte-buddy,代码行数:25,代码来源:AbstractDynamicTypeBuilderTest.java
示例12: withAnnotations
import net.bytebuddy.description.annotation.AnnotationDescription; //导入依赖的package包/类
@Override
public WithFlexibleName withAnnotations(List<? extends AnnotationDescription> annotationDescriptions) {
return new Default(name,
modifiers,
superClass,
typeVariables,
interfaceTypes,
fieldTokens,
methodTokens,
CompoundList.of(this.annotationDescriptions, annotationDescriptions),
typeInitializer,
loadedTypeInitializer,
declaringType,
enclosingMethod,
enclosingType,
declaredTypes,
memberClass,
anonymousClass,
localClass);
}
开发者ID:raphw,项目名称:byte-buddy,代码行数:21,代码来源:InstrumentedType.java
示例13: Latent
import net.bytebuddy.description.annotation.AnnotationDescription; //导入依赖的package包/类
/**
* Creates a new latent method description. All provided types are attached to this instance before they are returned.
*
* @param declaringType The type that is declaring this method.
* @param internalName The internal name of this method.
* @param modifiers The modifiers of this method.
* @param typeVariables The type variables of the described method.
* @param returnType The return type of this method.
* @param parameterTokens The parameter tokens describing this method.
* @param exceptionTypes This method's exception types.
* @param declaredAnnotations The annotations of this method.
* @param defaultValue The default value of this method or {@code null} if no default annotation value is defined.
* @param receiverType The receiver type of this method or {@code null} if the receiver type is defined implicitly.
*/
public Latent(TypeDescription declaringType,
String internalName,
int modifiers,
List<? extends TypeVariableToken> typeVariables,
TypeDescription.Generic returnType,
List<? extends ParameterDescription.Token> parameterTokens,
List<? extends TypeDescription.Generic> exceptionTypes,
List<? extends AnnotationDescription> declaredAnnotations,
AnnotationValue<?, ?> defaultValue,
TypeDescription.Generic receiverType) {
this.declaringType = declaringType;
this.internalName = internalName;
this.modifiers = modifiers;
this.typeVariables = typeVariables;
this.returnType = returnType;
this.parameterTokens = parameterTokens;
this.exceptionTypes = exceptionTypes;
this.declaredAnnotations = declaredAnnotations;
this.defaultValue = defaultValue;
this.receiverType = receiverType;
}
开发者ID:raphw,项目名称:byte-buddy,代码行数:36,代码来源:MethodDescription.java
示例14: Token
import net.bytebuddy.description.annotation.AnnotationDescription; //导入依赖的package包/类
/**
* Creates a new token for a method description. All types must be represented in an detached format.
*
* @param name The internal name of the represented method.
* @param modifiers The modifiers of the represented method.
* @param typeVariableTokens The type variables of the the represented method.
* @param returnType The return type of the represented method.
* @param parameterTokens The parameter tokens of the represented method.
* @param exceptionTypes The exception types of the represented method.
* @param annotations The annotations of the represented method.
* @param defaultValue The default value of the represented method or {@code null} if no such value exists.
* @param receiverType The receiver type of the represented method or {@code null} if the receiver type is implicit.
*/
public Token(String name,
int modifiers,
List<? extends TypeVariableToken> typeVariableTokens,
TypeDescription.Generic returnType,
List<? extends ParameterDescription.Token> parameterTokens,
List<? extends TypeDescription.Generic> exceptionTypes,
List<? extends AnnotationDescription> annotations,
AnnotationValue<?, ?> defaultValue,
TypeDescription.Generic receiverType) {
this.name = name;
this.modifiers = modifiers;
this.typeVariableTokens = typeVariableTokens;
this.returnType = returnType;
this.parameterTokens = parameterTokens;
this.exceptionTypes = exceptionTypes;
this.annotations = annotations;
this.defaultValue = defaultValue;
this.receiverType = receiverType;
}
开发者ID:raphw,项目名称:byte-buddy,代码行数:33,代码来源:MethodDescription.java
示例15: Latent
import net.bytebuddy.description.annotation.AnnotationDescription; //导入依赖的package包/类
/**
* Creates a latent parameter description. All provided types are attached to this instance before they are returned.
*
* @param declaringMethod The method that is declaring the parameter.
* @param parameterType The parameter's type.
* @param declaredAnnotations The annotations of the parameter.
* @param name The name of the parameter or {@code null} if no name is explicitly defined.
* @param modifiers The modifiers of the parameter or {@code null} if no modifiers are explicitly defined.
* @param index The index of the parameter.
* @param offset The parameter's offset in the local method variables array.
*/
public Latent(MethodDescription.InDefinedShape declaringMethod,
TypeDescription.Generic parameterType,
List<? extends AnnotationDescription> declaredAnnotations,
String name,
Integer modifiers,
int index,
int offset) {
this.declaringMethod = declaringMethod;
this.parameterType = parameterType;
this.declaredAnnotations = declaredAnnotations;
this.name = name;
this.modifiers = modifiers;
this.index = index;
this.offset = offset;
}
开发者ID:raphw,项目名称:byte-buddy,代码行数:27,代码来源:ParameterDescription.java
示例16: testMethodParameterTypeTypeAnnotationRuntimeRetention
import net.bytebuddy.description.annotation.AnnotationDescription; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testMethodParameterTypeTypeAnnotationRuntimeRetention() throws Exception {
when(annotationValueFilter.isRelevant(any(AnnotationDescription.class), any(MethodDescription.InDefinedShape.class))).thenReturn(true);
when(methodDescription.getDeclaredAnnotations()).thenReturn(new AnnotationList.Empty());
ParameterDescription parameterDescription = mock(ParameterDescription.class);
when(parameterDescription.getDeclaredAnnotations()).thenReturn(new AnnotationList.Empty());
when(parameterDescription.getType()).thenReturn(simpleAnnotatedType);
when(methodDescription.getParameters()).thenReturn((ParameterList) new ParameterList.Explicit<ParameterDescription>(parameterDescription));
when(methodDescription.getReturnType()).thenReturn(TypeDescription.Generic.VOID);
when(methodDescription.getTypeVariables()).thenReturn(new TypeList.Generic.Empty());
when(methodDescription.getExceptionTypes()).thenReturn(new TypeList.Generic.Empty());
when(simpleAnnotatedType.getDeclaredAnnotations()).thenReturn(new AnnotationList.ForLoadedAnnotations(new Baz.Instance()));
methodAttributeAppender.apply(methodVisitor, methodDescription, annotationValueFilter);
verify(methodVisitor).visitTypeAnnotation(TypeReference.newFormalParameterReference(0).getValue(),
null,
Type.getDescriptor(Baz.class),
true);
verifyNoMoreInteractions(methodVisitor);
}
开发者ID:raphw,项目名称:byte-buddy,代码行数:21,代码来源:MethodAttributeAppenderForInstrumentedMethodTest.java
示例17: testAnnotationTypeOnSuperClass
import net.bytebuddy.description.annotation.AnnotationDescription; //导入依赖的package包/类
@Test
@JavaVersionRule.Enforce(8)
@SuppressWarnings("unchecked")
public void testAnnotationTypeOnSuperClass() throws Exception {
Class<? extends Annotation> typeAnnotationType = (Class<? extends Annotation>) Class.forName(TYPE_VARIABLE_NAME);
MethodDescription.InDefinedShape value = new TypeDescription.ForLoadedType(typeAnnotationType).getDeclaredMethods().filter(named(VALUE)).getOnly();
Class<?> type = new ByteBuddy()
.subclass(TypeDescription.Generic.Builder.rawType(Object.class)
.build(AnnotationDescription.Builder.ofType(typeAnnotationType).define(VALUE, BAZ).build()))
.make()
.load(typeAnnotationType.getClassLoader(), ClassLoadingStrategy.Default.CHILD_FIRST)
.getLoaded();
assertThat(type.getSuperclass(), is((Object) Object.class));
assertThat(TypeDescription.Generic.AnnotationReader.DISPATCHER.resolveSuperClassType(type).asList().size(), is(1));
assertThat(TypeDescription.Generic.AnnotationReader.DISPATCHER.resolveSuperClassType(type).asList().ofType(typeAnnotationType)
.getValue(value).resolve(Integer.class), is(BAZ));
}
开发者ID:raphw,项目名称:byte-buddy,代码行数:18,代码来源:SubclassDynamicTypeBuilderTest.java
示例18: testAnnotationTypeOnNonGenericComponentType
import net.bytebuddy.description.annotation.AnnotationDescription; //导入依赖的package包/类
@Test
@JavaVersionRule.Enforce(8)
@SuppressWarnings("unchecked")
public void testAnnotationTypeOnNonGenericComponentType() throws Exception {
Class<? extends Annotation> typeAnnotationType = (Class<? extends Annotation>) Class.forName(TYPE_VARIABLE_NAME);
MethodDescription.InDefinedShape value = new TypeDescription.ForLoadedType(typeAnnotationType).getDeclaredMethods().filter(named(VALUE)).getOnly();
Field field = createPlain()
.defineField(FOO, TypeDescription.Generic.Builder.rawType(Object.class)
.annotate(AnnotationDescription.Builder.ofType(typeAnnotationType).define(VALUE, INTEGER_VALUE).build())
.asArray()
.build())
.make()
.load(typeAnnotationType.getClassLoader(), ClassLoadingStrategy.Default.CHILD_FIRST)
.getLoaded()
.getDeclaredField(FOO);
assertThat(TypeDescription.Generic.AnnotationReader.DISPATCHER.resolveFieldType(field).ofComponentType().asList().size(), is(1));
assertThat(TypeDescription.Generic.AnnotationReader.DISPATCHER.resolveFieldType(field).ofComponentType().asList()
.ofType(typeAnnotationType).getValue(value).resolve(Integer.class), is(INTEGER_VALUE));
}
开发者ID:raphw,项目名称:byte-buddy,代码行数:20,代码来源:AbstractDynamicTypeBuilderTest.java
示例19: testAnnotationTypeOnNestedType
import net.bytebuddy.description.annotation.AnnotationDescription; //导入依赖的package包/类
@Test
@JavaVersionRule.Enforce(8)
@SuppressWarnings("unchecked")
public void testAnnotationTypeOnNestedType() throws Exception {
Class<? extends Annotation> typeAnnotationType = (Class<? extends Annotation>) Class.forName(TYPE_VARIABLE_NAME);
MethodDescription.InDefinedShape value = new TypeDescription.ForLoadedType(typeAnnotationType).getDeclaredMethods().filter(named(VALUE)).getOnly();
Field field = createPlain()
.defineField(FOO, TypeDescription.Generic.Builder.rawType(new TypeDescription.ForLoadedType(Nested.Inner.class),
TypeDescription.Generic.Builder.rawType(Nested.class).build())
.annotate(AnnotationDescription.Builder.ofType(typeAnnotationType).define(VALUE, INTEGER_VALUE).build())
.build())
.make()
.load(typeAnnotationType.getClassLoader(), ClassLoadingStrategy.Default.CHILD_FIRST)
.getLoaded()
.getDeclaredField(FOO);
assertThat(TypeDescription.Generic.AnnotationReader.DISPATCHER.resolveFieldType(field).asList().size(), is(1));
assertThat(TypeDescription.Generic.AnnotationReader.DISPATCHER.resolveFieldType(field).asList()
.ofType(typeAnnotationType).getValue(value).resolve(Integer.class), is(INTEGER_VALUE));
}
开发者ID:raphw,项目名称:byte-buddy,代码行数:20,代码来源:AbstractDynamicTypeBuilderTest.java
示例20: getParameterNullability
import net.bytebuddy.description.annotation.AnnotationDescription; //导入依赖的package包/类
/**
* @see me.seeber.gradle.ide.eclipse.annotations.Nullability#getParameterNullability(net.bytebuddy.description.method.ParameterDescription)
*/
@Override
public Nullness getParameterNullability(ParameterDescription parameter) {
PackageDescription pakkage = parameter.getDeclaringMethod().getDeclaringType().asErasure().getPackage();
Optional<AnnotationDescription> packageAnnotation = pakkage.getDeclaredAnnotations().stream()
.filter(a -> a.getAnnotationType().getName().equals(this.nonnullParameterDefaultAnnotation)).findAny();
Nullness defaultNullness = Validate
.notNull(packageAnnotation.map(a -> Nullness.NONNULL).orElse(Nullness.UNDEFINED));
Nullness nullability = getNullability(parameter.getDeclaredAnnotations());
return defaultNullness.override(nullability);
}
开发者ID:jochenseeber,项目名称:gradle-project-config,代码行数:15,代码来源:AnnotationNullability.java
注:本文中的net.bytebuddy.description.annotation.AnnotationDescription类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论