Use Method.getParameterCount() 81/77881/2
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 16 Nov 2018 06:38:51 +0000 (07:38 +0100)
committerRobert Varga <nite@hq.sk>
Wed, 21 Nov 2018 11:10:19 +0000 (11:10 +0000)
Java 8 introduced this method, which bypasses array cloning done
by getParameterTypes(), making it more efficient. Take advantage
of it.

JIRA: MDSAL-398
Change-Id: Id5d4972ba20d63a8ff79e4adbdf6d2adbfce0b87
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit d90adcf214a8f17ae5de22cf8964cbb2a9963972)

binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/RpcServiceAdapter.java
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/BindingCodecContext.java
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/LazyDataObject.java
binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/mdsal/binding/java/api/generator/test/CascadeUsesCompilationTest.java
binding/mdsal-binding-spec-util/src/main/java/org/opendaylight/mdsal/binding/spec/reflect/BindingReflections.java

index 0c36a7f533157f97260d7d72e89a610f0e65a624..6314b613c7f8425853db42c5fa5e8562490dc6f6 100644 (file)
@@ -76,7 +76,7 @@ class RpcServiceAdapter implements InvocationHandler {
 
         final RpcInvocationStrategy rpc = rpcNames.get(method);
         if (rpc != null) {
-            if (method.getParameterTypes().length == 0) {
+            if (method.getParameterCount() == 0) {
                 return rpc.invokeEmpty();
             }
             if (args.length != 1) {
@@ -87,17 +87,17 @@ class RpcServiceAdapter implements InvocationHandler {
 
         switch (method.getName()) {
             case "toString":
-                if (method.getReturnType().equals(String.class) && method.getParameterTypes().length == 0) {
+                if (method.getReturnType().equals(String.class) && method.getParameterCount() == 0) {
                     return type.getName() + "$Adapter{delegate=" + delegate.toString() + "}";
                 }
                 break;
             case "hashCode":
-                if (method.getReturnType().equals(int.class) && method.getParameterTypes().length == 0) {
+                if (method.getReturnType().equals(int.class) && method.getParameterCount() == 0) {
                     return System.identityHashCode(proxy);
                 }
                 break;
             case "equals":
-                if (method.getReturnType().equals(boolean.class) && method.getParameterTypes().length == 1
+                if (method.getReturnType().equals(boolean.class) && method.getParameterCount() == 1
                         && method.getParameterTypes()[0] == Object.class) {
                     return proxy == args[0];
                 }
index 967e45b5db700e99b5b63f6fb85009220d493504..533be37e5c26c979b3dcac88dda3d316e1638278 100644 (file)
@@ -253,7 +253,7 @@ final class BindingCodecContext implements CodecContextFactory, BindingCodecTree
             final Map<String, DataSchemaNode> getterToLeafSchema) {
         final Map<String, LeafNodeCodecContext<?>> leaves = new HashMap<>();
         for (final Method method : parentClass.getMethods()) {
-            if (method.getParameterTypes().length == 0) {
+            if (method.getParameterCount() == 0) {
                 final DataSchemaNode schema = getterToLeafSchema.get(method.getName());
                 final Class<?> valueType;
                 if (schema instanceof LeafSchemaNode) {
index cf6701ae8d5c24e76d53ea22d0d3428260f329c4..4520a2cc29b4769193f91596044eadfbed397cca 100644 (file)
@@ -62,7 +62,7 @@ class LazyDataObject<D extends DataObject> implements InvocationHandler, Augment
 
     @Override
     public Object invoke(final Object proxy, final Method method, final Object[] args) {
-        if (method.getParameterTypes().length == 0) {
+        if (method.getParameterCount() == 0) {
             final String name = method.getName();
             if (DATA_CONTAINER_GET_IMPLEMENTED_INTERFACE_NAME.equals(name)) {
                 return context.getBindingClass();
index 2186d8c2b797afcfdb415e8f5940dc81f9bd4c91..65863072b834e06e3a25ca4a7bc735dd97edabd0 100644 (file)
@@ -120,7 +120,7 @@ public class CascadeUsesCompilationTest extends BaseCompilationTest {
             }
         }
         assertNotNull(fieldsFromMethod);
-        assertEquals(1, fieldsFromMethod.getParameterTypes().length);
+        assertEquals(1, fieldsFromMethod.getParameterCount());
 
         cleanUp(sourcesOutputDir, compiledOutputDir);
     }
index c4a0d34abf85c2ebd15ef9ab76ef3baa291fa229..57e4089a7a1c17fc8deaf2f50bdfa31876ef298c 100644 (file)
@@ -136,7 +136,7 @@ public final class BindingReflections {
                 // resolveRpcInputClass() check.While RpcMethodInvoker counts with one argument for
                 // non input type and two arguments for input type, resolveRpcInputClass() counting
                 // with zero for non input and one for input type
-                && possibleMethod.getParameterTypes().length <= 2;
+                && possibleMethod.getParameterCount() <= 2;
     }
 
     /**
@@ -297,7 +297,7 @@ public final class BindingReflections {
      */
     public static boolean isNotificationCallback(final Method method) {
         checkArgument(method != null);
-        if (method.getName().startsWith("on") && method.getParameterTypes().length == 1) {
+        if (method.getName().startsWith("on") && method.getParameterCount() == 1) {
             Class<?> potentialNotification = method.getParameterTypes()[0];
             if (isNotification(potentialNotification)
                     && method.getName().equals("on" + potentialNotification.getSimpleName())) {
@@ -424,7 +424,7 @@ public final class BindingReflections {
     @SuppressWarnings({ "unchecked", "rawtypes", "checkstyle:illegalCatch" })
     private static Optional<Class<? extends DataContainer>> getYangModeledReturnType(final Method method) {
         if ("getClass".equals(method.getName()) || !method.getName().startsWith("get")
-                || method.getParameterTypes().length > 0) {
+                || method.getParameterCount() > 0) {
             return Optional.absent();
         }