Skip to content

Commit

Permalink
Ignore @Bind-annotated fields in UnnecessaryLambda
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=244213859
  • Loading branch information
cushon authored and ronshapiro committed May 5, 2019
1 parent fe2e3cc commit cb88850
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Expand Up @@ -37,6 +37,7 @@
import com.google.errorprone.fixes.SuggestedFix;
import com.google.errorprone.fixes.SuggestedFixes;
import com.google.errorprone.matchers.Description;
import com.google.errorprone.util.ASTHelpers;
import com.sun.source.tree.BlockTree;
import com.sun.source.tree.ExpressionTree;
import com.sun.source.tree.IdentifierTree;
Expand Down Expand Up @@ -122,6 +123,9 @@ public Description matchVariable(VariableTree tree, VisitorState state) {
|| !sym.getModifiers().contains(Modifier.FINAL)) {
return NO_MATCH;
}
if (ASTHelpers.hasAnnotation(tree, "com.google.inject.testing.fieldbinder.Bind", state)) {
return NO_MATCH;
}
Tree type = tree.getType();
if (!canFix(type, sym, state)) {
return NO_MATCH;
Expand Down
Expand Up @@ -235,6 +235,36 @@ public void nonFunctionalInterfaceMethod() {
" }",
"}")
.expectUnchanged()
.doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH);
.doTest();
}

@Test
public void variable_bind() {
testHelper
.addInputLines(
"Bind.java",
"package com.google.inject.testing.fieldbinder;",
"import static java.lang.annotation.ElementType.FIELD;",
"import static java.lang.annotation.RetentionPolicy.RUNTIME;",
"import java.lang.annotation.Retention;",
"import java.lang.annotation.Target;",
"@Retention(RUNTIME)",
"@Target({FIELD})",
"public @interface Bind {}")
.expectUnchanged()
.addInputLines(
"Test.java",
"import java.util.function.Function;",
"import com.google.inject.testing.fieldbinder.Bind;",
"class Test {",
" @Bind",
" private final Function<String, String> camelCase = x -> \"hello \" + x;",
" void g() {",
" Function<String, String> f = camelCase;",
" System.err.println(camelCase.apply(\"world\"));",
" }",
"}")
.expectUnchanged()
.doTest();
}
}

0 comments on commit cb88850

Please sign in to comment.