*/
package org.opendaylight.yangtools.yang.data.impl.leafref;
-import static com.google.common.base.Preconditions.checkNotNull;
-
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.PathExpression;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.TypedDataSchemaNode;
return rootBuilder.build();
}
- private LeafRefContext buildLeafRefContextReferencingTree(final DataSchemaNode node, final Module currentModule)
- throws LeafRefYangSyntaxErrorException {
+ private LeafRefContext buildLeafRefContextReferencingTree(final DataSchemaNode node, final Module currentModule) {
final LeafRefContextBuilder currentLeafRefContextBuilder = new LeafRefContextBuilder(node.getQName(),
node.getPath(), schemaContext);
}
} else if (node instanceof TypedDataSchemaNode) {
- final TypeDefinition<?> type = ((TypedDataSchemaNode) node).getType();
+ final TypedDataSchemaNode typedNode = (TypedDataSchemaNode) node;
+ final TypeDefinition<?> type = typedNode.getType();
// FIXME: fix case when type is e.g. typedef -> typedef -> leafref
if (type instanceof LeafrefTypeDefinition) {
final LeafrefTypeDefinition leafrefType = (LeafrefTypeDefinition) type;
- final String leafRefPathString = leafrefType.getPathStatement().getOriginalString();
- final LeafRefPathParserImpl leafRefPathParser = new LeafRefPathParserImpl(schemaContext,
- checkNotNull(getBaseTypeModule(leafrefType), "Unable to find base module for leafref %s", node),
- node);
- final LeafRefPath leafRefPath = leafRefPathParser.parseLeafRefPath(leafRefPathString);
+ final PathExpression path = leafrefType.getPathStatement();
+ final LeafRefPathParserImpl leafRefPathParser = new LeafRefPathParserImpl(leafrefType, typedNode);
+ final LeafRefPath leafRefPath = leafRefPathParser.parseLeafRefPath(path);
- currentLeafRefContextBuilder.setLeafRefTargetPathString(leafRefPathString);
+ currentLeafRefContextBuilder.setLeafRefTargetPathString(path.getOriginalString());
currentLeafRefContextBuilder.setReferencing(true);
currentLeafRefContextBuilder.setLeafRefTargetPath(leafRefPath);
return currentLeafRefContextBuilder.build();
}
- private Module getBaseTypeModule(final LeafrefTypeDefinition leafrefType) {
- /*
- * Find the first definition of supplied leafref type and return the
- * module which contains this definition.
- */
- LeafrefTypeDefinition baseLeafRefType = leafrefType;
- while (baseLeafRefType.getBaseType() != null) {
- baseLeafRefType = baseLeafRefType.getBaseType();
- }
- return schemaContext.findModule(baseLeafRefType.getQName().getModule()).orElse(null);
- }
-
private LeafRefContext buildLeafRefContextReferencedByTree(final DataSchemaNode node, final Module currentModule)
throws LeafRefYangSyntaxErrorException {
final LeafRefContextBuilder currentLeafRefContextBuilder = new LeafRefContextBuilder(node.getQName(),