Move BindingSchemaContextUtils.findInstantiatedCase() 29/87829/9
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 17 Feb 2020 21:58:39 +0000 (22:58 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 18 Feb 2020 14:17:08 +0000 (15:17 +0100)
The only user is BindingRuntimeContext, move the method there
and sever its dependence in binding.generator.impl.

JIRA: MDSAL-392
Change-Id: I4cc349f5d99a4f9ee0c35b01c553e1ddda263e6e
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/impl/BindingSchemaContextUtils.java
binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/util/BindingRuntimeContext.java

index 719e6095a0a156c920ad622de60d3415b7b4080d..cbc4d3b12d0e2ce92d990b11c4c9f03cc46be38f 100644 (file)
@@ -30,8 +30,6 @@ import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.api.SchemaNode;
-import org.opendaylight.yangtools.yang.model.util.SchemaNodeUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -189,35 +187,4 @@ public final class BindingSchemaContextUtils {
 
         return Optional.empty();
     }
-
-    public static Optional<CaseSchemaNode> findInstantiatedCase(final ChoiceSchemaNode instantiatedChoice,
-            final CaseSchemaNode originalDefinition) {
-        CaseSchemaNode potential = instantiatedChoice.getCaseNodeByName(originalDefinition.getQName());
-        if (originalDefinition.equals(potential)) {
-            return Optional.of(potential);
-        }
-        if (potential != null) {
-            SchemaNode potentialRoot = SchemaNodeUtils.getRootOriginalIfPossible(potential);
-            if (originalDefinition.equals(potentialRoot)) {
-                return Optional.of(potential);
-            }
-        }
-
-        // We try to find case by name, then lookup its root definition
-        // and compare it with original definition
-        // This solves case, if choice was inside grouping
-        // which was used in different module and thus namespaces are
-        // different, but local names are still same.
-        //
-        // Still we need to check equality of definition, because local name is not
-        // sufficient to uniquelly determine equality of cases
-        //
-        for (CaseSchemaNode caze : instantiatedChoice.findCaseNodes(originalDefinition.getQName().getLocalName())) {
-            if (originalDefinition.equals(SchemaNodeUtils.getRootOriginalIfPossible(caze))) {
-                return Optional.of(caze);
-            }
-        }
-        return Optional.empty();
-    }
-
 }
index 47f7af2e9f201f8d52e2e540d6f3be0903f645e2..dbf20abc334557d476796f3461249edcfac37458 100644 (file)
@@ -37,7 +37,6 @@ import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.mdsal.binding.generator.api.BindingRuntimeGenerator;
 import org.opendaylight.mdsal.binding.generator.api.BindingRuntimeTypes;
 import org.opendaylight.mdsal.binding.generator.api.ClassLoadingStrategy;
-import org.opendaylight.mdsal.binding.generator.impl.BindingSchemaContextUtils;
 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
 import org.opendaylight.mdsal.binding.model.api.JavaTypeName;
 import org.opendaylight.mdsal.binding.model.api.MethodSignature;
@@ -254,8 +253,7 @@ public final class BindingRuntimeContext implements SchemaContextProvider, Immut
          * that user may be unaware that he is using incorrect case
          * which was generated for choice inside grouping.
          */
-        final Optional<CaseSchemaNode> found = BindingSchemaContextUtils.findInstantiatedCase(schema,
-                (CaseSchemaNode) origSchema);
+        final Optional<CaseSchemaNode> found = findInstantiatedCase(schema, (CaseSchemaNode) origSchema);
         return found;
     }
 
@@ -443,6 +441,18 @@ public final class BindingRuntimeContext implements SchemaContextProvider, Immut
         return ImmutableMap.copyOf(identifierToType);
     }
 
+    public Class<?> getIdentityClass(final QName input) {
+        return identityClasses.getUnchecked(input);
+    }
+
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(this)
+                .add("ClassLoadingStrategy", strategy)
+                .add("runtimeTypes", runtimeTypes)
+                .toString();
+    }
+
     private static AugmentationIdentifier getAugmentationIdentifier(final AugmentationSchemaNode augment) {
         // FIXME: use DataSchemaContextNode.augmentationIdentifierFrom() once it does caching
         return AugmentationIdentifier.create(augment.getChildNodes().stream().map(DataSchemaNode::getQName)
@@ -487,15 +497,33 @@ public final class BindingRuntimeContext implements SchemaContextProvider, Immut
         return choice;
     }
 
-    public Class<?> getIdentityClass(final QName input) {
-        return identityClasses.getUnchecked(input);
-    }
+    private static Optional<CaseSchemaNode> findInstantiatedCase(final ChoiceSchemaNode instantiatedChoice,
+            final CaseSchemaNode originalDefinition) {
+        CaseSchemaNode potential = instantiatedChoice.getCaseNodeByName(originalDefinition.getQName());
+        if (originalDefinition.equals(potential)) {
+            return Optional.of(potential);
+        }
+        if (potential != null) {
+            SchemaNode potentialRoot = SchemaNodeUtils.getRootOriginalIfPossible(potential);
+            if (originalDefinition.equals(potentialRoot)) {
+                return Optional.of(potential);
+            }
+        }
 
-    @Override
-    public String toString() {
-        return MoreObjects.toStringHelper(this)
-                .add("ClassLoadingStrategy", strategy)
-                .add("runtimeTypes", runtimeTypes)
-                .toString();
+        // We try to find case by name, then lookup its root definition
+        // and compare it with original definition
+        // This solves case, if choice was inside grouping
+        // which was used in different module and thus namespaces are
+        // different, but local names are still same.
+        //
+        // Still we need to check equality of definition, because local name is not
+        // sufficient to uniquelly determine equality of cases
+        //
+        for (CaseSchemaNode caze : instantiatedChoice.findCaseNodes(originalDefinition.getQName().getLocalName())) {
+            if (originalDefinition.equals(SchemaNodeUtils.getRootOriginalIfPossible(caze))) {
+                return Optional.of(caze);
+            }
+        }
+        return Optional.empty();
     }
 }