spoon.reflect.code.CtExpression Java Examples
The following examples show how to use
spoon.reflect.code.CtExpression.
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: LogicalExpressionMetaMutator.java From metamutator with GNU General Public License v3.0 | 6 votes |
private boolean isNumber(CtExpression<?> operand) { if (operand.getType().toString().equals(CtTypeReference.NULL_TYPE_NAME)) return false; if (operand.toString().contains(".class")) return false; return operand.getType().getSimpleName().equals("int") || operand.getType().getSimpleName().equals("long") || operand.getType().getSimpleName().equals("byte") || operand.getType().getSimpleName().equals("char") || operand.getType().getSimpleName().equals("float") || operand.getType().getSimpleName().equals("double") || operand.getType().isSubtypeOf(getFactory().Type().createReference(Number.class)); }
Example #2
Source File: BoundProcessor.java From spoon-examples with GNU General Public License v2.0 | 6 votes |
public void process(Bound annotation, CtParameter<?> element) { final CtMethod parent = element.getParent(CtMethod.class); // Build if check for min. CtIf anIf = getFactory().Core().createIf(); anIf.setCondition(getFactory().Code().<Boolean>createCodeSnippetExpression(element.getSimpleName() + " < " + annotation.min())); CtThrow throwStmt = getFactory().Core().createThrow(); throwStmt.setThrownExpression((CtExpression<? extends Throwable>) getFactory().Core().createCodeSnippetExpression().setValue("new RuntimeException(\"out of min bound (\" + " + element.getSimpleName() + " + \" < " + annotation.min() + "\")")); anIf.setThenStatement(throwStmt); parent.getBody().insertBegin(anIf); anIf.setParent(parent); // Build if check for max. anIf = getFactory().Core().createIf(); anIf.setCondition(getFactory().Code().<Boolean>createCodeSnippetExpression(element.getSimpleName() + " > " + annotation.max())); anIf.setThenStatement(getFactory().Code().createCtThrow("new RuntimeException(\"out of max bound (\" + " + element.getSimpleName() + " + \" > " + annotation.max() + "\")")); parent.getBody().insertBegin(anIf); anIf.setParent(parent); }
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: MetaGenerator.java From astor with GNU General Public License v2.0 | 6 votes |
public static MetaOperatorInstance createMetaFineGrainedReplacement(ModificationPoint modificationPoint, CtExpression elementSource, int variableCounter, List<Ingredient> ingredients, List<CtParameter<?>> parameters, List<CtExpression<?>> realParameters, AstorOperator parentOperator, CtTypeReference returnType) { MetaOperatorInstance opMega = new MetaOperatorInstance((MetaOperator) parentOperator, MetaGenerator.getNewIdentifier()); List<OperatorInstance> opsOfVariant = new ArrayList(); Map<Integer, Ingredient> ingredientOfMapped = new HashMap<>(); createMetaForSingleElement(opMega, modificationPoint, elementSource, variableCounter, ingredients, parameters, realParameters, returnType, opsOfVariant, ingredientOfMapped); opMega.setOperatorInstances(opsOfVariant); opMega.setAllIngredients(ingredientOfMapped); opMega.setOperationApplied(parentOperator); opMega.setOriginal(elementSource); opMega.setModificationPoint(modificationPoint); return opMega; }
Example #5
Source File: ExpressionTransform.java From astor with GNU General Public License v2.0 | 6 votes |
@Override public <T> void visitCtFieldRead(CtFieldRead<T> fieldRead) { String type = fieldRead.getType().getQualifiedName(); type = type.replaceAll("\\d",""); CtEnum enumRead=enummap.get(type); @SuppressWarnings("rawtypes") CtExpression exp = null; if(enumRead==null) exp = ExpressionGenerator.fetchEXP(this.mutSupporter, this.modificationPoint, type, querytype); else exp = ExpressionGenerator.fetchENUM(enumRead, this.mutSupporter, type, querytype); if (exp != null) candidates.put(fieldRead, exp); }
Example #6
Source File: BinaryOperatorMutator.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Creates alternatives Expressions (Binary Operations) given a list of Binary * operators kind operators. The original kind (that one included in the * original expression is not analyzed) * * @param result * @param op * @param kind * @param operators */ protected void addRemainings(List<CtExpression> result, CtBinaryOperator<?> op, BinaryOperatorKind kind, List<BinaryOperatorKind> operators) { // TODO: recursive? if (operators.contains(kind)) { for (BinaryOperatorKind binaryOperatorKind : operators) { if (binaryOperatorKind != kind) { // Cloning CtExpression right = factory.Core().clone(op.getRightHandOperand()); CtExpression left = factory.Core().clone(op.getLeftHandOperand()); CtBinaryOperator binaryOp = factory.Code().createBinaryOperator(left, right, binaryOperatorKind); // Set parent right.setParent(binaryOp); left.setParent(binaryOp); result.add(binaryOp); } } } }
Example #7
Source File: SingleLogicExpOperator.java From astor with GNU General Public License v2.0 | 6 votes |
@Override public boolean applyModification() { CtBinaryOperator binaryOperator = new CtBinaryOperatorImpl<>(); binaryOperator.setKind(operator); CtExpression leftOriginal2 = (CtExpression) MetaGenerator.geOriginalElement(leftOriginal); binaryOperator.setLeftHandOperand(leftOriginal2.clone()); CtExpression newRightExpression = rightNew; binaryOperator.setRightHandOperand(newRightExpression); // binaryOperator.setFactory(MutationSupporter.getFactory()); binaryOperator.setParent(leftOriginal2.getParent()); // super.setOriginal(leftOriginal2); super.setModified(binaryOperator); return super.applyModification(); }
Example #8
Source File: AbstractCodeAnalyzer.java From coming with MIT License | 6 votes |
/** * Return if the Condition is a guard * * @param condition * @return */ // we want the condition not to be null related check public boolean checkNormalGuardCondition(CtExpression condition) { if (condition != null) { List<CtBinaryOperator> binOp = condition.getElements(new TypeFilter<>(CtBinaryOperator.class)); if (binOp != null && binOp.size() > 0) { for (CtBinaryOperator ctBinaryOperator : binOp) { if (ctBinaryOperator.getRightHandOperand().toString().equals("null") || ctBinaryOperator.getLeftHandOperand().toString().equals("null")) { return false; } } } return true; } return false; }
Example #9
Source File: AbstractCodeAnalyzer.java From coming with MIT License | 6 votes |
public boolean checkNullCheckGuardCondition(CtExpression condition) { if (condition != null) { List<CtBinaryOperator> binOp = condition.getElements(new TypeFilter<>(CtBinaryOperator.class)); if (binOp != null && binOp.size() > 0) { for (CtBinaryOperator ctBinaryOperator : binOp) { if (!ctBinaryOperator.getRightHandOperand().toString().equals("null") && !ctBinaryOperator.getLeftHandOperand().toString().equals("null")) { return false; } } return true; } return false; } return false; }
Example #10
Source File: ExpressionTransformer.java From astor with GNU General Public License v2.0 | 6 votes |
public static boolean doReplace(OperatorInstance operation) { boolean successful = false; try { CtExpression ctst = (CtExpression) operation.getOriginal(); CtExpression fix = (CtExpression) operation.getModified(); ctst.replace((CtExpression) fix); successful = true; operation.setSuccessfulyApplied((successful)); } catch (Exception ex) { log.error("Error applying an operation, exception: " + ex.getMessage()); operation.setExceptionAtApplied(ex); operation.setSuccessfulyApplied(false); } return successful; }
Example #11
Source File: MetaGenerator.java From astor with GNU General Public License v2.0 | 6 votes |
private static List<CtExpression<?>> filterParameter(List<CtExpression<?>> realParameters) { List<CtExpression<?>> parametersN = new ArrayList<>(); HashMap<String, CtVariableAccess> seen = new HashMap(); for (CtExpression<?> ctParameter : realParameters) { if (ctParameter instanceof CtVariableAccess) { CtVariableAccess va = (CtVariableAccess) ctParameter; if (!seen.containsKey(va.getVariable().getSimpleName())) { parametersN.add(ctParameter); seen.put(va.getVariable().getSimpleName(), va); } else { // we have a var with the same name CtVariableAccess other = seen.get(va.getVariable().getSimpleName()); if (other instanceof CtFieldAccess && !(va instanceof CtFieldAccess)) { // replace the field access by the other var access int ind = parametersN.indexOf(other); parametersN.remove(ind); parametersN.add(ind, va); seen.put(va.getVariable().getSimpleName(), va); } } } } return parametersN; }
Example #12
Source File: ExpressionTransform.java From astor with GNU General Public License v2.0 | 6 votes |
@Override public <T> void visitCtBinaryOperator(CtBinaryOperator<T> operator) { super.visitCtBinaryOperator(operator); @SuppressWarnings("rawtypes") CtExpression left = operator.getLeftHandOperand(); if (candidates.containsKey(left)) { operator.setLeftHandOperand(candidates.get(left)); saveSketchAndSynthesize(); operator.setLeftHandOperand(left); resoreDiskFile(); } @SuppressWarnings("rawtypes") CtExpression right = operator.getRightHandOperand(); if (candidates.containsKey(right)) { operator.setRightHandOperand(candidates.get(right)); saveSketchAndSynthesize(); operator.setRightHandOperand(right); resoreDiskFile(); } }
Example #13
Source File: OverloadMethodTransform.java From astor with GNU General Public License v2.0 | 6 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public <T> void visitCtConstructorCall(CtConstructorCall<T> ctConstructorCall) { super.visitCtConstructorCall(ctConstructorCall); String type = ctConstructorCall.getType().getQualifiedName(); List<CtExpression<?>> argumentlist = ctConstructorCall.getArguments(); List<String> orig = resolveTypes(argumentlist); CtClass classname = parser.getClassMap().get(type); if(classname!=null) { Set<CtConstructor<T>> constructors=classname.getConstructors(); for(CtConstructor constructor:constructors) { List<CtParameter> paramlist=constructor.getParameters(); List<String> target=resolveParams(paramlist); transformOneMethod(orig,target,ctConstructorCall); } } else { List<Class[]> params = parser.fetchMethods(type, type); for (Class[] p : params) transformOneConstructor(orig, ctConstructorCall, p); } }
Example #14
Source File: SupportOperators.java From astor with GNU General Public License v2.0 | 6 votes |
public static List<CtInvocation> realInvocationsFromCombination(CtMethod anotherMethod, CtExpression target, List<List<CtExpression<?>>> possibleArguments) { List<CtInvocation> newInvocations = new ArrayList<>(); for (List<CtExpression<?>> arguments : possibleArguments) { CtInvocation newInvocation = MutationSupporter.getFactory().createInvocation(target, anotherMethod.getReference(), arguments); newInvocation.setExecutable(anotherMethod.getReference()); newInvocation.setArguments(arguments); newInvocation.setTarget(target); newInvocations.add(newInvocation); } return newInvocations; }
Example #15
Source File: TransformStrategy.java From astor with GNU General Public License v2.0 | 6 votes |
@Override public <T> void visitCtConstructorCall(CtConstructorCall<T> ctConstructorCall) { super.visitCtConstructorCall(ctConstructorCall); List<CtExpression<?>> argumentlist = ctConstructorCall.getArguments(); for (int i = 0; i < argumentlist.size(); i++) { @SuppressWarnings("rawtypes") CtExpression p = argumentlist.get(i); if (candidates.containsKey(p)) { argumentlist.set(i, candidates.get(p)); // ctConstructorCall.setArguments(argumentlist); saveSketchAndSynthesize(); argumentlist.set(i, p); resoreDiskFile(); // ctConstructorCall.setArguments(argumentlist); } } }
Example #16
Source File: LogicalExpressionAnalyzer.java From coming with MIT License | 6 votes |
public boolean isBooleanExpression(CtElement currentexpression) { if (currentexpression == null|| currentexpression instanceof CtVariableAccess) return false; if (isLogicalExpression(currentexpression)) { return true; } if(currentexpression instanceof CtExpression) { CtExpression exper= (CtExpression) currentexpression; try { if (exper.getType() != null && exper.getType().unbox().toString().equals("boolean")) { return true; } } catch (Exception e) { return false; } } return false; }
Example #17
Source File: ConditionRemoveTransform.java From astor with GNU General Public License v2.0 | 6 votes |
@SuppressWarnings({ "rawtypes", "static-access" }) @Override public <T> void visitCtBinaryOperator(CtBinaryOperator<T> operator) { super.visitCtBinaryOperator(operator); if(operator.getKind()==BinaryOperatorKind.AND||operator.getKind()==BinaryOperatorKind.OR) { CtExpression right = operator.getRightHandOperand(); operator.setKind(BinaryOperatorKind.AND); CtLiteral<Boolean> literalvalue = this.mutSupporter.getFactory().Core().createLiteral(); Boolean bval=true; literalvalue.setValue(bval); operator.setRightHandOperand(literalvalue); saveSketchAndSynthesize(); operator.setRightHandOperand(right); resoreDiskFile(); CtExpression left = operator.getLeftHandOperand(); operator.setKind(BinaryOperatorKind.AND); operator.setLeftHandOperand(literalvalue); saveSketchAndSynthesize(); operator.setLeftHandOperand(left); resoreDiskFile(); } }
Example #18
Source File: TransformStrategy.java From astor with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public <S> void visitCtCase(CtCase<S> caseStatement) { super.visitCtCase(caseStatement); CtExpression exper=caseStatement.getCaseExpression(); if (candidates.containsKey(exper)) { caseStatement.setCaseExpression(candidates.get(exper)); saveSketchAndSynthesize(); caseStatement.setCaseExpression(exper); resoreDiskFile(); } }
Example #19
Source File: BinaryOperatorAnalyzer.java From coming with MIT License | 5 votes |
private void analyzeBinaryLogicalOperator(CtBinaryOperator operatorunderstudy, int operatorindex, Cntx<Object> context) { boolean whethercontainnotoperator = false; BinaryOperatorKind operatorkind = operatorunderstudy.getKind(); if(logicalOperator.contains(operatorkind)) { CtExpression leftexpression = operatorunderstudy.getLeftHandOperand(); CtExpression rightexpression = operatorunderstudy.getRightHandOperand(); List<CtBinaryOperator> logicalOperatorLeft = leftexpression.getElements( e -> e instanceof CtBinaryOperator && logicalOperator.contains(((CtBinaryOperator) e).getKind())); List<CtBinaryOperator> logicalOperatorRight = rightexpression.getElements( e -> e instanceof CtBinaryOperator && logicalOperator.contains(((CtBinaryOperator) e).getKind())); if(logicalOperatorLeft.size() == 0) { if(scannotoperator(leftexpression)) whethercontainnotoperator=true; } if(!whethercontainnotoperator && logicalOperatorRight.size() == 0) { if(scannotoperator(rightexpression)) whethercontainnotoperator=true; } } writeGroupedInfo(context, Integer.toString(operatorindex)+"_"+operatorunderstudy, CodeFeatures.O2_LOGICAL_CONTAIN_NOT, whethercontainnotoperator, "FEATURES_BINARYOPERATOR"); }
Example #20
Source File: TransformStrategy.java From astor with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public <R> void visitCtReturn(CtReturn<R> returnStatement) { super.visitCtReturn(returnStatement); CtExpression exper=returnStatement.getReturnedExpression(); if (candidates.containsKey(exper)) { returnStatement.setReturnedExpression(candidates.get(exper)); saveSketchAndSynthesize(); returnStatement.setReturnedExpression(exper); resoreDiskFile(); } }
Example #21
Source File: SupportOperators.java From astor with GNU General Public License v2.0 | 5 votes |
public static List<List<CtExpression<?>>> computeParameters(CtMethod anotherMethod, ModificationPoint point) { List<CtVariable> variablesInScope = point.getContextOfModificationPoint(); List<CtParameter> parameterTypes = anotherMethod.getParameters(); MapList<CtTypeReference, CtElement> candidateMappings = new MapList<>(); // Groups vars according to types for (CtParameter ctTypeParameter : parameterTypes) { CtTypeReference parType = ctTypeParameter.getType(); if (!candidateMappings.containsKey(parType)) { List compatible = variablesInScope.stream().filter(e -> e.getType().isSubtypeOf(parType)) .collect(Collectors.toList()); // A par without a var if (compatible.isEmpty()) return null; candidateMappings.put(parType, compatible); } } List<List<CtExpression<?>>> candidateArguments = createAllParametersCombinations(parameterTypes, candidateMappings); return candidateArguments; }
Example #22
Source File: DataCombinatorListenerSpoon.java From astor with GNU General Public License v2.0 | 5 votes |
@Override public boolean check(CtExpression expression) { // if (!allCombinedNotEvaluatedExpressions.contains(expression)) { allCombinedNotEvaluatedExpressions.add(expression); return true; // } // return false; }
Example #23
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 #24
Source File: TransformStrategy.java From astor with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override public <T> void visitCtUnaryOperator(CtUnaryOperator<T> operator) { super.visitCtUnaryOperator(operator); CtExpression exper=operator.getOperand(); if (candidates.containsKey(exper)) { operator.setOperand(candidates.get(exper)); saveSketchAndSynthesize(); operator.setOperand(exper); resoreDiskFile(); } }
Example #25
Source File: OperatorTransform.java From astor with GNU General Public License v2.0 | 5 votes |
@Override public <T> void visitCtBinaryOperator(CtBinaryOperator<T> operator) { super.visitCtBinaryOperator(operator); @SuppressWarnings("rawtypes") CtExpression left = operator.getLeftHandOperand(); String typelefthand=left.getType().getQualifiedName(); String typeoperator=operator.getType().getQualifiedName(); typelefthand = typelefthand.replaceAll("\\d",""); typeoperator = typeoperator.replaceAll("\\d",""); @SuppressWarnings("rawtypes") CtExpression exp = null; BinaryOperatorKind kind=operator.getKind(); if(rop.contains(kind)) exp = OperatorGenerator.fetchROP(operator, this.mutSupporter, this.modificationPoint, typelefthand, "ROP"); else if(aop.contains(kind)) exp = OperatorGenerator.fetchROP(operator, this.mutSupporter, this.modificationPoint, typeoperator, "AOP"); if (exp != null) candidates.put(operator, exp); if (candidates.containsKey(left)) { operator.setLeftHandOperand(candidates.get(left)); saveSketchAndSynthesize(); operator.setLeftHandOperand(left); resoreDiskFile(); } @SuppressWarnings("rawtypes") CtExpression right = operator.getRightHandOperand(); if (candidates.containsKey(right)) { operator.setRightHandOperand(candidates.get(right)); saveSketchAndSynthesize(); operator.setRightHandOperand(right); resoreDiskFile(); } }
Example #26
Source File: LogicExpOperator.java From astor with GNU General Public License v2.0 | 5 votes |
private List<Ingredient> computeIngredientsFromExpressionExplansion(ModificationPoint modificationPoint, CtExpression previousExpression, List<IngredientFromDyna> ingredientsDynamoth, BinaryOperatorKind operatorKind2) { List<Ingredient> ingredientsNewBinaryExpressions = new ArrayList(); for (IngredientFromDyna ingredientFromDyna : ingredientsDynamoth) { CtBinaryOperator binaryOperator = new CtBinaryOperatorImpl<>(); binaryOperator.setKind(operatorKind2); CtExpression previousExpressionCloned = previousExpression.clone(); MutationSupporter.clearPosition(previousExpressionCloned); binaryOperator.setLeftHandOperand(previousExpressionCloned); CtExpression newRightExpression = MutationSupporter.getFactory() .createCodeSnippetExpression(ingredientFromDyna.getDynmothExpression().toString()); binaryOperator.setRightHandOperand(newRightExpression); // binaryOperator.setFactory(MutationSupporter.getFactory()); binaryOperator.setParent(previousExpression.getParent()); Ingredient newIngredientExtended = new Ingredient(binaryOperator); // Updated: new code newIngredientExtended.getMetadata().put("operator", operatorKind2); newIngredientExtended.getMetadata().put("right", newRightExpression); newIngredientExtended.getMetadata().put("leftoriginal", previousExpression); // ingredientsNewBinaryExpressions.add(newIngredientExtended); } return ingredientsNewBinaryExpressions; }
Example #27
Source File: LogicExpOperator.java From astor with GNU General Public License v2.0 | 5 votes |
@Override public boolean checkTargetCompatibility(CtElement target) { if (target instanceof CtExpression) { CtExpression e = (CtExpression) target; return (e.getType() != null && e.getType().unbox().getSimpleName().equals("boolean")); } else return false; }
Example #28
Source File: Cardumen1HApproach.java From astor with GNU General Public License v2.0 | 5 votes |
@Override protected void loadIngredientPool() throws JSAPException, Exception { List<TargetElementProcessor<?>> ingredientProcessors = this.getTargetElementProcessors(); TOSIngredientPool<CtExpression<?>> ingredientPool = new TOSIngredientPool<CtExpression<?>>( ingredientProcessors); String scope = ConfigurationProperties.getProperty(ExtensionPoints.INGREDIENT_STRATEGY_SCOPE.identifier); if (scope != null) { ingredientPool.scope = IngredientPoolScope.valueOf(scope.toUpperCase()); } this.setIngredientPool(ingredientPool); }
Example #29
Source File: WrapwithIfOp.java From astor with GNU General Public License v2.0 | 5 votes |
@Override public List<MetaOperatorInstance> createMetaOperatorInstances(ModificationPoint modificationPoint, List<IngredientFromDyna> ingredients) { // The parameters to be included in the new method List<CtVariableAccess> varsToBeParameters = SupportOperators.collectAllVarsFromDynaIngredients(ingredients, modificationPoint); // List of parameters List<CtParameter<?>> parameters = new ArrayList<>(); List<CtExpression<?>> realParameters = new ArrayList<>(); for (CtVariableAccess ctVariableAccess : varsToBeParameters) { // the parent is null, it is setter latter CtParameter pari = MutationSupporter.getFactory().createParameter(null, ctVariableAccess.getType(), ctVariableAccess.getVariable().getSimpleName()); parameters.add(pari); realParameters.add(ctVariableAccess.clone().setPositions(new NoSourcePosition())); } // let's start with one, and let's keep the Zero for the default (all ifs are // false) int candidateNumber = 0; CtTypeReference returnType = MutationSupporter.getFactory().createCtTypeReference(Boolean.class); CtElement codeElement = (targetElement == null) ? modificationPoint.getCodeElement() : targetElement; // let's create the meta MetaOperatorInstance megaOp = MetaGenerator.createMetaStatementReplacement(modificationPoint, codeElement, MutationSupporter.getFactory().createCodeSnippetExpression("true"), candidateNumber, ingredients.stream().map(Ingredient.class::cast).collect(Collectors.toList())// , parameters, realParameters, this, returnType); List<MetaOperatorInstance> opsMega = new ArrayList(); opsMega.add(megaOp); return opsMega; }
Example #30
Source File: ConditionAddTransform.java From astor with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings({ "rawtypes", "static-access", "unchecked" }) private void writeIfReturn(String type, CtBlock parent, int id) { CtExpression conditionExp = ExpressionGenerator.fetchEXP(this.mutSupporter, this.modificationPoint, type, querytype); CtIf ifstmt = this.mutSupporter.getFactory().Core().createIf(); ifstmt.setCondition(conditionExp); CtElement parentmethod=parent; do { parentmethod=parentmethod.getParent(); } while (!(parentmethod instanceof CtMethod)); String returntype="void"; returntype=((CtMethod)parentmethod).getType().getQualifiedName(); returntype = returntype.replaceAll("\\d",""); CtReturn returnstmt = this.mutSupporter.getFactory().Core().createReturn(); if (!returntype.toLowerCase().equals("void")) { CtExpression returnexp = ExpressionGenerator.fetchEXP(this.mutSupporter, this.modificationPoint, returntype, "EXP"); returnstmt.setReturnedExpression(returnexp); } ifstmt.setThenStatement(returnstmt); parent.addStatement(id, ifstmt); saveSketchAndSynthesize(); parent.removeStatement(ifstmt); resoreDiskFile(); }