
public class Simplifier extends Object
| Modifier and Type | Method and Description |
|---|---|
static JExpression |
cast(JType type,
JExpression exp)
Simplify cast operations.
|
static JExpression |
simplifyAnd(JBinaryOperation expression)
Simplify short circuit AND expressions.
|
static JExpression |
simplifyCast(JCastOperation castExpression)
Simplify cast operations.
|
static JExpression |
simplifyConditional(JConditional expression)
Simplify conditional expressions.
|
static JStatement |
simplifyIfStatement(JIfStatement ifStatement,
JType methodReturnType)
Simplifies an if then else statement.
|
static JExpression |
simplifyNot(JPrefixOperation expression)
Simplifies an negation expression.
|
static JExpression |
simplifyOr(JBinaryOperation expression)
Simplify short circuit OR expressions.
|
public static JExpression cast(JType type, JExpression exp)
(int) 1 -> 1 (A) (a,b) -> (a, (A) b)
type - the Type to cast the expression exp to.exp - the current JExpression under the cast as it is being simplified.public static JExpression simplifyCast(JCastOperation castExpression)
(int) 1 -> 1 (A) (a,b) -> (a, (A) b)
castExpression - a JCastOperation to be simplified.exp otherwise.public static JExpression simplifyConditional(JConditional expression)
(a,b,c)?d:e -> a,b,(c?d:e) true ? then : else -> then false ? then : else -> else cond ? true : else) -> cond || else cond ? false : else -> !cond && else cond ? then : true -> !cond || then cond ? then : false -> cond && then !cond ? then : else -> cond ? else : then
expression - a JCondintional to be simplified.exp otherwise.public static JStatement simplifyIfStatement(JIfStatement ifStatement, JType methodReturnType)
if(a,b,c) d [else e] -> {a; b; if(c) d [else e]; }
if(true) a [else b] -> a
if(false) a else b -> b
if(notImpl(c)) a else b -> if(c) b else a
if(true) ; else b -> true
if(false) a [else ;] -> false
if(c) ; [else ;] -> c
ifStatement - the statement to simplify.methodReturnType - the return type of the method where the statement resides if anyifStatement
otherwise.public static JExpression simplifyNot(JPrefixOperation expression)
expression - the expression to simplify.expr
otherwise.public static JExpression simplifyAnd(JBinaryOperation expression)
true && isWhatever() -> isWhatever() false && isWhatever() -> false isWhatever() && true -> isWhatever() isWhatever() && false -> false, unless side effects (a, b) && c -> (a, b && c)
expression - an AND JBinaryExpression to be simplified.exp otherwise.public static JExpression simplifyOr(JBinaryOperation expression)
true || isWhatever() -> true false || isWhatever() -> isWhatever() isWhatever() || false isWhatever() isWhatever() || true -> true, unless side effects (a, b) || c -> (a, b || c)
expression - an OR JBinaryExpression to be simplified.exp otherwise.Copyright © 2018. All rights reserved.