Changeset 17252 in josm for trunk/src/org


Ignore:
Timestamp:
2020-10-22T12:08:47+02:00 (3 years ago)
Author:
GerdP
Message:

fix #19956 Double check if error still exists before executing autofix

  • let ValidatorDialog do this so that different manual changes or autofixes don't disturb each other
Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/TestError.java

    r16553 r17252  
    1111import java.util.List;
    1212import java.util.Locale;
     13import java.util.Set;
    1314import java.util.TreeSet;
    1415import java.util.function.Supplier;
     
    2425import org.openstreetmap.josm.data.osm.Way;
    2526import org.openstreetmap.josm.data.osm.WaySegment;
     27import org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker;
    2628import org.openstreetmap.josm.data.validation.util.MultipleNameVisitor;
     29import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    2730import org.openstreetmap.josm.tools.AlphanumComparator;
    2831import org.openstreetmap.josm.tools.CheckParameterUtil;
    2932import org.openstreetmap.josm.tools.I18n;
     33import org.openstreetmap.josm.tools.Logging;
    3034
    3135/**
     
    545549    }
    546550
     551    /**
     552     * Test if the primitives still show the same error. Maybe data was already changed. See #19956
     553     * @return updated test or null if error cannot be reproduced.
     554     * @since 17252
     555     */
     556    public TestError doubleCheck() {
     557        // see #19956 check again
     558        if (getTester() instanceof MapCSSTagChecker)
     559            return this;
     560        Test tester2;
     561        try {
     562            tester2 = getTester().getClass().newInstance();
     563            Set<OsmPrimitive> toFix = primitives.stream()
     564                    .filter(tester2::isPrimitiveUsable)
     565                    .collect(Collectors.toSet());
     566            if (toFix.isEmpty())
     567                return null;
     568
     569            tester2.startTest(NullProgressMonitor.INSTANCE);
     570            tester2.visit(toFix);
     571            tester2.endTest();
     572            for (TestError e : tester2.getErrors()) {
     573                if (e.getCode() == this.getCode()) {
     574                    return e;
     575                }
     576            }
     577        } catch (InstantiationException | IllegalAccessException e1) {
     578            Logging.error(e1);
     579        }
     580        return null;
     581
     582    }
     583
    547584}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ValidatorDialog.java

    r17188 r17252  
    628628            if (error.isFixable()) {
    629629                if (error.getPrimitives().stream().noneMatch(p -> p.isDeleted() || p.getDataSet() == null)) {
    630                     final Command fixCommand = error.getFix();
    631                     if (fixCommand != null) {
    632                         SwingUtilities.invokeAndWait(fixCommand::executeCommand);
    633                         fixCommands.add(fixCommand);
     630                    TestError checked = error.doubleCheck();
     631                    if (checked != null) {
     632                        final Command fixCommand = checked.getFix();
     633                        if (fixCommand != null) {
     634                            SwingUtilities.invokeAndWait(fixCommand::executeCommand);
     635                            fixCommands.add(fixCommand);
     636                        }
    634637                    }
    635638                }
Note: See TracChangeset for help on using the changeset viewer.