@Override public <T> void visitCtInvocation(CtInvocation<T> invocation) { CtInvocation<T> i = invocation.getFactory().Core().createInvocation(); i.setExecutable(invocation.getExecutable()); i.setTypeCasts(invocation.getTypeCasts()); r = RtHelper.invoke(i); if (isLiteralType(r)) { CtLiteral<T> l = invocation.getFactory().Core().createLiteral(); l.setValue(r); setResult(l);
public <T> void visitCtInvocation(final spoon.reflect.code.CtInvocation<T> invocation) { spoon.reflect.code.CtInvocation<T> aCtInvocation = invocation.getFactory().Core().createInvocation(); this.builder.copy(invocation, aCtInvocation); aCtInvocation.setAnnotations(this.cloneHelper.clone(invocation.getAnnotations())); aCtInvocation.setTypeCasts(this.cloneHelper.clone(invocation.getTypeCasts())); aCtInvocation.setTarget(this.cloneHelper.clone(invocation.getTarget())); aCtInvocation.setExecutable(this.cloneHelper.clone(invocation.getExecutable())); aCtInvocation.setArguments(this.cloneHelper.clone(invocation.getArguments())); aCtInvocation.setComments(this.cloneHelper.clone(invocation.getComments())); this.cloneHelper.tailor(invocation, aCtInvocation); this.other = aCtInvocation; }
static boolean isVoidReturn(CtInvocation invocation) { return (invocation.getType().equals(invocation.getFactory().Type().voidType()) || invocation.getType().equals(invocation.getFactory().Type().voidPrimitiveType())); }
CtIf newIf = ctInvocation.getFactory().Core().createIf(); CtCodeSnippetExpression<Boolean> condition = ctInvocation.getFactory() .Core().createCodeSnippetExpression(); CtExpression<?> elem1 = arguments.get(0); if (arguments.size() > 2 && (elem1.getType().equals( ctInvocation.getFactory().Class().STRING) || elem1 .getType().equals(getFactory().Class().nullType()))) { elem1 = arguments.get(1);
/** * replace assertNotNull * * @param ctInvocation * @return */ private CtStatement replaceAssertNotNull(CtInvocation<?> ctInvocation) { List<?> arguments = ctInvocation.getArguments(); CtIf newIf = ctInvocation.getFactory().Core().createIf(); Object elem1 = arguments.get(0); CtExpression<Boolean> condition = ctInvocation.getFactory().Code() .createCodeSnippetExpression("(" + elem1 + ") != null"); newIf.setCondition(condition); // newIf.setThenStatement(getFactory().Code().createCodeSnippetStatement( // Debug.class.getCanonicalName() + ".printPC(\"Path Condition: \")")); /* * CtBlock<Object> thenStatement = ctInvocation.getFactory().Core() * .createBlock(); thenStatement .addStatement((getFactory().Code() * .createCodeSnippetStatement("System.out.println(\"Then...\")"))); * thenStatement.addStatement((getFactory().Code() * .createCodeSnippetStatement("System.out.println(" + * Debug.class.getCanonicalName() + ".getSolvedPC())"))); * newIf.setThenStatement(thenStatement); */ newIf.setThenStatement(createThen(ctInvocation)); return newIf; }
/** * replace assertNull * * @param ctInvocation * @return */ private CtStatement replaceAssertNull(CtInvocation<?> ctInvocation) { List<?> arguments = ctInvocation.getArguments(); CtIf newIf = ctInvocation.getFactory().Core().createIf(); Object elem1 = arguments.get(0); CtExpression<Boolean> condition = ctInvocation.getFactory().Code() .createCodeSnippetExpression("(" + elem1 + ") == null"); newIf.setCondition(condition); // newIf.setThenStatement(getFactory().Code().createCodeSnippetStatement( // Debug.class.getCanonicalName() + ".printPC(\"Path Condition: \")")); /* * CtBlock<Object> thenStatement = ctInvocation.getFactory().Core() * .createBlock(); thenStatement .addStatement((getFactory().Code() * .createCodeSnippetStatement("System.out.println(\"Then...\")"))); * thenStatement.addStatement((getFactory().Code() * .createCodeSnippetStatement("System.out.println(" + * Debug.class.getCanonicalName() + ".getSolvedPC())"))); * newIf.setThenStatement(thenStatement); */ newIf.setThenStatement(createThen(ctInvocation)); return newIf; }
CtInvocation<?> ctInvocation) { List<?> arguments = ctInvocation.getArguments(); CtIf newIf = ctInvocation.getFactory().Core().createIf(); .getFactory() .Code() .createCodeSnippetExpression(
private CtElement checkListStatements(List<?> teList) { for (Object tem : teList) { if (variables.contains(tem) && (tem instanceof CtInvocation)) { CtInvocation<?> listCand = (CtInvocation<?>) tem; boolean ok = listCand.getFactory().Type().createReference(TemplateParameter.class).isAssignableFrom(listCand.getTarget().getType()); return ok ? listCand : null; } if (tem instanceof CtVariable) { CtVariable<?> var = (CtVariable<?>) tem; String name = var.getSimpleName(); for (CtFieldReference<?> f : varArgs) { if (f.getSimpleName().equals(name)) { return f.getDeclaration(); } } } } return null; }
/** * 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; }
final Factory factory = invocation.getFactory(); final TypeFilter<CtStatement> statementTypeFilter = new TypeFilter<CtStatement>(CtStatement.class) { @Override
if (parent.getConstructor() == null) { if (parent.getConstructor(ctInvocation.getFactory().Class().STRING) != null) { invocation += "\"" + parent.getSimpleName() + "\""; } else {
public <T> void visitCtInvocation(CtInvocation<T> invocation) { CtInvocation<T> i = invocation.getFactory().Core().createInvocation(); i.setType(invocation.getType()); i.setExecutable(invocation.getExecutable()); CtLiteral<T> l = invocation.getFactory().Core().createLiteral(); l.setValue(r); setResult(l);
CtBlock<Object> tryBody = ctInvocation.getFactory().Core() .createBlock();