Skip to content
Closed
Show file tree
Hide file tree
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 @@ -77,6 +77,10 @@ public class FieldCanBeFinal extends BugChecker implements CompilationUnitTreeMa
"com.google.inject.Inject",
"com.google.inject.testing.fieldbinder.Bind",
"com.google.testing.junit.testparameterinjector.TestParameter",
"jakarta.inject.Inject",
"jakarta.jdo.annotations.Persistent",
"jakarta.persistence.Id",
"jakarta.xml.bind.annotation.XmlAttribute",
"javax.inject.Inject",
"javax.jdo.annotations.Persistent",
"javax.persistence.Id",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class TooManyParameters extends BugChecker implements MethodTreeMatcher {
"java.lang.Deprecated",
"java.lang.Override",
// dependency injection annotations
"jakarta.inject.Inject",
"javax.inject.Inject",
"com.google.inject.Inject",
"com.google.inject.Provides",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,15 @@ public final class UnnecessarilyVisible extends BugChecker implements MethodTree
"com.google.inject.multibindings.ProvidesIntoMap",
"com.google.inject.multibindings.ProvidesIntoSet",
"dagger.Provides",
"jakarta.inject.Inject",
"javax.inject.Inject")
.map(s::getName)
.collect(toImmutableSet()));

private static final Supplier<ImmutableSet<Name>> INJECT_ANNOTATIONS =
VisitorState.memoize(
s ->
Stream.of("com.google.inject.Inject", "javax.inject.Inject")
Stream.of("com.google.inject.Inject", "javax.inject.Inject", "jakarta.inject.Inject")
.map(s::getName)
.collect(toImmutableSet()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public final class UnnecessaryAssignment extends BugChecker
ImmutableSet.of(
"com.google.testing.junit.testparameterinjector.TestParameter",
"com.google.inject.Inject",
"jakarta.inject.Inject",
"javax.inject.Inject");

private static final Matcher<Tree> HAS_MOCK_ANNOTATION = hasAnnotation("org.mockito.Mock");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ public final class UnusedMethod extends BugChecker implements CompilationUnitTre
"jakarta.persistence.PrePersist",
"jakarta.persistence.PreRemove",
"jakarta.persistence.PreUpdate",
"jakarta.validation.constraints.AssertFalse",
"jakarta.validation.constraints.AssertTrue",
"javax.annotation.PreDestroy",
"javax.annotation.PostConstruct",
"javax.inject.Inject",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ public final class UnusedVariable extends BugChecker implements CompilationUnitT
*/
private static final ImmutableSet<String> EXEMPTING_VARIABLE_ANNOTATIONS =
ImmutableSet.of(
"jakarta.persistence.Basic",
"jakarta.persistence.Column",
"jakarta.persistence.Id",
"jakarta.persistence.Version",
"jakarta.xml.bind.annotation.XmlElement",
"javax.persistence.Basic",
"javax.persistence.Column",
"javax.persistence.Id",
Expand All @@ -168,6 +173,7 @@ public final class UnusedVariable extends BugChecker implements CompilationUnitT
"com.google.inject.multibindings.ProvidesIntoMap",
"com.google.inject.multibindings.ProvidesIntoSet",
"dagger.Provides",
"jakarta.inject.Inject",
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe also add this to UnnecessarilyVisible? (as hinted in the TODO comment above the constant)

Copy link
Contributor Author

@gavlyukovskiy gavlyukovskiy Jan 20, 2025

Choose a reason for hiding this comment

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

Added it there as well as to few other places I found. Thanks!
I've seen it also in InjectMatchers and other places that seem to relate to dependency injection / Guice. I didn't change that, because the logic is a bit more complicated, and since we're not using Guice, I'm not that confident in changing those. I'm not sure whether it even supports Jakarta EE already.

Copy link
Contributor

Choose a reason for hiding this comment

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

since we're not using Guice, I'm not that confident in changing those. I'm not sure whether it even supports Jakarta EE already.

FYI, it does!
https://github.com/google/guice/wiki/Guice600
https://github.com/google/guice/wiki/Guice700

Copy link
Contributor Author

@gavlyukovskiy gavlyukovskiy Jan 20, 2025

Choose a reason for hiding this comment

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

@tbroyer good to know :) But do you think we can have these checks merged separately from Guice or are they somehow intertwined?
I also noticed that sometimes there are suggested fixes to add javax.inject.Inject annotation, but it doesn't make sense if the project is already using jakarta / Guice 7 🤷 I think there could be some heuristic, but I'm not the best person to define that as we're using spring instead 😅

"javax.inject.Inject",
// Parameters on test methods imply the test is parameterised, and those parameters should
// be used or removed.
Expand Down