Skip to content

Commit

Permalink
Remove ModuleAnnotation.annotationClass() as it relies on reflection …
Browse files Browse the repository at this point in the history
…on the processor classpath.

RELNOTES=n/a

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=274689900
  • Loading branch information
Chang-Eric authored and kluever committed Oct 15, 2019
1 parent 6f6a9d0 commit f5c773a
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 16 deletions.
7 changes: 5 additions & 2 deletions java/dagger/internal/codegen/base/ComponentAnnotation.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@
package dagger.internal.codegen.base;

import static com.google.auto.common.AnnotationMirrors.getAnnotationValue;
import static com.google.auto.common.MoreElements.asType;
import static com.google.auto.common.MoreTypes.asTypeElements;
import static com.google.auto.common.MoreTypes.isTypeOf;
import static dagger.internal.codegen.base.MoreAnnotationValues.asAnnotationValues;
import static dagger.internal.codegen.extension.DaggerStreams.toImmutableList;
import static dagger.internal.codegen.javapoet.TypeNames.PRODUCER_MODULE;
import static dagger.internal.codegen.langmodel.DaggerElements.getAnyAnnotation;

import com.google.auto.value.AutoValue;
import com.google.auto.value.extension.memoized.Memoized;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.squareup.javapoet.ClassName;
import dagger.Component;
import dagger.Subcomponent;
import dagger.producers.ProducerModule;
import dagger.producers.ProductionComponent;
import dagger.producers.ProductionSubcomponent;
import java.lang.annotation.Annotation;
Expand Down Expand Up @@ -288,7 +290,8 @@ public boolean isSubcomponent() {

@Override
public boolean isProduction() {
return moduleAnnotation().annotationClass().equals(ProducerModule.class);
return ClassName.get(asType(moduleAnnotation().annotation().getAnnotationType().asElement()))
.equals(PRODUCER_MODULE);
}

@Override
Expand Down
14 changes: 3 additions & 11 deletions java/dagger/internal/codegen/base/ModuleAnnotation.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,9 @@ public abstract class ModuleAnnotation {
// instance.
public abstract AnnotationMirror annotation();

/** The type of the annotation. */
@Memoized
public Class<?> annotationClass() {
try {
return Class.forName(
asTypeElement(annotation().getAnnotationType()).getQualifiedName().toString());
} catch (ClassNotFoundException e) {
AssertionError assertionError = new AssertionError();
assertionError.initCause(e);
throw assertionError;
}
/** The simple name of the annotation. */
public String annotationName() {
return annotation().getAnnotationType().asElement().getSimpleName().toString();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private String formatSubcomponentDeclaration(SubcomponentDeclaration subcomponen

return String.format(
"@%s(subcomponents = %s) for %s",
subcomponentDeclaration.moduleAnnotation().annotationClass().getSimpleName(),
subcomponentDeclaration.moduleAnnotation().annotationName(),
annotationValue,
subcomponentDeclaration.contributingModule().get());
}
Expand Down
2 changes: 2 additions & 0 deletions java/dagger/internal/codegen/javapoet/TypeNames.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import dagger.internal.SingleCheck;
import dagger.producers.Produced;
import dagger.producers.Producer;
import dagger.producers.ProducerModule;
import dagger.producers.internal.AbstractProducer;
import dagger.producers.internal.DependencyMethodProducer;
import dagger.producers.internal.MapOfProducedProducer;
Expand Down Expand Up @@ -74,6 +75,7 @@ public final class TypeNames {
public static final ClassName PRODUCED = ClassName.get(Produced.class);
public static final ClassName PRODUCER = ClassName.get(Producer.class);
public static final ClassName PRODUCERS = ClassName.get(Producers.class);
public static final ClassName PRODUCER_MODULE = ClassName.get(ProducerModule.class);
public static final ClassName PRODUCTION_COMPONENT_MONITOR_FACTORY =
ClassName.get(ProductionComponentMonitor.Factory.class);
public static final ClassName PROVIDER = ClassName.get(Provider.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@ protected Optional<TypeMirror> bindingElementType() {
private static String didYouMeanBinds(ModuleAnnotation moduleAnnotation) {
return String.format(
"@BindsInstance methods should not be included in @%ss. Did you mean @Binds?",
moduleAnnotation.annotationClass().getSimpleName());
moduleAnnotation.annotationName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ private void validateSelfCycles(
@Override
public Void visitType(TypeMirror includedModule, Void aVoid) {
if (MoreTypes.equivalence().equivalent(module.asType(), includedModule)) {
String moduleKind = moduleAnnotation.annotationClass().getSimpleName();
String moduleKind = moduleAnnotation.annotationName();
builder.addError(
String.format("@%s cannot include themselves.", moduleKind),
module,
Expand Down

0 comments on commit f5c773a

Please sign in to comment.