Simplify DeviateStatementImpl.addStatement() 37/61237/9
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 6 Aug 2017 23:10:25 +0000 (01:10 +0200)
committerRobert Varga <nite@hq.sk>
Wed, 16 Aug 2017 16:11:49 +0000 (16:11 +0000)
There is a copy&paste line here which can be eliminated with some
application of structured programming.

Change-Id: If3fffc7f07648de1456a8fbe02feba44ed40b0e9
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/DeviateStatementImpl.java

index 60fc2f32550ef0e79c9f4b6fb1c8472a986dec64..d3eca3e746789f86c69d6d72812b2429c49f00f5 100644 (file)
@@ -211,23 +211,19 @@ public class DeviateStatementImpl extends AbstractDeclaredStatement<DeviateKind>
 
         private static void addStatement(final Mutable<?, ?, ?> stmtCtxToBeAdded,
                 final StatementContextBase<?, ?, ?> targetCtx) {
-            if (StmtContextUtils.isUnknownStatement(stmtCtxToBeAdded)) {
-                targetCtx.addEffectiveSubstatement(targetCtx.childCopyOf(stmtCtxToBeAdded, CopyType.ORIGINAL));
-                return;
-            }
-
-            final StatementDefinition stmtToBeAdded = stmtCtxToBeAdded.getPublicDefinition();
-
-            if (SINGLETON_STATEMENTS.contains(stmtToBeAdded) || YangStmtMapping.DEFAULT.equals(stmtToBeAdded)
-                    && YangStmtMapping.LEAF.equals(targetCtx.getPublicDefinition())) {
-                final Iterable<StmtContext<?, ?, ?>> targetCtxSubstatements = Iterables.concat(
-                        targetCtx.declaredSubstatements(), targetCtx.effectiveSubstatements());
-
-                for (final StmtContext<?, ?, ?> targetCtxSubstatement : targetCtxSubstatements) {
-                    InferenceException.throwIf(stmtToBeAdded.equals(targetCtxSubstatement.getPublicDefinition()),
-                            stmtCtxToBeAdded.getStatementSourceReference(), "Deviation cannot add substatement %s " +
-                            "to target node %s because it is already defined in target and can appear only once.",
-                            stmtToBeAdded.getStatementName(), targetCtx.getStatementArgument());
+            if (!StmtContextUtils.isUnknownStatement(stmtCtxToBeAdded)) {
+                final StatementDefinition stmtToBeAdded = stmtCtxToBeAdded.getPublicDefinition();
+                if (SINGLETON_STATEMENTS.contains(stmtToBeAdded) || YangStmtMapping.DEFAULT.equals(stmtToBeAdded)
+                        && YangStmtMapping.LEAF.equals(targetCtx.getPublicDefinition())) {
+                    final Iterable<StmtContext<?, ?, ?>> targetCtxSubstatements = Iterables.concat(
+                            targetCtx.declaredSubstatements(), targetCtx.effectiveSubstatements());
+
+                    for (final StmtContext<?, ?, ?> targetCtxSubstatement : targetCtxSubstatements) {
+                        InferenceException.throwIf(stmtToBeAdded.equals(targetCtxSubstatement.getPublicDefinition()),
+                            stmtCtxToBeAdded.getStatementSourceReference(), "Deviation cannot add substatement %s "
+                        + "to target node %s because it is already defined in target and can appear only once.",
+                        stmtToBeAdded.getStatementName(), targetCtx.getStatementArgument());
+                    }
                 }
             }