Search in sources :

Example 71 with AnnotatedElement

use of java.lang.reflect.AnnotatedElement in project jdbi by jdbi.

the class SqlObjectFactory method forEachConfigurer.

private void forEachConfigurer(AnnotatedElement element, BiConsumer<Configurer, Annotation> consumer) {
    Stream.of(element.getAnnotations()).filter(a -> a.annotationType().isAnnotationPresent(ConfiguringAnnotation.class)).forEach(a -> {
        ConfiguringAnnotation meta = a.annotationType().getAnnotation(ConfiguringAnnotation.class);
        consumer.accept(getConfigurer(meta.value()), a);
    });
}
Also used : ExtensionMethod(org.jdbi.v3.core.extension.ExtensionMethod) HandleSupplier(org.jdbi.v3.core.extension.HandleSupplier) Arrays(java.util.Arrays) Proxy(java.lang.reflect.Proxy) ConfiguringAnnotation(org.jdbi.v3.sqlobject.config.ConfiguringAnnotation) HashMap(java.util.HashMap) ConfigRegistry(org.jdbi.v3.core.config.ConfigRegistry) Stream(java.util.stream.Stream) Collections.synchronizedMap(java.util.Collections.synchronizedMap) Map(java.util.Map) Annotation(java.lang.annotation.Annotation) BiConsumer(java.util.function.BiConsumer) ExtensionFactory(org.jdbi.v3.core.extension.ExtensionFactory) InvocationHandler(java.lang.reflect.InvocationHandler) Configurer(org.jdbi.v3.sqlobject.config.Configurer) Method(java.lang.reflect.Method) Collections(java.util.Collections) WeakHashMap(java.util.WeakHashMap) AnnotatedElement(java.lang.reflect.AnnotatedElement) ConfiguringAnnotation(org.jdbi.v3.sqlobject.config.ConfiguringAnnotation)

Example 72 with AnnotatedElement

use of java.lang.reflect.AnnotatedElement in project junit5 by junit-team.

the class ScriptExecutionConditionTests method throwingEvaluatorIsCreatedWhenDefaultEvaluatorClassNameIsIllegal.

@Test
void throwingEvaluatorIsCreatedWhenDefaultEvaluatorClassNameIsIllegal() throws ReflectiveOperationException {
    String name = "illegal class name";
    ScriptExecutionCondition condition = new ScriptExecutionCondition(name);
    ExtensionContext context = Mockito.mock(ExtensionContext.class);
    AnnotatedElement element = SimpleTestCases.class.getDeclaredMethod("testIsEnabled");
    Mockito.when(context.getElement()).thenReturn(Optional.of(element));
    Exception e = assertThrows(Exception.class, () -> condition.evaluateExecutionCondition(context));
    // 
    assertThat(e).isInstanceOf(// 
    ExtensionConfigurationException.class).hasMessageStartingWith("Creating instance of class `" + name + "` failed");
}
Also used : ExtensionConfigurationException(org.junit.jupiter.api.extension.ExtensionConfigurationException) AnnotatedElement(java.lang.reflect.AnnotatedElement) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) JUnitException(org.junit.platform.commons.JUnitException) ExtensionConfigurationException(org.junit.jupiter.api.extension.ExtensionConfigurationException) Test(org.junit.jupiter.api.Test)

Example 73 with AnnotatedElement

use of java.lang.reflect.AnnotatedElement in project Payara by payara.

the class StatefulHandler method createEjbDescriptor.

/**
 * Create a new EjbDescriptor for a given elementName and AnnotationInfo.
 * @param elementName
 * @param ainfo
 * @return a new EjbDescriptor
 */
protected EjbDescriptor createEjbDescriptor(String elementName, AnnotationInfo ainfo) throws AnnotationProcessorException {
    AnnotatedElement ae = ainfo.getAnnotatedElement();
    Class ejbClass = (Class) ae;
    EjbSessionDescriptor newDescriptor = new EjbSessionDescriptor();
    newDescriptor.setName(elementName);
    newDescriptor.setEjbClassName(ejbClass.getName());
    newDescriptor.setSessionType(EjbSessionDescriptor.STATEFUL);
    return newDescriptor;
}
Also used : AnnotatedElement(java.lang.reflect.AnnotatedElement) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)

Example 74 with AnnotatedElement

use of java.lang.reflect.AnnotatedElement in project Payara by payara.

the class AbstractAttributeHandler method processAnnotation.

/**
 * Process a particular annotation which type is the same as the
 * one returned by @see getAnnotationType(). All information
 * pertinent to the annotation and its context is encapsulated
 * in the passed AnnotationInfo instance.
 * This is a method in interface AnnotationHandler.
 *
 * @param ainfo the annotation information
 */
public HandlerProcessingResult processAnnotation(AnnotationInfo ainfo) throws AnnotationProcessorException {
    AnnotatedElement ae = ainfo.getAnnotatedElement();
    Annotation annotation = ainfo.getAnnotation();
    if (logger.isLoggable(Level.FINER)) {
        logger.finer("@process annotation " + annotation + " in " + ae);
    }
    AnnotatedElementHandler aeHandler = ainfo.getProcessingContext().getHandler();
    if (aeHandler instanceof EjbBundleContext) {
        EjbBundleContext ejbBundleContext = (EjbBundleContext) aeHandler;
        AnnotatedElementHandler aeh = ejbBundleContext.createContextForEjb();
        if (aeh != null) {
            aeHandler = aeh;
        } else {
            if (isDelegatee()) {
                aeHandler = ejbBundleContext.createContextForEjbInterceptor();
            }
            if (aeHandler == null) {
                return getInvalidAnnotatedElementHandlerResult(null, ainfo);
            }
        }
    }
    if (!supportTypeInheritance() && ElementType.TYPE.equals(ainfo.getElementType()) && aeHandler instanceof ComponentContext) {
        ComponentContext context = (ComponentContext) aeHandler;
        Class clazz = (Class) ainfo.getAnnotatedElement();
        if (!clazz.getName().equals(context.getComponentClassName())) {
            if (logger.isLoggable(Level.WARNING)) {
                log(Level.WARNING, ainfo, localStrings.getLocalString("enterprise.deployment.annotation.handlers.typeinhernotsupp", "The annotation symbol inheritance is not supported."));
            }
            return getDefaultProcessedResult();
        }
    }
    EjbContext[] ejbContexts = null;
    EjbInterceptorContext ejbInterceptorContext = null;
    if (aeHandler instanceof EjbContext) {
        EjbContext ejbContext = (EjbContext) aeHandler;
        ejbContexts = new EjbContext[] { ejbContext };
    } else if (aeHandler instanceof EjbsContext) {
        ejbContexts = ((EjbsContext) aeHandler).getEjbContexts();
    } else if (isDelegatee() && aeHandler instanceof EjbInterceptorContext) {
        ejbInterceptorContext = (EjbInterceptorContext) aeHandler;
    } else {
        return getInvalidAnnotatedElementHandlerResult(aeHandler, ainfo);
    }
    HandlerProcessingResult procResult = null;
    if (ejbInterceptorContext != null) {
        procResult = processAnnotation(ainfo, ejbInterceptorContext);
    } else {
        procResult = processAnnotation(ainfo, ejbContexts);
    }
    if (logger.isLoggable(Level.FINER)) {
        logger.finer("New annotation for " + annotation);
    }
    return procResult;
}
Also used : EjbBundleContext(com.sun.enterprise.deployment.annotation.context.EjbBundleContext) ComponentContext(com.sun.enterprise.deployment.annotation.context.ComponentContext) EjbInterceptorContext(com.sun.enterprise.deployment.annotation.context.EjbInterceptorContext) EjbContext(com.sun.enterprise.deployment.annotation.context.EjbContext) HandlerProcessingResult(org.glassfish.apf.HandlerProcessingResult) AnnotatedElement(java.lang.reflect.AnnotatedElement) AnnotatedElementHandler(org.glassfish.apf.AnnotatedElementHandler) Annotation(java.lang.annotation.Annotation) EjbsContext(com.sun.enterprise.deployment.annotation.context.EjbsContext)

Example 75 with AnnotatedElement

use of java.lang.reflect.AnnotatedElement in project Payara by payara.

the class SingletonHandler method createEjbDescriptor.

/**
 * Create a new EjbDescriptor for a given elementName and AnnotationInfo.
 * @param elementName
 * @param ainfo
 * @return a new EjbDescriptor
 */
protected EjbDescriptor createEjbDescriptor(String elementName, AnnotationInfo ainfo) throws AnnotationProcessorException {
    AnnotatedElement ae = ainfo.getAnnotatedElement();
    Class ejbClass = (Class) ae;
    EjbSessionDescriptor newDescriptor = new EjbSessionDescriptor();
    newDescriptor.setName(elementName);
    newDescriptor.setEjbClassName(ejbClass.getName());
    newDescriptor.setSessionType(EjbSessionDescriptor.SINGLETON);
    doSingletonSpecificProcessing(newDescriptor, ejbClass);
    return newDescriptor;
}
Also used : AnnotatedElement(java.lang.reflect.AnnotatedElement) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)

Aggregations

AnnotatedElement (java.lang.reflect.AnnotatedElement)106 Method (java.lang.reflect.Method)23 Annotation (java.lang.annotation.Annotation)17 Field (java.lang.reflect.Field)17 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)11 HashMap (java.util.HashMap)9 Test (org.junit.jupiter.api.Test)8 Member (java.lang.reflect.Member)7 LinkedHashSet (java.util.LinkedHashSet)7 List (java.util.List)7 Constructor (java.lang.reflect.Constructor)6 Type (java.lang.reflect.Type)6 Map (java.util.Map)6 HashSet (java.util.HashSet)5 By (org.openqa.selenium.By)5 Statement (org.junit.runners.model.Statement)4 FindBy (org.openqa.selenium.support.FindBy)4 EntityType (com.querydsl.codegen.EntityType)3 Collection (java.util.Collection)3