use of com.github.mvp4g.mvp4g2.processor.ProcessorException in project mvp4g2 by mvp4g.
the class ApplicationAnnotationScanner method scan.
public ApplicationMetaModel scan(RoundEnvironment roundEnvironment) throws ProcessorException {
// First we try to read an already created resource ...
ApplicationMetaModel model = this.restore();
// Check if we have an element annotated with @Application
if (!roundEnvironment.getElementsAnnotatedWith(Application.class).isEmpty()) {
// check, whether we have o do something ...
ApplicationAnnotationValidator validator = ApplicationAnnotationValidator.builder().roundEnvironment(roundEnvironment).processingEnvironment(this.processingEnvironment).build();
validator.validate();
// should only be one, so we can search for the first! ...
Optional<? extends Element> optionalElement = this.roundEnvironment.getElementsAnnotatedWith(Application.class).stream().findFirst();
if (optionalElement.isPresent()) {
Element applicationAnnotationElement = optionalElement.get();
validator.validate(applicationAnnotationElement);
Application applicationAnnotation = applicationAnnotationElement.getAnnotation(Application.class);
if (!isNull(applicationAnnotation)) {
TypeElement eventBusTypeElement = this.getEventBusTypeElement(applicationAnnotation);
TypeElement applicationLoaderTypeElement = this.getApplicationLoaderTypeElement(applicationAnnotation);
model = new ApplicationMetaModel(applicationAnnotationElement.toString(), isNull(eventBusTypeElement) ? "" : eventBusTypeElement.toString(), isNull(applicationLoaderTypeElement) ? "" : applicationLoaderTypeElement.toString(), String.valueOf(applicationAnnotation.historyOnStart()));
// let's store the updated model
this.processorUtils.store(model, this.createRelativeFileName());
}
}
}
return model;
}
use of com.github.mvp4g.mvp4g2.processor.ProcessorException in project mvp4g2 by mvp4g.
the class DebugAnnotationScanner method scan.
public EventBusMetaModel scan(RoundEnvironment roundEnvironment) throws ProcessorException {
// do validation
DebugAnnotationValidator.builder().roundEnvironment(roundEnvironment).processingEnvironment(processingEnvironment).build().validate();
// handle debug-annotation
Debug debugAnnotation = eventBusTypeElement.getAnnotation(Debug.class);
if (!isNull(debugAnnotation)) {
this.eventBusMetaModel.setHasDebugAnnotation("true");
this.eventBusMetaModel.setDebugLogLevel(debugAnnotation.logLevel().toString());
if (!isNull(getLogger(debugAnnotation))) {
this.eventBusMetaModel.setDebugLogger(getLogger(debugAnnotation).getQualifiedName().toString());
}
} else {
this.eventBusMetaModel.setHasDebugAnnotation("false");
this.eventBusMetaModel.setDebugLogLevel("");
this.eventBusMetaModel.setDebugLogger("");
}
return this.eventBusMetaModel;
}
use of com.github.mvp4g.mvp4g2.processor.ProcessorException in project mvp4g2 by mvp4g.
the class HistoryAnnotationScanner method scan.
public HistoryMetaModel scan(RoundEnvironment roundEnvironment) throws ProcessorException {
// First we try to read an already created resource ...
HistoryMetaModel model = this.restore();
// Check if we have an element annotated with @Application
if (!roundEnvironment.getElementsAnnotatedWith(History.class).isEmpty()) {
// check annotation ...
HistoryAnnotationValidator validator = HistoryAnnotationValidator.builder().roundEnvironment(roundEnvironment).processingEnvironment(this.processingEnvironment).build();
// iterate over all history converters
for (Element element : roundEnvironment.getElementsAnnotatedWith(History.class)) {
// validate
validator.validate(element);
// process ...
TypeElement typeElement = (TypeElement) element;
History historyAnnotation = typeElement.getAnnotation(History.class);
validator.validate(element);
model.add(typeElement.getQualifiedName().toString(), historyAnnotation.type().toString());
}
// let's store the updated model
this.processorUtils.store(model, this.createRelativeFileName());
}
return model;
}
use of com.github.mvp4g.mvp4g2.processor.ProcessorException in project mvp4g2 by mvp4g.
the class PresenterAnnotationScanner method scan.
public PresenterMetaModel scan(RoundEnvironment roundEnvironment) throws ProcessorException {
// Validator
PresenterAnnotationValidator validator = PresenterAnnotationValidator.builder().processingEnvironment(processingEnvironment).build();
// read all already created model
PresenterMetaModel model = this.restore();
// iterate over Presenter
for (Element element : roundEnvironment.getElementsAnnotatedWith(Presenter.class)) {
TypeElement typeElement = (TypeElement) element;
// validate
validator.validate(typeElement, this.getViewClassTypeElement(typeElement.getAnnotation(Presenter.class)), this.getViewInterfaceTypeElement(typeElement.getAnnotation(Presenter.class)));
// update model
model.add(((TypeElement) element).getQualifiedName().toString(), typeElement.getAnnotation(Presenter.class).multiple() ? "true" : "false", this.processorUtils.extendsClassOrInterface(this.processingEnvironment.getTypeUtils(), typeElement.asType(), this.processingEnvironment.getElementUtils().getTypeElement(IsShell.class.getCanonicalName()).asType()) ? "true" : "false", this.getViewClassTypeElement(element.getAnnotation(Presenter.class)).getQualifiedName().toString(), this.getViewInterfaceTypeElement(element.getAnnotation(Presenter.class)).getQualifiedName().toString(), typeElement.getAnnotation(Presenter.class).viewCreator().toString(), this.processorUtils.createHandledEventArray(typeElement));
}
// let's store the updated model
this.processorUtils.store(model, this.createRelativeFileName());
return model;
}
use of com.github.mvp4g.mvp4g2.processor.ProcessorException in project mvp4g2 by mvp4g.
the class ApplicationGenerator method generate.
public void generate(ApplicationMetaModel metaModel) throws ProcessorException {
// check if element is existing (to avoid generating code for deleted items)
if (!this.processorUtils.doesExist(metaModel.getApplication())) {
return;
}
// generate code
TypeSpec.Builder typeSpec = TypeSpec.classBuilder(metaModel.getApplication().getSimpleName() + ApplicationGenerator.IMPL_NAME).superclass(ParameterizedTypeName.get(ClassName.get(AbstractApplication.class), metaModel.getEventBus().getTypeName())).addModifiers(Modifier.PUBLIC, Modifier.FINAL).addSuperinterface(metaModel.getApplication().getTypeName());
// constructor ...
MethodSpec constructor = MethodSpec.constructorBuilder().addModifiers(Modifier.PUBLIC).addStatement("super()").addStatement("super.eventBus = new $N.$N()", metaModel.getEventBus().getPackage(), metaModel.getEventBus().getSimpleName() + ApplicationGenerator.IMPL_NAME).addStatement("super.historyOnStart = $L", metaModel.getHistoryOnStart()).build();
typeSpec.addMethod(constructor);
// method "getApplicaitonLoader"
MethodSpec getApplicaitonLaoderMethod = MethodSpec.methodBuilder("getApplicationLoader").addModifiers(Modifier.PUBLIC).addAnnotation(Override.class).returns(IsApplicationLoader.class).addStatement("return new $T()", metaModel.getLoader().getTypeName()).build();
typeSpec.addMethod(getApplicaitonLaoderMethod);
JavaFile javaFile = JavaFile.builder(metaModel.getEventBus().getPackage(), typeSpec.build()).build();
try {
javaFile.writeTo(this.processingEnvironment.getFiler());
} catch (IOException e) {
throw new ProcessorException("Unable to write generated file: >>" + metaModel.getEventBus().getSimpleName() + ApplicationGenerator.IMPL_NAME + "<< -> exception: " + e.getMessage());
}
}
Aggregations