X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-parser-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fparser%2Fstmt%2Frfc6020%2Feffective%2FEffectiveStatementBase.java;h=2a621b2c9fd838e390142b9ad26ed7c051dc3f88;hb=07a461a735316f15f9a78455e1c1c3caf91b2a3e;hp=a381200a8439fb63b3d5003715218121b7e0450e;hpb=0d77417cb1aab5cacac7503052eb0ca8faacc01e;p=yangtools.git
diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/EffectiveStatementBase.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/EffectiveStatementBase.java
index a381200a84..2a621b2c9f 100644
--- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/EffectiveStatementBase.java
+++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/EffectiveStatementBase.java
@@ -25,6 +25,7 @@ import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
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> implements EffectiveStatement {
@@ -45,26 +46,14 @@ public abstract class EffectiveStatementBase>
};
private final List extends EffectiveStatement, ?>> substatements;
- private final List> unknownSubstatementsToBuild;
-
- protected EffectiveStatementBase(final StmtContext ctx) {
- this(ctx, true);
- }
/**
* Constructor.
*
* @param ctx
* context of statement.
- * @param buildUnknownSubstatements
- * if it is false, the unknown substatements are omitted from
- * build of effective substatements till the call of either
- * effectiveSubstatements or getOmittedUnknownSubstatements
- * method. The main purpose of this is to allow the build of
- * recursive extension definitions.
*/
- protected EffectiveStatementBase(final StmtContext ctx, boolean buildUnknownSubstatements) {
-
+ protected EffectiveStatementBase(final StmtContext ctx) {
final Collection> effectiveSubstatements = ctx.effectiveSubstatements();
final Collection> substatementsInit = new ArrayList<>();
@@ -80,24 +69,11 @@ public abstract class EffectiveStatementBase>
}
substatementsInit.addAll(effectiveSubstatements);
- Collection> substatementsToBuild = Collections2.filter(substatementsInit,
- IS_SUPPORTED_TO_BUILD_EFFECTIVE);
- if (!buildUnknownSubstatements) {
- this.unknownSubstatementsToBuild = ImmutableList.copyOf(Collections2.filter(substatementsToBuild,
- IS_UNKNOWN_STATEMENT_CONTEXT));
- substatementsToBuild = Collections2.filter(substatementsToBuild,
- Predicates.not(IS_UNKNOWN_STATEMENT_CONTEXT));
- } else {
- this.unknownSubstatementsToBuild = ImmutableList.of();
- }
+ // WARNING: this leaks an incompletely-initialized pbject
+ RecursiveObjectLeaker.inConstructor(this);
- this.substatements = ImmutableList.copyOf(Collections2.transform(substatementsToBuild,
- StmtContextUtils.buildEffective()));
- }
-
- Collection> getOmittedUnknownSubstatements() {
- return Collections2.transform(unknownSubstatementsToBuild,
- StmtContextUtils.buildEffective());
+ this.substatements = ImmutableList.copyOf(Collections2.transform(Collections2.filter(substatementsInit,
+ IS_SUPPORTED_TO_BUILD_EFFECTIVE), StmtContextUtils.buildEffective()));
}
@Override
@@ -112,11 +88,7 @@ public abstract class EffectiveStatementBase>
@Override
public final Collection extends EffectiveStatement, ?>> effectiveSubstatements() {
- if (unknownSubstatementsToBuild.isEmpty()) {
- return substatements;
- } else {
- return ImmutableList.copyOf(Iterables.concat(substatements, getOmittedUnknownSubstatements()));
- }
+ return substatements;
}
protected final > S firstEffective(final Class type) {
@@ -149,8 +121,6 @@ public abstract class EffectiveStatementBase>
}
protected final EffectiveStatement, ?> firstEffectiveSubstatementOfType(final Class> type) {
- Optional extends EffectiveStatement, ?>> possible = Iterables.tryFind(substatements,
- Predicates.instanceOf(type));
- return possible.isPresent() ? possible.get() : null;
+ return Iterables.tryFind(substatements, Predicates.instanceOf(type)).orNull();
}
}