use of spoon.reflect.code.CtStatement in project spoon by INRIA.
the class CtCaseImpl method setStatements.
@Override
public <T extends CtStatementList> T setStatements(List<CtStatement> statements) {
if (statements == null || statements.isEmpty()) {
this.statements = CtElementImpl.emptyList();
return (T) this;
}
getFactory().getEnvironment().getModelChangeListener().onListDeleteAll(this, STATEMENT, this.statements, new ArrayList<>(this.statements));
this.statements.clear();
for (CtStatement stmt : statements) {
addStatement(stmt);
}
return (T) this;
}
use of spoon.reflect.code.CtStatement in project spoon by INRIA.
the class CtForImpl method setForInit.
@Override
public <T extends CtFor> T setForInit(List<CtStatement> statements) {
if (statements == null || statements.isEmpty()) {
this.forInit = CtElementImpl.emptyList();
return (T) this;
}
getFactory().getEnvironment().getModelChangeListener().onListDeleteAll(this, FOR_INIT, this.forInit, new ArrayList<>(this.forInit));
this.forInit.clear();
for (CtStatement stmt : statements) {
addForInit(stmt);
}
return (T) this;
}
use of spoon.reflect.code.CtStatement in project spoon by INRIA.
the class CtForImpl method setForUpdate.
@Override
public <T extends CtFor> T setForUpdate(List<CtStatement> statements) {
if (statements == null || statements.isEmpty()) {
this.forUpdate = CtElementImpl.emptyList();
return (T) this;
}
getFactory().getEnvironment().getModelChangeListener().onListDeleteAll(this, FOR_UPDATE, this.forUpdate, new ArrayList<>(this.forUpdate));
this.forUpdate.clear();
for (CtStatement stmt : statements) {
addForUpdate(stmt);
}
return (T) this;
}
use of spoon.reflect.code.CtStatement in project spoon by INRIA.
the class CommentTest method testAddCommentsToSnippet.
@Test
public void testAddCommentsToSnippet() {
Factory factory = new FactoryImpl(new DefaultCoreFactory(), new StandardEnvironment());
factory.getEnvironment().setNoClasspath(true);
factory.getEnvironment().setCommentEnabled(true);
CtStatement statement = factory.Code().createCodeSnippetStatement("System.out.println(\"Caenorhabditis\")");
CtComment comment = factory.createComment("My comment on my statement", CtComment.CommentType.INLINE);
statement.addComment(comment);
CtExpression expression = factory.Code().createCodeSnippetExpression("\"Caenorhabditis\" + \"Caenorhabditis\"");
CtComment commentExpression = factory.createComment("My comment on my expression", CtComment.CommentType.INLINE);
expression.addComment(commentExpression);
assertEquals("// My comment on my statement" + newLine + "System.out.println(\"Caenorhabditis\")", statement.toString());
assertEquals("// My comment on my expression" + newLine + "\"Caenorhabditis\" + \"Caenorhabditis\"", expression.toString());
}
use of spoon.reflect.code.CtStatement in project spoon by INRIA.
the class DeleteTest method testDeleteAStatementInStaticAnonymousExecutable.
@Test
public void testDeleteAStatementInStaticAnonymousExecutable() throws Exception {
final Factory factory = build(Adobada.class);
final CtClass<Adobada> adobada = factory.Class().get(Adobada.class);
final List<CtAnonymousExecutable> anonymousExecutables = adobada.getAnonymousExecutables();
final CtAnonymousExecutable staticExec = anonymousExecutables.get(1);
assertEquals(2, staticExec.getBody().getStatements().size());
final CtStatement statement = staticExec.getBody().getStatement(1);
statement.delete();
assertEquals(1, staticExec.getBody().getStatements().size());
assertFalse(staticExec.getBody().getStatements().contains(statement));
}
Aggregations