spoon.reflect.code.CtConditional Java Examples
The following examples show how to use
spoon.reflect.code.CtConditional.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConditionalProcessor.java From nopol with GNU General Public License v2.0 | 5 votes |
public static CtExpression<Boolean> getCondition(CtElement element) { CtExpression<Boolean> condition; if (element instanceof CtIf) { condition = ((CtIf) element).getCondition(); } else if (element instanceof CtConditional) { condition = ((CtConditional<?>) element).getCondition(); } else { throw new IllegalStateException("Unknown conditional class: " + element.getClass()); } return condition; }
Example #2
Source File: AbstractCodeAnalyzer.java From coming with MIT License | 5 votes |
/** * Return if the element is a guard * * @param element * @return */ public boolean isNormalGuard(CtElement element, CtStatement parentStatement) { // Two cases: if and conditional CtExpression condition = null; CtConditional parentConditional = element.getParent(CtConditional.class); if (parentConditional != null) { // TODO, maybe force that the var must be in the condition, or not. CtConditional cond = (CtConditional) parentConditional; condition = cond.getCondition(); return checkNormalGuardCondition(condition); } else { CtElement parentElement = getParentNotBlock(parentStatement); // First, find the condition if (parentElement instanceof CtIf) { CtIf guardCandidateIf = (CtIf) parentElement; if (whethereffectiveguard(guardCandidateIf, parentStatement)) { condition = guardCandidateIf.getCondition(); boolean isConditionAGuard = checkNormalGuardCondition(condition); return isConditionAGuard; } } } return false; }
Example #3
Source File: AbstractCodeAnalyzer.java From coming with MIT License | 5 votes |
public boolean isNullCheckGuard(CtElement element, CtStatement parentStatement) { // Two cases: if and conditional CtExpression condition = null; CtConditional parentConditional = element.getParent(CtConditional.class); if (parentConditional != null) {// TODO, maybe force that the var must be in the condition, or not. CtConditional cond = (CtConditional) parentConditional; condition = cond.getCondition(); return checkNullCheckGuardCondition(condition); } else { CtElement parentElement = getParentNotBlock(parentStatement); // First, find the condition if (parentElement instanceof CtIf) { CtIf guardCandidateIf = (CtIf) parentElement; if (whethereffectiveguard(guardCandidateIf, parentStatement)) { condition = guardCandidateIf.getCondition(); boolean isConditionAGuard = checkNullCheckGuardCondition(condition); return isConditionAGuard; } } } return false; }
Example #4
Source File: TransformStrategy.java From astor with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override public <T> void visitCtConditional(CtConditional<T> conditional) { super.visitCtConditional(conditional); CtExpression exp = conditional.getCondition(); if (candidates.containsKey(exp)) { conditional.setCondition(candidates.get(exp)); saveSketchAndSynthesize(); conditional.setCondition(exp); resoreDiskFile(); } exp = conditional.getElseExpression(); if (candidates.containsKey(exp)) { conditional.setElseExpression(candidates.get(exp)); saveSketchAndSynthesize(); conditional.setElseExpression(exp); resoreDiskFile(); } exp = conditional.getThenExpression(); if (candidates.containsKey(exp)) { conditional.setThenExpression(candidates.get(exp)); saveSketchAndSynthesize(); conditional.setThenExpression(exp); resoreDiskFile(); } }