@Override public <T extends CtBlock<R>> T insertAfter( Filter<? extends CtStatement> insertionPoints, CtStatementList statements) { for (CtStatement e : Query.getElements(this, insertionPoints)) { e.insertAfter(statements); } return (T) this; }
@Override public <T extends CtBlock<R>> T insertBegin(CtStatementList statements) { if (getParent() != null && getParent() instanceof CtConstructor && getStatements().size() > 0) { CtStatement first = getStatements().get(0); if (first instanceof CtInvocation && ((CtInvocation<?>) first).getExecutable().getSimpleName().startsWith("<init>")) { first.insertAfter(statements); return (T) this; } } if (this.statements == CtElementImpl.<CtStatement>emptyList()) { this.statements = new ArrayList<CtStatement>( statements.getStatements().size() + BLOCK_STATEMENTS_CONTAINER_DEFAULT_CAPACITY); } this.statements.addAll(0, statements.getStatements()); return (T) this; }
@Override public <T extends CtBlock<R>> T insertBegin(CtStatement statement) { try { if (getParent() != null && getParent() instanceof CtConstructor && getStatements().size() > 0) { CtStatement first = getStatements().get(0); if (first instanceof CtInvocation && ((CtInvocation<?>) first).getExecutable().getSimpleName().startsWith("<init>")) { first.insertAfter(statement); return (T) this; } } } catch (ParentNotInitializedException ignore) { // CtBlock hasn't a parent. So, it isn't in a constructor. } ensureModifiableStatementsList(); this.statements.add(0, statement); return (T) this; }