+ substatements.forEach(Preconditions::checkNotNull);
+ beforeAddEffectiveStatement(substatements.size());
+ effective.addAll(substatements);
+ }
+
+ private void beforeAddEffectiveStatement(final int toAdd) {
+ final ModelProcessingPhase inProgressPhase = getRoot().getSourceContext().getInProgressPhase();
+ Preconditions.checkState(inProgressPhase == ModelProcessingPhase.FULL_DECLARATION
+ || inProgressPhase == ModelProcessingPhase.EFFECTIVE_MODEL,
+ "Effective statement cannot be added in declared phase at: %s", getStatementSourceReference());
+
+ if (effective.isEmpty()) {
+ effective = new ArrayList<>(toAdd);
+ }
+ }
+
+ /**
+ * adds declared statement to collection of substatements
+ *
+ * @param substatement substatement
+ * @throws IllegalStateException
+ * if added in effective phase
+ * @throws NullPointerException
+ * if statement parameter is null
+ */
+ public void addDeclaredSubstatement(final StatementContextBase<?, ?, ?> substatement) {
+
+ final ModelProcessingPhase inProgressPhase = getRoot().getSourceContext().getInProgressPhase();
+ Preconditions.checkState(inProgressPhase != ModelProcessingPhase.EFFECTIVE_MODEL,
+ "Declared statement cannot be added in effective phase at: %s", getStatementSourceReference());
+
+ if (declared.isEmpty()) {
+ declared = new ArrayList<>(1);
+ }
+ declared.add(Preconditions.checkNotNull(substatement,
+ "StatementContextBase declared substatement cannot be null at: %s", getStatementSourceReference()));
+ }
+
+ /**
+ * builds a new substatement from statement definition context and statement source reference
+ *
+ * @param def definition context
+ * @param ref source reference
+ *
+ * @return instance of ContextBuilder
+ */
+ public ContextBuilder<?, ?, ?> substatementBuilder(final StatementDefinitionContext<?, ?, ?> def,
+ final StatementSourceReference ref) {
+ return new SubContextBuilder(def, ref);
+ }