public <T> void visitCtCodeSnippetExpression(spoon.reflect.code.CtCodeSnippetExpression<T> e) { ((spoon.reflect.code.CtCodeSnippetExpression<T>) (other)).setValue(e.getValue()); super.visitCtCodeSnippetExpression(e); }
/** * Creates a Code Snippet expression. * * @param <T> * The type of the expression represented by the CodeSnippet * @param expression * The string that contains the expression. * @return a new CtCodeSnippetExpression. */ public <T> CtCodeSnippetExpression<T> createCodeSnippetExpression(String expression) { CtCodeSnippetExpression<T> e = factory.Core().createCodeSnippetExpression(); e.setValue(expression); return e; }
/** * Creates a Code Snippet expression. * * @param <T> * The type of the expression represented by the CodeSnippet * @param expression * The string that contains the expression. * @return a new CtCodeSnippetExpression. */ public <T> CtCodeSnippetExpression<T> createCodeSnippetExpression(String expression) { CtCodeSnippetExpression<T> e = factory.Core().createCodeSnippetExpression(); e.setValue(expression); return e; }
@Override public List<CtElement> executeSynthesis(ModificationPoint modificationPoint, CtElement hole, CtType expectedtype, List<CtVariable> contextOfModificationPoint, ExecutionContext values) { List<CtElement> result = new ArrayList<>(); DynamothSynthesizer dynamothSynthesizer = new DynamothSynthesizer((DynamothSynthesisContext) values); Candidates candidates = dynamothSynthesizer.combineValues(); for (fr.inria.lille.repair.expression.Expression expression : candidates) { String candidateCode = expression.toString(); log.info("Candidate: " + candidateCode); if (hole instanceof CtExpression) { CtCodeSnippetExpression<Boolean> snippet = MutationSupporter.getFactory().Core() .createCodeSnippetExpression(); snippet.setValue(candidateCode); result.add(snippet); } else { log.debug("Error: Other type not analyzed " + hole.getClass().getName()); } } return result; }
protected IngredientFromDyna createIngredient(Expression expression) { String candidateCode = expression.asPatch(); CtCodeSnippetExpression<Boolean> snippet = MutationSupporter.getFactory().Core().createCodeSnippetExpression(); snippet.setValue(candidateCode); IngredientFromDyna ingredient = new IngredientFromDyna(snippet, expression); // take one form the cluster by type log.debug("Creating ingredient from Dynamoth expression: " + expression + " --result--> Spoon Ingredient: " + ingredient + "| value: " + expression.getValue().getRealValue()); return ingredient; }
@Override public CtIf processCondition(CtStatement element, String newCondition) { CtCodeSnippetExpression<Boolean> snippet = element.getFactory().Core().createCodeSnippetExpression(); snippet.setValue(newCondition); CtExpression<Boolean> condition = getCondition(element); condition.replace(snippet); return (CtIf) element; } }
void mergeChildNodes() { CtClass<?> mergedClass = getMergedClass(); for (CompilationNode child : innerNodes) { CtClass<?> childMergedClass = child.getMergedClass(); add(mergedClass, childMergedClass, mergedClass::addNestedType); CtCodeSnippetExpression constructor = f.Core().createCodeSnippetExpression(); constructor.setValue("new " + childMergedClass.getSimpleName() + "()"); child.parentAccessField.setDefaultExpression(constructor); child.parentAccessField.setType((CtTypeReference) childMergedClass.getReference()); child.parentAccessField.addModifier(FINAL); child.mergeChildNodes(); } } }
/** * Create the content of the condition * * @param ctInvocation * @return */ private CtBlock<Object> createThen(CtInvocation<?> ctInvocation) { CtBlock<Object> thenStatement = ctInvocation.getFactory().Core() .createBlock(); thenStatement .addStatement((getFactory().Code() .createCodeSnippetStatement("System.out.println(\"Else...\")"))); thenStatement.addStatement((getFactory().Code() .createCodeSnippetStatement("System.out.println(" + Debug.class.getCanonicalName() + ".getSolvedPC())"))); CtAssert<Object> ctAssert = ctInvocation.getFactory().Core() .createAssert(); CtCodeSnippetExpression<Boolean> assertExpression = getFactory().Core() .createCodeSnippetExpression(); assertExpression.setValue("false"); ctAssert.setAssertExpression(assertExpression); ctAssert.setExpression(getFactory().Code().createCodeSnippetExpression( String.format("\"%s\"", ctInvocation.toString().replaceAll("\"", "'")))); thenStatement.addStatement(ctAssert); return thenStatement; }
@Override public CtIf processCondition(CtStatement element, String newCondition) { //logger.debug("##### {} ##### Before:\n{}", element, element.getParent()); // if the element is not a line if (!new LineFilter().matches(element)) { element = element.getParent(new LineFilter()); } CtElement parent = element.getParent(); CtIf newIf = element.getFactory().Core().createIf(); CtCodeSnippetExpression<Boolean> condition = element.getFactory().Core().createCodeSnippetExpression(); condition.setValue(newCondition); newIf.setCondition(condition); // Fix : warning: ignoring inconsistent parent for [CtElem1] ( [CtElem2] != [CtElem3] ) newIf.setParent(parent); element.replace(newIf); // this should be after the replace to avoid an StackOverflowException caused by the circular reference. newIf.setThenStatement(element); //logger.debug("##### {} ##### After:\n{}", element, element.getParent().getParent()); return newIf; } }