Skip to content
Annotation library which create a decorator for interfaces that delegate any actions to an executor
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
executordecorator-android-arch-extensions
executordecorator-android-extensions
executordecorator-annotations
executordecorator-compiler
executordecorator-samples
gradle/wrapper
.gitignore
CHANGELOG.md
LICENSE.txt
README.md
build.gradle
gradlew
gradlew.bat
settings.gradle

README.md

Executor Decorator

Annotation library which create a decorator for interfaces that delegate any actions with a executor

Installation

With android gradle plugin:

provided 'com.nicolasmouchel:executordecorator-annotations:2.0'
annotationProcessor 'com.nicolasmouchel:executordecorator-compiler:2.0'

Usage

Annotate a method that return a interface and a *Decorator will be generated

Example

interface MyInterface {
    void method();
}
@ImmutableExecutorDecorator public MyInterface provideMyInterface() {
    ...
}

Will generate:

public final class MyInterfaceDecorator implements MyInterface {
    private final Executor executor;

    private final MyInterface decorated;

    public MyInterfaceDecorator(Executor executor, MyInterface decorated) {
        this.executor = executor;
        this.decorated = decorated;
    }

    @Override
    public void method() {
        executor.execute(new Runnable() {

            @Override()
            public void run() {
                decorated.method();
            }
        });
    }
}

If you are using Dagger, then you could decorate your MyInterface using Dagger Module:

class ImmutableModule {
    @ImmutableExecutorDecorator
    MyInterface provideMyInterface(Executor executor, MyInterfaceImpl impl) {
        return new MyInterfaceDecorator(executor, impl);
    }
}

For more example, look at the unit tests and the sample project.

Also

The decorator can be mutable: @MutableExecutorDecorator and with a WeakReference with @WeakExecutorDecorator

Migration from 1.0 to 2.0

ExecutorDecorator has been removed and must be replaced:

  • @ExecutorDecorator or @ExecutorDecorator(mutable = false) should be replaced by @ImmutableExecutorDecorator
  • @ExecutorDecorator(mutable = true) should be replaced by @MutableExecutorDecorator

If a project uses Kotlin with Dagger, a module can not provide generated classes. So now, MutableDecorator<T> can be provided and a TDecorator class will be generated, implementing both T and MutableDecorator<T> interfaces. A cast of MutableDecorator<T> to T can be done with method T asDecorated()

You can’t perform that action at this time.