本文整理了Java中java.lang.reflect.Constructor.getAnnotationsByType()
方法的一些代码示例,展示了Constructor.getAnnotationsByType()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Constructor.getAnnotationsByType()
方法的具体详情如下:
包路径:java.lang.reflect.Constructor
类名称:Constructor
方法名:getAnnotationsByType
暂无
代码示例来源:origin: javax.enterprise/cdi-api
@Override default <T extends Annotation> Set<T> getAnnotations(Class<T> annotationType) {
T[] annotationsByType = getJavaMember().getAnnotationsByType(annotationType);
return new LinkedHashSet<>(asList(annotationsByType));
}
}
代码示例来源:origin: prestodb/presto
private Optional<MethodHandle> getConstructor(Method method, Optional<Constructor<?>> optionalConstructor)
{
if (isStatic(method.getModifiers())) {
return Optional.empty();
}
checkArgument(optionalConstructor.isPresent(), "Method [%s] is an instance method. It must be in a class annotated with @ScalarFunction, and the class is required to have a public constructor.", method);
Constructor<?> constructor = optionalConstructor.get();
Set<TypeParameter> constructorTypeParameters = Stream.of(constructor.getAnnotationsByType(TypeParameter.class))
.collect(ImmutableSet.toImmutableSet());
checkArgument(constructorTypeParameters.containsAll(typeParameters), "Method [%s] is an instance method and requires a public constructor containing all type parameters: %s", method, typeParameters);
for (int i = 0; i < constructor.getParameterCount(); i++) {
Annotation[] annotations = constructor.getParameterAnnotations()[i];
checkArgument(containsImplementationDependencyAnnotation(annotations), "Constructors may only have meta parameters [%s]", constructor);
checkArgument(annotations.length == 1, "Meta parameters may only have a single annotation [%s]", constructor);
Annotation annotation = annotations[0];
if (annotation instanceof TypeParameter) {
checkTypeParameters(parseTypeSignature(((TypeParameter) annotation).value()), typeParameterNames, method);
}
constructorDependencies.add(createDependency(annotation, literalParameters));
}
MethodHandle result = constructorMethodHandle(FUNCTION_IMPLEMENTATION_ERROR, constructor);
// Change type of return value to Object to make sure callers won't have classloader issues
return Optional.of(result.asType(result.type().changeReturnType(Object.class)));
}
代码示例来源:origin: line/armeria
final RequestConverter[] converters = constructor.getAnnotationsByType(RequestConverter.class);
final List<AnnotatedValueResolver> resolvers =
AnnotatedValueResolver.ofBeanConstructorOrMethod(
代码示例来源:origin: uk.co.nichesolutions.presto/presto-main
private static Map<Set<TypeParameter>, Constructor<?>> findConstructors(Class<?> clazz)
{
ImmutableMap.Builder<Set<TypeParameter>, Constructor<?>> builder = ImmutableMap.builder();
for (Constructor<?> constructor : clazz.getConstructors()) {
Set<TypeParameter> typeParameters = new HashSet<>();
Stream.of(constructor.getAnnotationsByType(TypeParameter.class))
.forEach(typeParameters::add);
builder.put(typeParameters, constructor);
}
return builder.build();
}
代码示例来源:origin: javax/javaee-web-api
@Override default <T extends Annotation> Set<T> getAnnotations(Class<T> annotationType) {
T[] annotationsByType = getJavaMember().getAnnotationsByType(annotationType);
return new LinkedHashSet<>(asList(annotationsByType));
}
}
代码示例来源:origin: org.jboss.weld.servlet/weld-servlet-shaded
@Override default <T extends Annotation> Set<T> getAnnotations(Class<T> annotationType) {
T[] annotationsByType = getJavaMember().getAnnotationsByType(annotationType);
return new LinkedHashSet<>(asList(annotationsByType));
}
}
代码示例来源:origin: weld/core
@Override default <T extends Annotation> Set<T> getAnnotations(Class<T> annotationType) {
T[] annotationsByType = getJavaMember().getAnnotationsByType(annotationType);
return new LinkedHashSet<>(asList(annotationsByType));
}
}
代码示例来源:origin: weld/core
@Override default <T extends Annotation> Set<T> getAnnotations(Class<T> annotationType) {
T[] annotationsByType = getJavaMember().getAnnotationsByType(annotationType);
return new LinkedHashSet<>(asList(annotationsByType));
}
}
代码示例来源:origin: jboss/jboss-javaee-specs
@Override default <T extends Annotation> Set<T> getAnnotations(Class<T> annotationType) {
T[] annotationsByType = getJavaMember().getAnnotationsByType(annotationType);
return new LinkedHashSet<>(asList(annotationsByType));
}
}
代码示例来源:origin: org.apache.geronimo.specs/geronimo-jcdi_2.0_spec
@Override
default <T extends Annotation> Set<T> getAnnotations(Class<T> annotationType)
{
return new LinkedHashSet<>(Arrays.asList(getJavaMember().getAnnotationsByType(annotationType)));
}
}
代码示例来源:origin: org.apache.meecrowave/meecrowave-specs-api
@Override
default <T extends Annotation> Set<T> getAnnotations(Class<T> annotationType)
{
return new LinkedHashSet<>(Arrays.asList(getJavaMember().getAnnotationsByType(annotationType)));
}
}
代码示例来源:origin: org.jboss.weld.se/weld-se-shaded
@Override default <T extends Annotation> Set<T> getAnnotations(Class<T> annotationType) {
T[] annotationsByType = getJavaMember().getAnnotationsByType(annotationType);
return new LinkedHashSet<>(asList(annotationsByType));
}
}
代码示例来源:origin: apache/meecrowave
@Override
default <T extends Annotation> Set<T> getAnnotations(Class<T> annotationType)
{
return new LinkedHashSet<>(Arrays.asList(getJavaMember().getAnnotationsByType(annotationType)));
}
}
代码示例来源:origin: com.puresoltechnologies.streaming/common.mapper
protected <C> Constructor<?> findCreator(Class<C> clazz) throws MappingException {
Constructor<?> binaryCreator = null;
Constructor<?> defaultConstructor = null;
for (Constructor<?> constructor : clazz.getConstructors()) {
if (constructor.getParameterTypes().length == 0) {
defaultConstructor = constructor;
}
T[] binaryCreators = constructor.getAnnotationsByType(creatorAnnotation);
if (binaryCreators.length == 0) {
continue;
} else if (binaryCreators.length > 1) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("@");
stringBuilder.append(creatorAnnotation.getSimpleName());
stringBuilder.append(" annotation is only allowed once.");
throw new MappingException(stringBuilder.toString());
}
if (binaryCreator != null) {
throw new MappingException("Only one constructor can be binary creator.");
}
binaryCreator = constructor;
}
if (binaryCreator.equals(defaultConstructor)) {
throw new MappingException("Defining default constructor as creator is meaningless.");
}
return binaryCreator;
}
代码示例来源:origin: io.prestosql/presto-main
private Optional<MethodHandle> getConstructor(Method method, Optional<Constructor<?>> optionalConstructor)
{
if (isStatic(method.getModifiers())) {
return Optional.empty();
}
checkArgument(optionalConstructor.isPresent(), "Method [%s] is an instance method. It must be in a class annotated with @ScalarFunction, and the class is required to have a public constructor.", method);
Constructor<?> constructor = optionalConstructor.get();
Set<TypeParameter> constructorTypeParameters = Stream.of(constructor.getAnnotationsByType(TypeParameter.class))
.collect(ImmutableSet.toImmutableSet());
checkArgument(constructorTypeParameters.containsAll(typeParameters), "Method [%s] is an instance method and requires a public constructor containing all type parameters: %s", method, typeParameters);
for (int i = 0; i < constructor.getParameterCount(); i++) {
Annotation[] annotations = constructor.getParameterAnnotations()[i];
checkArgument(containsImplementationDependencyAnnotation(annotations), "Constructors may only have meta parameters [%s]", constructor);
checkArgument(annotations.length == 1, "Meta parameters may only have a single annotation [%s]", constructor);
Annotation annotation = annotations[0];
if (annotation instanceof TypeParameter) {
checkTypeParameters(parseTypeSignature(((TypeParameter) annotation).value()), typeParameterNames, method);
}
constructorDependencies.add(createDependency(annotation, literalParameters));
}
MethodHandle result = constructorMethodHandle(FUNCTION_IMPLEMENTATION_ERROR, constructor);
// Change type of return value to Object to make sure callers won't have classloader issues
return Optional.of(result.asType(result.type().changeReturnType(Object.class)));
}
代码示例来源:origin: prestosql/presto
private Optional<MethodHandle> getConstructor(Method method, Optional<Constructor<?>> optionalConstructor)
{
if (isStatic(method.getModifiers())) {
return Optional.empty();
}
checkArgument(optionalConstructor.isPresent(), "Method [%s] is an instance method. It must be in a class annotated with @ScalarFunction, and the class is required to have a public constructor.", method);
Constructor<?> constructor = optionalConstructor.get();
Set<TypeParameter> constructorTypeParameters = Stream.of(constructor.getAnnotationsByType(TypeParameter.class))
.collect(ImmutableSet.toImmutableSet());
checkArgument(constructorTypeParameters.containsAll(typeParameters), "Method [%s] is an instance method and requires a public constructor containing all type parameters: %s", method, typeParameters);
for (int i = 0; i < constructor.getParameterCount(); i++) {
Annotation[] annotations = constructor.getParameterAnnotations()[i];
checkArgument(containsImplementationDependencyAnnotation(annotations), "Constructors may only have meta parameters [%s]", constructor);
checkArgument(annotations.length == 1, "Meta parameters may only have a single annotation [%s]", constructor);
Annotation annotation = annotations[0];
if (annotation instanceof TypeParameter) {
checkTypeParameters(parseTypeSignature(((TypeParameter) annotation).value()), typeParameterNames, method);
}
constructorDependencies.add(createDependency(annotation, literalParameters));
}
MethodHandle result = constructorMethodHandle(FUNCTION_IMPLEMENTATION_ERROR, constructor);
// Change type of return value to Object to make sure callers won't have classloader issues
return Optional.of(result.asType(result.type().changeReturnType(Object.class)));
}
代码示例来源:origin: com.fossgalaxy.games/fireworks
public AgentFactory buildFactory(Class<? extends Agent> agentClazz) {
Constructor<?> bestMatch = null;
Constructor<?>[] constructors = agentClazz.getConstructors();
for (Constructor<?> constructor : constructors) {
if (constructor.getParameterCount() == 0 && Modifier.isPublic(constructor.getModifiers())) {
bestMatch = constructor;
} else {
AgentConstructor builder = constructor.getAnnotation(AgentConstructor.class);
if (builder == null) {
continue;
}
String name = builder.value().equals("") ? agentClazz.getSimpleName() : builder.value();
bestMatch = constructor;
HashMap<Integer, Parameter> parameters = new HashMap<>();
for (Parameter p : constructor.getAnnotationsByType(Parameter.class)) {
if (!parameters.containsKey(p.id())) {
parameters.put(p.id(), p);
}
}
Function<String, ?>[] convertersInst = getConverters(agentClazz, constructor.getParameterTypes(), parameters);
return new ConstructorFactory(agentClazz, constructor, convertersInst, name);
}
}
if (bestMatch == null) {
throw new IllegalArgumentException("You must either annotate a constructor or provide a public no-args constructor");
}
return new ConstructorFactory(agentClazz, bestMatch, null);
}
代码示例来源:origin: superckl/BiomeTweaker
if(con.isAnnotationPresent(RegisterExempt.class))
continue;
final AutoRegister[] methodAnns = con.getAnnotationsByType(AutoRegister.class);
if(classAnns.length == 0 && methodAnns.length == 0)
continue;
final Class<?>[] cTypes = con.getParameterTypes();
final ParameterWrapper<?>[] pTypes = new ParameterWrapper[cTypes.length];
for(final ParameterOverride override:con.getAnnotationsByType(ParameterOverride.class))
pTypes[override.parameterIndex()] = ParameterTypes.getExceptionWrapper(override.exceptionKey());
for(int i = 0; i < cTypes.length; i++){
内容来源于网络,如有侵权,请联系作者删除!