Changeset 15640 in josm for trunk/src/org
- Timestamp:
- 2020-01-05T21:09:21+01:00 (5 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/Test.java
r15463 r15640 115 115 public TagTest(String name) { 116 116 super(name); 117 } 118 119 @Override 120 public boolean isPrimitiveUsable(OsmPrimitive p) { 121 return super.isPrimitiveUsable(p) && p.isTagged(); 117 122 } 118 123 -
trunk/src/org/openstreetmap/josm/data/validation/TestError.java
r14913 r15640 85 85 * Sets the error message. 86 86 * 87 * @param message The themessage of this error group87 * @param message The message of this error group 88 88 * @param description The translated description of this error 89 89 * @param descriptionEn The English description (for ignoring errors) -
trunk/src/org/openstreetmap/josm/data/validation/tests/ConditionalKeys.java
r15347 r15640 249 249 @Override 250 250 public void check(OsmPrimitive p) { 251 if (p.isTagged()) { 252 errors.addAll(validatePrimitive(p)); 253 } 251 errors.addAll(validatePrimitive(p)); 254 252 } 255 253 } -
trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java
r15588 r15640 786 786 addIfNotSimilar(e, errors); 787 787 } 788 if (partialSelection && p.isTagged()) {788 if (partialSelection) { 789 789 tested.add(p); 790 790 } -
trunk/src/org/openstreetmap/josm/data/validation/tests/OpeningHourTest.java
r15328 r15640 18 18 import org.openstreetmap.josm.data.osm.OsmPrimitive; 19 19 import org.openstreetmap.josm.data.validation.Severity; 20 import org.openstreetmap.josm.data.validation.Test ;20 import org.openstreetmap.josm.data.validation.Test.TagTest; 21 21 import org.openstreetmap.josm.data.validation.TestError; 22 22 import org.openstreetmap.josm.gui.Notification; … … 34 34 * @since 6370 35 35 */ 36 public class OpeningHourTest extends T est.TagTest {36 public class OpeningHourTest extends TagTest { 37 37 38 38 /** … … 328 328 @Override 329 329 public void check(final OsmPrimitive p) { 330 if (p.isTagged()) { 331 check(p, "opening_hours"); 332 check(p, "collection_times"); 333 check(p, "service_times"); 334 } 330 check(p, "opening_hours"); 331 check(p, "collection_times"); 332 check(p, "service_times"); 335 333 } 336 334 } -
trunk/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java
r15614 r15640 14 14 import java.util.Collection; 15 15 import java.util.Collections; 16 import java.util.EnumSet; 16 17 import java.util.HashMap; 17 18 import java.util.HashSet; … … 44 45 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItem; 45 46 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetListener; 47 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetType; 46 48 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets; 47 49 import org.openstreetmap.josm.gui.tagging.presets.items.Check; … … 106 108 */ 107 109 public static final String PREF_CHECK_FIXMES = PREFIX + ".checkFixmes"; 110 /** 111 * The preference key to check presets 112 */ 113 public static final String PREF_CHECK_PRESETS_TYPES = PREFIX + ".checkPresetsTypes"; 108 114 109 115 /** … … 130 136 */ 131 137 public static final String PREF_CHECK_FIXMES_BEFORE_UPLOAD = PREF_CHECK_FIXMES + BEFORE_UPLOAD; 138 /** 139 * The preference key to search for presets - used before upload 140 */ 141 public static final String PREF_CHECK_PRESETS_TYPES_BEFORE_UPLOAD = PREF_CHECK_PRESETS_TYPES + BEFORE_UPLOAD; 132 142 133 143 private static final int MAX_LEVENSHTEIN_DISTANCE = 2; … … 138 148 protected boolean checkComplex; 139 149 protected boolean checkFixmes; 150 protected boolean checkPresetsTypes; 140 151 141 152 protected JCheckBox prefCheckKeys; … … 143 154 protected JCheckBox prefCheckComplex; 144 155 protected JCheckBox prefCheckFixmes; 145 protected JCheckBox prefCheckP aint;156 protected JCheckBox prefCheckPresetsTypes; 146 157 147 158 protected JCheckBox prefCheckKeysBeforeUpload; … … 149 160 protected JCheckBox prefCheckComplexBeforeUpload; 150 161 protected JCheckBox prefCheckFixmesBeforeUpload; 151 protected JCheckBox prefCheckP aintBeforeUpload;162 protected JCheckBox prefCheckPresetsTypesBeforeUpload; 152 163 153 164 // CHECKSTYLE.OFF: SingleSpaceSeparator … … 168 179 protected static final int MISSPELLED_VALUE_NO_FIX = 1215; 169 180 protected static final int UNUSUAL_UNICODE_CHAR_VALUE = 1216; 181 protected static final int INVALID_PRESETS_TYPE = 1217; 170 182 // CHECKSTYLE.ON: SingleSpaceSeparator 171 183 … … 578 590 @Override 579 591 public void check(OsmPrimitive p) { 580 if (!p.isTagged())581 return;582 583 592 // Just a collection to know if a primitive has been already marked with error 584 593 MultiMap<OsmPrimitive, String> withErrors = new MultiMap<>(); … … 602 611 .build()); 603 612 withErrors.put(p, "FIXME"); 613 } 614 } 615 616 if (checkPresetsTypes) { 617 for (TaggingPreset tp : TaggingPresets.getMatchingPresets(null, p.getKeys(), false)) { 618 TaggingPresetType presetType = TaggingPresetType.forPrimitive(p); 619 if (!tp.typeMatches(EnumSet.of(presetType))) { 620 errors.add(TestError.builder(this, Severity.OTHER, INVALID_PRESETS_TYPE) 621 .message(tr("Wrong presets types"), 622 marktr("{0} is not supported by tagging preset: {1}"), tr(presetType.getName()), tp.getLocaleName()) 623 .primitives(p) 624 .build()); 625 } 604 626 } 605 627 } … … 881 903 checkFixmes = checkFixmes && Config.getPref().getBoolean(PREF_CHECK_FIXMES_BEFORE_UPLOAD, true); 882 904 } 905 906 checkPresetsTypes = Config.getPref().getBoolean(PREF_CHECK_PRESETS_TYPES, true); 907 if (isBeforeUpload) { 908 checkPresetsTypes = checkPresetsTypes && Config.getPref().getBoolean(PREF_CHECK_PRESETS_TYPES_BEFORE_UPLOAD, true); 909 } 883 910 } 884 911 885 912 @Override 886 913 public void visit(Collection<OsmPrimitive> selection) { 887 if (checkKeys || checkValues || checkComplex || checkFixmes ) {914 if (checkKeys || checkValues || checkComplex || checkFixmes || checkPresetsTypes) { 888 915 super.visit(selection); 889 916 } … … 942 969 prefCheckFixmesBeforeUpload.setSelected(Config.getPref().getBoolean(PREF_CHECK_FIXMES_BEFORE_UPLOAD, true)); 943 970 testPanel.add(prefCheckFixmesBeforeUpload, a); 971 972 prefCheckPresetsTypes = new JCheckBox(tr("Check for presets types."), Config.getPref().getBoolean(PREF_CHECK_PRESETS_TYPES, true)); 973 prefCheckPresetsTypes.setToolTipText(tr("Validate that objects types are valid checking against presets.")); 974 testPanel.add(prefCheckPresetsTypes, GBC.std().insets(20, 0, 0, 0)); 975 976 prefCheckPresetsTypesBeforeUpload = new JCheckBox(); 977 prefCheckPresetsTypesBeforeUpload.setSelected(Config.getPref().getBoolean(PREF_CHECK_PRESETS_TYPES_BEFORE_UPLOAD, true)); 978 testPanel.add(prefCheckPresetsTypesBeforeUpload, a); 944 979 } 945 980 … … 963 998 Config.getPref().putBoolean(PREF_CHECK_KEYS, prefCheckKeys.isSelected()); 964 999 Config.getPref().putBoolean(PREF_CHECK_FIXMES, prefCheckFixmes.isSelected()); 1000 Config.getPref().putBoolean(PREF_CHECK_PRESETS_TYPES, prefCheckPresetsTypes.isSelected()); 965 1001 Config.getPref().putBoolean(PREF_CHECK_VALUES_BEFORE_UPLOAD, prefCheckValuesBeforeUpload.isSelected()); 966 1002 Config.getPref().putBoolean(PREF_CHECK_COMPLEX_BEFORE_UPLOAD, prefCheckComplexBeforeUpload.isSelected()); 967 1003 Config.getPref().putBoolean(PREF_CHECK_KEYS_BEFORE_UPLOAD, prefCheckKeysBeforeUpload.isSelected()); 968 1004 Config.getPref().putBoolean(PREF_CHECK_FIXMES_BEFORE_UPLOAD, prefCheckFixmesBeforeUpload.isSelected()); 1005 Config.getPref().putBoolean(PREF_CHECK_PRESETS_TYPES_BEFORE_UPLOAD, prefCheckPresetsTypesBeforeUpload.isSelected()); 969 1006 return Config.getPref().putList(PREF_SOURCES, sourcesList.getItems()); 970 1007 } -
trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java
r15029 r15640 23 23 import java.util.concurrent.CompletableFuture; 24 24 import java.util.function.Predicate; 25 import java.util.stream.Collectors; 25 26 26 27 import javax.swing.AbstractAction; … … 525 526 public Collection<OsmPrimitive> createSelection(Collection<OsmPrimitive> participants) { 526 527 originalSelectionEmpty = participants.isEmpty(); 527 Collection<OsmPrimitive> sel = new LinkedList<>(); 528 for (OsmPrimitive osm : participants) { 529 if (typeMatches(EnumSet.of(TaggingPresetType.forPrimitive(osm)))) { 530 sel.add(osm); 531 } 532 } 533 return sel; 528 return participants.stream().filter(this::typeMatches).collect(Collectors.toList()); 534 529 } 535 530 … … 540 535 public List<Tag> getChangedTags() { 541 536 List<Tag> result = new ArrayList<>(); 542 for (TaggingPresetItem i: data) { 543 i.addCommands(result); 544 } 537 data.forEach(i -> i.addCommands(result)); 545 538 return result; 546 539 } … … 585 578 public String toString() { 586 579 return (types == null ? "" : types.toString()) + ' ' + name; 580 } 581 582 /** 583 * Determines whether this preset matches the OSM primitive type. 584 * @param primitive The OSM primitive for which type must match 585 * @return <code>true</code> if type matches. 586 * @since 15640 587 */ 588 public final boolean typeMatches(IPrimitive primitive) { 589 return typeMatches(EnumSet.of(TaggingPresetType.forPrimitive(primitive))); 587 590 } 588 591
Note:
See TracChangeset
for help on using the changeset viewer.