@@ -0,0 +1,2198 @@
+/*%0A * Copyright 2022 The Error Prone Authors.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage com.google.errorprone.bugpatterns.checkreturnvalue;%0A%0Aimport com.google.common.collect.ImmutableMap;%0Aimport com.google.errorprone.VisitorState;%0Aimport com.google.errorprone.bugpatterns.checkreturnvalue.ResultUseRule.SymbolRule;%0Aimport com.sun.tools.javac.code.Symbol;%0Aimport com.sun.tools.javac.code.Symbol.PackageSymbol;%0Aimport com.sun.tools.javac.util.Name;%0Aimport java.util.Optional;%0A%0A/**%0A * A rule that enables checking for methods belonging to a set of packages or any of their%0A * subpackages.%0A */%0Afinal class PackagesRule extends SymbolRule %7B%0A%0A  private final ImmutableMap%3CName, Boolean%3E packages;%0A%0A  public PackagesRule(VisitorState state, Iterable%3CString%3E patterns) %7B%0A    ImmutableMap.Builder%3CName, Boolean%3E builder = ImmutableMap.builder();%0A    for (String pattern : patterns) %7B%0A      if (pattern.charAt(0) == '-') %7B%0A        builder.put(state.getName(pattern.substring(1)), false);%0A      %7D else %7B%0A        builder.put(state.getName(pattern), true);%0A      %7D%0A    %7D%0A    this.packages = builder.buildOrThrow();%0A  %7D%0A%0A  @Override%0A  public final String id() %7B%0A    return %22Packages%22;%0A  %7D%0A%0A  @Override%0A  public Optional%3CResultUsePolicy%3E evaluate(Symbol symbol, VisitorState state) %7B%0A    while (symbol instanceof PackageSymbol) %7B%0A      Boolean value = packages.get(((PackageSymbol) symbol).fullname);%0A      if (value != null) %7B%0A        return value%0A            ? Optional.of(ResultUsePolicy.EXPECTED)%0A            // stop evaluating if the package matched a negative pattern%0A            : Optional.empty();%0A      %7D%0A      symbol = symbol.owner;%0A    %7D%0A    return Optional.empty();%0A  %7D%0A%7D%0A

Add a rule for matching packages.