Skip to content

Commit

Permalink
Permit classes that have @Inject on one constructor and @autofactory
Browse files Browse the repository at this point in the history
…on other constructors.

These cases are more explicit about which methods should get called under each context.

RELNOTES:n/a

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=156268076
  • Loading branch information
ronshapiro committed May 24, 2017
1 parent 0d4994f commit daa72b7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static com.google.errorprone.matchers.Matchers.methodIsConstructor;
import static com.google.errorprone.util.ASTHelpers.findEnclosingNode;
import static com.google.errorprone.util.ASTHelpers.getConstructors;
import static com.sun.source.tree.Tree.Kind.CLASS;
import static com.sun.source.tree.Tree.Kind.METHOD;

import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -73,7 +74,9 @@ public final Description matchAnnotation(AnnotationTree annotationTree, VisitorS
ImmutableList<Tree> potentiallyAnnotatedTrees =
new ImmutableList.Builder<Tree>().add(classTree).addAll(getConstructors(classTree)).build();
for (Tree potentiallyAnnotatedTree : potentiallyAnnotatedTrees) {
if (HAS_AUTO_FACTORY_ANNOTATION.matches(potentiallyAnnotatedTree, state)) {
if (HAS_AUTO_FACTORY_ANNOTATION.matches(potentiallyAnnotatedTree, state)
&& (potentiallyAnnotatedTree.getKind().equals(CLASS)
|| potentiallyAnnotatedTree.equals(annotatedTree))) {
return describeMatch(annotationTree, SuggestedFix.delete(annotationTree));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,12 @@ static class AutoFactoryOnInnerType {
@AutoFactory
static class InnerType {}
}

static class OnDifferentConstructors {
@Inject
OnDifferentConstructors(String string) {}

@AutoFactory
OnDifferentConstructors(Object object) {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,4 @@ static class HasAutoFactoryOnConstructor {
@AutoFactory
HasAutoFactoryOnConstructor() {}
}

static class HasAutoFactoryOnOtherConstructor {
// BUG: Diagnostic contains: remove
@Inject
HasAutoFactoryOnOtherConstructor() {}

@AutoFactory
HasAutoFactoryOnOtherConstructor(String string) {}
}
}

0 comments on commit daa72b7

Please sign in to comment.