Skip to content

Commit

Permalink
Obey @keep in PreferredInterfaceType.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 499172455
  • Loading branch information
graememorgan authored and Error Prone Team committed Jan 3, 2023
1 parent a3005b1 commit b6b1b4e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import static com.google.errorprone.util.ASTHelpers.isConsideredFinal;
import static com.google.errorprone.util.ASTHelpers.isSubtype;
import static com.google.errorprone.util.ASTHelpers.methodCanBeOverridden;
import static com.google.errorprone.util.ASTHelpers.shouldKeep;

import com.google.auto.value.AutoValue;
import com.google.common.collect.ArrayListMultimap;
Expand Down Expand Up @@ -200,6 +201,10 @@ private boolean variableIsFixable(VariableTree tree, VarSymbol symbol) {
if (symbol.getKind() == ElementKind.PARAMETER) {
return false;
}
if (shouldKeep(tree)) {
return false;
}
// TODO(ghm): Open source @Keep on the elements in SHOULD_IGNORE, and remove this.
if (SHOULD_IGNORE.matches(tree, state)) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -897,4 +897,18 @@ public void charSequences() {
"}")
.doTest();
}

@Test
public void obeysKeep() {
refactoringHelper
.addInputLines(
"Test.java",
"import com.google.errorprone.annotations.Keep;",
"import java.util.ArrayList;",
"class Test {",
" @Keep private static final Iterable<Integer> FOO = new ArrayList<>();",
"}")
.expectUnchanged()
.doTest();
}
}

0 comments on commit b6b1b4e

Please sign in to comment.