- final SchemaNode dataNode;
- if (xpath.isAbsolute()) {
- dataNode = findDataSchemaNode(schemaContext, module, xpath);
- } else {
- dataNode = findDataSchemaNodeForRelativeXPath(schemaContext, module, parentNode, xpath);
- }
- Preconditions.checkArgument(dataNode != null, "Failed to find leafref target: %s in module %s (%s)",
- strXPath, this.getParentModule(parentNode).getName(), parentNode.getQName().getModule());
-
- // FIXME: this block seems to be some weird magic hack. Analyze and refactor it.
- if (leafContainsEnumDefinition(dataNode)) {
- returnType = referencedTypes.get(dataNode.getPath());
- } else if (leafListContainsEnumDefinition(dataNode)) {
- returnType = Types.listTypeFor(referencedTypes.get(dataNode.getPath()));
- }
- if (returnType == null) {
- returnType = resolveTypeFromDataSchemaNode(dataNode);
- }
- } else {
- returnType = Types.objectType();
+ final Module module = findParentModule(schemaContext, parentNode);
+ Preconditions.checkArgument(module != null, "Failed to find module for parent %s", parentNode);
+
+ final SchemaNode dataNode;
+ if (xpath.isAbsolute()) {
+ dataNode = findDataSchemaNode(schemaContext, module, xpath);
+ } else {
+ dataNode = findDataSchemaNodeForRelativeXPath(schemaContext, module, parentNode, xpath);
+ if (dataNode == null && inGrouping) {
+ // Relative path within a grouping may end up being unresolvable because it may refer outside
+ // the grouping, in which case it is polymorphic based on instantiation, for example:
+ //
+ // grouping foo {
+ // leaf foo {
+ // type leafref {
+ // path "../../bar";
+ // }
+ // }
+ // }
+ //
+ // container one {
+ // leaf bar {
+ // type string;
+ // }
+ // uses foo;
+ // }
+ //
+ // container two {
+ // leaf bar {
+ // type uint16;
+ // }
+ // uses foo;
+ // }
+ LOG.debug("Leafref type {} not found in parent {}, assuming polymorphic object", leafrefType,
+ parentNode);
+ return Types.objectType();