7: Create FormatterProvider
This commit is contained in:
@@ -8,6 +8,7 @@ import com.bartek.esa.core.di.PluginModule;
|
|||||||
import com.bartek.esa.decompiler.di.DecompilerModule;
|
import com.bartek.esa.decompiler.di.DecompilerModule;
|
||||||
import com.bartek.esa.dispatcher.di.DispatcherModule;
|
import com.bartek.esa.dispatcher.di.DispatcherModule;
|
||||||
import com.bartek.esa.file.di.FileModule;
|
import com.bartek.esa.file.di.FileModule;
|
||||||
|
import com.bartek.esa.formatter.di.FormatterModule;
|
||||||
import dagger.Component;
|
import dagger.Component;
|
||||||
|
|
||||||
@Component(modules = {
|
@Component(modules = {
|
||||||
@@ -17,7 +18,8 @@ import dagger.Component;
|
|||||||
DecompilerModule.class,
|
DecompilerModule.class,
|
||||||
CoreModule.class,
|
CoreModule.class,
|
||||||
PluginModule.class,
|
PluginModule.class,
|
||||||
AnalyserModule.class
|
AnalyserModule.class,
|
||||||
|
FormatterModule.class
|
||||||
})
|
})
|
||||||
public interface DependencyInjector {
|
public interface DependencyInjector {
|
||||||
EsaMain esa();
|
EsaMain esa();
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.bartek.esa.formatter.di;
|
|||||||
import com.bartek.esa.core.desc.provider.DescriptionProvider;
|
import com.bartek.esa.core.desc.provider.DescriptionProvider;
|
||||||
import com.bartek.esa.formatter.formatter.ColorFormatter;
|
import com.bartek.esa.formatter.formatter.ColorFormatter;
|
||||||
import com.bartek.esa.formatter.formatter.SimpleFormatter;
|
import com.bartek.esa.formatter.formatter.SimpleFormatter;
|
||||||
|
import com.bartek.esa.formatter.provider.FormatterProvider;
|
||||||
import dagger.Module;
|
import dagger.Module;
|
||||||
import dagger.Provides;
|
import dagger.Provides;
|
||||||
|
|
||||||
@@ -18,4 +19,9 @@ public class FormatterModule {
|
|||||||
public ColorFormatter colorFormatter(DescriptionProvider descriptionProvider) {
|
public ColorFormatter colorFormatter(DescriptionProvider descriptionProvider) {
|
||||||
return new ColorFormatter(descriptionProvider);
|
return new ColorFormatter(descriptionProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
public FormatterProvider formatterProvider(SimpleFormatter simpleFormatter, ColorFormatter colorFormatter) {
|
||||||
|
return new FormatterProvider(simpleFormatter, colorFormatter);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.bartek.esa.formatter.provider;
|
||||||
|
|
||||||
|
import com.bartek.esa.cli.model.CliArgsOptions;
|
||||||
|
import com.bartek.esa.formatter.archetype.Formatter;
|
||||||
|
import com.bartek.esa.formatter.formatter.ColorFormatter;
|
||||||
|
import com.bartek.esa.formatter.formatter.SimpleFormatter;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
public class FormatterProvider {
|
||||||
|
private final SimpleFormatter simpleFormatter;
|
||||||
|
private final ColorFormatter colorFormatter;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public FormatterProvider(SimpleFormatter simpleFormatter, ColorFormatter colorFormatter) {
|
||||||
|
this.simpleFormatter = simpleFormatter;
|
||||||
|
this.colorFormatter = colorFormatter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Formatter provide(CliArgsOptions options) {
|
||||||
|
return options.isColor() ? colorFormatter : simpleFormatter;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user