Skip to content

Commit

Permalink
Validation of FrameworkTypesReturn for @BINDS. Fixes #24
Browse files Browse the repository at this point in the history
  • Loading branch information
thsaravana committed May 26, 2020
1 parent a528638 commit 96da93b
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ object BindsProblem : Problem {
this += method.validateMultipleScope(range, "@Binds methods cannot use more than one @Scope %s")
this += method.validateMultipleQualifier(range, "@Binds methods may not use more than one @Qualifier %s")
this += method.validateVoidReturn(range, "@Binds methods must return a value (not void)")
this += method.validateFrameworkTypesReturn(range, "@Binds methods must not return framework types %s")
}
}
}
40 changes: 40 additions & 0 deletions src/test/testData/binds/FrameworkTypeReturn/FrameworkTypes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import javax.inject.Inject;
import dagger.Module;
import dagger.Provides;
import dagger.Binds;
import assets.Car;
import assets.CarImpl;
import dagger.Lazy;
import dagger.MembersInjector;
import javax.inject.Provider;

@Module
public abstract class FrameworkTypes {

@<error descr="@Binds methods must not return framework types [Lazy]">Binds</error>
public abstract Lazy lazyReturn(CarImpl car);

@<error descr="@Binds methods must not return framework types [Lazy]">Binds</error>
public abstract Lazy<?> lazyWildReturn(CarImpl car);

@<error descr="@Binds methods must not return framework types [Lazy]">Binds</error>
public abstract Lazy<Car> lazyWrappedReturn(CarImpl car);

@<error descr="@Binds methods must not return framework types [Provider]">Binds</error>
public abstract Provider providerReturn(CarImpl car);

@<error descr="@Binds methods must not return framework types [Provider]">Binds</error>
public abstract Provider<?> providerWildReturn(CarImpl car);

@<error descr="@Binds methods must not return framework types [Provider]">Binds</error>
public abstract Provider<Car> providerWrappedReturn(CarImpl car);

@<error descr="@Binds methods must not return framework types [MembersInjector]">Binds</error>
public abstract MembersInjector membersInjectorReturn(CarImpl car);

@<error descr="@Binds methods must not return framework types [MembersInjector]">Binds</error>
public abstract MembersInjector<?> membersInjectorWildReturn(CarImpl car);

@<error descr="@Binds methods must not return framework types [MembersInjector]">Binds</error>
public abstract MembersInjector<Car> membersInjectorWrappedReturn(CarImpl car);
}
31 changes: 31 additions & 0 deletions src/test/testData/binds/FrameworkTypeReturn/KFailureComponent.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import javax.inject.Inject
import dagger.Module
import dagger.Provides
import dagger.Binds
import assets.Car
import assets.CarImpl
import dagger.Lazy
import dagger.MembersInjector
import javax.inject.Provider

@Module
abstract class KFrameworkTypes {

@<error descr="@Binds methods must not return framework types [Lazy]">Binds</error>
abstract fun lazyWildReturn(car: CarImpl): Lazy<*>

@<error descr="@Binds methods must not return framework types [Lazy]">Binds</error>
abstract fun lazyWrappedReturn(car: CarImpl): Lazy<Car>

@<error descr="@Binds methods must not return framework types [Provider]">Binds</error>
abstract fun providerWildReturn(car: CarImpl): Provider<*>

@<error descr="@Binds methods must not return framework types [Provider]">Binds</error>
abstract fun providerWrappedReturn(car: CarImpl): Provider<Car>

@<error descr="@Binds methods must not return framework types [MembersInjector]">Binds</error>
abstract fun membersInjectorWildReturn(car: CarImpl): MembersInjector<*>

@<error descr="@Binds methods must not return framework types [MembersInjector]">Binds</error>
abstract fun membersInjectorWrappedReturn(car: CarImpl): MembersInjector<Car>
}
31 changes: 31 additions & 0 deletions src/test/testData/binds/FrameworkTypeReturn/KSuccessComponent.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import javax.inject.Inject
import dagger.Module
import dagger.Provides
import dagger.Binds
import assets.Car
import assets.CarImpl
import dagger.Lazy
import dagger.MembersInjector
import javax.inject.Provider

@Module
abstract class KWrappedFrameworkTypes {

@Binds
abstract fun lazyWildReturn(car: CarImpl): Set<Lazy<*>>

@Binds
abstract fun lazyWrappedReturn(car: CarImpl): Set<Lazy<Car>>

@Binds
abstract fun providerWildReturn(car: CarImpl): Set<Provider<*>>

@Binds
abstract fun providerWrappedReturn(car: CarImpl): Set<Provider<Car>>

@Binds
abstract fun membersInjectorWildReturn(car: CarImpl): Set<MembersInjector<*>>

@Binds
abstract fun membersInjectorWrappedReturn(car: CarImpl): Set<MembersInjector<Car>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import javax.inject.Inject;
import dagger.Module;
import dagger.Provides;
import dagger.Binds;
import assets.Car;
import assets.CarImpl;
import dagger.Lazy;
import dagger.MembersInjector;
import javax.inject.Provider;
import java.util.Set;

@Module
public abstract class WrappedFrameworkTypes {

@Binds
public abstract Set<Lazy> lazyReturn(CarImpl car);

@Binds
public abstract Set<Lazy<?>> lazyWildReturn(CarImpl car);

@Binds
public abstract Set<Lazy<Car>> lazyWrappedReturn(CarImpl car);

@Binds
public abstract Set<Provider> providerReturn(CarImpl car);

@Binds
public abstract Set<Provider<?>> providerWildReturn(CarImpl car);

@Binds
public abstract Set<Provider<Car>> providerWrappedReturn(CarImpl car);

@Binds
public abstract Set<MembersInjector> membersInjectorReturn(CarImpl car);

@Binds
public abstract Set<MembersInjector<?>> membersInjectorWildReturn(CarImpl car);

@Binds
public abstract Set<MembersInjector<Car>> membersInjectorWrappedReturn(CarImpl car);
}

0 comments on commit 96da93b

Please sign in to comment.