Skip to content

Commit

Permalink
Merge GuardedByValidator into GuardedByChecker
Browse files Browse the repository at this point in the history
MOE_MIGRATED_REVID=149316613
  • Loading branch information
cushon committed Mar 8, 2017
1 parent b1f011d commit 1f6dc3d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 88 deletions.
Expand Up @@ -23,11 +23,13 @@
import com.google.common.base.Joiner;
import com.google.errorprone.BugPattern;
import com.google.errorprone.VisitorState;
import com.google.errorprone.bugpatterns.BugChecker;
import com.google.errorprone.bugpatterns.BugChecker.LambdaExpressionTreeMatcher;
import com.google.errorprone.bugpatterns.BugChecker.MethodTreeMatcher;
import com.google.errorprone.bugpatterns.BugChecker.VariableTreeMatcher;
import com.google.errorprone.bugpatterns.threadsafety.GuardedByExpression.Kind;
import com.google.errorprone.bugpatterns.threadsafety.GuardedByExpression.Select;
import com.google.errorprone.bugpatterns.threadsafety.GuardedByUtils.GuardedByValidationResult;
import com.google.errorprone.matchers.Description;
import com.google.errorprone.util.ASTHelpers;
import com.sun.source.tree.ExpressionTree;
Expand All @@ -47,7 +49,7 @@
category = JDK,
severity = ERROR
)
public class GuardedByChecker extends GuardedByValidator
public class GuardedByChecker extends BugChecker
implements VariableTreeMatcher, MethodTreeMatcher, LambdaExpressionTreeMatcher {

private static final String JUC_READ_WRITE_LOCK = "java.util.concurrent.locks.ReadWriteLock";
Expand All @@ -61,7 +63,7 @@ public Description matchMethod(MethodTree tree, final VisitorState state) {
return NO_MATCH;
}
analyze(state);
return GuardedByValidator.validate(this, tree, state);
return validate(tree, state);
}

@Override
Expand All @@ -84,7 +86,7 @@ public Description matchVariable(VariableTree tree, VisitorState state) {
// for a local or a parameter, but they won't have @GuardedBy annotations.
//
// Field initializers (like constructors) are not checked for accesses of guarded fields.
return GuardedByValidator.validate(this, tree, state);
return validate(tree, state);
}

protected Description checkGuardedAccess(
Expand Down Expand Up @@ -214,4 +216,15 @@ private void report(Description description, VisitorState state) {
}
state.reportMatch(description);
}

/** Validates that {@code @GuardedBy} strings can be resolved. */
Description validate(Tree tree, VisitorState state) {
GuardedByValidationResult result = GuardedByUtils.isGuardedByValid(tree, state);
if (result.isValid()) {
return Description.NO_MATCH;
}
return buildDescription(tree)
.setMessage(String.format("Invalid @GuardedBy expression: %s", result.message()))
.build();
}
}

This file was deleted.

Expand Up @@ -219,7 +219,6 @@
import com.google.errorprone.bugpatterns.inject.guice.ProvidesMethodOutsideOfModule;
import com.google.errorprone.bugpatterns.threadsafety.DoubleCheckedLocking;
import com.google.errorprone.bugpatterns.threadsafety.GuardedByChecker;
import com.google.errorprone.bugpatterns.threadsafety.GuardedByValidator;
import com.google.errorprone.bugpatterns.threadsafety.ImmutableAnnotationChecker;
import com.google.errorprone.bugpatterns.threadsafety.ImmutableChecker;
import com.google.errorprone.bugpatterns.threadsafety.ImmutableEnumChecker;
Expand Down Expand Up @@ -297,7 +296,6 @@ public static ScannerSupplier errorChecks() {
GetClassOnAnnotation.class,
GetClassOnClass.class,
GuardedByChecker.class,
GuardedByValidator.class,
GuavaSelfEquals.class,
HashtableContains.class,
IdentityBinaryExpression.class,
Expand Down
Expand Up @@ -22,14 +22,14 @@
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/** {@link GuardedByValidator}Test */
/** {@link GuardedByChecker} annotation syntax GuardedByValidationResult test */
@RunWith(JUnit4.class)
public class GuardedByValidatorTest {
private CompilationTestHelper compilationHelper;

@Before
public void setUp() {
compilationHelper = CompilationTestHelper.newInstance(GuardedByValidator.class, getClass());
compilationHelper = CompilationTestHelper.newInstance(GuardedByChecker.class, getClass());
}

@Test
Expand Down
15 changes: 0 additions & 15 deletions docs/bugpattern/GuardedByValidator.md

This file was deleted.

0 comments on commit 1f6dc3d

Please sign in to comment.