use of com.github.mvp4g.mvp4g2.core.ui.annotation.Presenter in project mvp4g2 by mvp4g.
the class PresenterTest method testPresenterNotExtendingAbstractPresenter.
@Test
public void testPresenterNotExtendingAbstractPresenter() {
Compilation compilation = javac().withProcessors(new Mvp4g2Processor()).compile(new ArrayList<JavaFileObject>() {
{
add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterAnnotationNotExtendingAbstractPresenter/PresenterAnnotationNotExtendingAbstractPresenter.java"));
}
});
CompilationSubject.assertThat(compilation).failed();
CompilationSubject.assertThat(compilation).hadErrorContaining("@Presenter must extend AbstractPresenter.class");
}
use of com.github.mvp4g.mvp4g2.core.ui.annotation.Presenter in project mvp4g2 by mvp4g.
the class PresenterTest method testPresenterWithWrongImplementation01.
@Test
public void testPresenterWithWrongImplementation01() {
Compilation compilation = javac().withProcessors(new Mvp4g2Processor()).compile(new ArrayList<JavaFileObject>() {
{
add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterWithWrongImplementation01/EventBusHandlerWithNotImplementedEvent.java"));
add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterWithWrongImplementation01/MockShellPresenter01.java"));
add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterWithWrongImplementation01/IMockShellView01.java"));
add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterWithWrongImplementation01/MockShellView01.java"));
}
});
CompilationSubject.assertThat(compilation).failed();
CompilationSubject.assertThat(compilation).hadErrorContaining("event >>doSomething()<< is never handled by a presenter or handler");
}
use of com.github.mvp4g.mvp4g2.core.ui.annotation.Presenter in project mvp4g2 by mvp4g.
the class PresenterTest method testPresenterIsShellAndIsMultipleNotOk.
// a shell presenter can not implement is multiple!
@Test
public void testPresenterIsShellAndIsMultipleNotOk() {
Compilation compilation = javac().withProcessors(new Mvp4g2Processor()).compile(new ArrayList<JavaFileObject>() {
{
add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterIsShellAndIsMultipleNotOk/EventBusPresenterIsShellAndIsMultipleNotOk.java"));
add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterIsShellAndIsMultipleNotOk/MockShellPresenter01.java"));
add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterIsShellAndIsMultipleNotOk/IMockShellView01.java"));
add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterIsShellAndIsMultipleNotOk/MockShellView01.java"));
}
});
CompilationSubject.assertThat(compilation).failed();
CompilationSubject.assertThat(compilation).hadErrorContaining("IsShell interface can not be used on a presenter which is defiend as multiple = true");
}
use of com.github.mvp4g.mvp4g2.core.ui.annotation.Presenter in project mvp4g2 by mvp4g.
the class PresenterTest method testPresenterAnnotationAnnotatedOnAbstractClass.
@Test
public void testPresenterAnnotationAnnotatedOnAbstractClass() {
Compilation compilation = javac().withProcessors(new Mvp4g2Processor()).compile(new ArrayList<JavaFileObject>() {
{
add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterAnnotationAnnotatedOnAbstractClass" + "/PresenterAnnotationAnnotatedOnAbstractClass.java"));
}
});
CompilationSubject.assertThat(compilation).failed();
CompilationSubject.assertThat(compilation).hadErrorContaining("@Presenter can not be ABSTRACT");
}
use of com.github.mvp4g.mvp4g2.core.ui.annotation.Presenter in project mvp4g2 by mvp4g.
the class PresenterGenerator method generate.
public void generate(PresenterMetaModel metaModel) throws ProcessorException {
ClassName presenterrMetaDataClassName = ClassName.get(PresenterMetaData.class);
ClassName presenterMetaDataKindClassName = ClassName.get(HandlerMetaData.Kind.class);
ClassName presenterViewCreationMethodClassName = ClassName.get(Presenter.VIEW_CREATION_METHOD.class);
for (String presenter : metaModel.getPresenterKeys()) {
// check if element is existing (to avoid generating code for deleted items)
if (this.processorUtils.doesExist(new ClassNameModel(presenter))) {
PresenterMetaModel.PresenterData data = metaModel.getPresenterData(presenter);
String className = this.processorUtils.createFullClassName(data.getPresenter().getPackage(), data.getPresenter().getSimpleName() + ProcessorConstants.META_DATA);
TypeSpec.Builder typeSpec = TypeSpec.classBuilder(this.processorUtils.setFirstCharacterToUpperCase(className)).superclass(ParameterizedTypeName.get(presenterrMetaDataClassName, data.getPresenter().getTypeName(), data.getViewInterface().getTypeName())).addModifiers(Modifier.PUBLIC, Modifier.FINAL);
// constructor ...
MethodSpec.Builder constructor = MethodSpec.constructorBuilder().addModifiers(Modifier.PUBLIC).addStatement("super($S, $T.PRESENTER, $N, $T.$L)", data.getPresenter().getClassName(), presenterMetaDataKindClassName, data.getIsMultiple(), presenterViewCreationMethodClassName, data.getViewCreationMethod());
if (!metaModel.getPresenterData(presenter).isMultiple()) {
constructor.addStatement("super.presenter = new $T()", data.getPresenter().getTypeName());
if (Presenter.VIEW_CREATION_METHOD.FRAMEWORK.toString().equals(data.getViewCreationMethod())) {
constructor.addStatement("super.view = ($T) new $T()", data.getViewInterface().getTypeName(), data.getViewClass().getTypeName());
} else {
constructor.addStatement("super.view = presenter.createView()");
}
}
typeSpec.addMethod(constructor.build());
JavaFile javaFile = JavaFile.builder(data.getPresenter().getPackage(), typeSpec.build()).build();
try {
javaFile.writeTo(this.processingEnvironment.getFiler());
} catch (IOException e) {
throw new ProcessorException("Unable to write generated file: >>" + data.getPresenter().getSimpleName() + ProcessorConstants.META_DATA + "<< -> exception: " + e.getMessage());
}
}
}
}
Aggregations