Skip to content

Commit

Permalink
Clean ups
Browse files Browse the repository at this point in the history
  • Loading branch information
IVIanuu committed Dec 31, 2017
1 parent 4901d8a commit 9f50422
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 39 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ buildscript {
autoCommon = 'com.google.auto:auto-common:0.8'
autoService = 'com.google.auto.service:auto-service:1.0-rc2'

autoValue = 'com.google.auto.value:auto-value:1.2'
autoValue = 'com.google.auto.value:auto-value:1.5'

javaPoet = 'com.squareup:javapoet:1.9.0'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import static javax.lang.model.util.ElementFilter.typesIn;

/**
* Finds android key registry
* Finds android key registry and contains a list of all supported map keys
*/
final class AndroidInjectKeyFinder implements BasicAnnotationProcessor.ProcessingStep {

Expand All @@ -46,8 +46,7 @@ final class AndroidInjectKeyFinder implements BasicAnnotationProcessor.Processin
private final Map<TypeMirror, TypeMirror> annotationsAndTypes = new HashMap<>();

AndroidInjectKeyFinder(Elements elements,
Messager messager,
Types types) {
Messager messager) {
this.elements = elements;
this.messager = messager;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,34 +53,21 @@
*/
@AutoValue
abstract class AndroidInjectorDescriptor {
/** The type to be injected; the return type of the {@link ContributesAndroidInjector} method. */

abstract ClassName injectedType();

/**
* The base framework type of {@link #injectedType()}, e.g. {@code Activity}, {@code Fragment},
* etc.
*/
abstract ClassName frameworkType();

/** Scopes to apply to the generated {@link dagger.Subcomponent}. */
abstract ImmutableSet<AnnotationSpec> scopes();

/** @see ContributesAndroidInjector#modules() */
abstract ImmutableSet<ClassName> modules();

/** The {@link Module} that contains the {@link ContributesAndroidInjector} method. */
abstract ClassName enclosingModule();

/** The map key **/
abstract ClassName mapKeyType();

/** Simple name of the {@link ContributesAndroidInjector} method. */
abstract String methodName();

/**
* The {@link dagger.MapKey} annotation that groups {@link #frameworkType()}s, e.g.
* {@code @ActivityKey(MyActivity.class)}.
*/
AnnotationSpec mapKeyAnnotation() {
return AnnotationSpec.builder(mapKeyType())
.addMember("value", "$T.class", injectedType())
Expand Down Expand Up @@ -117,10 +104,6 @@ static final class Validator {
this.keyFinder = keyFinder;
}

/**
* Validates a {@link ContributesAndroidInjector} method, returning an {@link
* AndroidInjectorDescriptor} if it is valid, or {@link Optional#empty()} otherwise.
*/
Optional<AndroidInjectorDescriptor> createIfValid(ExecutableElement method) {
ErrorReporter reporter = new ErrorReporter(method, messager);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,27 +113,12 @@ private void validateMethod(Class<? extends Annotation> annotation, ExecutableEl
method);
}

// @Binds methods should only have one parameter, but we can't guarantee the order of Processors
// in javac, so do a basic check for valid form
if (isAnnotationPresent(method, Binds.class) && method.getParameters().size() == 1) {
validateMapKeyMatchesBindsParameter(annotation, method);
}
}

/**
* A valid @Binds method could bind an {@link AndroidInjector.Factory} for one type, while giving
* it a map key of a different type. The return type and parameter type would pass typical @Binds
* validation, but the map lookup in {@link dagger.android.DispatchingAndroidInjector} would
* retrieve the wrong injector factory.
*
* <pre>{@code
* {@literal @Binds}
* {@literal @IntoMap}
* {@literal @ActivityKey(GreenActivity.class)}
* abstract AndroidInjector.Factory<? extends Activity> bindBlueActivity(
* BlueActivityComponent.Builder builder);
* }</pre>
*/

private void validateMapKeyMatchesBindsParameter(
Class<? extends Annotation> annotation, ExecutableElement method) {
TypeMirror parameterType = getOnlyElement(method.getParameters()).asType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected Iterable<? extends ProcessingStep> initSteps() {
Elements elements = processingEnv.getElementUtils();
Types types = processingEnv.getTypeUtils();

AndroidInjectKeyFinder keyFinder = new AndroidInjectKeyFinder(elements, messager, types);
AndroidInjectKeyFinder keyFinder = new AndroidInjectKeyFinder(elements, messager);

return ImmutableList.of(
keyFinder,
Expand Down

0 comments on commit 9f50422

Please sign in to comment.