Move BindingReflections.isNotificationCallback() 93/106593/4
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 21 Jun 2023 12:49:39 +0000 (14:49 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 21 Jun 2023 16:22:42 +0000 (18:22 +0200)
This method has only one user, mdsal-binding-dom-adapter. Move it there.

JIRA: MDSAL-781
Change-Id: I128d588d58a75e00b63ebdbba6f503dd261646c7
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDOMNotificationListenerAdapter.java
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/invoke/NotificationListenerInvoker.java
binding/mdsal-binding-spec-util/src/main/java/org/opendaylight/mdsal/binding/spec/reflect/BindingReflections.java
binding/mdsal-binding-spec-util/src/test/java/org/opendaylight/mdsal/binding/spec/reflect/BindingReflectionsTest.java

index 28e5c631d3dfcc9f600d627cf86b02e82a39facf..b97853e7d729a23b5621b21dc5d16c9b930a106e 100644 (file)
@@ -66,7 +66,7 @@ final class BindingDOMNotificationListenerAdapter extends AbstractDOMNotificatio
         // it from NotificationListenerInvoker
         final Set<Absolute> ret = new HashSet<>();
         for (final Method method : type.getMethods()) {
-            if (BindingReflections.isNotificationCallback(method)) {
+            if (NotificationListenerInvoker.isNotificationCallback(method)) {
                 final Class<?> notification = method.getParameterTypes()[0];
                 ret.add(Absolute.of(BindingReflections.findQName(notification)));
             }
index 471d6d13786fc9b6ec42ff0e3937ee73a05a4b8f..b177cebcb2452d62af837a684839a5d178cea2b9 100644 (file)
@@ -18,13 +18,13 @@ import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableMap.Builder;
 import java.lang.invoke.MethodHandle;
 import java.lang.invoke.MethodHandles;
-import java.lang.invoke.MethodHandles.Lookup;
 import java.lang.invoke.MethodType;
 import java.lang.reflect.Method;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
 import org.opendaylight.yangtools.yang.binding.DataContainer;
+import org.opendaylight.yangtools.yang.binding.Notification;
 import org.opendaylight.yangtools.yang.binding.NotificationListener;
 import org.opendaylight.yangtools.yang.common.QName;
 
@@ -36,9 +36,6 @@ import org.opendaylight.yangtools.yang.common.QName;
  * via {@link #invokeNotification(NotificationListener, QName, DataContainer)} method.
  */
 public final class NotificationListenerInvoker {
-
-    private static final Lookup LOOKUP = MethodHandles.publicLookup();
-
     private static final LoadingCache<Class<? extends NotificationListener>, NotificationListenerInvoker> INVOKERS =
             CacheBuilder.newBuilder().weakKeys()
             .build(new CacheLoader<Class<? extends NotificationListener>, NotificationListenerInvoker>() {
@@ -51,14 +48,13 @@ public final class NotificationListenerInvoker {
                         final Class<? extends NotificationListener> key) {
                     final Builder<QName, MethodHandle> ret = ImmutableMap.builder();
                     for (final Method method : key.getMethods()) {
-                        if (BindingReflections.isNotificationCallback(method)) {
-
+                        if (isNotificationCallback(method)) {
                             final Class<?> notification = method.getParameterTypes()[0];
                             final QName name = BindingReflections.findQName(notification);
                             MethodHandle handle;
                             try {
-                                handle = LOOKUP.unreflect(method).asType(MethodType.methodType(void.class,
-                                    NotificationListener.class, DataContainer.class));
+                                handle = MethodHandles.publicLookup().unreflect(method).asType(
+                                    MethodType.methodType(void.class, NotificationListener.class, DataContainer.class));
                                 ret.put(name, handle);
                             } catch (final IllegalAccessException e) {
                                 throw new IllegalStateException("Can not access public method.", e);
@@ -73,7 +69,7 @@ public final class NotificationListenerInvoker {
     private final ImmutableMap<QName, MethodHandle> methodInvokers;
 
     NotificationListenerInvoker(final ImmutableMap<QName, MethodHandle> map) {
-        this.methodInvokers = map;
+        methodInvokers = map;
     }
 
     /**
@@ -110,4 +106,21 @@ public final class NotificationListenerInvoker {
             throw new IllegalStateException(e);
         }
     }
+
+    /**
+     * Checks if supplied method is callback for notifications.
+     *
+     * @param method method to check
+     * @return true if method is notification callback.
+     */
+    public static boolean isNotificationCallback(final Method method) {
+        if (method.getName().startsWith("on") && method.getParameterCount() == 1) {
+            Class<?> potentialNotification = method.getParameterTypes()[0];
+            if (Notification.class.isAssignableFrom(potentialNotification)
+                    && method.getName().equals("on" + potentialNotification.getSimpleName())) {
+                return true;
+            }
+        }
+        return false;
+    }
 }
index be9704c2de2a0cd0e6da7e0e36decc6ada02ca20..33d426584127b04aab33e16af5a67459d1d1ee82 100644 (file)
@@ -10,13 +10,11 @@ package org.opendaylight.mdsal.binding.spec.reflect;
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkState;
 
-import com.google.common.annotations.VisibleForTesting;
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.CacheLoader;
 import com.google.common.cache.LoadingCache;
 import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
 import java.util.Optional;
 import java.util.concurrent.TimeUnit;
 import org.eclipse.jdt.annotation.NonNull;
@@ -123,36 +121,6 @@ public final class BindingReflections {
         return cls.getName().startsWith(Naming.PACKAGE_PREFIX);
     }
 
-    /**
-     * Checks if supplied method is callback for notifications.
-     *
-     * @param method method to check
-     * @return true if method is notification callback.
-     */
-    public static boolean isNotificationCallback(final Method method) {
-        checkArgument(method != null);
-        if (method.getName().startsWith("on") && method.getParameterCount() == 1) {
-            Class<?> potentialNotification = method.getParameterTypes()[0];
-            if (isNotification(potentialNotification)
-                    && method.getName().equals("on" + potentialNotification.getSimpleName())) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    /**
-     * Checks is supplied class is a {@link Notification}.
-     *
-     * @param potentialNotification class to examine
-     * @return True if the class represents a Notification.
-     */
-    @VisibleForTesting
-    static boolean isNotification(final Class<?> potentialNotification) {
-        checkArgument(potentialNotification != null, "potentialNotification must not be null.");
-        return Notification.class.isAssignableFrom(potentialNotification);
-    }
-
     /**
      * Checks if supplied class represents RPC Input / RPC Output.
      *
index 83b19615552b9b5a70773366d7a985a1b8be5786..472f174bfe4fcdfe71c22ead14ebaedbcd244e78 100644 (file)
@@ -26,7 +26,6 @@ public class BindingReflectionsTest {
     public void testBindingWithDummyObject() throws Exception {
         assertFalse("Should not be RpcType", BindingReflections.isRpcType(DataObject.class));
         assertTrue("Should be BindingClass", BindingReflections.isBindingClass(DataObject.class));
-        assertFalse("Should not be Notification", BindingReflections.isNotification(DataObject.class));
 
         assertEquals(QName.create("test", "test"), BindingReflections.getQName(TestIdentity.VALUE));
     }