Skip to content

Commit 3347997

Browse files
klueverError Prone Team
authored and
Error Prone Team
committed
Delete STATIC_IMPORT_ASSERT_THAT and just always static import assertThat.
PiperOrigin-RevId: 735363545
1 parent b172f9a commit 3347997

File tree

1 file changed

+12
-26
lines changed

1 file changed

+12
-26
lines changed

core/src/main/java/com/google/errorprone/refaster/ImportPolicy.java

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,15 @@ public enum ImportPolicy {
5151
* Import the outermost class and explicitly qualify references below that. For example, to
5252
* reference {@code com.google.Foo.Bar}, we import {@code com.google.Foo} and explicitly qualify
5353
* {@code Foo.Bar}.
54+
*
55+
* <p><b>Note:</b> static methods named {@code assertThat}, {@code assertWithMessage} and {@code
56+
* assertAbout} are always statically imported.
5457
*/
5558
IMPORT_TOP_LEVEL {
59+
60+
private static final ImmutableSet<String> METHOD_NAMES_TO_STATICALLY_IMPORT =
61+
ImmutableSet.of("assertThat", "assertAbout", "assertWithMessage");
62+
5663
@Override
5764
public JCExpression classReference(
5865
Inliner inliner, CharSequence topLevelClazz, CharSequence fullyQualifiedClazz) {
@@ -111,6 +118,11 @@ public JCExpression staticReference(
111118
CharSequence topLevelClazz,
112119
CharSequence fullyQualifiedClazz,
113120
CharSequence member) {
121+
// NOTE(b/17121704): we always statically import certain method names
122+
if (METHOD_NAMES_TO_STATICALLY_IMPORT.contains(member.toString())) {
123+
return STATIC_IMPORT_ALWAYS.staticReference(
124+
inliner, topLevelClazz, fullyQualifiedClazz, member);
125+
}
114126
return inliner
115127
.maker()
116128
.Select(
@@ -206,32 +218,6 @@ public JCExpression staticReference(
206218
}
207219
return inliner.maker().Ident(inliner.asName(member));
208220
}
209-
},
210-
211-
/**
212-
* When inlining static methods, always static import the method if it is called {@code
213-
* assertThat}. Non-static references to classes are imported from the top level as in {@code
214-
* IMPORT_TOP_LEVEL}.
215-
*/
216-
STATIC_IMPORT_ASSERT_THAT {
217-
@Override
218-
public JCExpression classReference(
219-
Inliner inliner, CharSequence topLevelClazz, CharSequence fullyQualifiedClazz) {
220-
return IMPORT_TOP_LEVEL.classReference(inliner, topLevelClazz, fullyQualifiedClazz);
221-
}
222-
223-
@Override
224-
public JCExpression staticReference(
225-
Inliner inliner,
226-
CharSequence topLevelClazz,
227-
CharSequence fullyQualifiedClazz,
228-
CharSequence member) {
229-
if (member.toString().equals("assertThat")) {
230-
return STATIC_IMPORT_ALWAYS.staticReference(
231-
inliner, topLevelClazz, fullyQualifiedClazz, member);
232-
}
233-
return IMPORT_TOP_LEVEL.staticReference(inliner, topLevelClazz, fullyQualifiedClazz, member);
234-
}
235221
};
236222

237223
public static void bind(Context context, ImportPolicy policy) {

0 commit comments

Comments
 (0)