Ticket #14287: 14287-v2.patch
File 14287-v2.patch, 5.2 KB (added by , 6 years ago) |
---|
-
src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java
69 69 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource.MapCSSRuleIndex; 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;74 72 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.GeneralSelector; 75 73 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.OptimizedGeneralSelector; 76 74 import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.MapCSSParser; … … 99 97 */ 100 98 public class MapCSSTagChecker extends Test.TagTest { 101 99 IndexData indexData; 100 final Set<OsmPrimitive> tested = new HashSet<>(); 102 101 103 102 /** 104 103 * Helper class to store indexes of rules. … … 864 863 while (candidates.hasNext()) { 865 864 MapCSSRule r = candidates.next(); 866 865 env.clearSelectorMatchingInformation(); 867 if (partialSelection && r.selector instanceof Selector.ChildOrParentSelector) {868 ChildOrParentSelector sel = (Selector.ChildOrParentSelector) r.selector;869 boolean needEnclosing = sel.type == ChildOrParentSelectorType.SUBSET_OR_EQUAL870 || sel.type == ChildOrParentSelectorType.NOT_SUBSET_OR_EQUAL;871 if (needEnclosing && p.getDataSet() != null) {872 List<OsmPrimitive> toCheck = new ArrayList<>();873 toCheck.addAll(p.getDataSet().searchWays(p.getBBox()));874 toCheck.addAll(p.getDataSet().searchRelations(p.getBBox()));875 toCheck.removeIf(OsmPrimitive::isSelected);876 if (!toCheck.isEmpty()) {877 Set<Set<TagCheck>> checksCol = Collections.singleton(Collections.singleton(indexData.getCheck(r)));878 for (OsmPrimitive p2 : toCheck) {879 for (TestError e : getErrorsForPrimitive(p2, includeOtherSeverity, checksCol)) {880 if (e.getPrimitives().contains(p)) {881 addIfNotSimilar(e, res);882 }883 }884 }885 }886 }887 }888 866 if (r.selector.matches(env)) { // as side effect env.parent will be set (if s is a child selector) 889 867 TagCheck check = indexData.getCheck(r); 890 868 if (check != null) { … … 963 941 for (TestError e : getErrorsForPrimitive(p, ValidatorPrefHelper.PREF_OTHER.get())) { 964 942 addIfNotSimilar(e, errors); 965 943 } 944 if (partialSelection && p.isTagged()) { 945 tested.add(p); 946 } 966 947 } 967 948 968 949 /** … … 1145 1126 } 1146 1127 1147 1128 @Override 1148 public void startTest(ProgressMonitor progressMonitor) {1129 public synchronized void startTest(ProgressMonitor progressMonitor) { 1149 1130 super.startTest(progressMonitor); 1150 1131 super.setShowElements(true); 1151 1132 if (indexData == null) { 1152 indexData = new IndexData(checks, ValidatorPrefHelper.PREF_OTHER.get());1133 indexData = new IndexData(checks, includeOtherSeverityChecks()); 1153 1134 } 1135 tested.clear(); 1154 1136 } 1155 1137 1156 1138 @Override 1157 public void endTest() { 1139 public synchronized void endTest() { 1140 if (partialSelection && !tested.isEmpty()) { 1141 // see ticket 14287 1142 // execute tests for objects which might contain previously tested elements 1143 Set<OsmPrimitive> surrounding = new HashSet<>(); 1144 for (OsmPrimitive p : tested) { 1145 if (p.getDataSet() != null) { 1146 surrounding.addAll(p.getDataSet().searchWays(p.getBBox())); 1147 surrounding.addAll(p.getDataSet().searchRelations(p.getBBox())); 1148 } 1149 } 1150 1151 final boolean includeOtherSeverity = includeOtherSeverityChecks(); 1152 for (OsmPrimitive p : surrounding) { 1153 if (tested.contains(p) ) 1154 continue; 1155 if (p.isMultipolygon()) { 1156 long dd = 4; 1157 } 1158 Collection<TestError> additionalErrors = getErrorsForPrimitive(p, includeOtherSeverity); 1159 for (TestError e : additionalErrors) { 1160 if (e.getPrimitives().stream().anyMatch(tested::contains)) 1161 addIfNotSimilar(e, errors); 1162 } 1163 } 1164 tested.clear(); 1165 } 1158 1166 super.endTest(); 1159 1167 // no need to keep the index, it is quickly build and doubles the memory needs 1160 1168 indexData = null; 1161 1169 } 1162 1170 1171 private boolean includeOtherSeverityChecks() { 1172 return isBeforeUpload ? ValidatorPrefHelper.PREF_OTHER_UPLOAD.get() : ValidatorPrefHelper.PREF_OTHER.get(); 1173 } 1174 1163 1175 }