public List<CtExpression<?>> cloneList(List<CtExpression<?>> list) { List<CtExpression<?>> clone = new ArrayList<CtExpression<?>>(list.size()); for (CtExpression<?> item : list) clone.add(item.clone()); return clone; }
@Override public <T extends CtExpression> T getWrappedValue(String key) { CtExpression ctExpression = this.getValue(key); CtTypeReference typeReference = this.getAnnotationType(); CtType type = typeReference.getTypeDeclaration(); if (type != null) { CtMethod method = type.getMethod(key); if (method != null) { CtTypeReference returnType = method.getType(); if (returnType instanceof CtArrayTypeReference && !(ctExpression instanceof CtNewArray)) { CtNewArray newArray = getFactory().Core().createNewArray(); CtArrayTypeReference typeReference2 = this.getFactory().createArrayTypeReference(); typeReference2.setComponentType(ctExpression.getType().clone()); newArray.setType(typeReference2); newArray.addElement(ctExpression.clone()); return (T) newArray; } } } return (T) ctExpression; }
private void inlineLocalVariable(CtMethod<?> amplifiedTestToBeMinimized) { final List<CtLocalVariable> localVariables = amplifiedTestToBeMinimized.getElements(new TypeFilter<>(CtLocalVariable.class)); final List<CtVariableRead> variableReads = localVariables.stream().map(LOCAL_VARIABLE_READ_FILTER::new) .flatMap(filter -> amplifiedTestToBeMinimized.getElements(filter).stream()) .collect(Collectors.toList()); // we can inline all local variables that are used one time and that have been generated by DSpot final List<CtLocalVariable> oneTimeUsedLocalVariable = localVariables.stream() .filter(localVariable -> variableReads.stream() .map(CtVariableRead::getVariable) .filter(variableRead -> variableRead.equals(localVariable.getReference())) .count() == 1 ).collect(Collectors.toList()); oneTimeUsedLocalVariable.stream().map(localVariable -> { DSpotUtils.printProgress(oneTimeUsedLocalVariable.indexOf(localVariable), oneTimeUsedLocalVariable.size()); variableReads.stream() .filter(variableRead -> variableRead.getVariable().equals(localVariable.getReference()) ).findFirst() .get() .replace(localVariable.getAssignment().clone()); return localVariable; }).forEach(amplifiedTestToBeMinimized.getBody()::removeStatement); //TODO we can inline all local variables that are used only in assertion }
private void inlineLocalVariable(CtMethod<?> amplifiedTestToBeMinimized) { final List<CtLocalVariable> localVariables = amplifiedTestToBeMinimized.getElements(new TypeFilter<>(CtLocalVariable.class)); final List<CtVariableRead> variableReads = localVariables.stream().map(LOCAL_VARIABLE_READ_FILTER::new) .flatMap(filter -> amplifiedTestToBeMinimized.getElements(filter).stream()) .collect(Collectors.toList()); // we can inline all local variables that are used one time and that have been generated by DSpot final List<CtLocalVariable> oneTimeUsedLocalVariable = localVariables.stream() .filter(localVariable -> variableReads.stream() .map(CtVariableRead::getVariable) .filter(variableRead -> variableRead.equals(localVariable.getReference())) .count() == 1 ).collect(Collectors.toList()); oneTimeUsedLocalVariable.stream().map(localVariable -> { DSpotUtils.printProgress(oneTimeUsedLocalVariable.indexOf(localVariable), oneTimeUsedLocalVariable.size()); variableReads.stream() .filter(variableRead -> variableRead.getVariable().equals(localVariable.getReference()) ).findFirst() .get() .replace(localVariable.getAssignment().clone()); return localVariable; }).forEach(amplifiedTestToBeMinimized.getBody()::removeStatement); //TODO we can inline all local variables that are used only in assertion }
private MapList<CtInvocation, Ingredient> retrieveMethodHasCompatibleParameterAndReturnSameMethod( CtElement suspiciousElement) { MapList<CtInvocation, Ingredient> result = new MapList<CtInvocation, Ingredient>(); List<CtInvocation> invocations = suspiciousElement.getElements(e -> (e instanceof CtInvocation)).stream() .map(CtInvocation.class::cast).collect(Collectors.toList()); for (CtInvocation invocation : invocations) { for (Object oparameter : invocation.getArguments()) { CtExpression argument = (CtExpression) oparameter; if (SupportOperators.compareTypes(invocation.getType(), argument.getType())) { CtExpression clonedExpressionArgument = argument.clone(); MutationSupporter.clearPosition(clonedExpressionArgument); Ingredient newIngredient = new Ingredient(clonedExpressionArgument); result.add(invocation, newIngredient); } } } return result; }
CtExpression targetClone = target.clone(); CtInvocation newInvocation = factory.Code().createInvocation(targetClone, methodToInvokeToAdd.getReference(), arguments);
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); newIngredientExtended.setDerivedFrom(previousExpression); ingredientsNewBinaryExpressions.add(newIngredientExtended); } return ingredientsNewBinaryExpressions; }
(boolean) invocation.getMetadata(AssertGeneratorHelper.METADATA_ASSERT_AMPLIFICATION))) { for (CtExpression<?> argument : invocation.getArguments()) { CtExpression clone = ((CtExpression) argument).clone(); if (clone instanceof CtUnaryOperator) { clone = ((CtUnaryOperator) clone).getOperand();
CtExpression expCloned = expressionToExpand.clone(); expCloned.setPosition(new NoSourcePosition()); MutationSupporter.clearPosition(expCloned);
CtExpression expCloned = expToChange.clone(); expCloned.setPosition(new NoSourcePosition()); clearPosition(expCloned);