@Override public <T extends CtExecutable<R>> T addParameter(CtParameter<?> parameter) { if (parameters == CtElementImpl.<CtParameter<?>>emptyList()) { parameters = new ArrayList<CtParameter<?>>(PARAMETERS_CONTAINER_DEFAULT_CAPACITY); } parameter.setParent(this); parameters.add(parameter); return (T) this; }
@Override public <T extends CtExecutable<R>> T addThrownType( CtTypeReference<? extends Throwable> throwType) { if (thrownTypes == CtElementImpl.<CtTypeReference<? extends Throwable>>emptySet()) { thrownTypes = new TreeSet<CtTypeReference<? extends Throwable>>(); } thrownTypes.add(throwType); return (T) this; }
@Override public <C extends CtExpression<T>> C addTypeCast(CtTypeReference<?> type) { if (typeCasts == CtElementImpl.<CtTypeReference<?>>emptyList()) { typeCasts = new ArrayList<CtTypeReference<?>>(CASTS_CONTAINER_DEFAULT_CAPACITY); } type.setParent(this); typeCasts.add(type); return (C) this; }
@Override public <C extends CtExpression<T>> C setTypeCasts(List<CtTypeReference<?>> casts) { if (this.typeCasts == CtElementImpl.<CtTypeReference<?>>emptyList()) { this.typeCasts = new ArrayList<CtTypeReference<?>>(CASTS_CONTAINER_DEFAULT_CAPACITY); } this.typeCasts.clear(); for (CtTypeReference<?> cast : casts) { addTypeCast(cast); } return (C) 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 void removeStatement(CtStatement statement) { if (this.statements != CtElementImpl.<CtStatement>emptyList()) { this.statements.remove(statement); } }
private void ensureModifiableStatementsList() { if (this.statements == CtElementImpl.<CtStatement>emptyList()) { this.statements = new ArrayList<CtStatement>(BLOCK_STATEMENTS_CONTAINER_DEFAULT_CAPACITY); } }
@Override public boolean removeParameter(CtParameter<?> parameter) { return parameters != CtElementImpl.<CtParameter<?>>emptyList() && parameters.remove(parameter); }