Use Method.getParameterCount() 86/77886/1
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 16 Nov 2018 06:38:51 +0000 (07:38 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 16 Nov 2018 07:58:19 +0000 (08:58 +0100)
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/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/util/BindingReflections.java

index 6363c279a022a95e14b2f1aeeb317341014526b8..6ff2defe32505457b254b950e34ba8abdcec1c8d 100644 (file)
@@ -82,7 +82,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) {
@@ -100,11 +100,11 @@ class RpcServiceAdapter implements InvocationHandler {
     private static boolean isObjectMethod(final Method method) {
         switch (method.getName()) {
             case "toString":
-                return method.getReturnType().equals(String.class) && method.getParameterTypes().length == 0;
+                return method.getReturnType().equals(String.class) && method.getParameterCount() == 0;
             case "hashCode":
-                return method.getReturnType().equals(int.class) && method.getParameterTypes().length == 0;
+                return method.getReturnType().equals(int.class) && method.getParameterCount() == 0;
             case "equals":
-                return method.getReturnType().equals(boolean.class) && method.getParameterTypes().length == 1
+                return method.getReturnType().equals(boolean.class) && method.getParameterCount() == 1
                         && method.getParameterTypes()[0] == Object.class;
             default:
                 return false;
index a6f76a6562f549bf4c60c57295cc97baea74e15f..15e5e71392e13cc3a8cbfb9ea41ff81450d90c76 100644 (file)
@@ -244,7 +244,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 9c22178788bffe773f993b77b3091e48f2c40812..a8da0dce83e40bd9f6a154d9da32818bf8955a96 100644 (file)
@@ -58,7 +58,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 d164574bff90a82d461ce6ed0f5439f212a31ea8..690ab17178f4b4ea74997c563d308b610ee3ba10 100644 (file)
@@ -137,7 +137,7 @@ public class CascadeUsesCompilationTest extends BaseCompilationTest {
             }
         }
         assertNotNull(fieldsFromMethod);
-        assertEquals(1, fieldsFromMethod.getParameterTypes().length);
+        assertEquals(1, fieldsFromMethod.getParameterCount());
 
         cleanUp(sourcesOutputDir, compiledOutputDir);
     }
index 32389650cd8f748194b19e645d5e7ff4389ec6a3..76087b95e7a14adaa32354be1a01ff7139921c98 100644 (file)
@@ -138,7 +138,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;
     }
 
     /**
@@ -289,7 +289,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())) {
@@ -415,7 +415,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();
         }