Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,13 @@ public Description matchVariable(VariableTree tree, VisitorState state) {
var symbol = getSymbol(tree);
switch (symbol.getKind()) {
case FIELD -> {
if (INJECTION_FIELDS.stream().anyMatch(ip -> hasAnnotation(tree, ip, state))) {
if (INJECTION_FIELDS.stream().anyMatch(ip -> hasAnnotation(tree, ip, state))
|| tree.getModifiers().getAnnotations().stream()
.anyMatch(
anno ->
INJECTION_PREFIXES.stream()
.anyMatch(
p -> getSymbol(anno).getSimpleName().toString().startsWith(p)))) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getSymbol(anno).getSimpleName().toString() is loop-invariant and can be moved to the outer lambda expression.

return NO_MATCH;
}
if (isRecord(symbol)) {
Expand Down Expand Up @@ -222,22 +228,12 @@ private static ImmutableList<AnnotationTree> getQualifiers(
private static final ImmutableSet<String> INJECTION_FIELDS =
ImmutableSet.of(
// keep-sorted start
"com.google.inject.Inject",
"dagger.Binds",
"dagger.BindsInstance",
"dagger.hilt.android.testing.BindElementsIntoSet",
"dagger.hilt.android.testing.BindValue",
"dagger.hilt.android.testing.BindValueIntoMap",
"dagger.hilt.android.testing.BindValueIntoSet",
"dagger.hilt.testing.BindElementsIntoSet",
"dagger.hilt.testing.BindValue",
"dagger.hilt.testing.BindValueIntoMap",
"dagger.hilt.testing.BindValueIntoSet",
"jakarta.inject.Inject",
"javax.inject.Inject"
// keep-sorted end
);

/** Prefixes for annotations on variables which can have qualifiers. */
private static final ImmutableSet<String> INJECTION_PREFIXES = ImmutableSet.of("Bind", "Inject");

private static final ImmutableSet<String> CLASS_ANNOTATIONS_EXEMPTING_METHODS =
ImmutableSet.of(
// keep-sorted start
Expand Down
Loading