Skip to content

Commit

Permalink
tweaks and enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
vegegoku committed Jul 3, 2024
1 parent a1099e2 commit 5b2a01d
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void register(StartupTask task) {
}

public void register(RoutingTask task) {
LOGGER.info("Registering routing task");
LOGGER.info("Registering routing task : " + task.getClass().getCanonicalName());
}

public void init(Map<String, String> config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.dominokit.brix.annotations.BrixRoutingTask;
import org.dominokit.brix.annotations.BrixTask;
import org.dominokit.brix.api.RoutingTask;
import org.dominokit.brix.api.StartupTask;
Expand All @@ -30,8 +29,7 @@ public class BrixModule extends BrixModuleAdapter {
private final Set<RoutingTask> routingTasks;

@Inject
public BrixModule(
@BrixTask Set<StartupTask> startupTasks, @BrixRoutingTask Set<RoutingTask> routingTasks) {
public BrixModule(@BrixTask Set<StartupTask> startupTasks, Set<RoutingTask> routingTasks) {
this.startupTasks = startupTasks;
this.routingTasks = routingTasks;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public abstract class Presenter<V extends Viewable>
private final Set<RegistrationRecord> registeredSlots = new HashSet<>();
protected V view;
private Set<ChildListener> childListeners = new HashSet<>();
private boolean reveled;

public Presenter() {
LOGGER.info("Presenter [" + this + "] have been created.");
Expand Down Expand Up @@ -120,6 +121,7 @@ protected void postConstruct() {

private void onAttached() {
LOGGER.info("Presenter [" + this + "] : Attached.");
this.reveled = true;
registerSlots();
onRevealed();
onReady();
Expand All @@ -143,6 +145,8 @@ private void onDetached() {
if (active) {
deactivate();
}

this.reveled = false;
}

protected boolean isAutoReveal() {
Expand Down Expand Up @@ -338,6 +342,10 @@ public final void setRoutingState(DominoHistory.State state) {
}
}

public boolean isReveled() {
return reveled;
}

public void setState() {}

void registerChildListener(ChildListener listener) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.dominokit.brix.annotations.BrixRoutingTask;
import org.dominokit.brix.annotations.BrixTask;
import org.dominokit.brix.api.RoutingTask;
import org.dominokit.brix.api.StartupTask;
Expand All @@ -30,8 +29,7 @@ public class BrixModule extends BrixModuleAdapter {
private final Set<RoutingTask> routingTasks;

@Inject
public BrixModule(
@BrixTask Set<StartupTask> startupTasks, @BrixRoutingTask Set<RoutingTask> routingTasks) {
public BrixModule(@BrixTask Set<StartupTask> startupTasks, Set<RoutingTask> routingTasks) {
this.startupTasks = startupTasks;
this.routingTasks = routingTasks;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import dagger.Module;
import dagger.multibindings.IntoSet;
import javax.inject.Singleton;
import org.dominokit.brix.annotations.BrixRoutingTask;
import org.dominokit.brix.api.RoutingTask;
import org.dominokit.brix.presenters.ChildPresenterRouting;
import org.dominokit.brix.presenters.ChildUiHandlers;
Expand All @@ -40,12 +39,10 @@ public interface MVPModule {
@Singleton
@Binds
@IntoSet
@BrixRoutingTask
RoutingTask testRoutingTask(TestPresenterRouting routing);

@Singleton
@Binds
@IntoSet
@BrixRoutingTask
RoutingTask childRoutingTask(ChildPresenterRouting routing);
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
import org.dominokit.brix.annotations.BrixModule;
import org.dominokit.brix.annotations.BrixPresenter;
import org.dominokit.brix.annotations.BrixRoute;
import org.dominokit.brix.annotations.BrixRoutingTask;
import org.dominokit.brix.annotations.BrixSlot;
import org.dominokit.brix.annotations.BrixTask;
import org.dominokit.brix.annotations.FragmentParameter;
Expand Down Expand Up @@ -478,33 +477,38 @@ private void generateSlotMethod(Element presenter, TypeSpec.Builder presenterBui
private void generateUiHandlers(Element presenter, TypeSpec.Builder presenterBuilder) {
List<Element> methods = sourceUtil.getAnnotatedMethods(presenter.asType(), UiHandler.class);

String name = presenter.getSimpleName().toString() + "UiHandlers";
TypeSpec.Builder builder = TypeSpec.interfaceBuilder(name).addModifiers(Modifier.PUBLIC);
methods.stream()
.map(element -> (ExecutableElement) element)
.forEach(
method -> {
MethodSpec.Builder interfaceMethod =
MethodSpec.methodBuilder(method.getSimpleName().toString())
.addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
.returns(TypeName.get(method.getReturnType()));

method
.getParameters()
.forEach(
variableElement -> {
interfaceMethod.addParameter(
ParameterSpec.builder(
TypeName.get(variableElement.asType()),
variableElement.getSimpleName().toString())
.build());
});
builder.addMethod(interfaceMethod.build());
});
processingEnv
.getMessager()
.printMessage(Diagnostic.Kind.NOTE, "======= > Writing uiHandlers : " + name);
writeFile(builder.build(), presenter);
if (!methods.isEmpty()) {
String name = presenter.getSimpleName().toString() + "UiHandlers";
TypeSpec.Builder builder =
TypeSpec.interfaceBuilder(name)
.addModifiers(Modifier.PUBLIC)
.addSuperinterface(UiHandlers.class);
methods.stream()
.map(element -> (ExecutableElement) element)
.forEach(
method -> {
MethodSpec.Builder interfaceMethod =
MethodSpec.methodBuilder(method.getSimpleName().toString())
.addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
.returns(TypeName.get(method.getReturnType()));

method
.getParameters()
.forEach(
variableElement -> {
interfaceMethod.addParameter(
ParameterSpec.builder(
TypeName.get(variableElement.asType()),
variableElement.getSimpleName().toString())
.build());
});
builder.addMethod(interfaceMethod.build());
});
processingEnv
.getMessager()
.printMessage(Diagnostic.Kind.NOTE, "======= > Writing uiHandlers : " + name);
writeFile(builder.build(), presenter);
}
}

private void collectAnnotatedMethods(
Expand Down Expand Up @@ -719,19 +723,28 @@ private void generateStateMethod(Element presenter, TypeSpec.Builder presenterBu
}

private void generatePresenterBinding(Element presenter, TypeSpec.Builder bindingModule) {

Set<? extends AnnotationMirror> qualifiers = getQualifiers(presenter);
sourceUtil
.findImplementedInterface(presenter, UiHandlers.class)
.ifPresent(
typeMirror -> {
ParameterSpec.Builder presenterParam =
ParameterSpec.builder(guessImpl(presenter, "Impl"), "impl");
qualifiers.forEach(
annotationMirror ->
presenterParam.addAnnotation(
ClassName.get(
(TypeElement) annotationMirror.getAnnotationType().asElement())));

MethodSpec.Builder bindMethod =
MethodSpec.methodBuilder(
sourceUtil.smallFirstLetter(presenter.getSimpleName().toString()))
.addAnnotation(Singleton.class)
.addAnnotation(Binds.class)
.addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
.returns(TypeName.get(typeMirror))
.addParameter(
ClassName.bestGuess(presenter.asType().toString() + "Impl"), "impl");
.addParameter(presenterParam.build());
getQualifiers(presenter)
.forEach(
annotationMirror ->
Expand All @@ -742,6 +755,14 @@ private void generatePresenterBinding(Element presenter, TypeSpec.Builder bindin
});
}

private ClassName guessImpl(Element element, String postfix) {
return ClassName.bestGuess(
elements().getPackageOf(element).getQualifiedName().toString()
+ "."
+ element.getSimpleName().toString()
+ postfix);
}

private void generateViewBinding(Element uiView, TypeSpec.Builder bindingModule) {
sourceUtil
.findImplementedInterface(uiView, Viewable.class)
Expand All @@ -754,8 +775,7 @@ private void generateViewBinding(Element uiView, TypeSpec.Builder bindingModule)
.addAnnotation(Binds.class)
.addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
.returns(TypeName.get(typeMirror))
.addParameter(
ClassName.bestGuess(uiView.asType().toString() + "_UiView"), "impl");
.addParameter(guessImpl(uiView, "_UiView"), "impl");

getQualifiers(uiView)
.forEach(
Expand Down Expand Up @@ -783,7 +803,7 @@ private void generateRoutingTask(Element presenter, TypeSpec.Builder bindingModu
TypeName.get(presenter.asType())));

ParameterSpec.Builder parentParam =
ParameterSpec.builder(ClassName.bestGuess(parentPresenter + "Impl"), "parent");
ParameterSpec.builder(guessImpl(types().asElement(parentPresenter), "Impl"), "parent");
Set<? extends AnnotationMirror> parentQualifiers =
getQualifiers(types().asElement(parentPresenter));
parentQualifiers.forEach(
Expand All @@ -795,12 +815,13 @@ private void generateRoutingTask(Element presenter, TypeSpec.Builder bindingModu
Set<? extends AnnotationMirror> qualifiers = getQualifiers(presenter);

ParameterSpec.Builder presenterParam =
ParameterSpec.builder(
ClassName.bestGuess(presenter.asType().toString() + "Impl"), "presenter");
ParameterSpec.builder(guessImpl(presenter, "Impl"), "presenter");
qualifiers.forEach(
annotationMirror -> {
presenterParam.addAnnotation(
ClassName.get((TypeElement) annotationMirror.getAnnotationType().asElement()));
routingTask.addAnnotation(
ClassName.get((TypeElement) annotationMirror.getAnnotationType().asElement()));
});

routingTask
Expand All @@ -818,21 +839,29 @@ private void generateRoutingTask(Element presenter, TypeSpec.Builder bindingModu
TypeSpec routingType = routingTask.build();
writeFile(routingType, presenter);

bindingModule.addMethod(
ParameterSpec.Builder parameter =
ParameterSpec.builder(guessImpl(presenter, "Routing"), "routing");

MethodSpec.Builder routingMethod =
MethodSpec.methodBuilder(
sourceUtil.smallFirstLetter(presenter.getSimpleName().toString() + "Routing"))
sourceUtil.smallFirstLetter(presenter.getSimpleName().toString() + "Routing"));

getQualifiers(presenter)
.forEach(
annotationMirror -> {
parameter.addAnnotation(
ClassName.get((TypeElement) annotationMirror.getAnnotationType().asElement()));
routingMethod.addAnnotation(
ClassName.get((TypeElement) annotationMirror.getAnnotationType().asElement()));
});

bindingModule.addMethod(
routingMethod
.addAnnotation(Singleton.class)
.addAnnotation(Binds.class)
.addAnnotation(IntoSet.class)
.addAnnotation(BrixRoutingTask.class)
.returns(RoutingTask.class)
.addParameter(
ClassName.bestGuess(
elements().getPackageOf(presenter).getQualifiedName().toString()
+ "."
+ presenter.getSimpleName().toString()
+ "Routing"),
"routing")
.addParameter(parameter.build())
.addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
.build());

Expand All @@ -844,14 +873,15 @@ private void generateRoutingTask(Element presenter, TypeSpec.Builder bindingModu
ClassName.get(AbstractRoutingTask.class), TypeName.get(presenter.asType())));

ParameterSpec.Builder presenterParam =
ParameterSpec.builder(
ClassName.bestGuess(presenter.asType().toString() + "Impl"), "presenter");
ParameterSpec.builder(guessImpl(presenter, "Impl"), "presenter");

Set<? extends AnnotationMirror> qualifiers = getQualifiers(presenter);
qualifiers.forEach(
annotationMirror -> {
presenterParam.addAnnotation(
ClassName.get((TypeElement) annotationMirror.getAnnotationType().asElement()));
routingTask.addAnnotation(
ClassName.get((TypeElement) annotationMirror.getAnnotationType().asElement()));
});

routingTask
Expand All @@ -872,21 +902,28 @@ private void generateRoutingTask(Element presenter, TypeSpec.Builder bindingModu
TypeSpec routingType = routingTask.build();
writeFile(routingType, presenter);

bindingModule.addMethod(
ParameterSpec.Builder parameter =
ParameterSpec.builder(guessImpl(presenter, "Routing"), "routing");

MethodSpec.Builder routingMethod =
MethodSpec.methodBuilder(
sourceUtil.smallFirstLetter(presenter.getSimpleName().toString() + "Routing"))
sourceUtil.smallFirstLetter(presenter.getSimpleName().toString() + "Routing"));
getQualifiers(presenter)
.forEach(
annotationMirror -> {
parameter.addAnnotation(
ClassName.get((TypeElement) annotationMirror.getAnnotationType().asElement()));
routingMethod.addAnnotation(
ClassName.get((TypeElement) annotationMirror.getAnnotationType().asElement()));
});

bindingModule.addMethod(
routingMethod
.addAnnotation(Singleton.class)
.addAnnotation(Binds.class)
.addAnnotation(IntoSet.class)
.addAnnotation(BrixRoutingTask.class)
.returns(RoutingTask.class)
.addParameter(
ClassName.bestGuess(
elements().getPackageOf(presenter).getQualifiedName().toString()
+ "."
+ presenter.getSimpleName().toString()
+ "Routing"),
"routing")
.addParameter(parameter.build())
.addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
.build());
}
Expand Down
Loading

0 comments on commit 5b2a01d

Please sign in to comment.