use of com.github.mvp4g.mvp4g2.core.eventbus.annotation.Start in project mvp4g2 by mvp4g.
the class EventBusAnnotationValidator method validate.
public void validate(Element element) throws ProcessorException {
// get elements annotated with EventBus annotation
Set<? extends Element> elementsWithEventBusAnnotation = this.roundEnvironment.getElementsAnnotatedWith(EventBus.class);
// annotated element has to be a interface
if (element instanceof TypeElement) {
TypeElement typeElement = (TypeElement) element;
// Eventbus must be an interface!
if (!typeElement.getKind().isInterface()) {
throw new ProcessorException("Mvp4g2Processor: @Eventbus can only be used with an interface");
}
// check, that the typeElement extends IsEventBus
if (!this.processorUtils.extendsClassOrInterface(this.processingEnvironment.getTypeUtils(), typeElement.asType(), this.processingEnvironment.getElementUtils().getTypeElement(IsEventBus.class.getCanonicalName()).asType())) {
throw new ProcessorException(typeElement.getSimpleName().toString() + ": @Eventbus must extend IsEventBus.class!");
}
// @Start validation
// check, if there are more than @Start annotated method
List<Element> elementsAnnotatedWithStart = this.processorUtils.getMethodFromTypeElementAnnotatedWith(this.processingEnvironment, typeElement, Start.class);
if (elementsAnnotatedWithStart.size() > 1) {
throw new ProcessorException("Mvp4g2Processor: @Start-annotation can only be used a single time in a eventbus interface");
} else {
// check, that the @Start annotation is only used on zero-argument methods!
if (elementsAnnotatedWithStart.size() == 1) {
ExecutableElement executableElement = (ExecutableElement) elementsAnnotatedWithStart.get(0);
if (executableElement.getParameters().size() > 0) {
throw new ProcessorException("Mvp4g2Processor: @Start-annotation can only be used on zero argument methods");
}
}
}
} else {
throw new ProcessorException("Mvp4g2Processor: @Eventbus can only be used on a type (interface)");
}
}
Aggregations