Search in sources :

Example 1 with ComponentInfo

use of org.glassfish.apf.ComponentInfo in project Payara by payara.

the class AnnotationProcessorImpl method process.

private ProcessingResult process(ProcessingContext ctx, Class c) throws AnnotationProcessorException {
    Scanner scanner = ctx.getProcessingInput();
    ProcessingResultImpl result = new ProcessingResultImpl();
    // let's see first if this package is new to us and annotated.
    Package classPackage = c.getPackage();
    if (classPackage != null && visitedPackages.add(classPackage)) {
        // new package
        result.add(classPackage, processAnnotations(ctx, ElementType.PACKAGE, classPackage));
    }
    ComponentInfo info = null;
    try {
        info = scanner.getComponentInfo(c);
    } catch (NoClassDefFoundError err) {
        // issue 456: allow verifier to report this issue
        AnnotationProcessorException ape = new AnnotationProcessorException(AnnotationUtils.getLocalString("enterprise.deployment.annotation.classnotfounderror", "Class [ {0} ] not found. Error while loading [ {1} ]", new Object[] { err.getMessage(), c }));
        ctx.getErrorHandler().error(ape);
        // annotation processing
        return result;
    }
    // process the class itself.
    AnnotatedElementHandler handler = ctx.getHandler();
    logStart(handler, ElementType.TYPE, c);
    result.add(c, processAnnotations(ctx, c));
    // now dive into the fields.
    for (Field field : info.getFields()) {
        result.add(field, processAnnotations(ctx, ElementType.FIELD, field));
    }
    // constructors...
    for (Constructor constructor : info.getConstructors()) {
        logStart(ctx.getHandler(), ElementType.CONSTRUCTOR, constructor);
        result.add(constructor, processAnnotations(ctx, constructor));
        // parameters
        processParameters(ctx, constructor.getParameterAnnotations());
        logEnd(ctx.getHandler(), ElementType.CONSTRUCTOR, constructor);
    }
    // methods...
    for (Method method : info.getMethods()) {
        logStart(ctx.getHandler(), ElementType.METHOD, method);
        result.add(method, processAnnotations(ctx, method));
        // parameters
        processParameters(ctx, method.getParameterAnnotations());
        logEnd(ctx.getHandler(), ElementType.METHOD, method);
    }
    // Because of annotation inheritance, we need to to travel to
    // the superclasses to ensure that annotations defined at the
    // TYPE level are processed at this component level.
    // Note : so far, I am ignoring the implemented interfaces
    Class currentClass = c.getSuperclass();
    while (currentClass != null && !currentClass.equals(Object.class)) {
        // the trick is to add the results for this class, not
        // for the ones they are defined in...
        result.add(c, processAnnotations(ctx, currentClass));
        currentClass = currentClass.getSuperclass();
    }
    // end of class processing, we need to get the top handler
    // since it may have changed during the annotation processing
    logEnd(ctx.getHandler(), ElementType.TYPE, c);
    return result;
}
Also used : Scanner(org.glassfish.apf.Scanner) Field(java.lang.reflect.Field) Constructor(java.lang.reflect.Constructor) ComponentInfo(org.glassfish.apf.ComponentInfo) Method(java.lang.reflect.Method) AnnotationProcessorException(org.glassfish.apf.AnnotationProcessorException) AnnotatedElementHandler(org.glassfish.apf.AnnotatedElementHandler)

Aggregations

Constructor (java.lang.reflect.Constructor)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 AnnotatedElementHandler (org.glassfish.apf.AnnotatedElementHandler)1 AnnotationProcessorException (org.glassfish.apf.AnnotationProcessorException)1 ComponentInfo (org.glassfish.apf.ComponentInfo)1 Scanner (org.glassfish.apf.Scanner)1