Example #1
0
 @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;
 }
Example #2
0
 @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;
 }
Example #3
0
 @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;
 }
Example #4
0
 @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;
 }
Example #5
0
 @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;
 }
Example #6
0
 @Override
 public void removeStatement(CtStatement statement) {
   if (this.statements != CtElementImpl.<CtStatement>emptyList()) {
     this.statements.remove(statement);
   }
 }
Example #7
0
 private void ensureModifiableStatementsList() {
   if (this.statements == CtElementImpl.<CtStatement>emptyList()) {
     this.statements = new ArrayList<CtStatement>(BLOCK_STATEMENTS_CONTAINER_DEFAULT_CAPACITY);
   }
 }
Example #8
0
 @Override
 public boolean removeParameter(CtParameter<?> parameter) {
   return parameters != CtElementImpl.<CtParameter<?>>emptyList() && parameters.remove(parameter);
 }