Skip to content

Commit

Permalink
UngroupedOverloads: ignore generated constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan202 committed Dec 31, 2022
1 parent 0f2c67c commit fc81ded
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ public Description matchClass(ClassTree classTree, VisitorState state) {
Tree member = classTree.getMembers().get(i);
if (member instanceof MethodTree) {
MethodTree methodTree = (MethodTree) member;
methods.put(OverloadKey.create(methodTree), MemberWithIndex.create(i, methodTree));
if (!ASTHelpers.isGeneratedConstructor(methodTree)) {
methods.put(OverloadKey.create(methodTree), MemberWithIndex.create(i, methodTree));
}
}
}
ImmutableList<Description> descriptions =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@

package com.google.errorprone.bugpatterns;

import static org.junit.Assume.assumeTrue;

import com.google.common.collect.ImmutableList;
import com.google.errorprone.BugCheckerRefactoringTestHelper;
import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode;
import com.google.errorprone.CompilationTestHelper;
import com.google.errorprone.util.RuntimeVersion;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -287,4 +290,22 @@ public void describingConstructors() {
"}")
.doTest();
}

@Test
public void recordConstructor() {
assumeTrue(RuntimeVersion.isAtLeast16());

compilationHelper
.addSourceLines(
"Test.java",
"import com.google.common.collect.ImmutableSet;",
"import java.util.Set;",
"",
"record MyRecord(ImmutableSet<String> strings) {",
" MyRecord(Set<String> strings) {",
" this(strings == null ? ImmutableSet.of() : ImmutableSet.copyOf(strings));",
" }",
"}")
.doTest();
}
}

0 comments on commit fc81ded

Please sign in to comment.