Skip to content

Commit 52a3318

Browse files
java-team-github-botError Prone Team
authored and
Error Prone Team
committed
Make TooManyParameters analyzer ignore constructors that have @autofactory annotation.
PiperOrigin-RevId: 736668481
1 parent ee8702c commit 52a3318

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

core/src/main/java/com/google/errorprone/bugpatterns/TooManyParameters.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ public class TooManyParameters extends BugChecker implements MethodTreeMatcher {
6363
"org.junit.Test",
6464
// dagger provider / producers
6565
"dagger.Provides",
66-
"dagger.producers.Produces");
66+
"dagger.producers.Produces",
67+
// AutoFactory can be put on a constructor.
68+
"com.google.auto.factory.AutoFactory");
6769

6870
private static final ImmutableSet<String> CLASS_ANNOTATIONS_TO_IGNORE =
6971
ImmutableSet.of("com.google.auto.factory.AutoFactory");

core/src/test/java/com/google/errorprone/bugpatterns/TooManyParametersTest.java

+31-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public ConstructorTest(short a, short b, short c, short d) {}
124124
}
125125

126126
@Test
127-
public void ignoresAutoFactory() {
127+
public void ignoresAutoFactoryOnClass() {
128128
compilationHelper
129129
.setArgs(ImmutableList.of("-XepOpt:" + TOO_MANY_PARAMETERS_FLAG_NAME + "=3"))
130130
.addSourceLines(
@@ -153,6 +153,36 @@ public TestWithoutAutoFactory(int a, int b, int c, int d) {}
153153
.doTest();
154154
}
155155

156+
@Test
157+
public void ignoresAutoFactoryOnConstructor() {
158+
compilationHelper
159+
.setArgs(ImmutableList.of("-XepOpt:" + TOO_MANY_PARAMETERS_FLAG_NAME + "=3"))
160+
.addSourceLines(
161+
"AutoFactory.java",
162+
"""
163+
package com.google.auto.factory;
164+
165+
public @interface AutoFactory {}
166+
""")
167+
.addSourceLines(
168+
"Test.java",
169+
"""
170+
public class Test {
171+
@com.google.auto.factory.AutoFactory
172+
public Test(int a, int b, int c, int d) {}
173+
}
174+
""")
175+
.addSourceLines(
176+
"TestWithoutAutoFactory.java",
177+
"""
178+
public class TestWithoutAutoFactory {
179+
// BUG: Diagnostic contains: 4 parameters
180+
public TestWithoutAutoFactory(int a, int b, int c, int d) {}
181+
}
182+
""")
183+
.doTest();
184+
}
185+
156186
@Test
157187
public void method() {
158188
compilationHelper

0 commit comments

Comments
 (0)