Skip to content

Commit

Permalink
Add a test that demonstrates the issue with unqualified static field …
Browse files Browse the repository at this point in the history
…references in the `@InlineMe` `Suggester`.

#inlineme

PiperOrigin-RevId: 452402823
  • Loading branch information
kluever authored and Error Prone Team committed Jun 1, 2022
1 parent 32fb22a commit c81f12e
Showing 1 changed file with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,64 @@ public void testStaticMethodInNewClass() {
.doTest();
}

@Test
public void testUnqualifiedStaticFieldReference() {
refactoringTestHelper
.addInputLines(
"Client.java",
"package com.google.frobber;",
"public final class Client {",
" public static final String STR = \"kurt\";",
" @Deprecated",
" public int stringLength() {",
" return STR.length();",
" }",
"}")
.addOutputLines(
"Client.java",
"package com.google.frobber;",
"import com.google.errorprone.annotations.InlineMe;",
"public final class Client {",
" public static final String STR = \"kurt\";",
// TODO(b/234643232): this is a bug; it should be "Client.STR.length()" plus an import
" @InlineMe(replacement = \"STR.length()\")",
" @Deprecated",
" public int stringLength() {",
" return STR.length();",
" }",
"}")
.doTest();
}

@Test
public void testQualifiedStaticFieldReference() {
refactoringTestHelper
.addInputLines(
"Client.java",
"package com.google.frobber;",
"public final class Client {",
" public static final String STR = \"kurt\";",
" @Deprecated",
" public int stringLength() {",
" return Client.STR.length();",
" }",
"}")
.addOutputLines(
"Client.java",
"package com.google.frobber;",
"import com.google.errorprone.annotations.InlineMe;",
"public final class Client {",
" public static final String STR = \"kurt\";",
" @InlineMe(replacement = \"Client.STR.length()\", "
+ "imports = \"com.google.frobber.Client\")",
" @Deprecated",
" public int stringLength() {",
" return Client.STR.length();",
" }",
"}")
.doTest();
}

@Test
public void testProtectedConstructor() {
refactoringTestHelper
Expand Down

0 comments on commit c81f12e

Please sign in to comment.