Skip to content

Commit

Permalink
Validation for MultipleQualifiers for @BINDS. Fixes #22
Browse files Browse the repository at this point in the history
  • Loading branch information
thsaravana committed May 26, 2020
1 parent 18d06fa commit 2e91b34
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ object BindsProblem : Problem {
this += method.validateTypeParameter(range, "@Binds methods may not have type parameters")
val isAbstractErrors =
method.validateMustBeAbstractMethod(range, "@Binds methods needs to be abstract")
this += isAbstractErrors
if (isAbstractErrors.isEmpty()) {
this += method.validatePrivateMethod(range, "@Binds methods cannot be private")
}
this += isAbstractErrors
this += method.validateCheckedExceptionMethod(range, "@Binds methods may only throw unchecked exceptions. %s not allowed")
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")
}
}
}
19 changes: 19 additions & 0 deletions src/test/testData/binds/MultipleQualifiers/KFailureComponent.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import javax.inject.Inject
import dagger.Module
import dagger.Provides
import dagger.Binds
import assets.Car
import assets.CarImpl
import javax.inject.Singleton
import javax.inject.Named
import assets.PrimaryScope
import assets.PrimaryQualifier

@Module
abstract class KMultipleQualifier {

@PrimaryQualifier
@Named
@<error descr="@Binds methods may not use more than one @Qualifier [@PrimaryQualifier, @Named]">Binds</error>
abstract fun getCar(car: CarImpl): Car
}
18 changes: 18 additions & 0 deletions src/test/testData/binds/MultipleQualifiers/KSuccessComponent.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import javax.inject.Inject
import dagger.Module
import dagger.Provides
import dagger.Binds
import assets.Car
import assets.CarImpl
import javax.inject.Singleton
import javax.inject.Named
import assets.PrimaryScope
import assets.PrimaryQualifier

@Module
abstract class KSingleQualifier {

@PrimaryQualifier
@Binds
abstract fun getCar(car: CarImpl): Car
}
19 changes: 19 additions & 0 deletions src/test/testData/binds/MultipleQualifiers/MultipleQualifier.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import javax.inject.Inject;
import dagger.Module;
import dagger.Provides;
import dagger.Binds;
import assets.Car;
import assets.CarImpl;
import javax.inject.Singleton;
import javax.inject.Named;
import assets.PrimaryScope;
import assets.PrimaryQualifier;

@Module
public abstract class MultipleQualifier {

@PrimaryQualifier
@Named
@<error descr="@Binds methods may not use more than one @Qualifier [@PrimaryQualifier, @Named]">Binds</error>
public abstract Car getCar(CarImpl car);
}
18 changes: 18 additions & 0 deletions src/test/testData/binds/MultipleQualifiers/SingleQualifier.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import javax.inject.Inject;
import dagger.Module;
import dagger.Provides;
import dagger.Binds;
import assets.Car;
import assets.CarImpl;
import javax.inject.Singleton;
import javax.inject.Named;
import assets.PrimaryScope;
import assets.PrimaryQualifier;

@Module
public abstract class SingleQualifier {

@PrimaryQualifier
@Binds
public abstract Car getCar(CarImpl car);
}

0 comments on commit 2e91b34

Please sign in to comment.