2020import static com .google .errorprone .matchers .Matchers .allOf ;
2121import static com .google .errorprone .matchers .Matchers .inLoop ;
2222import static com .google .errorprone .matchers .Matchers .not ;
23- import static com .google .errorprone .matchers .WaitMatchers .waitMethod ;
24- import static com .google .errorprone .matchers .WaitMatchers .waitMethodWithTimeout ;
23+ import static com .google .errorprone .matchers .WaitMatchers .WAIT_METHOD ;
24+ import static com .google .errorprone .matchers .WaitMatchers .WAIT_METHOD_WITH_TIMEOUT ;
25+ import static com .google .errorprone .util .ASTHelpers .findEnclosingNode ;
26+ import static com .google .errorprone .util .ASTHelpers .getSymbol ;
2527
2628import com .google .errorprone .BugPattern ;
2729import com .google .errorprone .BugPattern .StandardTags ;
3032import com .google .errorprone .fixes .SuggestedFix ;
3133import com .google .errorprone .matchers .Description ;
3234import com .google .errorprone .matchers .Matcher ;
33- import com .google .errorprone .util .ASTHelpers ;
3435import com .sun .source .tree .MethodInvocationTree ;
3536import com .sun .tools .javac .code .Symbol .MethodSymbol ;
3637import com .sun .tools .javac .tree .JCTree .JCIf ;
4748 tags = StandardTags .FRAGILE_CODE )
4849public class WaitNotInLoop extends BugChecker implements MethodInvocationTreeMatcher {
4950
50- private static final Matcher <MethodInvocationTree > matcher = allOf (waitMethod , not (inLoop ()));
51+ private static final Matcher <MethodInvocationTree > matcher = allOf (WAIT_METHOD , not (inLoop ()));
5152
5253 @ Override
5354 public Description matchMethodInvocation (MethodInvocationTree tree , VisitorState state ) {
@@ -56,17 +57,17 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState
5657 }
5758
5859 Description .Builder description = buildDescription (tree );
59- MethodSymbol sym = ASTHelpers . getSymbol (tree );
60+ MethodSymbol sym = getSymbol (tree );
6061 description .setMessage (
6162 String .format ("Because of spurious wakeups, %s must always be called in a loop" , sym ));
6263
6364 // If this looks like the "Wait until a condition becomes true" case from the wiki content,
6465 // rewrite the enclosing if to a while. Other fixes are too complicated to construct
6566 // mechanically, so we provide detailed instructions in the wiki content.
66- if (!waitMethodWithTimeout .matches (tree , state )) {
67- JCIf enclosingIf = ASTHelpers . findEnclosingNode (state .getPath ().getParentPath (), JCIf .class );
67+ if (!WAIT_METHOD_WITH_TIMEOUT .matches (tree , state )) {
68+ JCIf enclosingIf = findEnclosingNode (state .getPath ().getParentPath (), JCIf .class );
6869 if (enclosingIf != null && enclosingIf .getElseStatement () == null ) {
69- CharSequence ifSource = state .getSourceForNode (enclosingIf );
70+ String ifSource = state .getSourceForNode (enclosingIf );
7071 if (ifSource == null ) {
7172 // Source isn't available, so we can't construct a fix
7273 return description .build ();
0 commit comments