Changeset 19597 in josm for trunk


Ignore:
Timestamp:
2026-07-23T18:26:32+02:00 (37 hours ago)
Author:
stoecker
Message:

fix #24693 - Allow values_from in presets to use plugin classes - patch by Zverikk

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/autofilter/AutoFilterRule.java

    r19592 r19597  
    8383    /**
    8484     * Returns true if there should be a filter button for OSM primitives which have no value for the key.
    85      * @since xxx
     85     * @since 19592
    8686     */
    8787    public boolean getNoValueFilter() {
     
    9393     * @param value the numeric value to format
    9494     * @return the formatted value
    95      * @since xxx
     95     * @since 19592
    9696     */
    9797    public String formatValue(Integer value) {
     
    147147     * @return {@code this}
    148148     * @throws NullPointerException if {@code extraKeys} is null
    149      * @since xxx
     149     * @since 19592
    150150     */
    151151    public AutoFilterRule setExtraKeys(List<String> extraKeys) {
     
    161161     * @param directValuesOnly whether "inner" values from ranges (such as 6 and 7 for 5-8) should be omitted
    162162     * @return a stream of numeric values
    163      * @since xxx
     163     * @since 19592
    164164     */
    165165    public IntStream getTagValuesForPrimitive(OsmPrimitive osm, boolean directValuesOnly) {
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/ComboMultiSelect.java

    r19519 r19597  
    3131import org.openstreetmap.josm.tools.GBC;
    3232import org.openstreetmap.josm.tools.Logging;
     33import org.openstreetmap.josm.tools.ReflectionUtils;
    3334
    3435/**
     
    232233        if (classMethod.length == 2) {
    233234            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]);
    235242                // Check method is public static String[] methodName()
    236243                int mod = method.getModifiers();
    237244                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                    }
    243258                }
    244259            } catch (ReflectiveOperationException e) {
  • trunk/src/org/openstreetmap/josm/tools/ReflectionUtils.java

    r18871 r19597  
    6161    }
    6262
     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     * @since 19597
     68     */
     69    public static Class<?> findClass(String name) {
     70        try {
     71            return Class.forName(name);
     72        } catch (ClassNotFoundException e) {
     73            Logging.trace(e);
     74            for (ClassLoader cl : PluginHandler.getPluginClassLoaders()) {
     75                try {
     76                    return Class.forName(name, true, cl);
     77                } catch (ClassNotFoundException ex) {
     78                    Logging.trace(e);
     79                }
     80            }
     81            return null;
     82        }
     83    }
     84
    6385    private static <T> T findCaller(Function<StackTraceElement, T> getter, Collection<T> exclusions) {
    6486        StackTraceElement[] stack = Thread.currentThread().getStackTrace();
Note: See TracChangeset for help on using the changeset viewer.