]> source.dussan.org Git - vaadin-framework.git/commitdiff
Don't use synthetic methods for listener classes. (#10135)
authorAhmed Ashour <asashour@yahoo.com>
Wed, 4 Oct 2017 10:48:21 +0000 (12:48 +0200)
committerHenri Sara <henri.sara@gmail.com>
Wed, 4 Oct 2017 10:48:21 +0000 (13:48 +0300)
Fixes #9504

server/src/main/java/com/vaadin/data/Binder.java
server/src/main/java/com/vaadin/ui/components/grid/EditorImpl.java
server/src/main/java/com/vaadin/ui/components/grid/GridDragEndListener.java
server/src/main/java/com/vaadin/ui/components/grid/GridDragStartListener.java
server/src/main/java/com/vaadin/ui/components/grid/GridDropListener.java
server/src/main/java/com/vaadin/ui/components/grid/TreeGridDropListener.java
server/src/main/java/com/vaadin/ui/dnd/event/DragEndListener.java
server/src/main/java/com/vaadin/ui/dnd/event/DragStartListener.java
server/src/main/java/com/vaadin/ui/dnd/event/DropListener.java
server/src/main/java/com/vaadin/util/ReflectTools.java

index 7a2ed319c9bd088aa3d38d7457db172e360199ab..7f63cb3841d6175def6f0e8de7128501a11d9092 100644 (file)
@@ -1902,7 +1902,7 @@ public class Binder<BEAN> implements Serializable {
      */
     public Registration addStatusChangeListener(StatusChangeListener listener) {
         return getEventRouter().addListener(StatusChangeEvent.class, listener,
-                StatusChangeListener.class.getDeclaredMethods()[0]);
+                ReflectTools.getMethod(StatusChangeListener.class));
     }
 
     /**
@@ -1925,7 +1925,7 @@ public class Binder<BEAN> implements Serializable {
     public Registration addValueChangeListener(
             ValueChangeListener<?> listener) {
         return getEventRouter().addListener(ValueChangeEvent.class, listener,
-                ValueChangeListener.class.getDeclaredMethods()[0]);
+                ReflectTools.getMethod(ValueChangeListener.class));
     }
 
     /**
index 502f530d9acfdb3392dc2fdb164b85b3d053a1a8..4d5e91b67137a8ef7239ae42dcf0ddbb6297b362 100644 (file)
@@ -37,6 +37,7 @@ import com.vaadin.ui.Component;
 import com.vaadin.ui.Grid;
 import com.vaadin.ui.Grid.AbstractGridExtension;
 import com.vaadin.ui.Grid.Column;
+import com.vaadin.util.ReflectTools;
 
 import elemental.json.JsonObject;
 
@@ -338,19 +339,19 @@ public class EditorImpl<T> extends AbstractGridExtension<T>
     @Override
     public Registration addSaveListener(EditorSaveListener<T> listener) {
         return eventRouter.addListener(EditorSaveEvent.class, listener,
-                EditorSaveListener.class.getDeclaredMethods()[0]);
+                ReflectTools.getMethod(EditorSaveListener.class));
     }
 
     @Override
     public Registration addCancelListener(EditorCancelListener<T> listener) {
         return eventRouter.addListener(EditorCancelEvent.class, listener,
-                EditorCancelListener.class.getDeclaredMethods()[0]);
+                ReflectTools.getMethod(EditorCancelListener.class));
     }
 
     @Override
     public Registration addOpenListener(EditorOpenListener<T> listener) {
         return eventRouter.addListener(EditorOpenEvent.class, listener,
-                EditorOpenListener.class.getDeclaredMethods()[0]);
+                ReflectTools.getMethod(EditorOpenListener.class));
     }
 
     @Override
index d41a58bbb6cbbd3a9c8cb9d7310799fa17ad6652..4d2abf47e2de4ad08c360d4dbc64d457ed667895 100644 (file)
@@ -18,6 +18,7 @@ package com.vaadin.ui.components.grid;
 import java.lang.reflect.Method;
 
 import com.vaadin.event.ConnectorEventListener;
+import com.vaadin.util.ReflectTools;
 
 /**
  * Drop listener for HTML5 drop on a Grid row.
@@ -31,8 +32,8 @@ import com.vaadin.event.ConnectorEventListener;
 @FunctionalInterface
 public interface GridDragEndListener<T> extends ConnectorEventListener {
 
-    static final Method DRAG_END_METHOD = GridDragEndListener.class
-            .getDeclaredMethods()[0];
+    static final Method DRAG_END_METHOD = ReflectTools
+            .getMethod(GridDragEndListener.class);
 
     /**
      * Invoked when the user has dropped the dragged grid rows, or canceled the
index 10f57e85c1e9aade0fe1b86afab9f5f0fe3eda14..97acc34fcfa6aaa06d788caea70c2858e1652538 100644 (file)
@@ -18,6 +18,7 @@ package com.vaadin.ui.components.grid;
 import java.lang.reflect.Method;
 
 import com.vaadin.event.ConnectorEventListener;
+import com.vaadin.util.ReflectTools;
 
 /**
  * Drag start listener for HTML5 drag start on a Grid row.
@@ -31,8 +32,8 @@ import com.vaadin.event.ConnectorEventListener;
 @FunctionalInterface
 public interface GridDragStartListener<T> extends ConnectorEventListener {
 
-    static final Method DRAG_START_METHOD = GridDragStartListener.class
-            .getDeclaredMethods()[0];
+    static final Method DRAG_START_METHOD = ReflectTools
+            .getMethod(GridDragStartListener.class);
 
     /**
      * Invoked when the user has started dragging grid's rows.
index efac802ae79100b9f58bb4e3fa38b3cd4ad09540..2cf6ed06dd6b871deb114d2cba18b116469fd1e8 100644 (file)
@@ -18,6 +18,7 @@ package com.vaadin.ui.components.grid;
 import java.lang.reflect.Method;
 
 import com.vaadin.event.ConnectorEventListener;
+import com.vaadin.util.ReflectTools;
 
 /**
  * Drop listener for HTML5 drop on a Grid row.
@@ -31,8 +32,8 @@ import com.vaadin.event.ConnectorEventListener;
 @FunctionalInterface
 public interface GridDropListener<T> extends ConnectorEventListener {
 
-    static final Method DROP_METHOD = GridDropListener.class
-            .getDeclaredMethods()[0];
+    static final Method DROP_METHOD = ReflectTools
+            .getMethod(GridDropListener.class);
 
     /**
      * Called when drop event is fired on a Grid row.
index d413a7b42b913ff4e78a6ee8b741c6982d63a977..5db82c624613d45f151b178fa15d87fbf12a5154 100644 (file)
@@ -18,6 +18,7 @@ package com.vaadin.ui.components.grid;
 import java.lang.reflect.Method;
 
 import com.vaadin.event.ConnectorEventListener;
+import com.vaadin.util.ReflectTools;
 
 /**
  * Drop listener for HTML5 drop on a TreeGrid row.
@@ -31,8 +32,8 @@ import com.vaadin.event.ConnectorEventListener;
 @FunctionalInterface
 public interface TreeGridDropListener<T> extends ConnectorEventListener {
 
-    static final Method DROP_METHOD = TreeGridDropListener.class
-            .getDeclaredMethods()[0];
+    static final Method DROP_METHOD = ReflectTools
+            .getMethod(TreeGridDropListener.class);
 
     /**
      * Called when drop event is fired on a Grid row.
index b8ab67279e98c8ff44908042473943c8bcf9ff23..65c02ddc63c8f4eae65ab4000ea3653f2246030a 100644 (file)
@@ -20,28 +20,29 @@ import java.lang.reflect.Method;
 import com.vaadin.event.ConnectorEventListener;
 import com.vaadin.ui.AbstractComponent;
 import com.vaadin.ui.dnd.DragSourceExtension;
+import com.vaadin.util.ReflectTools;
 
 /**
- * Interface to be implemented when creating a dragend listener on a drag
- * source for HTML5 drag and drop.
+ * Interface to be implemented when creating a dragend listener on a drag source
+ * for HTML5 drag and drop.
  *
  * @param <T>
- *         Type of draggable component.
+ *            Type of draggable component.
  * @author Vaadin Ltd
  * @see DragSourceExtension#addDragEndListener(DragEndListener)
  * @since 8.1
  */
 @FunctionalInterface
-public interface DragEndListener<T extends AbstractComponent> extends
-        ConnectorEventListener {
-    static final Method DRAGEND_METHOD = DragEndListener.class
-            .getDeclaredMethods()[0];
+public interface DragEndListener<T extends AbstractComponent>
+        extends ConnectorEventListener {
+    static final Method DRAGEND_METHOD = ReflectTools
+            .getMethod(DragEndListener.class);
 
     /**
      * Called when dragend event is fired.
      *
      * @param event
-     *         Server side dragend event.
+     *            Server side dragend event.
      */
     void dragEnd(DragEndEvent<T> event);
 }
index 42c702f7dba815e7766916cc9fad8041ac7d7dde..db44c91637fd7d0d3981640758ffc5774dbe2872 100644 (file)
@@ -20,28 +20,29 @@ import java.lang.reflect.Method;
 import com.vaadin.event.ConnectorEventListener;
 import com.vaadin.ui.AbstractComponent;
 import com.vaadin.ui.dnd.DragSourceExtension;
+import com.vaadin.util.ReflectTools;
 
 /**
  * Interface to be implemented when creating a dragstart listener on a drag
  * source for HTML5 drag and drop.
  *
  * @param <T>
- *         Type of draggable component.
+ *            Type of draggable component.
  * @author Vaadin Ltd
  * @see DragSourceExtension#addDragStartListener(DragStartListener)
  * @since 8.1
  */
 @FunctionalInterface
-public interface DragStartListener<T extends AbstractComponent> extends
-        ConnectorEventListener {
-    static final Method DRAGSTART_METHOD = DragStartListener.class
-            .getDeclaredMethods()[0];
+public interface DragStartListener<T extends AbstractComponent>
+        extends ConnectorEventListener {
+    static final Method DRAGSTART_METHOD = ReflectTools
+            .getMethod(DragStartListener.class);
 
     /**
      * Called when dragstart event is fired.
      *
      * @param event
-     *         Server side dragstart event.
+     *            Server side dragstart event.
      */
     void dragStart(DragStartEvent<T> event);
 }
index 5f3167646895b91b8c006ba106f8b0724943a547..538c9a65802f04d4a76d3aee6c49704e96fd0765 100644 (file)
@@ -20,28 +20,29 @@ import java.lang.reflect.Method;
 import com.vaadin.event.ConnectorEventListener;
 import com.vaadin.ui.AbstractComponent;
 import com.vaadin.ui.dnd.DropTargetExtension;
+import com.vaadin.util.ReflectTools;
 
 /**
  * Interface to be implemented when creating a drop listener on a drop target
  * for HTML5 drag and drop.
  *
  * @param <T>
- *         Type of the drop target component.
+ *            Type of the drop target component.
  * @author Vaadin Ltd
  * @see DropTargetExtension#addDropListener(DropListener)
  * @since 8.1
  */
 @FunctionalInterface
-public interface DropListener<T extends AbstractComponent> extends
-        ConnectorEventListener {
-    static final Method DROP_METHOD = DropListener.class
-            .getDeclaredMethods()[0];
+public interface DropListener<T extends AbstractComponent>
+        extends ConnectorEventListener {
+    static final Method DROP_METHOD = ReflectTools
+            .getMethod(DropListener.class);
 
     /**
      * Called when drop event is fired.
      *
      * @param event
-     *         Server side drop event.
+     *            Server side drop event.
      */
     void drop(DropEvent<T> event);
 }
index daeb2384b8a4f3a238d27a3337e17b7f2caea727..b38a23b46eef8d502ce41ef4ff676c950a960890 100644 (file)
@@ -82,9 +82,9 @@ public class ReflectTools implements Serializable {
      * @throws IllegalArgumentException
      *             If the value could not be retrieved
      */
-    public static Object getJavaFieldValue(Object object,
-            Field field) throws IllegalArgumentException,
-            IllegalAccessException, InvocationTargetException {
+    public static Object getJavaFieldValue(Object object, Field field)
+            throws IllegalArgumentException, IllegalAccessException,
+            InvocationTargetException {
         PropertyDescriptor pd;
         try {
             pd = new PropertyDescriptor(field.getName(), object.getClass());
@@ -126,10 +126,9 @@ public class ReflectTools implements Serializable {
      * @throws IllegalArgumentException
      *             If the value could not be retrieved
      */
-    public static Object getJavaFieldValue(Object object,
-            Field field, Class<?> propertyType)
-            throws IllegalArgumentException, IllegalAccessException,
-            InvocationTargetException {
+    public static Object getJavaFieldValue(Object object, Field field,
+            Class<?> propertyType) throws IllegalArgumentException,
+            IllegalAccessException, InvocationTargetException {
         PropertyDescriptor pd;
         try {
             pd = new PropertyDescriptor(field.getName(), object.getClass());
@@ -173,10 +172,9 @@ public class ReflectTools implements Serializable {
      * @throws InvocationTargetException
      *             If the value could not be assigned to the field
      */
-    public static void setJavaFieldValue(Object object,
-            Field field, Object value)
-            throws IllegalAccessException, IllegalArgumentException,
-            InvocationTargetException {
+    public static void setJavaFieldValue(Object object, Field field,
+            Object value) throws IllegalAccessException,
+            IllegalArgumentException, InvocationTargetException {
         PropertyDescriptor pd;
         try {
             pd = new PropertyDescriptor(field.getName(), object.getClass());
@@ -322,4 +320,28 @@ public class ReflectTools implements Serializable {
         }
     }
 
+    /**
+     * Returns the first non-synthetic method of the specified
+     * {@code listenerClass}, which must have single method in the source-code.
+     * 
+     * This is needed, to remove the synthetic methods added if the class is
+     * instrumented.
+     * 
+     * @param listenerClass
+     *            The {@link Class} of the listener, which has a single method
+     *            in the source code
+     * @return the first non-synthetic method
+     * @throws IllegalStateException
+     *             if the specified class does not have found method
+     * @since
+     */
+    public static Method getMethod(Class<?> listenerClass) {
+        for (Method m : listenerClass.getDeclaredMethods()) {
+            if (!m.isSynthetic()) {
+                return m;
+            }
+        }
+        throw new IllegalStateException("Class " + listenerClass.getName()
+                + " does not have a method.");
+    }
 }