Ticket #24693: presetValuesForExtended.patch
| File presetValuesForExtended.patch, 4.3 KB (added by , 3 days ago) |
|---|
-
src/org/openstreetmap/josm/gui/tagging/presets/items/ComboMultiSelect.java
30 30 import org.openstreetmap.josm.tools.AlphanumComparator; 31 31 import org.openstreetmap.josm.tools.GBC; 32 32 import org.openstreetmap.josm.tools.Logging; 33 import org.openstreetmap.josm.tools.ReflectionUtils; 33 34 34 35 /** 35 36 * Abstract superclass for combo box and multi-select list types. … … 231 232 String[] classMethod = valuesFrom.split("#", -1); 232 233 if (classMethod.length == 2) { 233 234 try { 234 Method method = Class.forName(classMethod[0]).getMethod(classMethod[1]); 235 Class<?> cl = ReflectionUtils.findClass(classMethod[0]); 236 if (cl == null) { 237 Logging.error(tr("Broken tagging preset \"{0}-{1}\" - Java class {2} given in ''values_from'' was not found", 238 key, text, classMethod[0])); 239 return null; 240 } 241 Method method = cl.getMethod(classMethod[1]); 235 242 // Check method is public static String[] methodName() 236 243 int mod = method.getModifiers(); 237 244 if (Modifier.isPublic(mod) && Modifier.isStatic(mod) 238 && method.getReturnType().equals(String[].class) && method.getParameterTypes().length == 0) { 239 return Arrays.asList((String[]) method.invoke(null)); 240 } else { 241 Logging.error(tr("Broken tagging preset \"{0}-{1}\" - Java method given in ''values_from'' is not \"{2}\"", key, text, 242 "public static String[] methodName()")); 245 && method.getReturnType().equals(String[].class)) { 246 if (method.getParameterTypes().length == 0) { 247 return Arrays.asList((String[]) method.invoke(null)); 248 } else if (method.getParameterTypes().length == 1 && method.getParameterTypes()[0].equals(String.class)) { 249 return Arrays.asList((String[]) method.invoke(key)); 250 } else if (method.getParameterTypes().length == 2 251 && method.getParameterTypes()[0].equals(String.class) 252 && method.getParameterTypes()[1].equals(String.class)) { 253 return Arrays.asList((String[]) method.invoke(key, originalValue)); 254 } else { 255 Logging.error(tr("Broken tagging preset \"{0}-{1}\" - Java method given in ''values_from'' is not \"{2}\"", key, text, 256 "public static String[] methodName()")); 257 } 243 258 } 244 259 } catch (ReflectiveOperationException e) { 245 260 Logging.error(tr("Broken tagging preset \"{0}-{1}\" - Java method given in ''values_from'' threw {2} ({3})", key, text, -
src/org/openstreetmap/josm/tools/ReflectionUtils.java
60 60 }, exclusions); 61 61 } 62 62 63 /** 64 * Find a class either in the default class loader or in plugins. 65 * @param name class name to search 66 * @return found class object, or null if it was not found 67 */ 68 public static Class<?> findClass(String name) { 69 try { 70 return Class.forName(name); 71 } catch (ClassNotFoundException e) { 72 Logging.trace(e); 73 for (ClassLoader cl : PluginHandler.getPluginClassLoaders()) { 74 try { 75 return Class.forName(name, true, cl); 76 } catch (ClassNotFoundException ex) { 77 Logging.trace(e); 78 } 79 } 80 return null; 81 } 82 } 83 63 84 private static <T> T findCaller(Function<StackTraceElement, T> getter, Collection<T> exclusions) { 64 85 StackTraceElement[] stack = Thread.currentThread().getStackTrace(); 65 86 for (int i = 3; i < stack.length; i++) {
