Search in sources :

Example 1 with GeneratingAnnotationHandler

use of org.androidannotations.handler.GeneratingAnnotationHandler in project androidannotations by androidannotations.

the class ModelProcessor method generateElements.

@SuppressWarnings({ "unchecked", "rawtypes" })
private boolean generateElements(AnnotationElements validatedModel, ProcessHolder processHolder) throws Exception {
    boolean isElementRemaining = false;
    for (GeneratingAnnotationHandler generatingAnnotationHandler : environment.getGeneratingHandlers()) {
        if (!generatingAnnotationHandler.isEnabled()) {
            continue;
        }
        String annotationName = generatingAnnotationHandler.getTarget();
        Set<? extends Element> annotatedElements = validatedModel.getRootAnnotatedElements(annotationName);
        if (!annotatedElements.isEmpty()) {
            LOGGER.debug("Processing root elements {}: {}", generatingAnnotationHandler.getClass().getSimpleName(), annotatedElements);
        }
        for (Element annotatedElement : annotatedElements) {
            /*
				 * We do not generate code for abstract classes, because the
				 * generated classes are final anyway (we do not want anyone to
				 * extend them).
				 */
            if (!isAbstractClass(annotatedElement)) {
                if (processHolder.getGeneratedClassHolder(annotatedElement) == null) {
                    TypeElement typeElement = (TypeElement) annotatedElement;
                    Element enclosingElement = annotatedElement.getEnclosingElement();
                    if (typeElement.getNestingKind() == NestingKind.MEMBER && processHolder.getGeneratedClassHolder(enclosingElement) == null) {
                        isElementRemaining = true;
                    } else {
                        GeneratedClassHolder generatedClassHolder = generatingAnnotationHandler.createGeneratedClassHolder(environment, typeElement);
                        processHolder.put(annotatedElement, generatedClassHolder);
                        generatingAnnotationHandler.process(annotatedElement, generatedClassHolder);
                    }
                }
            } else {
                LOGGER.trace("Skip element {} because it's abstract", annotatedElement);
            }
        }
    /*
			 * We currently do not take into account class annotations from
			 * ancestors. We should careful design the priority rules first.
			 */
    }
    return isElementRemaining;
}
Also used : GeneratedClassHolder(org.androidannotations.holder.GeneratedClassHolder) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) GeneratingAnnotationHandler(org.androidannotations.handler.GeneratingAnnotationHandler)

Aggregations

Element (javax.lang.model.element.Element)1 ExecutableElement (javax.lang.model.element.ExecutableElement)1 TypeElement (javax.lang.model.element.TypeElement)1 GeneratingAnnotationHandler (org.androidannotations.handler.GeneratingAnnotationHandler)1 GeneratedClassHolder (org.androidannotations.holder.GeneratedClassHolder)1