Eliminate synthetic access to invoke0()
[mdsal.git] / binding / mdsal-binding-dom-adapter / src / main / java / org / opendaylight / mdsal / binding / dom / adapter / ContextReferenceExtractor.java
index 1cfe005e7a02a991ce53f06f3b334f99fe8cd12e..d9b4bf08add6b78dc463a38558a3b9cc2cb16963 100644 (file)
@@ -32,7 +32,6 @@ abstract class ContextReferenceExtractor {
         }
     };
 
-
     private static final LoadingCache<Class<?>, ContextReferenceExtractor> EXTRACTORS = CacheBuilder.newBuilder()
             .weakKeys().build(new CacheLoader<Class<?>, ContextReferenceExtractor>() {
 
@@ -40,6 +39,41 @@ abstract class ContextReferenceExtractor {
                 public ContextReferenceExtractor load(final Class<?> key) throws Exception {
                     return create(key);
                 }
+
+                @Nonnull
+                private ContextReferenceExtractor create(final Class<?> key) {
+                    final Method contextGetter = getContextGetter(key);
+                    if (contextGetter == null) {
+                        return NULL_EXTRACTOR;
+                    }
+                    final Class<?> returnType = contextGetter.getReturnType();
+                    try {
+                        if (InstanceIdentifier.class.isAssignableFrom(returnType)) {
+                            return DirectGetterRouteContextExtractor.create(contextGetter);
+                        }
+                        final Method getValueMethod = findGetValueMethod(returnType, InstanceIdentifier.class);
+                        if (getValueMethod != null) {
+                            return GetValueRouteContextExtractor.create(contextGetter, getValueMethod);
+                        } else {
+                            LOG.warn("Class {} can not be used to determine context, falling back to NULL_EXTRACTOR.",
+                                    returnType);
+                        }
+                    } catch (final IllegalAccessException e) {
+                        LOG.warn(
+                                "Class {} does not conform to Binding Specification v1. Falling back to NULL_EXTRACTOR",
+                                e);
+                    }
+                    return NULL_EXTRACTOR;
+                }
+
+                private Method getContextGetter(final Class<?> key) {
+                    for (final Method method : key.getMethods()) {
+                        if (method.getAnnotation(RoutingContext.class) != null) {
+                            return method;
+                        }
+                    }
+                    return null;
+                }
             });
 
 
@@ -54,41 +88,19 @@ abstract class ContextReferenceExtractor {
      * Binding DataObject.
      *
      * @param obj DataObject from which context reference
-     * should be extracted.
+     *     should be extracted.
      *
      * @return Instance Identifier representing context reference
-     * or null, if data object does not contain context reference.
+     *     or null, if data object does not contain context reference.
      */
-    abstract @Nullable InstanceIdentifier<?> extract(DataObject obj);
-
-    @Nonnull
-    private static ContextReferenceExtractor create(final Class<?> key) {
-        final Method contextGetter = getContextGetter(key);
-        if (contextGetter == null) {
-            return NULL_EXTRACTOR;
-        }
-        final Class<?> returnType = contextGetter.getReturnType();
-        try {
-            if (InstanceIdentifier.class.isAssignableFrom(returnType)) {
-                return DirectGetterRouteContextExtractor.create(contextGetter);
-            }
-            final Method getValueMethod = findGetValueMethod(returnType,InstanceIdentifier.class);
-            if (getValueMethod != null) {
-                return GetValueRouteContextExtractor.create(contextGetter, getValueMethod);
-            } else {
-                LOG.warn("Class {} can not be used to determine context, falling back to NULL_EXTRACTOR.",returnType);
-            }
-        } catch (final IllegalAccessException e) {
-            LOG.warn("Class {} does not conform to Binding Specification v1. Falling back to NULL_EXTRACTOR", e);
-        }
-        return NULL_EXTRACTOR;
-    }
+    @Nullable
+    abstract InstanceIdentifier<?> extract(DataObject obj);
 
     @Nullable
     private static Method findGetValueMethod(final Class<?> type, final Class<?> returnType) {
         try {
             final Method method = type.getMethod(GET_VALUE_NAME);
-            if(returnType.equals(method.getReturnType())) {
+            if (returnType.equals(method.getReturnType())) {
                 return method;
             }
         } catch (final NoSuchMethodException e) {
@@ -96,16 +108,4 @@ abstract class ContextReferenceExtractor {
         }
         return null;
     }
-
-    private static Method getContextGetter(final Class<?> key) {
-        for (final Method method : key.getMethods()) {
-            if (method.getAnnotation(RoutingContext.class) != null) {
-                return method;
-            }
-        }
-        return null;
-    }
-
-
-
 }