From 12c1e8fdac8294e5636dd82b8b2c39a3d3a8c3f5 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Mon, 30 Dec 2019 12:36:34 +0100 Subject: [PATCH] Collapse SchemaContextUtil.typeDefinition() We have TypedDataSchemaNode to hold the leaf/leaf-list trait of having a type. This allows us to ditch some code duplication. Change-Id: I959ff6a8f997e557736a081f89df6c16b69e1270 Signed-off-by: Robert Varga --- .../yang/model/util/SchemaContextUtil.java | 46 ++++--------------- 1 file changed, 9 insertions(+), 37 deletions(-) diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtil.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtil.java index 1f36250ed6..c2b8a4e245 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtil.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtil.java @@ -40,7 +40,6 @@ import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode; import org.opendaylight.yangtools.yang.model.api.GroupingDefinition; -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.ModuleImport; @@ -924,36 +923,6 @@ public final class SchemaContextUtil { return STRIP_PATTERN.matcher(pathStatement.getOriginalString()).replaceAll(""); } - /** - * Extracts the base type of leaf schema node until it reach concrete type of TypeDefinition. - * - * @param node - * a node representing LeafSchemaNode - * @return concrete type definition of node value - */ - private static TypeDefinition typeDefinition(final LeafSchemaNode node) { - TypeDefinition baseType = node.getType(); - while (baseType.getBaseType() != null) { - baseType = baseType.getBaseType(); - } - return baseType; - } - - /** - * Extracts the base type of leaf schema node until it reach concrete type of TypeDefinition. - * - * @param node - * a node representing LeafListSchemaNode - * @return concrete type definition of node value - */ - private static TypeDefinition typeDefinition(final LeafListSchemaNode node) { - TypeDefinition baseType = node.getType(); - while (baseType.getBaseType() != null) { - baseType = baseType.getBaseType(); - } - return baseType; - } - /** * Gets the base type of DataSchemaNode value. * @@ -962,12 +931,15 @@ public final class SchemaContextUtil { * @return concrete type definition of node value */ private static TypeDefinition typeDefinition(final DataSchemaNode node) { - if (node instanceof LeafListSchemaNode) { - return typeDefinition((LeafListSchemaNode) node); - } else if (node instanceof LeafSchemaNode) { - return typeDefinition((LeafSchemaNode) node); - } else { - throw new IllegalArgumentException("Unhandled parameter type: " + node); + checkArgument(node instanceof TypedDataSchemaNode, "Unhandled parameter type %s", node); + + TypeDefinition current = ((TypedDataSchemaNode) node).getType(); + // TODO: don't we have a utility for this? + TypeDefinition base = current.getBaseType(); + while (base != null) { + current = base; + base = current.getBaseType(); } + return current; } } -- 2.36.6