Merge RpcStatementSupport 07/94107/2
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 8 Dec 2020 12:10:37 +0000 (13:10 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 8 Dec 2020 12:12:48 +0000 (13:12 +0100)
The two subclasses differ only in their implicit input/output,
merge them together, reducing the number of classes we have.

Change-Id: Ic6c99a243f01bc23bae5d72e9e3ad45855fd8fec
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/reactor/RFC7950Reactors.java
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/rpc/RpcStatementRFC6020Support.java [deleted file]
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/rpc/RpcStatementRFC7950Support.java [deleted file]
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/rpc/RpcStatementSupport.java [moved from yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/rpc/AbstractRpcStatementSupport.java with 70% similarity]

index 0b925def0f7974ed21fb1bf7b3e11c6260dc7c60..2fb2e8c80a132431b38056e00d744e646025d861 100644 (file)
@@ -85,8 +85,7 @@ import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.refine.RefineStatemen
 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.require_instance.RequireInstanceStatementSupport;
 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.revision.RevisionStatementSupport;
 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.revision_date.RevisionDateStatementSupport;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.rpc.RpcStatementRFC6020Support;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.rpc.RpcStatementRFC7950Support;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.rpc.RpcStatementSupport;
 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.status.StatusStatementSupport;
 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.submodule.SubmoduleStatementRFC6020Support;
 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.submodule.SubmoduleStatementRFC7950Support;
@@ -241,8 +240,8 @@ public final class RFC7950Reactors {
             .addSupport(ConfigListWarningNamespace.BEHAVIOUR)
             .addSupport(UniqueStatementSupport.getInstance())
             .addVersionSpecificSupport(VERSION_1_1, ActionStatementSupport.getInstance())
-            .addVersionSpecificSupport(VERSION_1, RpcStatementRFC6020Support.getInstance())
-            .addVersionSpecificSupport(VERSION_1_1, RpcStatementRFC7950Support.getInstance())
+            .addVersionSpecificSupport(VERSION_1, RpcStatementSupport.rfc6020Instance())
+            .addVersionSpecificSupport(VERSION_1_1, RpcStatementSupport.rfc7950Instance())
             .addVersionSpecificSupport(VERSION_1, InputStatementSupport.rfc6020Instance())
             .addVersionSpecificSupport(VERSION_1_1, InputStatementSupport.rfc7950Instance())
             .addVersionSpecificSupport(VERSION_1, OutputStatementSupport.rfc6020Instance())
diff --git a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/rpc/RpcStatementRFC6020Support.java b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/rpc/RpcStatementRFC6020Support.java
deleted file mode 100644 (file)
index 685fafc..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (c) 2017 Pantheon Technologies, s.r.o. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.rpc;
-
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.input.InputStatementSupport;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.output.OutputStatementSupport;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupport;
-
-public final class RpcStatementRFC6020Support extends AbstractRpcStatementSupport {
-    private static final RpcStatementRFC6020Support INSTANCE = new RpcStatementRFC6020Support();
-
-    private RpcStatementRFC6020Support() {
-        // Hidden
-    }
-
-    public static RpcStatementRFC6020Support getInstance() {
-        return INSTANCE;
-    }
-
-    @Override
-    StatementSupport<?, ?, ?> implictInput() {
-        return InputStatementSupport.rfc6020Instance();
-    }
-
-    @Override
-    StatementSupport<?, ?, ?> implictOutput() {
-        return OutputStatementSupport.rfc6020Instance();
-    }
-}
\ No newline at end of file
diff --git a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/rpc/RpcStatementRFC7950Support.java b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/rpc/RpcStatementRFC7950Support.java
deleted file mode 100644 (file)
index 322dd38..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (c) 2017 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.rpc;
-
-import com.google.common.annotations.Beta;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.input.InputStatementSupport;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.output.OutputStatementSupport;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupport;
-
-/**
- * Bridge class for RFC7950 RPCs. Specializes implicit input/output statements.
- *
- * @author Robert Varga
- */
-@Beta
-public final class RpcStatementRFC7950Support extends AbstractRpcStatementSupport {
-    private static final RpcStatementRFC7950Support INSTANCE = new RpcStatementRFC7950Support();
-
-    private RpcStatementRFC7950Support() {
-        // Hidden
-    }
-
-    public static RpcStatementRFC7950Support getInstance() {
-        return INSTANCE;
-    }
-
-    @Override
-    StatementSupport<?, ?, ?> implictInput() {
-        return InputStatementSupport.rfc7950Instance();
-    }
-
-    @Override
-    StatementSupport<?, ?, ?> implictOutput() {
-        return OutputStatementSupport.rfc7950Instance();
-    }
-}
@@ -9,8 +9,11 @@ package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.rpc;
 
 import static com.google.common.base.Preconditions.checkState;
 import static com.google.common.base.Verify.verify;
+import static java.util.Objects.requireNonNull;
 
+import com.google.common.annotations.Beta;
 import com.google.common.collect.ImmutableList;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.Status;
 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
@@ -24,8 +27,9 @@ import org.opendaylight.yangtools.yang.model.api.stmt.StatusEffectiveStatement;
 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseSchemaTreeStatementSupport;
 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStatementMixins.EffectiveStatementWithFlags.FlagsBuilder;
 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.SubstatementIndexingException;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.input.InputStatementSupport;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.output.OutputStatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
-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.StmtContext.Mutable;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
@@ -33,7 +37,8 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
 
-abstract class AbstractRpcStatementSupport extends BaseSchemaTreeStatementSupport<RpcStatement, RpcEffectiveStatement> {
+@Beta
+public final class RpcStatementSupport extends BaseSchemaTreeStatementSupport<RpcStatement, RpcEffectiveStatement> {
     private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(
         YangStmtMapping.RPC)
         .addOptional(YangStmtMapping.DESCRIPTION)
@@ -45,37 +50,55 @@ abstract class AbstractRpcStatementSupport extends BaseSchemaTreeStatementSuppor
         .addOptional(YangStmtMapping.STATUS)
         .addAny(YangStmtMapping.TYPEDEF)
         .build();
+    private static final @NonNull RpcStatementSupport RFC6020_INSTANCE = new RpcStatementSupport(
+        InputStatementSupport.rfc6020Instance(), OutputStatementSupport.rfc6020Instance());
+    private static final @NonNull RpcStatementSupport RFC7950_INSTANCE = new RpcStatementSupport(
+        InputStatementSupport.rfc7950Instance(), OutputStatementSupport.rfc7950Instance());
 
-    AbstractRpcStatementSupport() {
+    private final InputStatementSupport implicitInput;
+    private final OutputStatementSupport implicitOutput;
+
+    private RpcStatementSupport(final InputStatementSupport implicitInput,
+            final OutputStatementSupport implicitOutput) {
         super(YangStmtMapping.RPC, CopyPolicy.DECLARED_COPY);
+        this.implicitInput = requireNonNull(implicitInput);
+        this.implicitOutput = requireNonNull(implicitOutput);
+    }
+
+    public static @NonNull RpcStatementSupport rfc6020Instance() {
+        return RFC6020_INSTANCE;
+    }
+
+    public static @NonNull RpcStatementSupport rfc7950Instance() {
+        return RFC7950_INSTANCE;
     }
 
     @Override
-    public final void onFullDefinitionDeclared(final Mutable<QName, RpcStatement, RpcEffectiveStatement> stmt) {
+    public void onFullDefinitionDeclared(final Mutable<QName, RpcStatement, RpcEffectiveStatement> stmt) {
         super.onFullDefinitionDeclared(stmt);
 
         verify(stmt instanceof StatementContextBase);
         if (StmtContextUtils.findFirstDeclaredSubstatement(stmt, InputStatement.class) == null) {
-            ((StatementContextBase<?, ?, ?>) stmt).appendImplicitSubstatement(implictInput(), null);
+            ((StatementContextBase<?, ?, ?>) stmt).appendImplicitSubstatement(implicitInput, null);
         }
         if (StmtContextUtils.findFirstDeclaredSubstatement(stmt, OutputStatement.class) == null) {
-            ((StatementContextBase<?, ?, ?>) stmt).appendImplicitSubstatement(implictOutput(), null);
+            ((StatementContextBase<?, ?, ?>) stmt).appendImplicitSubstatement(implicitOutput, null);
         }
     }
 
     @Override
-    protected final SubstatementValidator getSubstatementValidator() {
+    protected SubstatementValidator getSubstatementValidator() {
         return SUBSTATEMENT_VALIDATOR;
     }
 
     @Override
-    protected final RpcStatement createDeclared(final StmtContext<QName, RpcStatement, ?> ctx,
+    protected RpcStatement createDeclared(final StmtContext<QName, RpcStatement, ?> ctx,
             final ImmutableList<? extends DeclaredStatement<?>> substatements) {
         return new RegularRpcStatement(ctx.getArgument(), substatements);
     }
 
     @Override
-    protected final RpcStatement createEmptyDeclared(final StmtContext<QName, RpcStatement, ?> ctx) {
+    protected RpcStatement createEmptyDeclared(final StmtContext<QName, RpcStatement, ?> ctx) {
         return new EmptyRpcStatement(ctx.getArgument());
     }
 
@@ -92,10 +115,6 @@ abstract class AbstractRpcStatementSupport extends BaseSchemaTreeStatementSuppor
         }
     }
 
-    abstract StatementSupport<?, ?, ?> implictInput();
-
-    abstract StatementSupport<?, ?, ?> implictOutput();
-
     private static int computeFlags(final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
         return new FlagsBuilder()
                 .setStatus(findFirstArgument(substatements, StatusEffectiveStatement.class, Status.CURRENT))