|
29 | 29 | import static com.google.errorprone.bugpatterns.checkreturnvalue.ProtoRules.protoBuilders;
|
30 | 30 | import static com.google.errorprone.bugpatterns.checkreturnvalue.ResultUsePolicy.EXPECTED;
|
31 | 31 | import static com.google.errorprone.bugpatterns.checkreturnvalue.ResultUsePolicy.OPTIONAL;
|
| 32 | +import static com.google.errorprone.bugpatterns.checkreturnvalue.ResultUsePolicy.UNSPECIFIED; |
32 | 33 | import static com.google.errorprone.bugpatterns.checkreturnvalue.Rules.globalDefault;
|
33 | 34 | import static com.google.errorprone.bugpatterns.checkreturnvalue.Rules.mapAnnotationSimpleName;
|
34 | 35 | import static com.google.errorprone.fixes.SuggestedFix.emptyFix;
|
@@ -149,11 +150,7 @@ private static Optional<ResultUsePolicy> defaultPolicy(ErrorProneFlags flags, St
|
149 | 150 | */
|
150 | 151 | @Override
|
151 | 152 | public Matcher<ExpressionTree> specializedMatcher() {
|
152 |
| - return (tree, state) -> |
153 |
| - methodToInspect(tree) |
154 |
| - .map(method -> evaluator.evaluate(method, state)) |
155 |
| - .orElse(OPTIONAL) |
156 |
| - .equals(EXPECTED); |
| 153 | + return (tree, state) -> getMethodPolicy(tree, state).equals(EXPECTED); |
157 | 154 | }
|
158 | 155 |
|
159 | 156 | private static Optional<MethodSymbol> methodToInspect(ExpressionTree tree) {
|
@@ -190,6 +187,13 @@ private static Optional<MethodSymbol> methodSymbol(ExpressionTree tree) {
|
190 | 187 | return sym instanceof MethodSymbol ? Optional.of((MethodSymbol) sym) : Optional.empty();
|
191 | 188 | }
|
192 | 189 |
|
| 190 | + /** Returns the {@link ResultUsePolicy} for the method used in the given {@code expression}. */ |
| 191 | + public ResultUsePolicy getMethodPolicy(ExpressionTree expression, VisitorState state) { |
| 192 | + return methodToInspect(expression) |
| 193 | + .map(method -> evaluator.evaluate(method, state)) |
| 194 | + .orElse(UNSPECIFIED); |
| 195 | + } |
| 196 | + |
193 | 197 | @Override
|
194 | 198 | public boolean isCovered(ExpressionTree tree, VisitorState state) {
|
195 | 199 | return methodToInspect(tree).stream()
|
|
0 commit comments