Make CamelCaseWithNamespaceNamingStrategy reusable 95/104195/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 30 Jan 2023 18:44:57 +0000 (19:44 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 30 Jan 2023 18:47:23 +0000 (19:47 +0100)
Appending a suffix is usable for other strategies as well, rename this
class to AppendNamespaceNamingStrategy and extract the fact that a
strategy has a namespace to AppendNamespaceNamingStrategy, which
automatic fallback.

JIRA: MDSAL-675
Change-Id: Ib1614b84591b4c0349f81785846f7216e0e87ec4
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-generator/src/main/java/org/opendaylight/mdsal/binding/generator/impl/reactor/AbstractNamespacedNamingStrategy.java [new file with mode: 0644]
binding/mdsal-binding-generator/src/main/java/org/opendaylight/mdsal/binding/generator/impl/reactor/AppendNamespaceNamingStrategy.java [moved from binding/mdsal-binding-generator/src/main/java/org/opendaylight/mdsal/binding/generator/impl/reactor/CamelCaseWithNamespaceNamingStrategy.java with 89% similarity]
binding/mdsal-binding-generator/src/main/java/org/opendaylight/mdsal/binding/generator/impl/reactor/CamelCaseNamingStrategy.java

diff --git a/binding/mdsal-binding-generator/src/main/java/org/opendaylight/mdsal/binding/generator/impl/reactor/AbstractNamespacedNamingStrategy.java b/binding/mdsal-binding-generator/src/main/java/org/opendaylight/mdsal/binding/generator/impl/reactor/AbstractNamespacedNamingStrategy.java
new file mode 100644 (file)
index 0000000..144c21c
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.binding.generator.impl.reactor;
+
+import static java.util.Objects.requireNonNull;
+
+import com.google.common.base.MoreObjects.ToStringHelper;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
+/**
+ * A {@link ClassNamingStrategy} which considers a {@link StatementNamespace} when assigning names.
+ */
+@NonNullByDefault
+abstract class AbstractNamespacedNamingStrategy extends ClassNamingStrategy {
+    private final StatementNamespace namespace;
+
+    AbstractNamespacedNamingStrategy(final StatementNamespace namespace) {
+        this.namespace = requireNonNull(namespace);
+    }
+
+    @Override
+    final @NonNull ClassNamingStrategy fallback() {
+        return new AppendNamespaceNamingStrategy(this);
+    }
+
+    final StatementNamespace namespace() {
+        return namespace;
+    }
+
+    @Override
+    ToStringHelper addToStringAttributes(final ToStringHelper helper) {
+        return helper.add("namespace", namespace);
+    }
+}
@@ -12,10 +12,10 @@ import static java.util.Objects.requireNonNull;
 import com.google.common.base.MoreObjects.ToStringHelper;
 import org.opendaylight.yangtools.yang.common.AbstractQName;
 
-final class CamelCaseWithNamespaceNamingStrategy extends ClassNamingStrategy {
-    private final CamelCaseNamingStrategy delegate;
+final class AppendNamespaceNamingStrategy extends ClassNamingStrategy {
+    private final AbstractNamespacedNamingStrategy delegate;
 
-    CamelCaseWithNamespaceNamingStrategy(final CamelCaseNamingStrategy delegate) {
+    AppendNamespaceNamingStrategy(final AbstractNamespacedNamingStrategy delegate) {
         this.delegate = requireNonNull(delegate);
     }
 
index c2f89b36343d7fba72d1cdfee06caa71e5f92157..b7b209dfdc28de064aa7d631fa0a41477f7ea16f 100644 (file)
@@ -10,17 +10,15 @@ package org.opendaylight.mdsal.binding.generator.impl.reactor;
 import static java.util.Objects.requireNonNull;
 
 import com.google.common.base.MoreObjects.ToStringHelper;
-import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.opendaylight.yangtools.yang.common.AbstractQName;
 
 @NonNullByDefault
-final class CamelCaseNamingStrategy extends ClassNamingStrategy {
-    private final StatementNamespace namespace;
+final class CamelCaseNamingStrategy extends AbstractNamespacedNamingStrategy {
     private final AbstractQName nodeIdentifier;
 
     CamelCaseNamingStrategy(final StatementNamespace namespace, final AbstractQName nodeIdentifier) {
-        this.namespace = requireNonNull(namespace);
+        super(namespace);
         this.nodeIdentifier = requireNonNull(nodeIdentifier);
     }
 
@@ -29,17 +27,8 @@ final class CamelCaseNamingStrategy extends ClassNamingStrategy {
         return nodeIdentifier;
     }
 
-    StatementNamespace namespace() {
-        return namespace;
-    }
-
-    @Override
-    @NonNull ClassNamingStrategy fallback() {
-        return new CamelCaseWithNamespaceNamingStrategy(this);
-    }
-
     @Override
     ToStringHelper addToStringAttributes(final ToStringHelper helper) {
-        return helper.add("localName", nodeIdentifier.getLocalName()).add("namespace", namespace);
+        return super.addToStringAttributes(helper.add("localName", nodeIdentifier.getLocalName()));
     }
 }