Class SideEffectAnalysis
- All Implemented Interfaces:
TreeVisitor<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.
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanhasSideEffect(ExpressionTree expression) Tries to establish whetherexpressionis side-effect free.visitCompoundAssignment(CompoundAssignmentTree tree, Void unused) visitMethodInvocation(MethodInvocationTree tree, Void unused) visitNewClass(NewClassTree tree, Void unused) visitUnary(UnaryTree tree, Void unused) Methods inherited from class TreeScanner
reduce, scan, scan, visitAnnotatedType, visitAnnotation, visitAnyPattern, visitArrayAccess, visitArrayType, visitAssert, visitAssignment, visitBinary, visitBindingPattern, visitBlock, visitBreak, visitCase, visitCatch, visitClass, visitCompilationUnit, visitConditionalExpression, visitConstantCaseLabel, visitContinue, visitDeconstructionPattern, visitDefaultCaseLabel, visitDoWhileLoop, visitEmptyStatement, visitEnhancedForLoop, visitErroneous, visitExports, visitExpressionStatement, visitForLoop, visitIdentifier, visitIf, visitImport, visitInstanceOf, visitIntersectionType, visitLabeledStatement, visitLambdaExpression, visitLiteral, visitMemberReference, visitMemberSelect, visitMethod, visitModifiers, visitModule, visitNewArray, visitOpens, visitOther, visitPackage, visitParameterizedType, visitParenthesized, visitPatternCaseLabel, visitPrimitiveType, visitProvides, visitRequires, visitReturn, visitSwitch, visitSwitchExpression, visitSynchronized, visitThrow, visitTry, visitTypeCast, visitTypeParameter, visitUnionType, visitUses, visitVariable, visitWhileLoop, visitWildcard, visitYield
-
Method Details
-
hasSideEffect
Tries to establish whetherexpressionis side-effect free. The heuristics here are very conservative. -
visitCompoundAssignment
- Specified by:
visitCompoundAssignmentin interfaceTreeVisitor<Void,Void> - Overrides:
visitCompoundAssignmentin classTreeScanner<Void,Void>
-
visitMethodInvocation
- Specified by:
visitMethodInvocationin interfaceTreeVisitor<Void,Void> - Overrides:
visitMethodInvocationin classTreeScanner<Void,Void>
-
visitNewClass
- Specified by:
visitNewClassin interfaceTreeVisitor<Void,Void> - Overrides:
visitNewClassin classTreeScanner<Void,Void>
-
visitUnary
- Specified by:
visitUnaryin interfaceTreeVisitor<Void,Void> - Overrides:
visitUnaryin classTreeScanner<Void,Void>
-