Skip to content

Commit

Permalink
ReturnValueIgnored: misc nits.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 375731821
  • Loading branch information
graememorgan authored and Error Prone Team committed May 25, 2021
1 parent faac827 commit 1d9ed94
Showing 1 changed file with 15 additions and 21 deletions.
Expand Up @@ -21,6 +21,7 @@
import static com.google.errorprone.matchers.Matchers.anyMethod;
import static com.google.errorprone.matchers.Matchers.anyOf;
import static com.google.errorprone.matchers.Matchers.not;
import static com.google.errorprone.matchers.Matchers.nothing;
import static com.google.errorprone.matchers.Matchers.packageStartsWith;
import static com.google.errorprone.matchers.method.MethodMatchers.instanceMethod;
import static com.google.errorprone.matchers.method.MethodMatchers.staticMethod;
Expand Down Expand Up @@ -107,30 +108,20 @@ private static boolean javaTimeTypes(ExpressionTree tree, VisitorState state) {
return false;
}
Symbol symbol = ASTHelpers.getSymbol(tree);
if (symbol instanceof MethodSymbol) {
MethodSymbol methodSymbol = (MethodSymbol) symbol;
if (methodSymbol.owner.packge().getQualifiedName().toString().startsWith("java.time")
&& methodSymbol.getModifiers().contains(Modifier.PUBLIC)) {
if (ALLOWED_JAVA_TIME_METHODS.matches(tree, state)) {
return false;
}
return true;
}
}
return false;
return symbol instanceof MethodSymbol
&& symbol.owner.packge().getQualifiedName().toString().startsWith("java.time")
&& symbol.getModifiers().contains(Modifier.PUBLIC)
&& !ALLOWED_JAVA_TIME_METHODS.matches(tree, state);
}

/**
* Methods in {@link java.util.function} are pure, and their returnvalues should not be discarded.
* Methods in {@link java.util.function} are pure, and their return values should not be
* discarded.
*/
private static boolean functionalMethod(ExpressionTree tree, VisitorState state) {
Symbol symbol = ASTHelpers.getSymbol(tree);
return symbol instanceof MethodSymbol
&& ((MethodSymbol) symbol)
.owner
.packge()
.getQualifiedName()
.contentEquals("java.util.function");
&& symbol.owner.packge().getQualifiedName().contentEquals("java.util.function");
}

/**
Expand Down Expand Up @@ -307,14 +298,17 @@ private static boolean functionalMethod(ExpressionTree tree, VisitorState state)
ITERABLE_METHODS,
ITERATOR_METHODS);

private Matcher<? super ExpressionTree> matcher;
private final Matcher<? super ExpressionTree> matcher;

public ReturnValueIgnored(ErrorProneFlags flags) {
boolean checkOptional = flags.getBoolean("ReturnValueIgnored:MoreOptional").orElse(true);
this.matcher =
checkOptional ? anyOf(SPECIALIZED_MATCHER, MORE_OPTIONAL_METHODS) : SPECIALIZED_MATCHER;
boolean checkMoreMap = flags.getBoolean("ReturnValueIgnored:MoreMap").orElse(true);
this.matcher = checkMoreMap ? anyOf(matcher, MORE_MAP_METHODS) : matcher;

this.matcher =
anyOf(
SPECIALIZED_MATCHER,
checkOptional ? MORE_OPTIONAL_METHODS : nothing(),
checkMoreMap ? MORE_MAP_METHODS : nothing());
}

@Override
Expand Down

0 comments on commit 1d9ed94

Please sign in to comment.