Class ConstantExpressions
java.lang.Object
com.google.errorprone.bugpatterns.threadsafety.ConstantExpressions
Helper for establishing whether expressions correspond to a constant expression.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceRepresents a constant expression.static interfaceVisitor for scanning over the components of a constant expression.static final recordRepresents sets of things known to be true and false if a boolean statement evaluated true. -
Method Summary
Modifier and TypeMethodDescriptionconstantExpression(ExpressionTree tree, VisitorState state) static ObjectReturns the key offact, which must be from aConstantExpressions.Truthiness.static @Nullable ObjectfactKey(ExpressionTree tree) Returns thekeythat any facttruthiness(ExpressionTree, boolean, VisitorState)derives directly fromtreewould have, ornulliftreecannot yield a fact.static ConstantExpressionsfromFlags(ErrorProneFlags flags) booleanisSame(ExpressionTree aTree, ExpressionTree bTree, VisitorState state) Returns whetheraTreeandbTreeseem to correspond to the same expression.static booleanmayImply(ExpressionTree tree, boolean not, Object key) Returns whethertruthiness(ExpressionTree, boolean, VisitorState)oftreemay contain a fact with the givenkey.symbolizeImmutableExpression(ExpressionTree tree, VisitorState state) Returns a list of the methods called to get to this expression, as well as a terminating variable if needed.truthiness(ExpressionTree tree, boolean not, VisitorState state) Scans anExpressionTreeto find anything guaranteed to be false or true if this expression is true.
-
Method Details
-
fromFlags
-
truthiness
public ConstantExpressions.Truthiness truthiness(ExpressionTree tree, boolean not, VisitorState state) Scans anExpressionTreeto find anything guaranteed to be false or true if this expression is true.mayImply(ExpressionTree, boolean, Object)andfactKey(ExpressionTree)mirror the expressions handled here, so update them when adding new kinds of facts. -
mayImply
Returns whethertruthiness(ExpressionTree, boolean, VisitorState)oftreemay contain a fact with the givenkey.This mirrors the traversal in
truthiness(ExpressionTree, boolean, VisitorState)without callingconstantExpression(ExpressionTree, VisitorState), which matches each method invocation against the known pure methods. -
factKey
Returns thekeythat any facttruthiness(ExpressionTree, boolean, VisitorState)derives directly fromtreewould have, ornulliftreecannot yield a fact.Keys are opaque, and should only be compared using
Object.equals(Object). -
factKey
Returns the key offact, which must be from aConstantExpressions.Truthiness. Equal facts have equal keys, which matchfactKey(ExpressionTree)for the trees they're derived from. -
constantExpression
public Optional<ConstantExpressions.ConstantExpression> constantExpression(ExpressionTree tree, VisitorState state) -
isSame
Returns whetheraTreeandbTreeseem to correspond to the same expression. -
symbolizeImmutableExpression
public Optional<ConstantExpressions.ConstantExpression.PureMethodInvocation> symbolizeImmutableExpression(ExpressionTree tree, VisitorState state) Returns a list of the methods called to get to this expression, as well as a terminating variable if needed.
-