Java Code Examples for spoon.reflect.code.CtIf#getCondition()
The following examples show how to use
spoon.reflect.code.CtIf#getCondition() .
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: ExtendedRepairGenerator.java From coming with MIT License | 6 votes |
private void genTightCondition(CtIf n) { CtExpression<Boolean> oldCondition = n.getCondition(); CtLiteral<Boolean> placeholder = factory.createLiteral(); placeholder.setValue(true); // consider the placeholder, should this be more concrete? CtUnaryOperator<Boolean> tmpCondition = factory.createUnaryOperator(); tmpCondition.setKind(UnaryOperatorKind.NOT); tmpCondition.setOperand(placeholder); CtBinaryOperator<Boolean> newCondition = factory.createBinaryOperator(); newCondition.setKind(BinaryOperatorKind.AND); newCondition.setLeftHandOperand(oldCondition); newCondition.setRightHandOperand(placeholder); CtIf S = n.clone(); S.setParent(n.getParent()); S.setCondition(newCondition); Repair repair = new Repair(); repair.kind = RepairKind.TightenConditionKind; repair.isReplace = true; repair.srcElem = n; repair.dstElem = S; repair.atoms.addAll(repairAnalyzer.getCondCandidateVars(n)); repairs.add(repair); // we do not consider the case of short-circuit evaluation at all }
Example 2
Source File: ExtendedRepairGenerator.java From coming with MIT License | 6 votes |
private void genLooseCondition(CtIf n) { CtExpression<Boolean> oldCondition = n.getCondition(); CtLiteral<Boolean> placeholder = factory.createLiteral(); placeholder.setValue(true); // consider the placeholder, should this be more concrete? CtBinaryOperator<Boolean> newCondition = factory.createBinaryOperator(); newCondition.setKind(BinaryOperatorKind.OR); newCondition.setLeftHandOperand(oldCondition); newCondition.setRightHandOperand(placeholder); CtIf S = n.clone(); S.setParent(n.getParent()); S.setCondition(newCondition); Repair repair = new Repair(); repair.kind = RepairKind.LoosenConditionKind; repair.isReplace = true; repair.srcElem = n; repair.dstElem = S; repair.atoms.addAll(repairAnalyzer.getCondCandidateVars(n)); repairs.add(repair); // we do not consider the case of short-circuit evaluation at all }
Example 3
Source File: ConditionRemoveTransform.java From astor with GNU General Public License v2.0 | 6 votes |
@SuppressWarnings({ "static-access", "rawtypes", "unchecked" }) public void visitCtIf(CtIf ifElement) { super.visitCtIf(ifElement); CtExpression cond = ifElement.getCondition(); CtLiteral<Boolean> literalvalue = this.mutSupporter.getFactory().Core().createLiteral(); Boolean bval=false; literalvalue.setValue(bval); CtBinaryOperator<?> newcond = this.mutSupporter.getFactory().Core().createBinaryOperator(); newcond.setKind(BinaryOperatorKind.AND); newcond.setRightHandOperand(literalvalue); newcond.setLeftHandOperand(cond); ifElement.setCondition((CtExpression<Boolean>) newcond); saveSketchAndSynthesize(); ifElement.setCondition(cond); resoreDiskFile(); }
Example 4
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 5
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 6
Source File: TransformStrategy.java From astor with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public void visitCtIf(CtIf ifElement) { super.visitCtIf(ifElement); @SuppressWarnings("rawtypes") CtExpression exper=ifElement.getCondition(); if (candidates.containsKey(exper)) { ifElement.setCondition(candidates.get(exper)); saveSketchAndSynthesize(); ifElement.setCondition(exper); resoreDiskFile(); } }
Example 7
Source File: LogicalExpressionAnalyzer.java From coming with MIT License | 4 votes |
@Override public void visitCtIf(CtIf ifElement) { toScan = ifElement.getCondition(); }