当前位置: 首页>>代码示例>>Java>>正文


Java AnnotatedParameter类代码示例

本文整理汇总了Java中javax.enterprise.inject.spi.AnnotatedParameter的典型用法代码示例。如果您正苦于以下问题:Java AnnotatedParameter类的具体用法?Java AnnotatedParameter怎么用?Java AnnotatedParameter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AnnotatedParameter类属于javax.enterprise.inject.spi包,在下文中一共展示了AnnotatedParameter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getPropertyName

import javax.enterprise.inject.spi.AnnotatedParameter; //导入依赖的package包/类
String getPropertyName(final InjectionPoint point, final String propertyName) {
    if (!propertyName.isEmpty()) {
        return propertyName;
    }

    Member member = point.getMember();
    final String name;

    if (member instanceof Executable) {
        Annotated annotated = point.getAnnotated();
        int p = ((AnnotatedParameter<?>) annotated).getPosition();
        name = member.getName() + ".arg" + p;
    } else {
        name = member.getName();
    }

    return name;
}
 
开发者ID:xlate,项目名称:property-inject,代码行数:19,代码来源:PropertyFactory.java

示例2: mockInjectionPoint

import javax.enterprise.inject.spi.AnnotatedParameter; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private InjectionPoint mockInjectionPoint(Property property,
                                          Type type,
                                          Class<? extends Member> memberType,
                                          String memberName,
                                          int memberPosition) {
    InjectionPoint injectionPoint = mock(InjectionPoint.class);

    Member member = mock(memberType);
    when(injectionPoint.getType()).thenReturn(type);
    when(injectionPoint.getMember()).thenReturn(member);
    when(member.getName()).thenReturn(memberName);

    @SuppressWarnings("rawtypes")
    Bean mockBean = mock(Bean.class);
    when(injectionPoint.getBean()).thenReturn(mockBean);
    when(mockBean.getBeanClass()).thenReturn(getClass());

    AnnotatedParameter<?> annotated = mock(AnnotatedParameter.class);
    when(annotated.getPosition()).thenReturn(memberPosition);
    when(injectionPoint.getAnnotated()).thenReturn(annotated);

    when(annotated.getAnnotation(Property.class)).thenReturn(property);

    return injectionPoint;
}
 
开发者ID:xlate,项目名称:property-inject,代码行数:27,代码来源:PropertyProducerBeanTest.java

示例3: mockInjectionPoint

import javax.enterprise.inject.spi.AnnotatedParameter; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private InjectionPoint mockInjectionPoint(Property property,
                                          Class<? extends Member> memberType,
                                          String memberName,
                                          int memberPosition) {
    InjectionPoint injectionPoint = mock(InjectionPoint.class);

    Member member = mock(memberType);
    when(injectionPoint.getMember()).thenReturn(member);
    when(member.getName()).thenReturn(memberName);

    @SuppressWarnings("rawtypes")
    Bean mockBean = mock(Bean.class);
    when(injectionPoint.getBean()).thenReturn(mockBean);
    when(mockBean.getBeanClass()).thenReturn(getClass());

    AnnotatedParameter<?> annotated = mock(AnnotatedParameter.class);
    when(annotated.getPosition()).thenReturn(memberPosition);
    when(injectionPoint.getAnnotated()).thenReturn(annotated);

    when(annotated.getAnnotation(Property.class)).thenReturn(property);

    return injectionPoint;
}
 
开发者ID:xlate,项目名称:property-inject,代码行数:25,代码来源:PropertyFactoryTest.java

示例4: checkMultipleAnnotationParameter

import javax.enterprise.inject.spi.AnnotatedParameter; //导入依赖的package包/类
/**
 * Checks if any property resolver method parameter is annotated with 
 * more than one of the following: {@link PropertyKey}, {@link PropertyBundle}, 
 * {@link PropertyLocale}
 */
private void checkMultipleAnnotationParameter() {
    int count;
    for (final AnnotatedParameter<?> parameter : propertyResolverMethod.getParameters()) {
        count = 0;
        if (parameter.isAnnotationPresent(PropertyKey.class)) {
            count++;
        }
        if (parameter.isAnnotationPresent(PropertyBundle.class)) {
            count++;
        }
        if (parameter.isAnnotationPresent(PropertyLocale.class)) {
            count++;
        }
        if (count > 1) {
            throw new ExtensionInitializationException(
                    "A property resolver method parameter must not be annotated with more than one of the following: "
                            + PropertyKey.class.getSimpleName() + ", " + PropertyBundle.class.getSimpleName()
                            + " or " + PropertyLocale.class.getSimpleName());
        }
    }
}
 
开发者ID:gonmarques,项目名称:cdi-properties,代码行数:27,代码来源:PropertyResolverMethodParametersVerifier.java

示例5: createParameterListId

import javax.enterprise.inject.spi.AnnotatedParameter; //导入依赖的package包/类
/**
 * Generates a unique string representation of a list of
 * {@link AnnotatedParameter}s.
 */
public static <X> String createParameterListId(List<AnnotatedParameter<X>> parameters)
{
    StringBuilder builder = new StringBuilder();
    builder.append("(");
    for (int i = 0; i < parameters.size(); ++i)
    {
        AnnotatedParameter<X> ap = parameters.get(i);
        builder.append(createParameterId(ap));
        if (i + 1 != parameters.size())
        {
            builder.append(',');
        }
    }
    builder.append(")");
    return builder.toString();
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:21,代码来源:Annotateds.java

示例6: compareAnnotatedParameters

import javax.enterprise.inject.spi.AnnotatedParameter; //导入依赖的package包/类
/**
 * Compares two annotated elements to see if they have the same annotations
 */
private static boolean compareAnnotatedParameters(List<? extends AnnotatedParameter<?>> p1,
                                                  List<? extends AnnotatedParameter<?>> p2)
{
    if (p1.size() != p2.size())
    {
        return false;
    }
    for (int i = 0; i < p1.size(); ++i)
    {
        if (!compareAnnotated(p1.get(i), p2.get(i)))
        {
            return false;
        }
    }
    return true;
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:20,代码来源:Annotateds.java

示例7: removeFromParameter

import javax.enterprise.inject.spi.AnnotatedParameter; //导入依赖的package包/类
/**
 * Remove an annotation from the specified parameter.
 *
 * @param parameter      the parameter to remove the annotation from
 * @param annotationType the annotation type to remove
 * @throws IllegalArgumentException if the annotationType is null, if the
 *                                  callable which declares the parameter is not currently declared
 *                                  on the type or if the parameter is not declared on either a
 *                                  constructor or a method
 */
public AnnotatedTypeBuilder<X> removeFromParameter(AnnotatedParameter<? super X> parameter,
                                                   Class<? extends Annotation> annotationType)
{
    if (parameter.getDeclaringCallable().getJavaMember() instanceof Method)
    {
        Method method = (Method) parameter.getDeclaringCallable().getJavaMember();
        return removeFromMethodParameter(method, parameter.getPosition(), annotationType);
    }
    if (parameter.getDeclaringCallable().getJavaMember() instanceof Constructor<?>)
    {
        @SuppressWarnings("unchecked")
        Constructor<X> constructor = (Constructor<X>) parameter.getDeclaringCallable().getJavaMember();
        return removeFromConstructorParameter(constructor, parameter.getPosition(), annotationType);
    }
    else
    {
        throw new IllegalArgumentException("Cannot remove from parameter " + parameter +
                " - cannot operate on member " + parameter.getDeclaringCallable().getJavaMember());
    }
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:31,代码来源:AnnotatedTypeBuilder.java

示例8: addToParameter

import javax.enterprise.inject.spi.AnnotatedParameter; //导入依赖的package包/类
/**
 * Add an annotation to the specified parameter. If the callable which
 * declares the parameter is not already present, it will be added. If the
 * parameter is not already present on the callable, it will be added.
 *
 * @param parameter  the parameter to add the annotation to
 * @param annotation the annotation to add
 * @throws IllegalArgumentException if the annotation is null or if the
 *                                  parameter is not declared on either a constructor or a method
 */
public AnnotatedTypeBuilder<X> addToParameter(AnnotatedParameter<? super X> parameter, Annotation annotation)
{
    if (parameter.getDeclaringCallable().getJavaMember() instanceof Method)
    {
        Method method = (Method) parameter.getDeclaringCallable().getJavaMember();
        return addToMethodParameter(method, parameter.getPosition(), annotation);
    }
    if (parameter.getDeclaringCallable().getJavaMember() instanceof Constructor<?>)
    {
        @SuppressWarnings("unchecked")
        Constructor<X> constructor = (Constructor<X>) parameter.getDeclaringCallable().getJavaMember();
        return addToConstructorParameter(constructor, parameter.getPosition(), annotation);
    }
    else
    {
        throw new IllegalArgumentException("Cannot remove from parameter " + parameter +
                " - cannot operate on member " + parameter.getDeclaringCallable().getJavaMember());
    }
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:30,代码来源:AnnotatedTypeBuilder.java

示例9: overrideParameterType

import javax.enterprise.inject.spi.AnnotatedParameter; //导入依赖的package包/类
/**
 * Override the declared type of a parameter.
 *
 * @param parameter the parameter to override the type on
 * @param type      the new type of the parameter
 * @throws IllegalArgumentException if parameter or type is null
 */
public AnnotatedTypeBuilder<X> overrideParameterType(AnnotatedParameter<? super X> parameter, Type type)
{
    if (parameter.getDeclaringCallable().getJavaMember() instanceof Method)
    {
        Method method = (Method) parameter.getDeclaringCallable().getJavaMember();
        return overrideMethodParameterType(method, parameter.getPosition(), type);
    }
    if (parameter.getDeclaringCallable().getJavaMember() instanceof Constructor<?>)
    {
        @SuppressWarnings("unchecked")
        Constructor<X> constructor = (Constructor<X>) parameter.getDeclaringCallable().getJavaMember();
        return overrideConstructorParameterType(constructor, parameter.getPosition(), type);
    }
    else
    {
        throw new IllegalArgumentException("Cannot remove from parameter " + parameter +
                " - cannot operate on member " + parameter.getDeclaringCallable().getJavaMember());
    }
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:27,代码来源:AnnotatedTypeBuilder.java

示例10: modifyAnnotationsOnConstructorParameter

import javax.enterprise.inject.spi.AnnotatedParameter; //导入依赖的package包/类
@Test
public void modifyAnnotationsOnConstructorParameter() throws NoSuchMethodException
{
    final AnnotatedTypeBuilder<Cat> builder = new AnnotatedTypeBuilder<Cat>();
    builder.readFromType(Cat.class, true);
    builder.removeFromConstructorParameter(Cat.class.getConstructor(String.class, String.class), 1, Default.class);
    builder.addToConstructorParameter(Cat.class.getConstructor(String.class, String.class), 1, new AnyLiteral());

    final AnnotatedType<Cat> catAnnotatedType = builder.create();
    Set<AnnotatedConstructor<Cat>> catCtors = catAnnotatedType.getConstructors();

    assertThat(catCtors.size(), is(2));

    for (AnnotatedConstructor<Cat> ctor : catCtors)
    {
        if (ctor.getParameters().size() == 2)
        {
            List<AnnotatedParameter<Cat>> ctorParams = ctor.getParameters();

            assertThat(ctorParams.get(1).getAnnotations().size(), is(1));
            assertThat((AnyLiteral) ctorParams.get(1).getAnnotations().toArray()[0], is(new AnyLiteral()));
        }
    }
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:25,代码来源:AnnotatedTypeBuilderTest.java

示例11: isHandler

import javax.enterprise.inject.spi.AnnotatedParameter; //导入依赖的package包/类
/**
 * Determines if the given method is a handler by looking for the {@link Handles} annotation on a parameter.
 *
 * @param method method to search
 * @return true if {@link Handles} is found, false otherwise
 */
public static boolean isHandler(final AnnotatedMethod<?> method)
{
    if (method == null)
    {
        throw new IllegalArgumentException("Method must not be null");
    }

    for (AnnotatedParameter<?> param : method.getParameters())
    {
        if (param.isAnnotationPresent(Handles.class) || param.isAnnotationPresent(BeforeHandles.class))
        {
            return true;
        }
    }

    return false;
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:24,代码来源:HandlerMethodImpl.java

示例12: findHandlerParameter

import javax.enterprise.inject.spi.AnnotatedParameter; //导入依赖的package包/类
public static AnnotatedParameter<?> findHandlerParameter(final AnnotatedMethod<?> method)
{
    if (!isHandler(method))
    {
        throw new IllegalArgumentException("Method is not a valid handler");
    }

    AnnotatedParameter<?> returnParam = null;

    for (AnnotatedParameter<?> param : method.getParameters())
    {
        if (param.isAnnotationPresent(Handles.class) || param.isAnnotationPresent(BeforeHandles.class))
        {
            returnParam = param;
            break;
        }
    }

    return returnParam;
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:21,代码来源:HandlerMethodImpl.java

示例13: getInjectionPoints

import javax.enterprise.inject.spi.AnnotatedParameter; //导入依赖的package包/类
/**
 * Obtain all the injection points for the handler
 *
 * @param bm a BeanManager to use to obtain the beans
 */
public Set<InjectionPoint> getInjectionPoints(final BeanManager bm)
{
    if (injectionPoints == null)
    {
        injectionPoints = new HashSet<InjectionPoint>(handler.getParameters().size() - 1);

        for (AnnotatedParameter<?> param : handler.getParameters())
        {
            if (!param.equals(handlerParameter))
            {
                injectionPoints.add(
                        new ImmutableInjectionPoint(param, bm, getDeclaringBean(), false, false));
            }
        }

    }
    return new HashSet<InjectionPoint>(injectionPoints);
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:24,代码来源:HandlerMethodImpl.java

示例14: getResourceAnnotation

import javax.enterprise.inject.spi.AnnotatedParameter; //导入依赖的package包/类
private Resource getResourceAnnotation(InjectionPoint injectionPoint) {
    Annotated annotated = injectionPoint.getAnnotated();
    if (annotated instanceof AnnotatedParameter<?>) {
        annotated = ((AnnotatedParameter<?>) annotated).getDeclaringCallable();
    }
    return annotated.getAnnotation(Resource.class);
}
 
开发者ID:weld,项目名称:weld-junit,代码行数:8,代码来源:MockResourceInjectionServices.java

示例15: process

import javax.enterprise.inject.spi.AnnotatedParameter; //导入依赖的package包/类
public void process(Set<AnnotatedType<?>> discoveredTypes) {
    for(AnnotatedType<?> at : discoveredTypes) {
        for(AnnotatedMethod<?> am : at.getMethods()) {
            boolean hasObserver = am.getParameters().stream().anyMatch(ap -> ap.getAnnotation(ObservesReactor.class) != null);
            if(hasObserver) {
                AnnotatedParameter<?> observerType = am.getParameters().stream().filter(ap -> ap.isAnnotationPresent(ObservesReactor.class)).findFirst().orElseThrow(() -> new RuntimeException("No observer found"));
                Class<?> returnType = null;
                Type genericReturnType = am.getJavaMember().getGenericReturnType();
                boolean returnsPublisher = false;
                if(genericReturnType instanceof ParameterizedType) {
                    ParameterizedType type = (ParameterizedType)genericReturnType;
                    if(Publisher.class.isAssignableFrom((Class<?>) type.getRawType())) {
                        returnsPublisher = true;
                        returnType = (Class<?>) type.getActualTypeArguments()[0];
                    } else {
                        throw new RuntimeException("Method "+am+" should either return a concrete type or an instance of "+Publisher.class.getName());
                    }
                }
                else {
                    returnType = (Class)genericReturnType;
                }
                Class<?> eventType = observerType.getJavaParameter().getType();
                Set<Annotation> annotations = new LinkedHashSet<>(asList(observerType.getJavaParameter().getAnnotations()));
                methods.add(new ReactorMethod(at,am,returnType,eventType,annotations,returnsPublisher));
            }
        }
    }
}
 
开发者ID:johnament,项目名称:reactive-cdi-events,代码行数:29,代码来源:ReactorObserverRegistry.java


注:本文中的javax.enterprise.inject.spi.AnnotatedParameter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。