Bug 4414: Shorthand case statement not working 68/28268/9
authorMartin Ciglan <mciglan@cisco.com>
Mon, 12 Oct 2015 07:40:46 +0000 (09:40 +0200)
committerMartin Ciglan <mciglan@cisco.com>
Tue, 27 Oct 2015 15:14:04 +0000 (16:14 +0100)
Original for shorthand-case was not set at all,
therefore definition in grouping causes
IncorrectNestingException: Supplied class is not valid case

- code refactored
- fix: getOriginal() returns proper value

Change-Id: I6941eea52a07967824d2653fbfaedebc5f35ddc9
Signed-off-by: Martin Ciglan <mciglan@cisco.com>
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/CaseShorthandImpl.java

index ce54d65427ca47f3ccf9521e09e5a714ed4d4129..a2b575133f11332fbfacf21f236d3c56f3bd2128 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
@@ -42,6 +42,7 @@ public class CaseShorthandImpl implements ChoiceCaseNode, DerivableSchemaNode {
     private final boolean addedByUses;
     private final ConstraintDefinition constraints;
     private final List<UnknownSchemaNode> unknownNodes;
+    private final ChoiceCaseNode original;
 
     public CaseShorthandImpl(final DataSchemaNode caseShorthandNode) {
         this.caseShorthandNode = caseShorthandNode;
@@ -55,6 +56,8 @@ public class CaseShorthandImpl implements ChoiceCaseNode, DerivableSchemaNode {
         this.addedByUses = caseShorthandNode.isAddedByUses();
         this.constraints = caseShorthandNode.getConstraints();
         this.unknownNodes = ImmutableList.copyOf(caseShorthandNode.getUnknownSchemaNodes());
+
+        this.original = getOriginalIfPresent(caseShorthandNode);
     }
 
     @Override
@@ -152,7 +155,7 @@ public class CaseShorthandImpl implements ChoiceCaseNode, DerivableSchemaNode {
 
     @Override
     public Optional<? extends SchemaNode> getOriginal() {
-        return Optional.absent();
+        return Optional.fromNullable(original);
     }
 
     @Override
@@ -188,4 +191,14 @@ public class CaseShorthandImpl implements ChoiceCaseNode, DerivableSchemaNode {
         sb.append("]");
         return sb.toString();
     }
+
+    private static ChoiceCaseNode getOriginalIfPresent(final SchemaNode caseShorthandNode) {
+        if (caseShorthandNode instanceof DerivableSchemaNode) {
+            final Optional<? extends SchemaNode> original = ((DerivableSchemaNode) caseShorthandNode).getOriginal();
+            if (original.isPresent()) {
+                return new CaseShorthandImpl((DataSchemaNode) original.get());
+            }
+        }
+        return null;
+    }
 }