Class SideEffectAnalysis

java.lang.Object
com.sun.source.util.TreeScanner<Void,​Void>
com.google.errorprone.util.SideEffectAnalysis
All Implemented Interfaces:
TreeVisitor<Void,​Void>

public final class SideEffectAnalysis
extends TreeScanner<Void,​Void>
This class is responsible for analyzing an expression and telling if the expression can have side effects. This class is used by calling the static hasSideEffect(ExpressionTree) method.

A side-effect is what that would change the state of the program. Here are examples of expressions that could possibly change the state of a program.

  • Any function call: toString(), hashCode(), setX(value), etc.
  • Unary expression: i += 1, i++, --j
  • New expression: new SomeClass()

Everything besides the above examples is considered side-effect free.

The analysis in this class initially assumes that the expression is side-effect free and then tries to prove it wrong.