Changeset 15132 in josm


Ignore:
Timestamp:
2019-05-28T19:53:19+02:00 (5 years ago)
Author:
GerdP
Message:

fix #17765: Move code for error "Area style way is not closed" to UnclosedWays
This simplifies the code. Method UnclosedWays.getCheckedKeys() is no longer needed
by any code in core or the plugins directory, but I did not dare to remove it.

Location:
trunk/src/org/openstreetmap/josm/data/validation/tests
Files:
2 edited

Legend:

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

    r15008 r15132  
    3030import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon;
    3131import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon.PolyData;
    32 import org.openstreetmap.josm.data.validation.OsmValidator;
    3332import org.openstreetmap.josm.data.validation.Severity;
    3433import org.openstreetmap.josm.data.validation.Test;
     
    3736import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
    3837import org.openstreetmap.josm.gui.mappaint.styleelement.AreaElement;
    39 import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    4038import org.openstreetmap.josm.tools.Geometry;
    4139import org.openstreetmap.josm.tools.Geometry.PolygonIntersection;
     
    6260    /** With the currently used mappaint style the style for inner way equals the multipolygon style */
    6361    public static final int INNER_STYLE_MISMATCH = 1608;
    64     /** Area style way is not closed */
    65     public static final int NOT_CLOSED = 1609;
     62    // no longer used: Area style way is not closed NOT_CLOSED = 1609
    6663    /** No area style for multipolygon */
    6764    public static final int NO_STYLE = 1610;
     
    8279    private static final int FOUND_OUTSIDE = 2;
    8380
    84     private final Set<String> keysCheckedByAnotherTest = new HashSet<>();
    85 
    8681    /**
    8782     * Constructs a new {@code MultipolygonTest}.
     
    9085        super(tr("Multipolygon"),
    9186                tr("This test checks if multipolygons are valid."));
    92     }
    93 
    94     @Override
    95     public void startTest(ProgressMonitor progressMonitor) {
    96         super.startTest(progressMonitor);
    97         keysCheckedByAnotherTest.clear();
    98         for (Test t : OsmValidator.getEnabledTests(false)) {
    99             if (t instanceof UnclosedWays) {
    100                 keysCheckedByAnotherTest.addAll(((UnclosedWays) t).getCheckedKeys());
    101                 break;
    102             }
    103         }
    104     }
    105 
    106     @Override
    107     public void endTest() {
    108         keysCheckedByAnotherTest.clear();
    109         super.endTest();
    110     }
    111 
    112     @Override
    113     public void visit(Way w) {
    114         if (!w.isArea() && ElemStyles.hasOnlyAreaElements(w)) {
    115             List<Node> nodes = w.getNodes();
    116             if (nodes.isEmpty()) return; // fix zero nodes bug
    117             for (String key : keysCheckedByAnotherTest) {
    118                 if (w.hasKey(key)) {
    119                     return;
    120                 }
    121             }
    122             errors.add(TestError.builder(this, Severity.WARNING, NOT_CLOSED)
    123                     .message(tr("Area style way is not closed"))
    124                     .primitives(w)
    125                     .highlight(Arrays.asList(nodes.get(0), nodes.get(nodes.size() - 1)))
    126                     .build());
    127         }
    12887    }
    12988
  • trunk/src/org/openstreetmap/josm/data/validation/tests/UnclosedWays.java

    r15093 r15132  
    88import java.util.Collections;
    99import java.util.HashSet;
     10import java.util.List;
    1011import java.util.Set;
    1112
     13import org.openstreetmap.josm.data.osm.Node;
    1214import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1315import org.openstreetmap.josm.data.osm.OsmUtils;
     
    1719import org.openstreetmap.josm.data.validation.Test;
    1820import org.openstreetmap.josm.data.validation.TestError;
     21import org.openstreetmap.josm.gui.mappaint.ElemStyles;
    1922
    2023/**
     
    156159        new UnclosedWaysBooleanCheck(1120, "building", marktr("building")),
    157160        new UnclosedWaysBooleanCheck(1130, "area",     marktr("area")),
     161        // 1131: Area style way is not closed
    158162        // CHECKSTYLE.ON: SingleSpaceSeparator
    159163    };
     
    190194            }
    191195        }
     196        // code 1131: other area style ways
     197        if (ElemStyles.hasOnlyAreaElements(w)) {
     198            List<Node> nodes = w.getNodes();
     199            if (nodes.isEmpty()) return; // fix zero nodes bug
     200            errors.add(TestError.builder(this, Severity.WARNING, 1131)
     201                    .message(tr("Unclosed way"), marktr("Area style way is not closed"), new Object())
     202                    .primitives(w)
     203                    .highlight(Arrays.asList(w.firstNode(), w.lastNode()))
     204                    .build());
     205        }
    192206    }
    193207}
Note: See TracChangeset for help on using the changeset viewer.