@Override
public EffectiveStatement<QName,ExtensionStatement> createEffective(
final StmtContext<QName,ExtensionStatement ,EffectiveStatement<QName,ExtensionStatement>> ctx) {
-
- // Look at the thread-local leak in case we are invoked recursively
- final ExtensionEffectiveStatementImpl existing = RecursiveObjectLeaker.lookup(ctx,
- ExtensionEffectiveStatementImpl.class);
- if (existing != null) {
- // Careful! this not fully initialized!
- return existing;
- }
-
- RecursiveObjectLeaker.beforeConstructor(ctx);
- try {
- // This result is fine, we know it has been completely initialized
- return new ExtensionEffectiveStatementImpl(ctx);
- } finally {
- RecursiveObjectLeaker.afterConstructor(ctx);
- }
+ return ExtensionEffectiveStatementImpl.create(ctx);
}
@Override
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.RecursiveObjectLeaker;
public abstract class EffectiveStatementBase<A, D extends DeclaredStatement<A>> implements EffectiveStatement<A, D> {
private final List<? extends EffectiveStatement<?, ?>> substatements;
}
substatementsInit.addAll(effectiveSubstatements);
- // WARNING: this leaks an incompletely-initialized pbject
- RecursiveObjectLeaker.inConstructor(this);
+ this.substatements = ImmutableList.copyOf(initSubstatements(substatementsInit));
+ }
- this.substatements = ImmutableList.copyOf(Collections2.transform(Collections2.filter(substatementsInit,
- StmtContext::isSupportedToBuildEffective), StatementContextBase::buildEffective));
+ /**
+ * Create a set of substatements. This method is split out so it can be overridden in
+ * {@link ExtensionEffectiveStatementImpl} to leak a not-fully-initialized instance.
+ *
+ * @param substatementsInit proposed substatements
+ * @return Filtered substatements
+ */
+ Collection<? extends EffectiveStatement<?, ?>> initSubstatements(
+ final Collection<StatementContextBase<?, ?, ?>> substatementsInit) {
+ return Collections2.transform(Collections2.filter(substatementsInit,
+ StmtContext::isSupportedToBuildEffective), StatementContextBase::buildEffective);
}
@Override
import com.google.common.collect.ImmutableList;
import java.util.ArrayDeque;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Deque;
import java.util.List;
import java.util.Objects;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ExtensionStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.RecursiveObjectLeaker;
public class ExtensionEffectiveStatementImpl extends AbstractEffectiveDocumentedNode<QName, ExtensionStatement>
implements ExtensionDefinition {
private final List<UnknownSchemaNode> unknownNodes;
private final boolean yin;
- public ExtensionEffectiveStatementImpl(
+ private ExtensionEffectiveStatementImpl(
final StmtContext<QName, ExtensionStatement, EffectiveStatement<QName, ExtensionStatement>> ctx) {
super(ctx);
this.qname = ctx.getStatementArgument();
}
}
+ /**
+ * Create a new ExtensionEffectiveStatement, dealing with potential recursion
+ *
+ * @param ctx Statement context
+ * @return A potentially under-initialized instance
+ */
+ public static EffectiveStatement<QName, ExtensionStatement> create(
+ final StmtContext<QName, ExtensionStatement, EffectiveStatement<QName, ExtensionStatement>> ctx) {
+ // Look at the thread-local leak in case we are invoked recursively
+ final ExtensionEffectiveStatementImpl existing = RecursiveObjectLeaker.lookup(ctx,
+ ExtensionEffectiveStatementImpl.class);
+ if (existing != null) {
+ // Careful! this not fully initialized!
+ return existing;
+ }
+
+ RecursiveObjectLeaker.beforeConstructor(ctx);
+ try {
+ // This result is fine, we know it has been completely initialized
+ return new ExtensionEffectiveStatementImpl(ctx);
+ } finally {
+ RecursiveObjectLeaker.afterConstructor(ctx);
+ }
+ }
+
+ @Override
+ Collection<? extends EffectiveStatement<?, ?>> initSubstatements(
+ final Collection<StatementContextBase<?, ?, ?>> substatementsInit) {
+ // WARNING: this leaks an incompletely-initialized object
+ RecursiveObjectLeaker.inConstructor(this);
+
+ return super.initSubstatements(substatementsInit);
+ }
+
@Override
public QName getQName() {
return qname;