本文整理了Java中javax.enterprise.inject.spi.AnnotatedParameter
类的一些代码示例,展示了AnnotatedParameter
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AnnotatedParameter
类的具体详情如下:
包路径:javax.enterprise.inject.spi.AnnotatedParameter
类名称:AnnotatedParameter
[英]Represents a parameter of a method or constructor.
[中]表示方法或构造函数的参数。
代码示例来源:origin: oracle/helidon
private String getFieldName(InjectionPoint ip) {
Annotated annotated = ip.getAnnotated();
if (annotated instanceof AnnotatedField) {
AnnotatedField f = (AnnotatedField) annotated;
return f.getJavaMember().getName();
}
if (annotated instanceof AnnotatedParameter) {
AnnotatedParameter p = (AnnotatedParameter) annotated;
Member member = ip.getMember();
if (member instanceof Method) {
return member.getName() + "_" + p.getPosition();
}
if (member instanceof Constructor) {
return "new_" + p.getPosition();
}
}
return ip.getMember().getName();
}
代码示例来源:origin: wildfly/wildfly
@Override
public Object resolveResource(InjectionPoint injectionPoint) {
final Member member = injectionPoint.getMember();
AnnotatedMember<?> annotatedMember;
if (injectionPoint.getAnnotated() instanceof AnnotatedField) {
annotatedMember = (AnnotatedField<?>) injectionPoint.getAnnotated();
} else {
annotatedMember = ((AnnotatedParameter<?>) injectionPoint.getAnnotated()).getDeclaringCallable();
}
if (!annotatedMember.isAnnotationPresent(Resource.class)) {
throw WeldLogger.ROOT_LOGGER.annotationNotFound(Resource.class, member);
}
if (member instanceof Method && ((Method) member).getParameterTypes().length != 1) {
throw WeldLogger.ROOT_LOGGER.injectionPointNotAJavabean((Method) member);
}
String name = getResourceName(injectionPoint);
for (ResourceInjectionResolver resolver : resourceResolvers) {
Object result = resolver.resolve(name);
if (result != null) {
return result;
}
}
try {
return context.lookup(name);
} catch (NamingException e) {
throw WeldLogger.ROOT_LOGGER.couldNotFindResource(name, injectionPoint.getMember().toString(), e);
}
}
代码示例来源:origin: javax.enterprise/cdi-api
/**
* Get the underlying {@link Parameter}.
*
* @return the {@link Parameter}
*/
default Parameter getJavaParameter() {
Member member = getDeclaringCallable().getJavaMember();
if (!(member instanceof Executable)) {
throw new IllegalStateException("Parameter does not belong to an executable: " + member);
}
Executable executable = (Executable) member;
return executable.getParameters()[getPosition()];
}
代码示例来源:origin: org.infinispan/infinispan-cdi
this.javaClass = type.getJavaClass();
for (AnnotatedField<? super X> field : type.getFields()) {
if (fields.get(field.getJavaMember()) == null) {
fields.put(field.getJavaMember(), new AnnotationBuilder());
mergeAnnotationsOnElement(field, overwrite, fields.get(field.getJavaMember()));
for (AnnotatedMethod<? super X> method : type.getMethods()) {
if (methods.get(method.getJavaMember()) == null) {
methods.put(method.getJavaMember(), new AnnotationBuilder());
if (methodParameters.get(method.getJavaMember()).get(p.getPosition()) == null) {
methodParameters.get(method.getJavaMember()).put(p.getPosition(), new AnnotationBuilder());
mergeAnnotationsOnElement(p, overwrite, methodParameters.get(method.getJavaMember()).get(p.getPosition()));
for (AnnotatedConstructor<? super X> constructor : type.getConstructors()) {
if (constructors.get(constructor.getJavaMember()) == null) {
constructors.put(constructor.getJavaMember(), new AnnotationBuilder());
if (constructorParameters.get(constructor.getJavaMember()).get(p.getPosition()) == null) {
constructorParameters.get(constructor.getJavaMember()).put(p.getPosition(), new AnnotationBuilder());
mergeAnnotationsOnElement(p, overwrite, constructorParameters.get(constructor.getJavaMember()).get(p.getPosition()));
代码示例来源:origin: weld/core
@Override
public ObserverMethodConfigurator<T> read(AnnotatedMethod<?> method) {
checkArgumentNotNull(method);
Set<AnnotatedParameter<?>> eventParameters = method.getParameters().stream()
.filter((p) -> p.isAnnotationPresent(Observes.class) || p.isAnnotationPresent(ObservesAsync.class)).collect(Collectors.toSet());
checkEventParams(eventParameters, method.getJavaMember());
AnnotatedParameter<?> eventParameter = eventParameters.iterator().next();
Observes observesAnnotation = eventParameter.getAnnotation(Observes.class);
if (observesAnnotation != null) {
reception(observesAnnotation.notifyObserver());
transactionPhase(observesAnnotation.during());
} else {
reception(eventParameter.getAnnotation(ObservesAsync.class).notifyObserver());
}
Priority priority = method.getAnnotation(Priority.class);
if (priority != null) {
priority(priority.value());
}
beanClass(eventParameter.getDeclaringCallable().getDeclaringType().getJavaClass());
observedType(eventParameter.getBaseType());
qualifiers(Configurators.getQualifiers(eventParameter));
return this;
}
代码示例来源:origin: org.jboss.weld.se/weld-se
public InjectionPointHolder(String contextId, InjectionPoint ip) {
super(ip);
Preconditions.checkArgumentNotNull(ip, "injectionPoint");
if (ip.getBean() == null) {
if (ip instanceof Serializable) {
this.identifier = new SerializableInjectionPointIdentifier(ip);
} else {
this.identifier = new TransientInjectionPointIdentifier(ip);
}
} else if (ip.getAnnotated() instanceof AnnotatedField<?>) {
AnnotatedField<?> field = Reflections.cast(ip.getAnnotated());
this.identifier = new FieldInjectionPointIdentifier(contextId, ip.getBean(), field);
} else if (ip.getAnnotated() instanceof AnnotatedParameter<?>) {
AnnotatedParameter<?> parameter = Reflections.cast(ip.getAnnotated());
if (parameter.getDeclaringCallable() instanceof AnnotatedConstructor<?>) {
AnnotatedConstructor<?> constructor = Reflections.cast(parameter.getDeclaringCallable());
this.identifier = new ConstructorParameterInjectionPointIdentifier(contextId, ip.getBean(), parameter.getPosition(), constructor);
} else if (parameter.getDeclaringCallable() instanceof AnnotatedMethod<?>) {
AnnotatedMethod<?> method = Reflections.cast(parameter.getDeclaringCallable());
this.identifier = new MethodParameterInjectionPointIdentifier(contextId, ip.getBean(), parameter.getPosition(), method);
} else {
throw BeanLogger.LOG.invalidAnnotatedCallable(parameter.getDeclaringCallable());
}
} else {
throw BeanLogger.LOG.invalidAnnotatedOfInjectionPoint(ip.getAnnotated(), ip);
}
}
代码示例来源:origin: weld/core
protected abstract boolean matches(InjectionPoint ip, AnnotatedCallable<?> annotatedCallable);
}
代码示例来源:origin: org.jboss.cdi.tck/cdi-tck-impl
@SpecAssertions({ @SpecAssertion(section = PROCESS_BEAN, id = "eaa"), @SpecAssertion(section = PROCESS_BEAN, id = "eab"),
@SpecAssertion(section = PROCESS_BEAN, id = "edc"), @SpecAssertion(section = PROCESS_BEAN, id = "efc"),
@SpecAssertion(section = PROCESS_BEAN, id = "fc"), @SpecAssertion(section = PROCESS_BEAN, id = "i"),
@SpecAssertion(section = PROCESS_BEAN, id = "j"), @SpecAssertion(section = BEAN_DISCOVERY_STEPS, id = "jb"),
@SpecAssertion(section = BEAN_DISCOVERY_STEPS, id = "jd") })
@Test
public void testProcessProducerMethodEvent() {
assertTrue(ProcessBeanObserver.getCowBean().getTypes().contains(Cow.class));
assertEquals(ProcessBeanObserver.getCowBean().getBeanClass(), Cowshed.class);
assertEquals(ProcessBeanObserver.getCowMethod().getBaseType(), Cow.class);
assertEquals(ProcessBeanObserver.getCowMethod().getDeclaringType().getBaseType(), Cowshed.class);
// There are bugs in the API that mean generic type parameter ordering is wrong for ProcessProducerField and
// ProcessProducerMethod
// https://issues.jboss.org/browse/CDITCK-168
// https://issues.jboss.org/browse/WELD-586
assertEquals(ProcessBeanObserver.getCowShedProcessBeanCount(), 2);
assertTrue(ProcessBeanObserver.getCowAnnotated() instanceof AnnotatedMethod<?>);
assertEquals(ProcessBeanObserver.getCowMethod().getJavaMember().getName(), "getDaisy");
assertEquals(ProcessBeanObserver.getCowMethod().getJavaMember().getDeclaringClass(), Cowshed.class);
AnnotatedParameter<Cow> disposedParam = ProcessBeanObserver.getCowParameter();
assertNotNull(disposedParam);
assertTrue(disposedParam.isAnnotationPresent(Disposes.class));
assertEquals(disposedParam.getBaseType(), Cow.class);
assertEquals(disposedParam.getDeclaringCallable().getJavaMember().getName(), "disposeOfDaisy");
assertEquals(disposedParam.getDeclaringCallable().getJavaMember().getDeclaringClass(), Cowshed.class);
assertEquals(disposedParam.getDeclaringCallable().getDeclaringType().getJavaClass(), Cowshed.class);
assertEquals(ProcessBeanObserver.getCowActionSeq().getData(),
Arrays.asList(ProcessBeanAttributes.class.getName(), ProcessProducerMethod.class.getName()));
}
代码示例来源:origin: org.apache.openwebbeans/openwebbeans-impl
private boolean annotatedTypeHasAnnotations(AnnotatedType annotatedType, Class<? extends Annotation>[] withAnnotations)
if (hasAnnotation(annotatedType.getAnnotations(), withAnnotations))
Set<AnnotatedField> fields = annotatedType.getFields();
for (AnnotatedField annotatedField : fields)
if (hasAnnotation(annotatedField.getAnnotations(), withAnnotations))
Set<AnnotatedMethod> annotatedMethods = annotatedType.getMethods();
for (AnnotatedMethod annotatedMethod : annotatedMethods)
if (hasAnnotation(annotatedMethod.getAnnotations(), withAnnotations))
for (AnnotatedParameter annotatedParameter : (List<AnnotatedParameter>) annotatedMethod.getParameters())
if (hasAnnotation(annotatedParameter.getAnnotations(), withAnnotations))
for (AnnotatedConstructor<?> annotatedConstructor : annotatedConstructors)
if (hasAnnotation(annotatedConstructor.getAnnotations(), withAnnotations))
for (AnnotatedParameter annotatedParameter : annotatedConstructor.getParameters())
if (hasAnnotation(annotatedParameter.getAnnotations(), withAnnotations))
代码示例来源:origin: org.apache.openwebbeans/openwebbeans-impl
/**
* Certain beans like CDI Interceptors and Decorators
* are not allowed to define producer methods.
*/
protected void validateNoProducerOrObserverMethod(AnnotatedType<T> annotatedType)
{
Set<AnnotatedMethod<? super T>> annotatedMethods = annotatedType.getMethods();
for (AnnotatedMethod<?> annotatedMethod : annotatedMethods)
{
if (annotatedMethod.isAnnotationPresent(Produces.class))
{
throw new WebBeansConfigurationException("This class must not have a @Produces method" + annotatedMethod.getJavaMember());
}
for (AnnotatedParameter<?> parameter : annotatedMethod.getParameters())
{
if (parameter.isAnnotationPresent(Observes.class) || parameter.isAnnotationPresent(ObservesAsync.class))
{
throw new WebBeansConfigurationException("This class must not have an @Observes nor @ObservesAsync method " + annotatedMethod.getJavaMember());
}
}
}
Set<AnnotatedField<? super T>> annotatedFields = annotatedType.getFields();
for (AnnotatedField<? super T> annotatedField : annotatedFields)
{
if (annotatedField.isAnnotationPresent(Produces.class))
{
throw new WebBeansConfigurationException("This class must not have a @Produces field" + annotatedField.getJavaMember());
}
}
}
代码示例来源:origin: weld/core
for (Annotation annotation : field.getAnnotations()) {
if (isEqualOrAnnotated(requiredAnnotation, annotation)) {
return true;
for (Annotation annotation : constructor.getAnnotations()) {
if (isEqualOrAnnotated(requiredAnnotation, annotation)) {
return true;
for (AnnotatedParameter<?> parameter : constructor.getParameters()) {
for (Annotation annotation : parameter.getAnnotations()) {
if (isEqualOrAnnotated(requiredAnnotation, annotation)) {
return true;
for (Annotation annotation : method.getAnnotations()) {
if (isEqualOrAnnotated(requiredAnnotation, annotation)) {
return true;
for (AnnotatedParameter<?> parameter : method.getParameters()) {
for (Annotation annotation : parameter.getAnnotations()) {
if (isEqualOrAnnotated(requiredAnnotation, annotation)) {
return true;
代码示例来源:origin: com.caucho/resin
private void introspectType()
if (getBeanType().isAnnotationPresent(javax.interceptor.Interceptor.class)
|| getBeanType().isAnnotationPresent(javax.decorator.Decorator.class)) {
_isInterceptorOrDecorator = true;
return;
for (AnnotatedField<? super X> field : getBeanType().getFields()) {
if (field.isAnnotationPresent(Delegate.class)) {
_isInterceptorOrDecorator = true;
return;
for (AnnotatedMethod<? super X> method : getBeanType().getMethods()) {
for (AnnotatedParameter<? super X> param : method.getParameters()) {
if (param.isAnnotationPresent(Delegate.class)) {
_isInterceptorOrDecorator = true;
return;
代码示例来源:origin: weld/core
@Override
protected InterceptionFactory<?> newInstance(InjectionPoint ip, CreationalContext<InterceptionFactory<?>> creationalContext) {
AnnotatedParameter<?> annotatedParameter = (AnnotatedParameter<?>) ip.getAnnotated();
ParameterizedType parameterizedType = (ParameterizedType) annotatedParameter.getBaseType();
AnnotatedType<?> annotatedType = beanManager.createAnnotatedType(Reflections.getRawType(parameterizedType.getActualTypeArguments()[0]));
return InterceptionFactoryImpl.of(beanManager, creationalContext, annotatedType);
}
代码示例来源:origin: org.jboss.weld.se/weld-se
@Override
public ParameterInjectionPointAttributes<?, ?> createInjectionPoint(AnnotatedParameter<?> parameter) {
AnnotatedTypeValidator.validateAnnotatedParameter(parameter);
EnhancedAnnotatedParameter<?, ?> enhancedParameter = services.get(MemberTransformer.class).loadEnhancedParameter(parameter, getId());
return validateInjectionPoint(InferringParameterInjectionPointAttributes.of(enhancedParameter, null, parameter.getDeclaringCallable().getDeclaringType().getJavaClass(), this));
}
代码示例来源:origin: com.sun.jersey/jersey-servlet
public AnnotatedParameterImpl(AnnotatedParameter<? super T> param, AnnotatedCallable<T> declaringCallable) {
this(param.getBaseType(),
param.getTypeClosure(),
param.getAnnotations(),
declaringCallable,
param.getPosition());
}
代码示例来源:origin: org.jboss.weld.se/weld-se
public MethodSignatureImpl(AnnotatedMethod<?> method) {
this.methodName = method.getJavaMember().getName();
this.parameterTypes = new String[method.getParameters().size()];
for (int i = 0; i < method.getParameters().size(); i++) {
parameterTypes[i] = Reflections.getRawType(method.getParameters().get(i).getBaseType()).getName();
}
}
代码示例来源:origin: org.apache.openwebbeans/openwebbeans-impl
protected void checkInterceptorConditions()
{
Set<AnnotatedMethod<? super T>> methods = webBeansContext.getAnnotatedElementFactory().getFilteredAnnotatedMethods(annotatedType);
for(AnnotatedMethod<?> method : methods)
{
for (AnnotatedParameter<?> parameter : method.getParameters())
{
if (parameter.isAnnotationPresent(Produces.class))
{
throw new WebBeansConfigurationException("Interceptor class : " + annotatedType.getJavaClass()
+ " can not have producer methods but it has one with name : "
+ method.getJavaMember().getName());
}
}
}
}
代码示例来源:origin: com.caucho/resin
Annotation []qualifiers)
for (AnnotatedMethod<? super X> beanMethod : beanType.getMethods()) {
List<AnnotatedParameter<?>> params = (List) beanMethod.getParameters();
if (! param.isAnnotationPresent(Disposes.class))
continue;
if (! producesBaseType.equals(param.getBaseType()))
continue;
Method javaMethod = beanMethod.getJavaMember();
if (beanMethod.isAnnotationPresent(Inject.class))
throw new ConfigException(L.l("{0}.{1} is an invalid @Disposes method because it has an @Inject annotation",
javaMethod.getDeclaringClass().getName(),
代码示例来源:origin: org.jboss.weld.se/weld-se
/**
*
* @param injectionPoint
* @param factory
*/
SetterResourceInjection(ParameterInjectionPoint<T, X> injectionPoint, ResourceReferenceFactory<T> factory) {
super(factory);
AnnotatedMethod<X> annotatedMethod = (AnnotatedMethod<X>) injectionPoint.getAnnotated().getDeclaringCallable();
accessibleMethod = AccessController.doPrivileged(new GetAccessibleCopyOfMember<Method>(annotatedMethod.getJavaMember()));
}
代码示例来源:origin: wildfly/wildfly
public static Annotated getResourceAnnotated(InjectionPoint injectionPoint) {
if(injectionPoint instanceof ParameterInjectionPoint) {
return ((ParameterInjectionPoint<?, ?>)injectionPoint).getAnnotated().getDeclaringCallable();
}
return injectionPoint.getAnnotated();
}
内容来源于网络,如有侵权,请联系作者删除!