Changeset 15064 in josm for trunk/src/org
- Timestamp:
- 2019-05-09T10:13:10+02:00 (6 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java
r15027 r15064 13 13 import java.text.MessageFormat; 14 14 import java.util.ArrayList; 15 import java.util.Arrays;16 15 import java.util.Collection; 17 16 import java.util.Collections; … … 40 39 import org.openstreetmap.josm.data.osm.DataSet; 41 40 import org.openstreetmap.josm.data.osm.INode; 41 import org.openstreetmap.josm.data.osm.IPrimitive; 42 42 import org.openstreetmap.josm.data.osm.IRelation; 43 43 import org.openstreetmap.josm.data.osm.IWay; … … 70 70 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector; 71 71 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.AbstractSelector; 72 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.ChildOrParentSelector; 73 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.ChildOrParentSelectorType; 72 74 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.GeneralSelector; 73 75 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.OptimizedGeneralSelector; … … 734 736 * @return an instance of {@link TestError}, or returns null if the primitive does not give rise to an error. 735 737 */ 736 TestError getErrorForPrimitive(OsmPrimitive p) {738 List<TestError> getErrorsForPrimitive(OsmPrimitive p) { 737 739 final Environment env = new Environment(p); 738 return getErrorForPrimitive(p, whichSelectorMatchesEnvironment(env), env, null); 739 } 740 741 TestError getErrorForPrimitive(OsmPrimitive p, Selector matchingSelector, Environment env, Test tester) { 740 return getErrorsForPrimitive(p, whichSelectorMatchesEnvironment(env), env, null); 741 } 742 743 private List<TestError> getErrorsForPrimitive(OsmPrimitive p, Selector matchingSelector, Environment env, Test tester) { 744 List<TestError> res = new ArrayList<>(); 742 745 if (matchingSelector != null && !errors.isEmpty()) { 743 746 final Command fix = fixPrimitive(p); … … 745 748 final String description1 = group == null ? description : group; 746 749 final String description2 = group == null ? null : description; 747 final List<OsmPrimitive> primitives; 750 TestError.Builder errorBuilder = TestError.builder(tester, getSeverity(), 3000) 751 .messageWithManuallyTranslatedDescription(description1, description2, matchingSelector.toString()); 752 if (fix != null) { 753 errorBuilder = errorBuilder.fix(() -> fix); 754 } 748 755 if (env.child instanceof OsmPrimitive) { 749 primitives = Arrays.asList(p, (OsmPrimitive) env.child); 756 res.add(errorBuilder.primitives(p, (OsmPrimitive) env.child).build()); 757 } else if (env.children != null) { 758 for (IPrimitive c : env.children) { 759 if (c instanceof OsmPrimitive) { 760 errorBuilder = TestError.builder(tester, getSeverity(), 3000) 761 .messageWithManuallyTranslatedDescription(description1, description2, 762 matchingSelector.toString()); 763 if (fix != null) { 764 errorBuilder = errorBuilder.fix(() -> fix); 765 } 766 res.add(errorBuilder.primitives(p, (OsmPrimitive) c).build()); 767 } 768 } 750 769 } else { 751 primitives = Collections.singletonList(p); 752 } 753 final TestError.Builder error = TestError.builder(tester, getSeverity(), 3000) 754 .messageWithManuallyTranslatedDescription(description1, description2, matchingSelector.toString()) 755 .primitives(primitives); 756 if (fix != null) { 757 return error.fix(() -> fix).build(); 758 } else { 759 return error.build(); 760 } 761 } else { 762 return null; 763 } 770 res.add(errorBuilder.primitives(p).build()); 771 } 772 } 773 return res; 764 774 } 765 775 … … 855 865 MapCSSRule r = candidates.next(); 856 866 env.clearSelectorMatchingInformation(); 867 if (partialSelection && r.selector instanceof Selector.ChildOrParentSelector) { 868 ChildOrParentSelector sel = (Selector.ChildOrParentSelector) r.selector; 869 if (sel.type == ChildOrParentSelectorType.ELEMENT_OF && p.getDataSet() != null) { 870 List<OsmPrimitive> toCheck = new ArrayList<>(); 871 toCheck.addAll(p.getDataSet().searchWays(p.getBBox())); 872 toCheck.addAll(p.getDataSet().searchRelations(p.getBBox())); 873 toCheck.removeIf(OsmPrimitive::isSelected); 874 if (!toCheck.isEmpty()) { 875 Set<Set<TagCheck>> checksCol = Collections.singleton(Collections.singleton(indexData.getCheck(r))); 876 for (OsmPrimitive p2 : toCheck) { 877 for (TestError e : getErrorsForPrimitive(p2, includeOtherSeverity, checksCol)) { 878 if (e.getPrimitives().contains(p)) { 879 addIfNotSimilar(e, res); 880 } 881 } 882 } 883 } 884 } 885 } 857 886 if (r.selector.matches(env)) { // as side effect env.parent will be set (if s is a child selector) 858 887 TagCheck check = indexData.getCheck(r); … … 864 893 r.declaration.execute(env); 865 894 if (!check.errors.isEmpty()) { 866 final TestError error = check.getErrorForPrimitive(p, r.selector, env, new MapCSSTagCheckerAndRule(check.rule)); 867 if (error != null) { 868 res.add(error); 895 for (TestError e: check.getErrorsForPrimitive(p, r.selector, env, new MapCSSTagCheckerAndRule(check.rule))) { 896 addIfNotSimilar(e, res); 869 897 } 870 898 } 871 872 899 } 873 900 } 874 901 } 875 902 return res; 903 } 904 905 /** 906 * See #12627 907 * Add error to given list if list doesn't already contain a similar error. 908 * Similar means same code and description and same combination of primitives and same combination of highlighted objects, 909 * but maybe with different orders. 910 * @param toAdd the error to add 911 * @param errors the list of errors 912 */ 913 private static void addIfNotSimilar(TestError toAdd, List<TestError> errors) { 914 boolean isDup = false; 915 if (toAdd.getPrimitives().size() >= 2) { 916 for (TestError e : errors) { 917 if (e.getCode() == toAdd.getCode() && e.getMessage().equals(toAdd.getMessage()) 918 && e.getPrimitives().size() == toAdd.getPrimitives().size() 919 && e.getPrimitives().containsAll(toAdd.getPrimitives()) 920 && e.getHighlighted().size() == toAdd.getHighlighted().size() 921 && e.getHighlighted().containsAll(toAdd.getHighlighted())) { 922 isDup = true; 923 break; 924 } 925 } 926 } 927 if (!isDup) 928 errors.add(toAdd); 876 929 } 877 930 … … 891 944 check.rule.declaration.execute(env); 892 945 if (!ignoreError && !check.errors.isEmpty()) { 893 final TestError error = check.getErrorForPrimitive(p, selector, env, new MapCSSTagCheckerAndRule(check.rule)); 894 if (error != null) { 895 r.add(error); 896 } 946 r.addAll(check.getErrorsForPrimitive(p, selector, env, new MapCSSTagCheckerAndRule(check.rule))); 897 947 } 898 948 } … … 909 959 @Override 910 960 public void check(OsmPrimitive p) { 911 errors.addAll(getErrorsForPrimitive(p, ValidatorPrefHelper.PREF_OTHER.get())); 961 for (TestError e : getErrorsForPrimitive(p, ValidatorPrefHelper.PREF_OTHER.get())) { 962 addIfNotSimilar(e, errors); 963 } 912 964 } 913 965 -
trunk/src/org/openstreetmap/josm/gui/mappaint/Environment.java
r14214 r15064 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.gui.mappaint; 3 4 import java.util.LinkedHashSet; 5 import java.util.Set; 3 6 4 7 import org.openstreetmap.josm.data.osm.IPrimitive; … … 59 62 */ 60 63 public Integer count; 64 65 /** 66 * Set of matched children filled by ContainsFinder and CrossingFinder, null if nothing matched 67 */ 68 public Set<IPrimitive> children; 61 69 62 70 /** … … 109 117 this.count = other.count; 110 118 this.context = other.getContext(); 119 this.children = other.children == null ? null : new LinkedHashSet<>(other.children); 111 120 } 112 121 … … 274 283 index = null; 275 284 count = null; 285 children = null; 276 286 } 277 287 -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java
r14654 r15064 7 7 import java.util.Collection; 8 8 import java.util.Collections; 9 import java.util.LinkedHashSet; 9 10 import java.util.List; 10 11 import java.util.NoSuchElementException; … … 258 259 return !e.osm.equals(p) && p.isUsable(); 259 260 } 261 262 protected void addToChildren(Environment e, IPrimitive p) { 263 if (e.children == null) { 264 e.children = new LinkedHashSet<>(); 265 } 266 e.children.add(p); 267 } 260 268 } 261 269 … … 299 307 @Override 300 308 public void visit(IWay<?> w) { 301 if ( e.child == null &&Objects.equals(layer, OsmUtils.getLayer(w))309 if (Objects.equals(layer, OsmUtils.getLayer(w)) 302 310 && left.matches(new Environment(w).withParent(e.osm)) 303 311 && e.osm instanceof IWay && Geometry.PolygonIntersection.CROSSING.equals( 304 312 Geometry.polygonIntersection(w.getNodes(), ((IWay<?>) e.osm).getNodes()))) { 305 e.child = w;313 addToChildren(e, w); 306 314 } 307 315 } … … 316 324 @Override 317 325 public void visit(INode n) { 318 if ( e.child == null &&left.matches(new Environment(n).withParent(e.osm))326 if (left.matches(new Environment(n).withParent(e.osm)) 319 327 && ((e.osm instanceof IWay && Geometry.nodeInsidePolygon(n, ((IWay<?>) e.osm).getNodes())) 320 328 || (e.osm instanceof Relation && ( 321 329 (Relation) e.osm).isMultipolygon() && Geometry.isNodeInsideMultiPolygon(n, (Relation) e.osm, null)))) { 322 e.child = n;330 addToChildren(e, n); 323 331 } 324 332 } … … 326 334 @Override 327 335 public void visit(IWay<?> w) { 328 if ( e.child == null &&left.matches(new Environment(w).withParent(e.osm))336 if (left.matches(new Environment(w).withParent(e.osm)) 329 337 && ((e.osm instanceof IWay && Geometry.PolygonIntersection.FIRST_INSIDE_SECOND.equals( 330 338 Geometry.polygonIntersection(w.getNodes(), ((IWay<?>) e.osm).getNodes()))) … … 332 340 (Relation) e.osm).isMultipolygon() 333 341 && Geometry.isPolygonInsideMultiPolygon(w.getNodes(), (Relation) e.osm, null)))) { 334 e.child = w;342 addToChildren(e, w); 335 343 } 336 344 } … … 388 396 } 389 397 390 return e.child != null;398 return e.children != null; 391 399 392 400 } else if (ChildOrParentSelectorType.CROSSING == type && e.osm instanceof IWay) { 393 401 e.parent = e.osm; 394 final CrossingFinder crossingFinder = new CrossingFinder(e);395 402 if (right instanceof OptimizedGeneralSelector 396 403 && ((OptimizedGeneralSelector) right).matchesBase(OsmPrimitiveType.WAY)) { 404 final CrossingFinder crossingFinder = new CrossingFinder(e); 397 405 crossingFinder.visit(e.osm.getDataSet().searchWays(e.osm.getBBox())); 398 406 } 399 return e.child != null;407 return e.children != null; 400 408 } else if (ChildOrParentSelectorType.SIBLING == type) { 401 409 if (e.osm instanceof INode) {
Note:
See TracChangeset
for help on using the changeset viewer.