Update yang-parser-api
[yangtools.git] / yang / rfc6241-parser-support / src / main / java / org / opendaylight / yangtools / rfc6241 / parser / GetFilterElementAttributesStatementSupport.java
index f64343a9871f7e0d63ace30ed6b76728bd0f919d..224f45423a09e5dfe2fe69e5fbb8dbad05f7ea3e 100644 (file)
@@ -10,19 +10,24 @@ package org.opendaylight.yangtools.rfc6241.parser;
 import com.google.common.annotations.Beta;
 import com.google.common.collect.ImmutableList;
 import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.concepts.Immutable;
 import org.opendaylight.yangtools.rfc6241.model.api.GetFilterElementAttributesEffectiveStatement;
 import org.opendaylight.yangtools.rfc6241.model.api.GetFilterElementAttributesSchemaNode;
 import org.opendaylight.yangtools.rfc6241.model.api.GetFilterElementAttributesStatement;
 import org.opendaylight.yangtools.rfc6241.model.api.NetconfStatements;
+import org.opendaylight.yangtools.yang.common.Empty;
 import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.SchemaNodeDefaults;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 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.StatementDefinition;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractDeclaredStatement.WithoutArgument.WithSubstatements;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseVoidStatementSupport;
+import org.opendaylight.yangtools.yang.model.spi.meta.AbstractDeclaredStatement.WithoutArgument.WithSubstatements;
+import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.UnknownEffectiveStatementBase;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractEmptyStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
+import org.opendaylight.yangtools.yang.parser.spi.meta.SchemaPathSupport;
 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.meta.SubstatementValidator;
@@ -30,7 +35,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 @Beta
-public final class GetFilterElementAttributesStatementSupport extends BaseVoidStatementSupport<
+public final class GetFilterElementAttributesStatementSupport extends AbstractEmptyStatementSupport<
         GetFilterElementAttributesStatement, GetFilterElementAttributesEffectiveStatement> {
 
     private static final class Declared extends WithSubstatements implements GetFilterElementAttributesStatement {
@@ -42,26 +47,26 @@ public final class GetFilterElementAttributesStatementSupport extends BaseVoidSt
     }
 
     private static final class Effective
-            extends UnknownEffectiveStatementBase<Void, GetFilterElementAttributesStatement>
+            extends UnknownEffectiveStatementBase<Empty, GetFilterElementAttributesStatement>
             implements GetFilterElementAttributesEffectiveStatement, GetFilterElementAttributesSchemaNode {
-        private final @NonNull SchemaPath path;
+        private final @NonNull Immutable path;
 
-        Effective(final StmtContext<Void, GetFilterElementAttributesStatement, ?> ctx,
+        Effective(final Current<Empty, GetFilterElementAttributesStatement> stmt,
                 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
-            super(ctx, substatements);
-            path = ctx.coerceParentContext().getSchemaPath().get().createChild(
-                ctx.getPublicDefinition().getStatementName());
+            super(stmt, substatements);
+            path = SchemaPathSupport.toEffectivePath(stmt.getEffectiveParent().getSchemaPath()
+                    .createChild(stmt.publicDefinition().getStatementName()));
         }
 
         @Override
         public QName getQName() {
-            return path.getLastComponent();
+            return SchemaNodeDefaults.extractQName(path);
         }
 
         @Override
         @Deprecated
         public SchemaPath getPath() {
-            return path;
+            return SchemaNodeDefaults.extractPath(this, path);
         }
 
         @Override
@@ -71,22 +76,15 @@ public final class GetFilterElementAttributesStatementSupport extends BaseVoidSt
     }
 
     private static final Logger LOG = LoggerFactory.getLogger(GetFilterElementAttributesStatementSupport.class);
-    private static final GetFilterElementAttributesStatementSupport INSTANCE =
-            new GetFilterElementAttributesStatementSupport(NetconfStatements.GET_FILTER_ELEMENT_ATTRIBUTES);
+    private static final SubstatementValidator VALIDATOR =
+        SubstatementValidator.builder(NetconfStatements.GET_FILTER_ELEMENT_ATTRIBUTES).build();
 
-    private final SubstatementValidator validator;
-
-    GetFilterElementAttributesStatementSupport(final StatementDefinition definition) {
-        super(definition);
-        this.validator = SubstatementValidator.builder(definition).build();
-    }
-
-    public static GetFilterElementAttributesStatementSupport getInstance() {
-        return INSTANCE;
+    public GetFilterElementAttributesStatementSupport(final YangParserConfiguration config) {
+        super(NetconfStatements.GET_FILTER_ELEMENT_ATTRIBUTES, StatementPolicy.reject(), config);
     }
 
     @Override
-    public void onFullDefinitionDeclared(final Mutable<Void, GetFilterElementAttributesStatement,
+    public void onFullDefinitionDeclared(final Mutable<Empty, GetFilterElementAttributesStatement,
             GetFilterElementAttributesEffectiveStatement> stmt) {
         super.onFullDefinitionDeclared(stmt);
         stmt.setIsSupportedToBuildEffective(computeSupported(stmt));
@@ -94,37 +92,21 @@ public final class GetFilterElementAttributesStatementSupport extends BaseVoidSt
 
     @Override
     protected SubstatementValidator getSubstatementValidator() {
-        return validator;
+        return VALIDATOR;
     }
 
     @Override
     protected GetFilterElementAttributesStatement createDeclared(
-            final StmtContext<Void, GetFilterElementAttributesStatement, ?> ctx,
+            final StmtContext<Empty, GetFilterElementAttributesStatement, ?> ctx,
             final ImmutableList<? extends DeclaredStatement<?>> substatements) {
-        return new Declared(substatements);
-    }
-
-    @Override
-    protected GetFilterElementAttributesStatement createEmptyDeclared(
-            final StmtContext<Void, GetFilterElementAttributesStatement, ?> ctx) {
-        return Declared.EMPTY;
+        return substatements.isEmpty() ? Declared.EMPTY : new Declared(substatements);
     }
 
     @Override
     protected GetFilterElementAttributesEffectiveStatement createEffective(
-            final StmtContext<Void, GetFilterElementAttributesStatement,
-                GetFilterElementAttributesEffectiveStatement> ctx,
-            final GetFilterElementAttributesStatement declared,
+            final Current<Empty, GetFilterElementAttributesStatement> stmt,
             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
-        return new Effective(ctx, substatements);
-    }
-
-    @Override
-    protected GetFilterElementAttributesEffectiveStatement createEmptyEffective(
-            final StmtContext<Void, GetFilterElementAttributesStatement,
-                GetFilterElementAttributesEffectiveStatement> ctx,
-            final GetFilterElementAttributesStatement declared) {
-        return createEffective(ctx, declared, ImmutableList.of());
+        return new Effective(stmt, substatements);
     }
 
     private static boolean computeSupported(final StmtContext<?, ?, ?> stmt) {
@@ -133,11 +115,11 @@ public final class GetFilterElementAttributesStatementSupport extends BaseVoidSt
             LOG.debug("No parent, ignoring get-filter-element-attributes statement");
             return false;
         }
-        if (parent.getPublicDefinition() != YangStmtMapping.ANYXML) {
+        if (parent.publicDefinition() != YangStmtMapping.ANYXML) {
             LOG.debug("Parent is not an anyxml node, ignoring get-filter-element-attributes statement");
             return false;
         }
-        if (!"filter".equals(parent.rawStatementArgument())) {
+        if (!"filter".equals(parent.rawArgument())) {
             LOG.debug("Parent is not named 'filter', ignoring get-filter-element-attributes statement");
             return false;
         }
@@ -147,7 +129,7 @@ public final class GetFilterElementAttributesStatementSupport extends BaseVoidSt
             LOG.debug("No grandparent, ignoring get-filter-element-attributes statement");
             return false;
         }
-        if (grandParent.getPublicDefinition() != YangStmtMapping.INPUT) {
+        if (grandParent.publicDefinition() != YangStmtMapping.INPUT) {
             LOG.debug("Grandparent is not an input node, ignoring get-filter-element-attributes statement");
             return false;
         }
@@ -157,12 +139,12 @@ public final class GetFilterElementAttributesStatementSupport extends BaseVoidSt
             LOG.debug("No grandparent, ignoring get-filter-element-attributes statement");
             return false;
         }
-        if (greatGrandParent.getPublicDefinition() != YangStmtMapping.RPC) {
+        if (greatGrandParent.publicDefinition() != YangStmtMapping.RPC) {
             LOG.debug("Grandparent is not an RPC node, ignoring get-filter-element-attributes statement");
             return false;
         }
 
-        switch (greatGrandParent.rawStatementArgument()) {
+        switch (greatGrandParent.getRawArgument()) {
             case "get":
             case "get-config":
                 return true;