6 package com.google.appinventor.components.runtime.util;
12 import java.lang.reflect.InvocationTargetException;
13 import java.lang.reflect.Method;
31 if (!source.getClass().equals(target.getClass())) {
32 throw new IllegalArgumentException(
"Source and target classes must be identical");
35 final Class componentClass = source.getClass();
36 final Method[] componentMethods = componentClass.getMethods();
37 for (Method componentMethod : componentMethods) {
40 && componentMethod.getParameterTypes().length == 1) {
41 final Method propertySetterMethod = componentMethod;
43 final String propertyName = propertySetterMethod.getName();
46 final Method propertyCopierMethod =
47 getPropertyCopierMethod(
"Copy" + propertyName, componentClass);
48 if (propertyCopierMethod !=
null) {
49 propertyCopierMethod.invoke(target, source);
55 final Method propertyGetterMethod = componentClass.getMethod(propertyName);
56 final Class propertySetterParameterType = propertySetterMethod.getParameterTypes()[0];
59 if (propertyGetterMethod.isAnnotationPresent(
SimpleProperty.class) &&
60 propertySetterParameterType.isAssignableFrom(propertyGetterMethod.getReturnType())) {
61 final Object propertyValue = propertyGetterMethod.invoke(source);
62 propertySetterMethod.invoke(target, propertyValue);
64 }
catch (NoSuchMethodException e) {
67 }
catch (InvocationTargetException e2) {
76 private static Method getPropertyCopierMethod(String copierMethodName, Class componentClass) {
84 Method propertyCopierMethod = componentClass.getMethod(copierMethodName, componentClass);
86 return propertyCopierMethod;
88 }
catch (NoSuchMethodException e) {
91 componentClass = componentClass.getSuperclass();
92 }
while (componentClass !=
null);