/** * 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; }
public <T> void visitCtCodeSnippetExpression(final spoon.reflect.code.CtCodeSnippetExpression<T> expression) { spoon.reflect.code.CtCodeSnippetExpression<T> aCtCodeSnippetExpression = expression.getFactory().Core().createCodeSnippetExpression(); this.builder.copy(expression, aCtCodeSnippetExpression); aCtCodeSnippetExpression.setType(this.cloneHelper.clone(expression.getType())); aCtCodeSnippetExpression.setComments(this.cloneHelper.clone(expression.getComments())); aCtCodeSnippetExpression.setAnnotations(this.cloneHelper.clone(expression.getAnnotations())); aCtCodeSnippetExpression.setTypeCasts(this.cloneHelper.clone(expression.getTypeCasts())); this.cloneHelper.tailor(expression, aCtCodeSnippetExpression); this.other = aCtCodeSnippetExpression; }
public <T> void visitCtCodeSnippetExpression(final spoon.reflect.code.CtCodeSnippetExpression<T> expression) { spoon.reflect.code.CtCodeSnippetExpression other = ((spoon.reflect.code.CtCodeSnippetExpression) (this.stack.peek())); enter(expression); biScan(spoon.reflect.path.CtRole.TYPE, expression.getType(), other.getType()); biScan(spoon.reflect.path.CtRole.COMMENT, expression.getComments(), other.getComments()); biScan(spoon.reflect.path.CtRole.ANNOTATION, expression.getAnnotations(), other.getAnnotations()); biScan(spoon.reflect.path.CtRole.CAST, expression.getTypeCasts(), other.getTypeCasts()); exit(expression); }
@Override public <T> void visitCtCodeSnippetExpression(CtCodeSnippetExpression<T> expression) { elementPrinterHelper.writeComment(expression); printer.writeCodeSnippet(expression.getValue()); }
@Override public <T> CtCodeSnippetExpression<T> createCodeSnippetExpression() { CtCodeSnippetExpression<T> e = new CtCodeSnippetExpressionImpl<>(); e.setFactory(getMainFactory()); return e; }
@SuppressWarnings("unchecked") public static <T> CtExpression<T> compileExpression( CtCodeSnippetExpression<T> expr) throws SnippetCompilationError { CtReturn<T> ret = (CtReturn<T>) internalCompileStatement(expr, expr.getFactory().Type().OBJECT); CtExpression<T> returnedExpression = ret.getReturnedExpression(); // this compiled expression is not in a parent, ready to be used returnedExpression.delete(); returnedExpression.setParent(null); return returnedExpression; }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public List<OperatorInstance> createOperatorInstances(ModificationPoint modificationPoint) { List<OperatorInstance> instances = new ArrayList<>(); CtInvocation invocation = (CtInvocation) modificationPoint.getCodeElement(); CtExpression targetExpresionOfMI = invocation.getTarget(); if (targetExpresionOfMI instanceof CtVariableAccess) { CtStatement parentStatement = modificationPoint.getCodeElement().getParent(CtStatement.class); CtExpression ifcondition = MutationSupporter.factory.createBinaryOperator(targetExpresionOfMI, MutationSupporter.factory.createCodeSnippetExpression("null").compile(), BinaryOperatorKind.NE); CtIf precodition = MutationSupporter.factory.createIf(); precodition.setCondition(ifcondition); precodition.setThenStatement(parentStatement); OperatorInstance operatorInstance = new StatementOperatorInstance(modificationPoint, this, parentStatement, precodition); instances.add(operatorInstance); } return instances; };
public <T> void visitCtCodeSnippetExpression(final CtCodeSnippetExpression<T> expression) { enter(expression); scan(CtRole.TYPE, expression.getType()); scan(CtRole.COMMENT, expression.getComments()); scan(CtRole.ANNOTATION, expression.getAnnotations()); scan(CtRole.CAST, expression.getTypeCasts()); exit(expression); }
public <T> void visitCtCodeSnippetExpression( CtCodeSnippetExpression<T> expression) { write(expression.getValue()); }
public <T> CtCodeSnippetExpression<T> createCodeSnippetExpression() { CtCodeSnippetExpression<T> e = new CtCodeSnippetExpressionImpl<T>(); e.setFactory(getMainFactory()); return e; }
@SuppressWarnings("unchecked") public static <T> CtExpression<T> compileExpression( CtCodeSnippetExpression<T> expr) throws SnippetCompilationError { // create wrapping template Factory f = expr.getFactory(); CtClass<?> w = createWrapper(expr, f); String contents = w.toString(); build(f, contents); CtType<?> c = f.Type().get("Wrapper"); // Get the part we want CtMethod<T> wrapper = Query.getElements(c, new Filter<CtMethod<T>>() { public boolean matches(CtMethod<T> element) { return element.getSimpleName().equals("wrap"); } }).get(0); CtReturn<T> ret = (CtReturn<T>) wrapper.getBody().getStatements() .get(0); // Clean up (delete wrapper from factory) c.getPackage().getTypes().remove(c); return ret.getReturnedExpression(); }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public List<OperatorInstance> createOperatorInstances(ModificationPoint modificationPoint) { List<OperatorInstance> instances = new ArrayList<>(); List<CtVariableAccess> varAccess = VariableResolver.collectVariableAccess(modificationPoint.getCodeElement()); for (CtVariableAccess iVariableAccess : varAccess) { if (!iVariableAccess.getType().isPrimitive()) { CtIf precodition = MutationSupporter.factory.createIf(); CtExpression ifcondition = MutationSupporter.factory.createBinaryOperator(iVariableAccess, MutationSupporter.factory.createCodeSnippetExpression("null").compile(), BinaryOperatorKind.NE); precodition.setCondition(ifcondition); precodition.setThenStatement((CtStatement) modificationPoint.getCodeElement().clone()); OperatorInstance operatorInstance = new StatementOperatorInstance(modificationPoint, this, precodition); instances.add(operatorInstance); } } return instances; };
/** * 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; }
@java.lang.Override public <T> void visitCtCodeSnippetExpression(final spoon.reflect.code.CtCodeSnippetExpression<T> expression) { replaceElementIfExist(expression.getType(), new spoon.support.visitor.replace.ReplacementVisitor.CtTypedElementTypeReplaceListener(expression)); replaceInListIfExist(expression.getComments(), new spoon.support.visitor.replace.ReplacementVisitor.CtElementCommentsReplaceListener(expression)); replaceInListIfExist(expression.getAnnotations(), new spoon.support.visitor.replace.ReplacementVisitor.CtElementAnnotationsReplaceListener(expression)); replaceInListIfExist(expression.getTypeCasts(), new spoon.support.visitor.replace.ReplacementVisitor.CtExpressionTypeCastsReplaceListener(expression)); }
public <T> void visitCtCodeSnippetExpression(CtCodeSnippetExpression<T> expression) { write(expression.getValue()); }
@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; } }