Expand test suite to cover uses-augment of actions
[mdsal.git] / binding / mdsal-binding-generator-impl / src / main / java / org / opendaylight / mdsal / binding / generator / impl / AbstractTypeGenerator.java
index f536e84bcdec3393482d0b197be211dc508c1ed0..447ba7cb804a0a02e22bd449b7243de00ea5d440 100644 (file)
@@ -916,11 +916,37 @@ abstract class AbstractTypeGenerator {
     private DataSchemaNode findOriginalTargetFromGrouping(final SchemaPath targetPath, final UsesNode parentUsesNode) {
         SchemaNode result = findUsedGrouping(parentUsesNode);
         for (final QName node : targetPath.getPathFromRoot()) {
+            // FIXME: this dispatch is rather ugly, we probably want to refactor it a bit
             if (result instanceof DataNodeContainer) {
                 final QName resultNode = node.withModule(result.getQName().getModule());
-                result = ((DataNodeContainer) result).getDataChildByName(resultNode);
+
+                SchemaNode found = ((DataNodeContainer) result).getDataChildByName(resultNode);
+                if (found == null) {
+                    if (result instanceof ActionNodeContainer) {
+                        found = ((ActionNodeContainer) result).findAction(resultNode).orElse(null);
+                    }
+                    if (found == null && result instanceof NotificationNodeContainer) {
+                        found = ((NotificationNodeContainer) result).findNotification(resultNode).orElse(null);
+                    }
+                }
+                result = found;
             } else if (result instanceof ChoiceSchemaNode) {
                 result = findNamedCase((ChoiceSchemaNode) result, node.getLocalName());
+            } else if (result instanceof ActionDefinition) {
+                final ActionDefinition action = (ActionDefinition) result;
+                final QName resultNode = node.withModule(result.getQName().getModule());
+
+                final ContainerSchemaNode input = action.getInput();
+                final ContainerSchemaNode output = action.getOutput();
+                if (resultNode.equals(input.getQName())) {
+                    result = input;
+                } else if (resultNode.equals(output.getQName())) {
+                    result = output;
+                } else {
+                    result = null;
+                }
+            } else if (result != null) {
+                throw new IllegalStateException("Cannot handle " + result);
             }
         }
         if (result == null) {