BUG-7052: reduce StatementContextBase proliferation 51/58451/5
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 7 Jun 2017 21:31:40 +0000 (23:31 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 8 Jun 2017 11:16:10 +0000 (13:16 +0200)
In some places we require StatementContextBase where only a simple
StmtContext or Mutable is enough. Fix those places up and move mutator
methods into Mutable.

This frees up parser.spi from reactor imports and lowers rfc6020's
reliance on reactor internals.

A nice side-effect is that we do not leak the mutable aspect of
StatementContextBase from StmtContext references.

One violation of this contract is caching of 'supportedByFeatures',
which is now costing an instanceof check. Since that is an optimization
this is a fair thing.

Change-Id: I6b4991264ef8c3322260f0962d41eeaa79b1b427
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
12 files changed:
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/SubstatementValidator.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContext.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContextUtils.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/RootStatementContext.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SubstatementContext.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/AnyxmlStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/AugmentStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/UsesStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/CaseEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/EffectiveStatementBase.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ExtensionEffectiveStatementImpl.java

index 43b1e9a426719c506041dcb09b666eeb857d9532..7412af03f68697763caf3a16208913e10440468d 100644 (file)
@@ -20,7 +20,6 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.InvalidSubstatementExcept
 import org.opendaylight.yangtools.yang.parser.spi.meta.MissingSubstatementException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
 
 public final class SubstatementValidator {
     /**
@@ -120,7 +119,7 @@ public final class SubstatementValidator {
             MissingSubstatementException {
 
         final Map<StatementDefinition, Counter> stmtCounts = new HashMap<>();
-        for (StatementContextBase<?, ?, ?> stmtCtx : Iterables.concat(ctx.declaredSubstatements(), ctx.effectiveSubstatements())) {
+        for (StmtContext<?, ?, ?> stmtCtx : Iterables.concat(ctx.declaredSubstatements(), ctx.effectiveSubstatements())) {
             stmtCounts.computeIfAbsent(stmtCtx.getPublicDefinition(), key -> new Counter()).increment();
         }
 
index 52bd1aa1c965af39a60cb069cbbea0c9203b9725..b26b1d6349e262d046e21d0adddd27d9b25a057e 100644 (file)
@@ -21,7 +21,6 @@ import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
 import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
 import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
 
@@ -90,7 +89,7 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
      * @return Collection of declared substatements
      */
     @Nonnull
-    Collection<StatementContextBase<?, ?, ?>> declaredSubstatements();
+    Collection<? extends StmtContext<?, ?, ?>> declaredSubstatements();
 
     /**
      * Return effective substatements. These are the statements which are added as this statement's substatements
@@ -99,7 +98,7 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
      * @return Collection of declared substatements
      */
     @Nonnull
-    Collection<StatementContextBase<?, ?, ?>> effectiveSubstatements();
+    Collection<? extends StmtContext<?, ?, ?>> effectiveSubstatements();
 
     /**
      * Builds {@link DeclaredStatement} for statement context.
@@ -113,44 +112,23 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
 
     boolean isSupportedToBuildEffective();
 
-    void setIsSupportedToBuildEffective(boolean isSupportedToBuild);
+    Collection<? extends StmtContext<?, ?, ?>> getEffectOfStatement();
 
-    Collection<StatementContextBase<?, ?, ?>> getEffectOfStatement();
+    StatementContextBase<A, D, E> createCopy(StatementContextBase<?, ?, ?> newParent, CopyType typeOfCopy);
 
-    void addAsEffectOfStatement(StatementContextBase<?, ?, ?> ctx);
-
-    void addAsEffectOfStatement(Collection<StatementContextBase<?, ?, ?>> ctxs);
-
-    StatementContextBase<?, ?, ?> createCopy(
-            StatementContextBase<?, ?, ?> newParent, CopyType typeOfCopy)
-            throws SourceException;
-
-    StatementContextBase<?, ?, ?> createCopy(QNameModule newQNameModule,
-            StatementContextBase<?, ?, ?> newParent, CopyType typeOfCopy)
-            throws SourceException;
+    StatementContextBase<A, D, E> createCopy(QNameModule newQNameModule, StatementContextBase<?, ?, ?> newParent,
+            CopyType typeOfCopy);
 
     CopyHistory getCopyHistory();
 
-    enum SupportedByFeatures {
-        UNDEFINED, SUPPORTED, NOT_SUPPORTED
-    }
-
-    SupportedByFeatures getSupportedByFeatures();
-
-    void appendCopyHistory(CopyType typeOfCopy, CopyHistory toAppend);
+    boolean isSupportedByFeatures();
 
-    StatementContextBase<?, ?, ?> getOriginalCtx();
-
-    void setOriginalCtx(StatementContextBase<?, ?, ?> originalCtx);
+    StmtContext<?, ?, ?> getOriginalCtx();
 
     boolean isRootContext();
 
-    void setOrder(int order);
-
     int getOrder();
 
-    void setCompletedPhase(ModelProcessingPhase completedPhase);
-
     ModelProcessingPhase getCompletedPhase();
 
     /**
@@ -174,6 +152,14 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
         @Override
         StmtContext.Mutable<?, ?, ?> getRoot();
 
+        @Override
+        @Nonnull
+        Collection<StatementContextBase<?, ?, ?>> declaredSubstatements();
+
+        @Override
+        @Nonnull
+        Collection<StatementContextBase<?, ?, ?>> effectiveSubstatements();
+
         /**
          * Create a new inference action to be executed during specified phase. The action cannot be cancelled
          * and will be executed even if its definition remains incomplete.
@@ -197,8 +183,6 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
         <K, KT extends K, N extends StatementNamespace<K, ?, ?>> void addContext(
                 Class<N> namespace, KT key, StmtContext<?, ?, ?> stmt);
 
-        void setSupportedByFeatures(boolean isSupported);
-
         /**
          * Set version of root statement context.
          *
@@ -226,6 +210,10 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
          */
         void addRequiredModule(ModuleIdentifier dependency);
 
+        void addAsEffectOfStatement(StmtContext<?, ?, ?> ctx);
+
+        void addAsEffectOfStatement(Collection<? extends StmtContext<?, ?, ?>> ctxs);
+
         /**
          * Set identifier of current root context.
          *
@@ -233,5 +221,16 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
          *            of current root context
          */
         void setRootIdentifier(ModuleIdentifier identifier);
+
+        void setIsSupportedToBuildEffective(boolean isSupportedToBuild);
+
+        void appendCopyHistory(CopyType typeOfCopy, CopyHistory toAppend);
+
+        void setOriginalCtx(StmtContext<?, ?, ?> originalCtx);
+
+        void setOrder(int order);
+
+        // FIXME: this seems to be unused, but looks useful.
+        void setCompletedPhase(ModelProcessingPhase completedPhase);
     }
 }
index ad3b07d84e162c7539fa40d83957b6397f440ca8..2877fc374f705636c7035a48cbb9e4cb98ac7b93 100644 (file)
@@ -29,12 +29,14 @@ import org.opendaylight.yangtools.yang.model.api.stmt.MinElementsStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.PresenceStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SupportedFeaturesNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.source.SupportedFeaturesNamespace.SupportedFeatures;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.UnknownStatementImpl;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangDataStatementImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public final class StmtContextUtils {
+    private static final Logger LOG = LoggerFactory.getLogger(StmtContextUtils.class);
+
     public static final Splitter LIST_KEY_SPLITTER = Splitter.on(' ').omitEmptyStrings().trimResults();
 
     private StmtContextUtils() {
@@ -241,33 +243,7 @@ public final class StmtContextUtils {
         return replaced ? builder.build() : keyStmtCtx.getStatementArgument();
     }
 
-    public static boolean areFeaturesSupported(final StmtContext.Mutable<?, ?, ?> stmtContext) {
-        switch (stmtContext.getSupportedByFeatures()) {
-        case SUPPORTED:
-            return true;
-        case NOT_SUPPORTED:
-            return false;
-        default:
-            break;
-        }
-
-        final Set<QName> supportedFeatures = stmtContext.getFromNamespace(SupportedFeaturesNamespace.class,
-                SupportedFeatures.SUPPORTED_FEATURES);
-        /*
-         * If set of supported features has not been provided, all features are
-         * supported by default.
-         */
-        if (supportedFeatures == null) {
-            stmtContext.setSupportedByFeatures(true);
-            return true;
-        }
-
-        final boolean result = checkFeatureSupport(stmtContext, supportedFeatures);
-        stmtContext.setSupportedByFeatures(result);
-        return result;
-    }
-
-    private static boolean checkFeatureSupport(final StmtContext.Mutable<?, ?, ?> stmtContext,
+    public static boolean checkFeatureSupport(final StmtContext<?, ?, ?> stmtContext,
             final Set<QName> supportedFeatures) {
         boolean isSupported = false;
         boolean containsIfFeature = false;
index 0ecbd93df1e1a8abaab8595edb7164e5ff2ee439..a86e7ecb2cb48a18c708dc1fc873efc95134440c 100644 (file)
@@ -32,7 +32,6 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.Namesp
 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.Registry;
 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.StorageNodeType;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
 import org.opendaylight.yangtools.yang.parser.spi.source.IncludedModuleContext;
 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
 
@@ -84,7 +83,7 @@ public class RootStatementContext<A, D extends DeclaredStatement<A>, E extends E
         final Collection<StatementContextBase<?, ?, ?>> buffer = new ArrayList<>(declared.size() + effective.size());
 
         for (final StatementContextBase<?, ?, ?> stmtContext : declared) {
-            if (StmtContextUtils.areFeaturesSupported(stmtContext)) {
+            if (stmtContext.isSupportedByFeatures()) {
                 buffer.add(stmtContext.createCopy(newQNameModule, this, typeOfCopy));
             }
         }
@@ -144,7 +143,7 @@ public class RootStatementContext<A, D extends DeclaredStatement<A>, E extends E
      * @throws org.opendaylight.yangtools.yang.parser.spi.source.SourceException instance of SourceException
      */
     @Override
-    public StatementContextBase<?, ?, ?> createCopy(final StatementContextBase<?, ?, ?> newParent,
+    public StatementContextBase<A, D, E> createCopy(final StatementContextBase<?, ?, ?> newParent,
             final CopyType typeOfCopy) {
         return createCopy(null, newParent, typeOfCopy);
     }
index 6edf9203435a26dde04918fecf6b735cd91911e3..eaf8aeb909e66976c2d5c9b69daf6ffc1c2cb566 100644 (file)
@@ -22,7 +22,9 @@ import java.util.EnumMap;
 import java.util.EventListener;
 import java.util.Iterator;
 import java.util.Optional;
+import java.util.Set;
 import javax.annotation.Nonnull;
+import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
@@ -36,15 +38,17 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StatementNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
+import org.opendaylight.yangtools.yang.parser.spi.source.SupportedFeaturesNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.source.SupportedFeaturesNamespace.SupportedFeatures;
 import org.opendaylight.yangtools.yang.parser.stmt.reactor.NamespaceBehaviourWithListeners.ValueAddedListener;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
         extends NamespaceStorageSupport implements StmtContext.Mutable<A, D, E> {
-
     /**
      * event listener when an item is added to model namespace.
      */
@@ -82,14 +86,14 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
     private Multimap<ModelProcessingPhase, OnPhaseFinished> phaseListeners = ImmutableMultimap.of();
     private Multimap<ModelProcessingPhase, ContextMutation> phaseMutation = ImmutableMultimap.of();
     private Collection<StatementContextBase<?, ?, ?>> effective = ImmutableList.of();
-    private Collection<StatementContextBase<?, ?, ?>> effectOfStatement = ImmutableList.of();
+    private Collection<StmtContext<?, ?, ?>> effectOfStatement = ImmutableList.of();
     private StatementMap substatements = StatementMap.empty();
 
-    private SupportedByFeatures supportedByFeatures = SupportedByFeatures.UNDEFINED;
+    private Boolean supportedByFeatures = null;
     private CopyHistory copyHistory = CopyHistory.original();
     private boolean isSupportedToBuildEffective = true;
     private ModelProcessingPhase completedPhase = null;
-    private StatementContextBase<?, ?, ?> originalCtx;
+    private StmtContext<?, ?, ?> originalCtx;
     private D declaredInstance;
     private E effectiveInstance;
     private int order = 0;
@@ -111,12 +115,12 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
     }
 
     @Override
-    public Collection<StatementContextBase<?, ?, ?>> getEffectOfStatement() {
+    public Collection<? extends StmtContext<?, ?, ?>> getEffectOfStatement() {
         return effectOfStatement;
     }
 
     @Override
-    public void addAsEffectOfStatement(final StatementContextBase<?, ?, ?> ctx) {
+    public void addAsEffectOfStatement(final StmtContext<?, ?, ?> ctx) {
         if (effectOfStatement.isEmpty()) {
             effectOfStatement = new ArrayList<>(1);
         }
@@ -124,7 +128,7 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
     }
 
     @Override
-    public void addAsEffectOfStatement(final Collection<StatementContextBase<?, ?, ?>> ctxs) {
+    public void addAsEffectOfStatement(final Collection<? extends StmtContext<?, ?, ?>> ctxs) {
         if (ctxs.isEmpty()) {
             return;
         }
@@ -136,13 +140,16 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
     }
 
     @Override
-    public SupportedByFeatures getSupportedByFeatures() {
-        return supportedByFeatures;
-    }
+    public boolean isSupportedByFeatures() {
+        if (supportedByFeatures == null) {
+            final Set<QName> supportedFeatures = getFromNamespace(SupportedFeaturesNamespace.class,
+                SupportedFeatures.SUPPORTED_FEATURES);
+            // If the set of supported features has not been provided, all features are supported by default.
+            supportedByFeatures = supportedFeatures == null ? Boolean.TRUE
+                    : StmtContextUtils.checkFeatureSupport(this, supportedFeatures);
+        }
 
-    @Override
-    public void setSupportedByFeatures(final boolean isSupported) {
-        this.supportedByFeatures = isSupported ? SupportedByFeatures.SUPPORTED : SupportedByFeatures.NOT_SUPPORTED;
+        return supportedByFeatures.booleanValue();
     }
 
     @Override
@@ -166,12 +173,12 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
     }
 
     @Override
-    public StatementContextBase<?, ?, ?> getOriginalCtx() {
+    public StmtContext<?, ?, ?> getOriginalCtx() {
         return originalCtx;
     }
 
     @Override
-    public void setOriginalCtx(final StatementContextBase<?, ?, ?> originalCtx) {
+    public void setOriginalCtx(final StmtContext<?, ?, ?> originalCtx) {
         this.originalCtx = originalCtx;
     }
 
@@ -244,7 +251,7 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
         return Collections.unmodifiableCollection(effective);
     }
 
-    public void removeStatementsFromEffectiveSubstatements(final Collection<StatementContextBase<?, ?, ?>> substatements) {
+    public void removeStatementsFromEffectiveSubstatements(final Collection<? extends StmtContext<?, ?, ?>> substatements) {
         if (!effective.isEmpty()) {
             effective.removeAll(substatements);
             shrinkEffective();
index b1adcde96efe11a8e335bdf0766a2abaf482c039..3380a1e21602023fbec4b47522341dbd63f9066f 100644 (file)
@@ -134,7 +134,7 @@ final class SubstatementContext<A, D extends DeclaredStatement<A>, E extends Eff
     }
 
     @Override
-    public StatementContextBase<?, ?, ?> createCopy(final StatementContextBase<?, ?, ?> newParent,
+    public StatementContextBase<A, D, E> createCopy(final StatementContextBase<?, ?, ?> newParent,
             final CopyType typeOfCopy) {
         return createCopy(null, newParent, typeOfCopy);
     }
@@ -168,7 +168,7 @@ final class SubstatementContext<A, D extends DeclaredStatement<A>, E extends Eff
         final Collection<StatementContextBase<?, ?, ?>> buffer = new ArrayList<>(declared.size() + effective.size());
 
         for (final StatementContextBase<?, ?, ?> stmtContext : declared) {
-            if (StmtContextUtils.areFeaturesSupported(stmtContext)) {
+            if (stmtContext.isSupportedByFeatures()) {
                 copySubstatement(stmtContext, newQNameModule, typeOfCopy, buffer);
             }
         }
@@ -255,7 +255,7 @@ final class SubstatementContext<A, D extends DeclaredStatement<A>, E extends Eff
         }
         if (argument instanceof String) {
             // FIXME: This may yield illegal argument exceptions
-            final StatementContextBase<?, ?, ?> originalCtx = getOriginalCtx();
+            final StmtContext<?, ?, ?> originalCtx = getOriginalCtx();
             final QName qname = originalCtx != null ? Utils.qNameFromArgument(originalCtx, (String) argument) : Utils
                     .qNameFromArgument(this, (String) argument);
             return parentPath.createChild(qname);
index b057490b38993e7f3960b71b7324cb26f1720303..6a9d016de61a3b057c448d6e083a4214f520708b 100644 (file)
@@ -33,7 +33,6 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
 import org.opendaylight.yangtools.yang.parser.spi.source.AnyxmlSchemaLocationNamespace;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.AnyXmlEffectiveStatementImpl;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.YangModeledAnyXmlEffectiveStatementImpl;
 
@@ -96,7 +95,7 @@ public class AnyxmlStatementImpl extends AbstractDeclaredStatement<QName> implem
         private static Optional<ContainerSchemaNode> getAnyXmlSchema(
                 final StmtContext<QName, AnyxmlStatement, EffectiveStatement<QName, AnyxmlStatement>> ctx,
                 final SchemaNodeIdentifier contentSchemaPath) {
-            final StatementContextBase<?, ?, ?> findNode = Utils.findNode(ctx.getRoot(), contentSchemaPath);
+            final StmtContext<?, ?, ?> findNode = Utils.findNode(ctx.getRoot(), contentSchemaPath);
             if (findNode != null) {
                 final EffectiveStatement<?, ?> anyXmlSchemaNode = findNode.buildEffective();
                 if (anyXmlSchemaNode instanceof ContainerSchemaNode) {
index 0aaaaee5483c9b7aab3a134e5f844b568aff97b6..7822c05c4c44612f8acca11e35c02b8af96712e5 100644 (file)
@@ -106,7 +106,7 @@ public class AugmentStatementImpl extends AbstractDeclaredStatement<SchemaNodeId
         @Override
         public void onFullDefinitionDeclared(
                 final StmtContext.Mutable<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>> augmentNode) {
-            if (!StmtContextUtils.areFeaturesSupported(augmentNode)) {
+            if (!augmentNode.isSupportedByFeatures()) {
                 return;
             }
 
@@ -216,7 +216,7 @@ public class AugmentStatementImpl extends AbstractDeclaredStatement<SchemaNodeId
             final Collection<StatementContextBase<?, ?, ?>> buffer = new ArrayList<>(declared.size() + effective.size());
 
             for (final StatementContextBase<?, ?, ?> originalStmtCtx : declared) {
-                if (StmtContextUtils.areFeaturesSupported(originalStmtCtx)) {
+                if (originalStmtCtx.isSupportedByFeatures()) {
                     copyStatement(originalStmtCtx, targetCtx, typeOfCopy, buffer, skipCheckOfMandatoryNodes);
                 }
             }
index 6682a3ab54e8c9a3da85ab95d3857d8162939fb6..283e72d97fe7bb901a3a1e10835660d4c4e23566 100644 (file)
@@ -84,7 +84,7 @@ public class UsesStatementImpl extends AbstractDeclaredStatement<QName> implemen
         @Override
         public void onFullDefinitionDeclared(
                 final StmtContext.Mutable<QName, UsesStatement, EffectiveStatement<QName, UsesStatement>> usesNode) {
-            if (!StmtContextUtils.areFeaturesSupported(usesNode)) {
+            if (!usesNode.isSupportedByFeatures()) {
                 return;
             }
             super.onFullDefinitionDeclared(usesNode);
@@ -199,7 +199,7 @@ public class UsesStatementImpl extends AbstractDeclaredStatement<QName> implemen
      * @throws SourceException
      *             instance of SourceException
      */
-    private static void copyFromSourceToTarget(final StmtContext<?, ?, ?> sourceGrpStmtCtx,
+    private static void copyFromSourceToTarget(final Mutable<?, ?, ?> sourceGrpStmtCtx,
             final StatementContextBase<?, ?, ?> targetCtx,
             final StmtContext.Mutable<QName, UsesStatement, EffectiveStatement<QName, UsesStatement>> usesNode) {
         final Collection<StatementContextBase<?, ?, ?>> declared = sourceGrpStmtCtx.declaredSubstatements();
@@ -208,7 +208,7 @@ public class UsesStatementImpl extends AbstractDeclaredStatement<QName> implemen
         final QNameModule newQNameModule = getNewQNameModule(targetCtx, sourceGrpStmtCtx);
 
         for (final StatementContextBase<?, ?, ?> original : declared) {
-            if (StmtContextUtils.areFeaturesSupported(original)) {
+            if (original.isSupportedByFeatures()) {
                 copyStatement(original, targetCtx, newQNameModule, buffer);
             }
         }
@@ -279,8 +279,7 @@ public class UsesStatementImpl extends AbstractDeclaredStatement<QName> implemen
         /*
          * In case of Yang 1.1, checks whether features are supported.
          */
-        return !YangVersion.VERSION_1_1.equals(subStmtCtx.getRootVersion()) || StmtContextUtils
-                .areFeaturesSupported(subStmtCtx);
+        return !YangVersion.VERSION_1_1.equals(subStmtCtx.getRootVersion()) || subStmtCtx.isSupportedByFeatures();
     }
 
     private static void performRefine(final StatementContextBase<?, ?, ?> refineCtx,
index 02caa695770d1ba53da074ddf347eb8083536324..a5c8b3bf5df9f64ac540d2c9a8ba2b3b7efc426b 100644 (file)
@@ -16,7 +16,6 @@ import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.CaseStatement;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
 
 public final class CaseEffectiveStatementImpl extends AbstractEffectiveSimpleDataNodeContainer<CaseStatement> implements
         ChoiceCaseNode, DerivableSchemaNode {
@@ -30,20 +29,15 @@ public final class CaseEffectiveStatementImpl extends AbstractEffectiveSimpleDat
         this.original = ctx.getOriginalCtx() == null ? null : (ChoiceCaseNode) ctx.getOriginalCtx().buildEffective();
 
         if (ctx.isConfiguration()) {
-            configuration = isAtLeastOneChildConfiguration(ctx.declaredSubstatements()) ||
-                    isAtLeastOneChildConfiguration(ctx.effectiveSubstatements());
+            configuration = isAtLeastOneChildConfiguration(ctx.declaredSubstatements())
+                    || isAtLeastOneChildConfiguration(ctx.effectiveSubstatements());
         } else {
             configuration = false;
         }
     }
 
-    private static boolean isAtLeastOneChildConfiguration(final Collection<StatementContextBase<?, ?, ?>> substatements) {
-        for (StatementContextBase<?, ?, ?> substatement : substatements) {
-            if (substatement.isConfiguration()) {
-                return true;
-            }
-        }
-        return false;
+    private static boolean isAtLeastOneChildConfiguration(final Collection<? extends StmtContext<?, ?, ?>> children) {
+        return children.stream().anyMatch(StmtContext::isConfiguration);
     }
 
     @Override
index 7307011f70e174ee9ee46c46aa263368cb044c13..c83b347d36d15f474608fc0e0bb60899f43edd58 100644 (file)
@@ -17,13 +17,12 @@ import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 import javax.annotation.Nonnull;
-import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
+import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 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;
 
 public abstract class EffectiveStatementBase<A, D extends DeclaredStatement<A>> implements EffectiveStatement<A, D> {
@@ -36,12 +35,12 @@ public abstract class EffectiveStatementBase<A, D extends DeclaredStatement<A>>
      *            context of statement.
      */
     protected EffectiveStatementBase(final StmtContext<A, D, ?> ctx) {
-        final Collection<StatementContextBase<?, ?, ?>> effectiveSubstatements = ctx.effectiveSubstatements();
-        final Collection<StatementContextBase<?, ?, ?>> substatementsInit = new ArrayList<>();
+        final Collection<? extends StmtContext<?, ?, ?>> effectiveSubstatements = ctx.effectiveSubstatements();
+        final Collection<StmtContext<?, ?, ?>> substatementsInit = new ArrayList<>();
 
-        final Collection<StatementContextBase<?, ?, ?>> supportedDeclaredSubStmts = Collections2.filter(
-                ctx.declaredSubstatements(), StmtContextUtils::areFeaturesSupported);
-        for (final StatementContextBase<?, ?, ?> declaredSubstatement : supportedDeclaredSubStmts) {
+        final Collection<? extends StmtContext<?, ?, ?>> supportedDeclaredSubStmts = Collections2.filter(
+                ctx.declaredSubstatements(), StmtContext::isSupportedByFeatures);
+        for (final StmtContext<?, ?, ?> declaredSubstatement : supportedDeclaredSubStmts) {
             if (declaredSubstatement.getPublicDefinition().equals(YangStmtMapping.USES)) {
                 substatementsInit.add(declaredSubstatement);
                 substatementsInit.addAll(declaredSubstatement.getEffectOfStatement());
@@ -64,9 +63,9 @@ public abstract class EffectiveStatementBase<A, D extends DeclaredStatement<A>>
      * @return Filtered substatements
      */
     Collection<? extends EffectiveStatement<?, ?>> initSubstatements(
-            final Collection<StatementContextBase<?, ?, ?>> substatementsInit) {
+            final Collection<? extends StmtContext<?, ?, ?>> substatementsInit) {
         return Collections2.transform(Collections2.filter(substatementsInit,
-            StmtContext::isSupportedToBuildEffective), StatementContextBase::buildEffective);
+            StmtContext::isSupportedToBuildEffective), StmtContext::buildEffective);
     }
 
     @Override
index 96689c9007fd15758071650b2c08f88df53a377b..7b1ee58c60686c17c38d6bb34798109d9249cc06 100644 (file)
@@ -22,7 +22,6 @@ import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
 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>
@@ -112,7 +111,7 @@ public class ExtensionEffectiveStatementImpl extends AbstractEffectiveDocumented
         final ExtensionEffectiveStatementImpl existing = RecursiveObjectLeaker.lookup(ctx,
             ExtensionEffectiveStatementImpl.class);
         if (existing != null) {
-            // Careful! this not fully initialized!
+            // Careful! this object is not fully initialized!
             return existing;
         }
 
@@ -127,7 +126,7 @@ public class ExtensionEffectiveStatementImpl extends AbstractEffectiveDocumented
 
     @Override
     Collection<? extends EffectiveStatement<?, ?>> initSubstatements(
-            final Collection<StatementContextBase<?, ?, ?>> substatementsInit) {
+            final Collection<? extends StmtContext<?, ?, ?>> substatementsInit) {
         // WARNING: this leaks an incompletely-initialized object
         RecursiveObjectLeaker.inConstructor(this);