use of com.github.mvp4g.mvp4g2.core.eventbus.annotation.EventBus in project mvp4g2 by mvp4g.
the class ImplementationTest method testOnlyApplicationData.
@Test
public void testOnlyApplicationData() {
Compilation compilation = javac().withProcessors(new Mvp4g2Processor()).compile(new ArrayList<JavaFileObject>() {
{
add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/implementation/testOnlyApplicationData/ApplicationAnnotation.java"));
}
});
CompilationSubject.assertThat(compilation).failed();
CompilationSubject.assertThat(compilation).hadErrorContaining("no EventBusMetaModel found! Did you forget to create an EventBus for mvp4g2 or forget to annotate the EventBus with @EventBus?");
}
use of com.github.mvp4g.mvp4g2.core.eventbus.annotation.EventBus in project mvp4g2 by mvp4g.
the class PresenterAnnotationValidator method validate.
public void validate(Element element, TypeElement viewClassTypeElement, TypeElement viewInterfaceTypeElement) throws ProcessorException {
if (element instanceof TypeElement) {
TypeElement typeElement = (TypeElement) element;
// check, that the presenter annotion is only used with classes
if (!typeElement.getKind().isClass()) {
throw new ProcessorException("Mvp4g2Processor:" + typeElement.getSimpleName().toString() + ": @Presenter can only be used with a class!");
}
// check, that the viewClass is a class
if (!viewClassTypeElement.getKind().isClass()) {
throw new ProcessorException("Mvp4g2Processor:" + typeElement.getSimpleName().toString() + ": the viewClass-attribute of a @Presenter must be a class!");
}
// chekc if the vioewInterface is a interface
if (!viewInterfaceTypeElement.getKind().isInterface()) {
throw new ProcessorException("Mvp4g2Processor:" + typeElement.getSimpleName().toString() + ": the viewInterface-attribute of a @Presenter must be a interface!");
}
// check, if viewClass is implementing viewInterface
if (!this.processorUtils.implementsInterface(this.processingEnvironment, viewClassTypeElement, viewInterfaceTypeElement.asType())) {
throw new ProcessorException("Mvp4g2Processor:" + typeElement.getSimpleName().toString() + ": the viewClass-attribute of a @Presenter must implement the viewInterface!");
}
// check, that the typeElement extends AbstractHandler
if (!this.processorUtils.extendsClassOrInterface(this.processingEnvironment.getTypeUtils(), typeElement.asType(), this.processingEnvironment.getElementUtils().getTypeElement(AbstractPresenter.class.getCanonicalName()).asType())) {
throw new ProcessorException(typeElement.getSimpleName().toString() + ": @Presenter must extend AbstractPresenter.class!");
}
// check if annotated class is abstract
if (typeElement.getModifiers().contains(Modifier.ABSTRACT)) {
throw new ProcessorException("Mvp4g2Processor:" + typeElement.getSimpleName().toString() + ": @Presenter can not be ABSTRACT");
}
// check if class attribute is not abstradt
if (viewClassTypeElement.getModifiers().contains(Modifier.ABSTRACT)) {
throw new ProcessorException(typeElement.getSimpleName().toString() + ": class-attribute of @Presenter can not be ABSTRACT");
}
// check if a shell presenter does not implememt the multiple feature
TypeMirror isShellMirror = this.processorUtils.getFlattenedSupertype(this.processingEnvironment.getTypeUtils(), typeElement.asType(), this.processingEnvironment.getElementUtils().getTypeElement(IsShell.class.getCanonicalName()).asType());
if (isShellMirror != null) {
if (typeElement.getAnnotation(Presenter.class).multiple()) {
throw new ProcessorException(typeElement.getSimpleName().toString() + ": IsShell interface can not be used on a presenter which is defiend as multiple = true");
}
}
Presenter presenterAnnotation = typeElement.getAnnotation(Presenter.class);
if (Presenter.VIEW_CREATION_METHOD.PRESENTER.equals(presenterAnnotation.viewCreator())) {
// IsViewCreator interface!
if (!this.processorUtils.extendsClassOrInterface(this.processingEnvironment.getTypeUtils(), typeElement.asType(), this.processingEnvironment.getElementUtils().getTypeElement(IsViewCreator.class.getCanonicalName()).asType())) {
throw new ProcessorException(typeElement.getSimpleName().toString() + ": @Presenter must implement the IsViewCreator interface");
}
// check, if the viewCreator has a generic parameter
if (!this.processorUtils.supertypeHasGeneric(this.processingEnvironment.getTypeUtils(), typeElement.asType(), this.processingEnvironment.getElementUtils().getTypeElement(IsViewCreator.class.getCanonicalName()).asType())) {
throw new ProcessorException(typeElement.getSimpleName().toString() + ": IsViewCreator interface needs " + "a generic parameter (add: >>" + viewInterfaceTypeElement.toString() + "<< as generic to IsViewCreator)");
} else {
TypeMirror isViewCreatorTypeMirror = this.processorUtils.getFlattenedSupertype(this.processingEnvironment.getTypeUtils(), typeElement.asType(), this.processingEnvironment.getElementUtils().getTypeElement(IsViewCreator.class.getCanonicalName()).asType());
ClassNameModel classNameModel = new ClassNameModel(viewInterfaceTypeElement.toString());
if (!isViewCreatorTypeMirror.toString().contains(classNameModel.getSimpleName())) {
throw new ProcessorException(typeElement.getSimpleName().toString() + ": IsViewCreator interface only allows the generic parameter -> " + viewInterfaceTypeElement.toString());
}
}
} else if (Presenter.VIEW_CREATION_METHOD.FRAMEWORK.equals(presenterAnnotation.viewCreator())) {
// check, if a presenter implements IsViewCreator, that the viewCreation method is set to PRESENTER!
if (this.processorUtils.extendsClassOrInterface(this.processingEnvironment.getTypeUtils(), typeElement.asType(), this.processingEnvironment.getElementUtils().getTypeElement(IsViewCreator.class.getCanonicalName()).asType())) {
throw new ProcessorException(typeElement.getSimpleName().toString() + ": the IsViewCreator interface can only be used in case of viewCreator = Presenter.VIEW_CREATION_METHOD.PRESENTER");
}
}
} else {
throw new ProcessorException("Mvp4g2Processor: @Presenter can only be used on a type (class)");
}
// TODo El Hoss: check, that @Event is only used inside a EventBus
}
use of com.github.mvp4g.mvp4g2.core.eventbus.annotation.EventBus in project mvp4g2 by mvp4g.
the class ApplicationTest method testApplicationAnnotationWithoutEventBusAttribute.
@Test
public void testApplicationAnnotationWithoutEventBusAttribute() {
Compilation compilation = javac().withProcessors(new Mvp4g2Processor()).compile(new ArrayList<JavaFileObject>() {
{
add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/application/applicationAnnotationWithoutEventBusAttribute/ApplicationAnnotationWithoutEventBusAttribute.java"));
}
});
CompilationSubject.assertThat(compilation).failed();
CompilationSubject.assertThat(compilation).hadErrorContaining("is missing a default value for the element 'eventBus");
}
use of com.github.mvp4g.mvp4g2.core.eventbus.annotation.EventBus in project mvp4g2 by mvp4g.
the class StartEventTest method testStartEventTestEventBusWithMoreThanOneStartAnnotation.
@Test
public void testStartEventTestEventBusWithMoreThanOneStartAnnotation() {
Compilation compilation = javac().withProcessors(new Mvp4g2Processor()).compile(new ArrayList<JavaFileObject>() {
{
add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/event/startEventTestEventBusWithMoreThanOneStartAnnotation/StartEventTestEventBusWithMoreThanOneStartAnnotation.java"));
}
});
CompilationSubject.assertThat(compilation).failed();
CompilationSubject.assertThat(compilation).hadErrorContaining("@Start-annotation can only be used a single time in a eventbus interface");
}
use of com.github.mvp4g.mvp4g2.core.eventbus.annotation.EventBus in project mvp4g2 by mvp4g.
the class DebugTest method testDebugAnnotationWithoutExtendsIsEventBus.
@Test
public void testDebugAnnotationWithoutExtendsIsEventBus() {
Compilation compilation = javac().withProcessors(new Mvp4g2Processor()).compile(new ArrayList<JavaFileObject>() {
{
add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventbus/debugAnnotationWithoutExtendsIsEventBus/DebugAnnotationWithoutExtendsIsEventBus.java"));
}
});
CompilationSubject.assertThat(compilation).failed();
CompilationSubject.assertThat(compilation).hadErrorContaining("@Debug can only be used with an interfaces annotated with @EventBus");
}
Aggregations