use of org.androidannotations.handler.AnnotationHandler in project androidannotations by androidannotations.
the class ModelProcessor method process.
@SuppressWarnings({ "unchecked", "rawtypes" })
public ProcessResult process(AnnotationElements validatedModel) throws Exception {
ProcessHolder processHolder = new ProcessHolder(environment.getProcessingEnvironment());
environment.setProcessHolder(processHolder);
LOGGER.info("Processing root elements");
/*
* We generate top classes then inner classes, then inner classes of
* inner classes, etc... until there is no more classes to generate.
*/
while (generateElements(validatedModel, processHolder)) {
// CHECKSTYLE:OFF
;
// CHECKSTYLE:ON
}
LOGGER.info("Processing enclosed elements");
for (AnnotationHandler annotationHandler : environment.getDecoratingHandlers()) {
if (!annotationHandler.isEnabled()) {
continue;
}
String annotationName = annotationHandler.getTarget();
/*
* For ancestors, the annotationHandler manipulates the annotated
* elements, but uses the holder for the root element
*/
Set<AnnotatedAndRootElements> ancestorAnnotatedElements = validatedModel.getAncestorAnnotatedElements(annotationName);
if (!ancestorAnnotatedElements.isEmpty()) {
LOGGER.debug("Processing enclosed elements with {}: {}", annotationHandler.getClass().getSimpleName(), ancestorAnnotatedElements);
}
for (AnnotatedAndRootElements elements : ancestorAnnotatedElements) {
GeneratedClassHolder holder = processHolder.getGeneratedClassHolder(elements.rootTypeElement);
/*
* Annotations coming from ancestors may be applied to root
* elements that are not validated, and therefore not available.
*/
if (holder != null) {
processThrowing(annotationHandler, elements.annotatedElement, holder);
}
}
Set<? extends Element> rootAnnotatedElements = validatedModel.getRootAnnotatedElements(annotationName);
for (Element annotatedElement : rootAnnotatedElements) {
Element enclosingElement;
if (annotatedElement instanceof TypeElement) {
enclosingElement = annotatedElement;
} else {
enclosingElement = annotatedElement.getEnclosingElement();
/*
* we are processing a method parameter
*/
if (enclosingElement instanceof ExecutableElement) {
enclosingElement = enclosingElement.getEnclosingElement();
}
}
/*
* We do not generate code for elements belonging to abstract
* classes, because the generated classes are final anyway
*/
if (!isAbstractClass(enclosingElement)) {
GeneratedClassHolder holder = processHolder.getGeneratedClassHolder(enclosingElement);
/*
* The holder can be null if the annotated holder class is
* already invalidated.
*/
if (holder != null) {
processThrowing(annotationHandler, annotatedElement, holder);
}
} else {
LOGGER.trace("Skip element {} because enclosing element {} is abstract", annotatedElement, enclosingElement);
}
}
}
return new //
ProcessResult(//
processHolder.codeModel(), processHolder.getOriginatingElements());
}
use of org.androidannotations.handler.AnnotationHandler in project androidannotations by androidannotations.
the class ModelValidator method validate.
public AnnotationElements validate(AnnotationElements extractedModel, AnnotationElementsHolder validatingHolder) throws ValidationException {
LOGGER.info("Validating elements");
List<ElementValidation> failedValidations = new ArrayList<>();
for (AnnotationHandler annotationHandler : environment.getHandlers()) {
if (!annotationHandler.isEnabled()) {
continue;
}
String validatorSimpleName = annotationHandler.getClass().getSimpleName();
String annotationName = annotationHandler.getTarget();
Set<? extends Element> annotatedElements = extractedModel.getRootAnnotatedElements(annotationName);
Set<Element> validatedAnnotatedElements = new LinkedHashSet<>();
validatingHolder.putRootAnnotatedElements(annotationName, validatedAnnotatedElements);
if (!annotatedElements.isEmpty()) {
LOGGER.debug("Validating with {}: {}", validatorSimpleName, annotatedElements);
}
for (Element annotatedElement : annotatedElements) {
ElementValidation elementValidation = annotationHandler.validate(annotatedElement);
AnnotationMirror annotationMirror = elementValidation.getAnnotationMirror();
for (ElementValidation.Error error : elementValidation.getErrors()) {
LOGGER.error(error.getMessage(), error.getElement(), annotationMirror);
}
for (String warning : elementValidation.getWarnings()) {
LOGGER.warn(warning, elementValidation.getElement(), elementValidation.getAnnotationMirror());
}
if (elementValidation.isValid()) {
validatedAnnotatedElements.add(annotatedElement);
} else {
failedValidations.add(elementValidation);
LOGGER.warn("Element {} invalidated by {}", annotatedElement, annotatedElement, validatorSimpleName);
}
}
}
if (!failedValidations.isEmpty()) {
throw new ValidationException(failedValidations);
}
return validatingHolder;
}
use of org.androidannotations.handler.AnnotationHandler in project androidannotations by androidannotations.
the class OttoPlugin method getHandlers.
@Override
public List<AnnotationHandler<?>> getHandlers(AndroidAnnotationsEnvironment androidAnnotationEnv) {
List<AnnotationHandler<?>> annotationHandlers = new ArrayList<>();
annotationHandlers.add(new SubscribeHandler(androidAnnotationEnv));
annotationHandlers.add(new ProduceHandler(androidAnnotationEnv));
return annotationHandlers;
}
Aggregations