-
Notifications
You must be signed in to change notification settings - Fork 745
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for specifying badEnclosingTypes for BadImport
via flags
#4228
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -388,4 +388,63 @@ public void doesNotMatchProtos() { | |||||||
"}") | ||||||||
.doTest(); | ||||||||
} | ||||||||
|
||||||||
@Test | ||||||||
public void badEnclosingTypes() { | ||||||||
refactoringTestHelper | ||||||||
.setArgs("-XepOpt:BadImport:BadEnclosingTypes=org.immutables.value.Value") | ||||||||
.addInputLines( | ||||||||
"org/immutables/value/Value.java", | ||||||||
"package org.immutables.value;", | ||||||||
"", | ||||||||
"public @interface Value {", | ||||||||
" @interface Immutable {}", | ||||||||
"}") | ||||||||
.expectUnchanged() | ||||||||
.addInputLines( | ||||||||
"Test.java", | ||||||||
"import org.immutables.value.Value.Immutable;", | ||||||||
"", | ||||||||
"@Immutable", | ||||||||
"interface Test {}") | ||||||||
.addOutputLines( | ||||||||
"Test.java", | ||||||||
"import org.immutables.value.Value;", | ||||||||
"", | ||||||||
"@Value.Immutable", | ||||||||
"interface Test {}") | ||||||||
.doTest(); | ||||||||
} | ||||||||
|
||||||||
@Test | ||||||||
public void badEnclosingTypes_doesNotMatchFullyQualifiedName() { | ||||||||
compilationTestHelper | ||||||||
.setArgs("-XepOpt:BadImport:BadEnclosingTypes=org.immutables.value.Value") | ||||||||
.addSourceLines( | ||||||||
"org/immutables/value/Value.java", | ||||||||
"package org.immutables.value;", | ||||||||
"", | ||||||||
"public @interface Value {", | ||||||||
" @interface Immutable {}", | ||||||||
"}") | ||||||||
.addSourceLines("Test.java", "@org.immutables.value.Value.Immutable", "interface Test {}") | ||||||||
.doTest(); | ||||||||
} | ||||||||
|
||||||||
@Test | ||||||||
public void badEnclosingTypes_staticMethod() { | ||||||||
compilationTestHelper | ||||||||
.setArgs("-XepOpt:BadImport:BadEnclosingTypes=com.google.common.collect.ImmutableList") | ||||||||
.addSourceLines( | ||||||||
"Test.java", | ||||||||
"import static com.google.common.collect.ImmutableList.toImmutableList;", | ||||||||
"import com.google.common.collect.ImmutableList;", | ||||||||
"import java.util.stream.Collector;", | ||||||||
"", | ||||||||
"class Test {", | ||||||||
" // BUG: Diagnostic contains: ImmutableList.toImmutableList()", | ||||||||
" Collector<?, ?, ImmutableList<Object>> immutableList = toImmutableList();", | ||||||||
Comment on lines
+434
to
+446
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is disallowing static import desirable? Should we change the behavior only for nested types? 🤔 error-prone/core/src/main/java/com/google/errorprone/bugpatterns/BadImport.java Lines 107 to 109 in 63cf192
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current behaviour of treating static imports consistently seems OK to me. Obviously |
||||||||
"}") | ||||||||
.doTest(); | ||||||||
} | ||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to early-exit if the flag is not set? Or, is the cost negligible? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either way is fine with me, I think the cost is probably negligible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leaving it as-is then 👍