Ticket #23290: 23290.patch
File 23290.patch, 72.8 KB (added by , 12 months ago) |
---|
-
resources/data/defaultpresets.xml
Subject: [PATCH] Fix #23290: Add support for regions attribute --- IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 diff --git a/resources/data/defaultpresets.xml b/resources/data/defaultpresets.xml
a b 1465 1465 <list_entry value="unmarked" icon="presets/vehicle/crossing_unmarked.svg" /> 1466 1466 <list_entry value="no" /> 1467 1467 </combo> 1468 <combo key="crossing_ref" text="Crossing type name (UK)" values="zebra,pelican,toucan,puffin,pegasus,tiger" />1468 <combo key="crossing_ref" text="Crossing type name (UK)" values="zebra,pelican,toucan,puffin,pegasus,tiger" regions="GB" /> 1469 1469 <combo key="kerb" text="Kerb" values="flush,lowered,no,raised,rolled,yes" values_context="kerb" /> 1470 1470 <combo key="supervised" text="Crossing attendant" delimiter="|" values="yes|no|06:00-20:00|Mo-Fr 09:00-18:00,Sa 08:00-14:00|May-Sep 09:30-12:30,14:15-19:30" values_i18n="false" values_sort="false" /> 1471 1471 <check key="crossing:island" text="With island" /> … … 1516 1516 <list_entry value="unmarked" icon="presets/vehicle/crossing_unmarked.svg" /> 1517 1517 </combo> 1518 1518 <reference ref="crossing_markings" /> 1519 <combo key="crossing_ref" text="Crossing type name (UK)" values="zebra,pelican,toucan,puffin,pegasus,tiger" values_searchable="true" />1519 <combo key="crossing_ref" text="Crossing type name (UK)" values="zebra,pelican,toucan,puffin,pegasus,tiger" values_searchable="true" regions="GB" /> 1520 1520 <combo key="kerb" text="Kerb" values="flush,lowered,no,raised,rolled,yes" values_context="kerb" /> 1521 1521 <combo key="supervised" text="Crossing attendant" delimiter="|" values="yes|no|06:00-20:00|Mo-Fr 09:00-18:00,Sa 08:00-14:00|May-Sep 09:30-12:30,14:15-19:30" values_i18n="false" values_sort="false" /> 1522 1522 <combo key="tactile_paving" text="Tactile Paving" values="yes,no,incorrect" /> … … 7264 7264 <list_entry value="war_memorial" short_description="A building, monument, statue or other edifice celebrating a victory or commemorating those who died or were injured in a war." /> 7265 7265 <list_entry value="sculpture" short_description="A non figurative sculpture which does not match any of the other categories." /> 7266 7266 <list_entry value="cross" short_description="A cross-shaped memorial." /> 7267 <list_entry value="blue_plaque" short_description="A blue plaque commemorating a historical link to that location. (UK)" />7267 <list_entry value="blue_plaque" short_description="A blue plaque commemorating a historical link to that location. (UK)" regions="GB" /> 7268 7268 <list_entry value="obelisk" short_description="An obelisk." /> 7269 7269 <list_entry value="ghost_bike" short_description="A bicycle painted white permanently placed as memorial for a victim of a road accident (usually cyclists)." /> 7270 <list_entry value="stolperstein" short_description="10cm × 10cm brass plaque commemorating victims of Nazi persecution. (EU,RU)" />7270 <list_entry value="stolperstein" short_description="10cm × 10cm brass plaque commemorating victims of Nazi persecution. (EU,RU)" regions="EU,RU" /> 7271 7271 <list_entry value="bench" short_description="A bench placed in memory of someone or something; usually has a plaque, and sometimes a statue sitting on (part of) it." /> 7272 7272 </combo> 7273 7273 <optional> … … 8217 8217 <check key="payment:girocard" text="Girocard" match="keyvalue" /> 8218 8218 <check key="payment:laser" text="Laser" match="keyvalue" /> 8219 8219 <check key="payment:maestro" text="Maestro" match="keyvalue" /> 8220 <check key="payment:postfinance_card" text="PostFinance Card (ch)" match="keyvalue" />8220 <check key="payment:postfinance_card" text="PostFinance Card (ch)" match="keyvalue" region="CH" /> 8221 8221 <check key="payment:visa_debit" text="Visa Debit" match="keyvalue" /> 8222 8222 <check key="payment:visa_electron" text="Visa Electron" match="keyvalue" /> 8223 8223 </checkgroup> … … 8236 8236 <space /> 8237 8237 <combo key="payment:electronic_purses" text="Electronic purses and Charge cards" values="yes,no" match="keyvalue" /> 8238 8238 <checkgroup columns="4"> 8239 <check key="payment:ep_avant" text="Avant (fi)" match="keyvalue" />8240 <check key="payment:ep_geldkarte" text="Geldkarte (de)" match="keyvalue" />8241 <check key="payment:ep_mep" text="Mep (pt)" match="keyvalue" />8242 <check key="payment:ep_minicash" text="Minicash (lu)" match="keyvalue" />8243 <check key="payment:ep_minipay" text="Minipay (it)" match="keyvalue" />8244 <check key="payment:ep_monedero4b" text="Mondero 4b (es)" match="keyvalue" />8239 <check key="payment:ep_avant" text="Avant (fi)" match="keyvalue" regions="FI" /> 8240 <check key="payment:ep_geldkarte" text="Geldkarte (de)" match="keyvalue" regions="DE" /> 8241 <check key="payment:ep_mep" text="Mep (pt)" match="keyvalue" regions="PT" /> 8242 <check key="payment:ep_minicash" text="Minicash (lu)" match="keyvalue" regions="LU" /> 8243 <check key="payment:ep_minipay" text="Minipay (it)" match="keyvalue" regions="IT" /> 8244 <check key="payment:ep_monedero4b" text="Mondero 4b (es)" match="keyvalue" regions="ES" /> 8245 8245 </checkgroup> 8246 8246 <space /> 8247 8247 <combo key="payment:cryptocurrencies" text="Cryptocurrencies" values="yes,no" match="keyvalue" /> … … 9924 9924 <optional> 9925 9925 <text key="destination" text="Name of river/lake/sea/ocean it runs into" /> 9926 9926 <text key="ref" text="Reference" /> 9927 <text key="ref:sandre" text="Reference Sandre (FR)" />9928 <text key="ref:fgkz" text="Reference FGKZ (DE)" />9929 <text key="ref:regine" text="Reference REGINE (NO)" />9930 <text key="ref:gnis" text="Reference GNIS (USA)" />9931 <text key="ref:gnbc" text="Reference GNBC (CA)" />9927 <text key="ref:sandre" text="Reference Sandre (FR)" regions="FR" /> 9928 <text key="ref:fgkz" text="Reference FGKZ (DE)" regions="DE" /> 9929 <text key="ref:regine" text="Reference REGINE (NO)" regions="NO" /> 9930 <text key="ref:gnis" text="Reference GNIS (USA)" regions="US" /> 9931 <text key="ref:gnbc" text="Reference GNBC (CA)" regions="CA" /> 9932 9932 <reference ref="wikipedia_wikidata" /> 9933 9933 </optional> 9934 9934 <roles> -
resources/data/tagging-preset.xsd
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 diff --git a/resources/data/tagging-preset.xsd b/resources/data/tagging-preset.xsd
a b 106 106 <complexContent> 107 107 <extension base="tns:group-parent"> 108 108 <attributeGroup ref="tns:attributes.name" /> 109 <attributeGroup ref="tns:attributes.regions"/> 109 110 </extension> 110 111 </complexContent> 111 112 </complexType> … … 121 122 <complexType name="item"> 122 123 <annotation> 123 124 <documentation> 124 Every item is one annotation set to select from. name is required, type and preset_name_label are recommended , icon and name_templateare optional attributes.125 Every item is one annotation set to select from. name is required, type and preset_name_label are recommended and icon, name_template, regions and exclude_regions are optional attributes. 125 126 </documentation> 126 127 </annotation> 127 128 <sequence> … … 134 135 </sequence> 135 136 <attributeGroup ref="tns:attributes.name" /> 136 137 <attributeGroup ref="tns:attributes.icon" /> 138 <attributeGroup ref="tns:attributes.regions"/> 137 139 <attribute name="type" type="string"> 138 140 <annotation> 139 141 <documentation><![CDATA[ … … 364 366 <complexType name="list_entry"> 365 367 <annotation> 366 368 <documentation><![CDATA[ 367 Used in <combo/> and <multiselect/>. More information see short_descriptions below. The attributes are value, display_value, short_description, icon and icon_size.369 Used in <combo/> and <multiselect/>. More information see short_descriptions below. The attributes are value, display_value, short_description, icon, icon_size, regions, and exclude_regions. 368 370 ]]></documentation> 369 371 </annotation> 370 372 <attribute name="value" type="string" use="required" /> … … 378 380 </annotation> 379 381 </attribute> 380 382 <attributeGroup ref="tns:attributes.icon" /> 383 <attributeGroup ref="tns:attributes.regions"/> 381 384 <anyAttribute processContents="skip" /> 382 385 </complexType> 383 386 … … 489 492 </attribute> 490 493 <attribute name="match" type="tns:match" /> 491 494 <attributeGroup ref="tns:attributes.icon" /> 495 <attributeGroup ref="tns:attributes.regions"/> 492 496 493 497 <attribute name="name" use="prohibited" /> 494 498 <attribute name="type" use="prohibited" /> … … 558 562 <complexType name="role"> 559 563 <annotation> 560 564 <documentation> 561 To specify possible roles of members in relations. The key attribute is required, text, requisite, count, type and member_expressionare optional.565 To specify possible roles of members in relations. The key attribute is required, text, requisite, count, type, member_expression, regions, and exclude_regions are optional. 562 566 </documentation> 563 567 </annotation> 564 568 <attribute name="key" type="string"> … … 574 578 <attribute name="count" type="integer" /> 575 579 <attribute name="member_expression" type="string" /> 576 580 <attribute name="regexp" type="boolean" /> 581 <attributeGroup ref="tns:attributes.regions"/> 577 582 <anyAttribute processContents="skip" /> 578 583 </complexType> 579 584 … … 728 733 </annotation> 729 734 </attribute> 730 735 </attributeGroup> 736 737 <attributeGroup name="attributes.regions"> 738 <attribute name="regions" type="string"> 739 <annotation> 740 <documentation> 741 Comma separated list of countries this preset group or item is applicable for. If not specified, the preset is applicable for all countries. 742 </documentation> 743 </annotation> 744 </attribute> 745 <attribute name="exclude_regions" type="boolean"> 746 <annotation> 747 <documentation> 748 If true, invert the meaning of regions. 749 </documentation> 750 </annotation> 751 </attribute> 752 </attributeGroup> 731 753 732 754 </schema> -
src/org/openstreetmap/josm/data/validation/tests/TagChecker.java
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 diff --git a/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java b/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java
a b 37 37 import org.openstreetmap.josm.command.ChangePropertyKeyCommand; 38 38 import org.openstreetmap.josm.command.Command; 39 39 import org.openstreetmap.josm.command.SequenceCommand; 40 import org.openstreetmap.josm.data.coor.LatLon; 40 41 import org.openstreetmap.josm.data.osm.AbstractPrimitive; 41 42 import org.openstreetmap.josm.data.osm.DataSet; 43 import org.openstreetmap.josm.data.osm.Node; 42 44 import org.openstreetmap.josm.data.osm.OsmPrimitive; 43 45 import org.openstreetmap.josm.data.osm.OsmUtils; 44 46 import org.openstreetmap.josm.data.osm.Relation; … … 62 64 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets; 63 65 import org.openstreetmap.josm.gui.tagging.presets.items.Check; 64 66 import org.openstreetmap.josm.gui.tagging.presets.items.CheckGroup; 67 import org.openstreetmap.josm.gui.tagging.presets.items.ComboMultiSelect; 68 import org.openstreetmap.josm.gui.tagging.presets.items.Key; 65 69 import org.openstreetmap.josm.gui.tagging.presets.items.KeyedItem; 70 import org.openstreetmap.josm.gui.tagging.presets.items.PresetListEntry; 71 import org.openstreetmap.josm.gui.tagging.presets.items.RegionSpecific; 66 72 import org.openstreetmap.josm.gui.widgets.EditableList; 67 73 import org.openstreetmap.josm.io.CachedFile; 68 74 import org.openstreetmap.josm.spi.preferences.Config; 69 75 import org.openstreetmap.josm.tools.GBC; 76 import org.openstreetmap.josm.tools.JosmRuntimeException; 70 77 import org.openstreetmap.josm.tools.Logging; 71 78 import org.openstreetmap.josm.tools.MultiMap; 79 import org.openstreetmap.josm.tools.Territories; 72 80 import org.openstreetmap.josm.tools.Utils; 73 81 74 82 /** … … 131 139 * The preference key to check presets 132 140 */ 133 141 public static final String PREF_CHECK_PRESETS_TYPES = PREFIX + ".checkPresetsTypes"; 142 public static final String PREF_CHECK_REGIONS = PREFIX + ".checkPresetsRegions"; 134 143 135 144 /** 136 145 * The preference key for source files … … 159 168 * The preference key to search for presets - used before upload 160 169 */ 161 170 public static final String PREF_CHECK_PRESETS_TYPES_BEFORE_UPLOAD = PREF_CHECK_PRESETS_TYPES + BEFORE_UPLOAD; 171 public static final String PREF_CHECK_REGIONS_BEFORE_UPLOAD = PREF_CHECK_REGIONS + BEFORE_UPLOAD; 162 172 163 173 /** 164 174 * The preference key for the list of tag keys that are allowed to be the same on a multipolygon and an outer way … … 175 185 protected boolean checkComplex; 176 186 protected boolean checkFixmes; 177 187 protected boolean checkPresetsTypes; 188 protected boolean checkRegions; 178 189 179 190 protected JCheckBox prefCheckKeys; 180 191 protected JCheckBox prefCheckValues; 181 192 protected JCheckBox prefCheckComplex; 182 193 protected JCheckBox prefCheckFixmes; 183 194 protected JCheckBox prefCheckPresetsTypes; 195 protected JCheckBox prefCheckRegions; 184 196 185 197 protected JCheckBox prefCheckKeysBeforeUpload; 186 198 protected JCheckBox prefCheckValuesBeforeUpload; 187 199 protected JCheckBox prefCheckComplexBeforeUpload; 188 200 protected JCheckBox prefCheckFixmesBeforeUpload; 189 201 protected JCheckBox prefCheckPresetsTypesBeforeUpload; 202 protected JCheckBox prefCheckRegionsBeforeUpload; 190 203 191 204 // CHECKSTYLE.OFF: SingleSpaceSeparator 192 205 protected static final int EMPTY_VALUES = 1200; … … 210 223 protected static final int MULTIPOLYGON_INCOMPLETE = 1219; 211 224 protected static final int MULTIPOLYGON_MAYBE_NO_AREA = 1220; 212 225 protected static final int MULTIPOLYGON_SAME_TAG_ON_OUTER = 1221; 226 protected static final int INVALID_REGION = 1222; 213 227 // CHECKSTYLE.ON: SingleSpaceSeparator 214 228 215 229 protected EditableList sourcesList; … … 559 573 * @param key key 560 574 * @return {@code true} if the given key is in internal presets 561 575 * @since 9023 562 * @deprecated Use {@link TaggingPresets#isKeyInPresets(String)} instead576 * @deprecated since 18281 -- use {@link TaggingPresets#isKeyInPresets(String)} instead 563 577 */ 564 578 @Deprecated 565 579 public static boolean isKeyInPresets(String key) { … … 652 666 } 653 667 654 668 if (p instanceof Relation && p.hasTag("type", "multipolygon")) { 655 checkMultipolygonTags(p);669 checkMultipolygonTags(p); 656 670 } 657 671 658 if (checkPresetsTypes) { 659 TagMap tags = p.getKeys(); 660 TaggingPresetType presetType = TaggingPresetType.forPrimitive(p); 661 EnumSet<TaggingPresetType> presetTypes = EnumSet.of(presetType); 662 663 Collection<TaggingPreset> matchingPresets = presetIndex.entrySet().stream() 672 final Collection<TaggingPreset> matchingPresets; 673 TagMap tags; 674 if (checkPresetsTypes || checkRegions) { 675 tags = p.getKeys(); 676 matchingPresets = presetIndex.entrySet().stream() 664 677 .filter(e -> TaggingPresetItem.matches(e.getValue(), tags)) 665 678 .map(Entry::getKey) 666 679 .collect(Collectors.toCollection(LinkedHashSet::new)); 667 Collection<TaggingPreset> matchingPresetsOK = matchingPresets.stream().filter( 668 tp -> tp.typeMatches(presetTypes)).collect(Collectors.toList()); 669 Collection<TaggingPreset> matchingPresetsKO = matchingPresets.stream().filter( 670 tp -> !tp.typeMatches(presetTypes)).collect(Collectors.toList()); 680 } else { 681 matchingPresets = null; 682 tags = null; 683 } 684 685 if (checkPresetsTypes) { 686 checkPresetsTypes(p, matchingPresets, tags); 687 } 688 689 if (checkRegions) { 690 checkRegions(p, matchingPresets); 691 } 692 } 693 694 /** 695 * Check that the primitive matches the preset types for the preset 696 * @param p The primitive to check 697 * @param matchingPresets The presets to go through 698 * @param tags Tags from the primitive to check 699 */ 700 private void checkPresetsTypes(OsmPrimitive p, Collection<TaggingPreset> matchingPresets, Map<String, String> tags) { 701 TaggingPresetType presetType = TaggingPresetType.forPrimitive(p); 702 EnumSet<TaggingPresetType> presetTypes = EnumSet.of(presetType); 703 704 Collection<TaggingPreset> matchingPresetsOK = matchingPresets.stream().filter( 705 tp -> tp.typeMatches(presetTypes)).collect(Collectors.toList()); 706 Collection<TaggingPreset> matchingPresetsKO = matchingPresets.stream().filter( 707 tp -> !tp.typeMatches(presetTypes)).collect(Collectors.toList()); 671 708 672 673 674 709 for (TaggingPreset tp : matchingPresetsKO) { 710 // Potential error, unless matching tags are all known by a supported preset 711 Map<String, String> matchingTags = tp.data.stream() 675 712 .filter(i -> Boolean.TRUE.equals(i.matches(tags))) 676 713 .filter(i -> i instanceof KeyedItem).map(i -> ((KeyedItem) i).key) 677 714 .collect(Collectors.toMap(k -> k, tags::get)); 678 if (matchingPresetsOK.stream().noneMatch( 679 tp2 -> matchingTags.entrySet().stream().allMatch( 680 e -> tp2.data.stream().anyMatch( 681 i -> i instanceof KeyedItem && ((KeyedItem) i).key.equals(e.getKey()))))) { 682 errors.add(TestError.builder(this, Severity.OTHER, INVALID_PRESETS_TYPE) 683 .message(tr("Object type not in preset"), 684 marktr("Object type {0} is not supported by tagging preset: {1}"), 685 tr(presetType.getName()), tp.getLocaleName()) 686 .primitives(p) 687 .build()); 688 } 689 } 690 } 715 if (matchingPresetsOK.stream().noneMatch( 716 tp2 -> matchingTags.entrySet().stream().allMatch( 717 e -> tp2.data.stream().anyMatch( 718 i -> i instanceof KeyedItem && ((KeyedItem) i).key.equals(e.getKey()))))) { 719 errors.add(TestError.builder(this, Severity.OTHER, INVALID_PRESETS_TYPE) 720 .message(tr("Object type not in preset"), 721 marktr("Object type {0} is not supported by tagging preset: {1}"), 722 tr(presetType.getName()), tp.getLocaleName()) 723 .primitives(p) 724 .build()); 725 } 726 } 727 } 728 729 /** 730 * Check that the preset is valid for the region the primitive is in 731 * @param p The primitive to check 732 * @param matchingPresets The presets to check against 733 */ 734 private void checkRegions(OsmPrimitive p, Collection<TaggingPreset> matchingPresets) { 735 LatLon center; 736 if (p instanceof Node) { 737 center = ((Node) p).getCoor(); 738 } else { 739 center = p.getBBox().getCenter(); 740 } 741 for (TaggingPreset preset : matchingPresets) { 742 if (preset.regions() != null) { 743 boolean isInRegion = false; //true if the object is in an applicable region 744 for (String region : preset.regions()) { 745 if (Territories.isIso3166Code(region, center)) { //check if center of the object is in a region 746 isInRegion = true; 747 } 748 } 749 if (isInRegion == preset.exclude_regions()) { 750 errors.add(TestError.builder(this, Severity.WARNING, INVALID_REGION) 751 .message(tr("Invalid region for this preset"), 752 marktr("Preset {0} should not be applied in this region"), 753 preset.getLocaleName()) 754 .primitives(p) 755 .build()); 756 } 757 } 758 // Check the tags 759 tagCheck(preset, p, center, preset.data); 760 } 761 } 762 763 /** 764 * Perform the checks against a given preset value 765 * @param preset The originating preset (used for error creation) 766 * @param p The originating primitive (used for error creation) 767 * @param center The center of the primitive or other location of the primitive to check 768 * @param tagInformation The sub items for the preset 769 */ 770 private void tagCheck(TaggingPreset preset, OsmPrimitive p, LatLon center, List<? extends TaggingPresetItem> tagInformation) { 771 for (TaggingPresetItem item : tagInformation) { 772 if (item instanceof CheckGroup) { 773 tagCheckReal(preset, p, center, ((CheckGroup) item).checks); 774 } else if (item instanceof ComboMultiSelect) { 775 tagCheckReal(preset, p, center, ((ComboMultiSelect) item).presetListEntries()); 776 } 777 if (item instanceof RegionSpecific && ((RegionSpecific) item).regions() != null) { 778 tagCheckReal(preset, p, center, (RegionSpecific) item); 779 } 780 } 781 } 782 783 /** 784 * Perform the checks against a given preset value 785 * @param preset The originating preset (used for error creation) 786 * @param p The originating primitive (used for error creation) 787 * @param center The center of the primitive or other location of the primitive to check 788 * @param data The data for the region specific information 789 */ 790 private void tagCheckReal(TaggingPreset preset, OsmPrimitive p, LatLon center, List<? extends RegionSpecific> data) { 791 for (RegionSpecific regionSpecific : data) { 792 if (regionSpecific.regions() != null) { 793 tagCheckReal(preset, p, center, regionSpecific); 794 } 795 } 796 } 797 798 /** 799 * Perform the checks against a given preset value 800 * @param preset The originating preset (used for error creation) 801 * @param p The originating primitive (used for error creation) 802 * @param center The center of the primitive or other location of the primitive to check 803 * @param data The data for the region specific information 804 */ 805 private void tagCheckReal(TaggingPreset preset, OsmPrimitive p, LatLon center, RegionSpecific data) { 806 // First, check if we aren't in the region for the tag 807 if (latLonInRegions(center, data.regions()) == data.exclude_regions()) { 808 final String key; 809 final String value; 810 if (data instanceof PresetListEntry) { 811 key = ((PresetListEntry) data).cms.key; 812 value = ((PresetListEntry) data).value; 813 } else if (data instanceof KeyedItem) { 814 key = ((KeyedItem) data).key; 815 if (data instanceof Key) { 816 value = ((Key) data).value; 817 } else { 818 value = null; 819 } 820 } else { 821 throw new JosmRuntimeException("Unknown implementor for RegionSpecific"); 822 } 823 if (p.hasTag(key) && (value == null || value.equals(p.get(key)))) { 824 final TestError.Builder builder = TestError.builder(this, Severity.WARNING, INVALID_REGION) 825 .primitives(p); 826 if (value == null) { 827 builder.message(tr("Invalid region for this preset"), 828 marktr("Preset {0} should not have the key {1}"), 829 preset.getLocaleName(), key); 830 } else { 831 builder.message(tr("Invalid region for this preset"), 832 marktr("Preset {0} should not have the tag {1}={2}"), 833 preset.getLocaleName(), key, value); 834 } 835 errors.add(builder.build()); 836 } 837 } 838 } 839 840 /** 841 * Check if the specified latlon is inside any of the specified regions 842 * @param latLon The {@link LatLon} to check 843 * @param regions The regions to see if the {@link LatLon} is in 844 * @return {@code true} if the coordinate is inside any of the regions 845 */ 846 private static boolean latLonInRegions(LatLon latLon, Collection<String> regions) { 847 if (regions != null) { 848 for (String region : regions) { 849 if (Territories.isIso3166Code(region, latLon)) { 850 return true; 851 } 852 } 853 } 854 return false; 691 855 } 692 856 693 857 private static final Collection<String> NO_AREA_KEYS = Arrays.asList("name", "area", "ref", "access", "operator"); … … 1100 1264 if (isBeforeUpload) { 1101 1265 checkPresetsTypes = checkPresetsTypes && Config.getPref().getBoolean(PREF_CHECK_PRESETS_TYPES_BEFORE_UPLOAD, true); 1102 1266 } 1267 1268 checkRegions = includeOtherSeverity && Config.getPref().getBoolean(PREF_CHECK_REGIONS, true); 1269 if (isBeforeUpload) { 1270 checkRegions = checkRegions && Config.getPref().getBoolean(PREF_CHECK_REGIONS_BEFORE_UPLOAD, true); 1271 } 1103 1272 deprecatedChecker = OsmValidator.getTest(MapCSSTagChecker.class); 1104 1273 ignoreForOuterMPSameTagCheck.addAll(Config.getPref().getList(PREF_KEYS_IGNORE_OUTER_MP_SAME_TAG, Collections.emptyList())); 1105 1274 } … … 1112 1281 1113 1282 @Override 1114 1283 public void visit(Collection<OsmPrimitive> selection) { 1115 if (checkKeys || checkValues || checkComplex || checkFixmes || checkPresetsTypes ) {1284 if (checkKeys || checkValues || checkComplex || checkFixmes || checkPresetsTypes || checkRegions) { 1116 1285 super.visit(selection); 1117 1286 } 1118 1287 } … … 1177 1346 prefCheckPresetsTypesBeforeUpload = new JCheckBox(); 1178 1347 prefCheckPresetsTypesBeforeUpload.setSelected(Config.getPref().getBoolean(PREF_CHECK_PRESETS_TYPES_BEFORE_UPLOAD, true)); 1179 1348 testPanel.add(prefCheckPresetsTypesBeforeUpload, a); 1349 1350 prefCheckRegions = new JCheckBox(tr("Check for regions."), Config.getPref().getBoolean(PREF_CHECK_REGIONS, true)); 1351 prefCheckRegions.setToolTipText(tr("Validate that objects are in the correct region.")); 1352 testPanel.add(prefCheckRegions, GBC.std().insets(20, 0, 0, 0)); 1353 1354 prefCheckRegionsBeforeUpload = new JCheckBox(); 1355 prefCheckRegionsBeforeUpload.setSelected(Config.getPref().getBoolean(PREF_CHECK_REGIONS_BEFORE_UPLOAD, true)); 1356 testPanel.add(prefCheckRegionsBeforeUpload, a); 1180 1357 } 1181 1358 1182 1359 /** … … 1199 1376 Config.getPref().putBoolean(PREF_CHECK_KEYS, prefCheckKeys.isSelected()); 1200 1377 Config.getPref().putBoolean(PREF_CHECK_FIXMES, prefCheckFixmes.isSelected()); 1201 1378 Config.getPref().putBoolean(PREF_CHECK_PRESETS_TYPES, prefCheckPresetsTypes.isSelected()); 1379 Config.getPref().putBoolean(PREF_CHECK_REGIONS, prefCheckRegions.isSelected()); 1202 1380 Config.getPref().putBoolean(PREF_CHECK_VALUES_BEFORE_UPLOAD, prefCheckValuesBeforeUpload.isSelected()); 1203 1381 Config.getPref().putBoolean(PREF_CHECK_COMPLEX_BEFORE_UPLOAD, prefCheckComplexBeforeUpload.isSelected()); 1204 1382 Config.getPref().putBoolean(PREF_CHECK_KEYS_BEFORE_UPLOAD, prefCheckKeysBeforeUpload.isSelected()); 1205 1383 Config.getPref().putBoolean(PREF_CHECK_FIXMES_BEFORE_UPLOAD, prefCheckFixmesBeforeUpload.isSelected()); 1206 1384 Config.getPref().putBoolean(PREF_CHECK_PRESETS_TYPES_BEFORE_UPLOAD, prefCheckPresetsTypesBeforeUpload.isSelected()); 1385 Config.getPref().putBoolean(PREF_CHECK_REGIONS_BEFORE_UPLOAD, prefCheckRegionsBeforeUpload.isSelected()); 1207 1386 return Config.getPref().putList(PREF_SOURCES, sourcesList.getItems()); 1208 1387 } 1209 1388 -
src/org/openstreetmap/josm/gui/tagging/presets/items/ComboMultiSelect.java
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 diff --git a/src/org/openstreetmap/josm/gui/tagging/presets/items/ComboMultiSelect.java b/src/org/openstreetmap/josm/gui/tagging/presets/items/ComboMultiSelect.java
a b 10 10 import java.util.ArrayList; 11 11 import java.util.Arrays; 12 12 import java.util.Collection; 13 import java.util.Collections; 13 14 import java.util.List; 14 15 import java.util.Map; 15 16 import java.util.TreeMap; … … 402 403 return use_last_as_default == 2; 403 404 } 404 405 406 /** 407 * Get the entries for this {@link ComboMultiSelect} object 408 * @return The {@link PresetListEntry} values for this object 409 */ 410 public List<PresetListEntry> presetListEntries() { 411 return Collections.unmodifiableList(this.presetListEntries); 412 } 413 405 414 /** 406 415 * Adds a preset list entry. 407 416 * @param e list entry to add -
src/org/openstreetmap/josm/gui/tagging/presets/items/KeyedItem.java
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 diff --git a/src/org/openstreetmap/josm/gui/tagging/presets/items/KeyedItem.java b/src/org/openstreetmap/josm/gui/tagging/presets/items/KeyedItem.java
a b 7 7 import java.util.EnumSet; 8 8 import java.util.HashMap; 9 9 import java.util.Map; 10 import java.util.SortedMap;11 10 import java.util.NoSuchElementException; 11 import java.util.SortedMap; 12 12 import java.util.TreeMap; 13 13 14 14 import javax.swing.JPopupMenu; … … 24 24 /** 25 25 * Preset item associated to an OSM key. 26 26 */ 27 public abstract class KeyedItem extends TextItem {27 public abstract class KeyedItem extends TextItem implements RegionSpecific { 28 28 29 29 /** The constant value {@code "<different>"}. */ 30 30 protected static final String DIFFERENT = "<different>"; … … 52 52 */ 53 53 public String match = getDefaultMatch().getValue(); // NOSONAR 54 54 55 /** 56 * List of regions the preset is applicable for. 57 */ 58 private Collection<String> regions; 59 /** 60 * If true, invert the meaning of regions. 61 */ 62 private boolean excludeRegions; 63 55 64 /** 56 65 * Enum denoting how a match (see {@link TaggingPresetItem#matches}) is performed. 57 66 */ … … 260 269 return popupMenu; 261 270 } 262 271 272 @Override 273 public final Collection<String> regions() { 274 return this.regions; 275 } 276 277 @Override 278 public final void realSetRegions(Collection<String> regions) { 279 this.regions = regions; 280 } 281 282 @Override 283 public final boolean exclude_regions() { 284 return this.excludeRegions; 285 } 286 287 @Override 288 public final void setExclude_regions(boolean excludeRegions) { 289 this.excludeRegions = excludeRegions; 290 } 291 263 292 @Override 264 293 public String toString() { 265 294 return "KeyedItem [key=" + key + ", text=" + text -
src/org/openstreetmap/josm/gui/tagging/presets/items/PresetListEntry.java
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 diff --git a/src/org/openstreetmap/josm/gui/tagging/presets/items/PresetListEntry.java b/src/org/openstreetmap/josm/gui/tagging/presets/items/PresetListEntry.java
a b 5 5 import static org.openstreetmap.josm.tools.I18n.tr; 6 6 import static org.openstreetmap.josm.tools.I18n.trc; 7 7 8 import java.util.Collection; 8 9 import java.util.Objects; 9 10 10 11 import javax.swing.ImageIcon; … … 20 21 * Used for controls that offer a list of items to choose from like {@link Combo} and 21 22 * {@link MultiSelect}. 22 23 */ 23 public class PresetListEntry implements Comparable<PresetListEntry> {24 public class PresetListEntry implements Comparable<PresetListEntry>, RegionSpecific { 24 25 /** Used to display an entry matching several different values. */ 25 26 protected static final PresetListEntry ENTRY_DIFFERENT = new PresetListEntry(KeyedItem.DIFFERENT, null); 26 27 /** Used to display an empty entry used to clear values. */ … … 47 48 /** The localized version of {@link #short_description}. */ 48 49 public String locale_short_description; // NOSONAR 49 50 51 /** 52 * List of regions the entry is applicable for. 53 */ 54 private Collection<String> regions; 55 56 /** 57 * If true, invert the meaning of regions. 58 */ 59 private boolean excludeRegions; 60 50 61 private String cachedDisplayValue; 51 62 private String cachedShortDescription; 52 63 private ImageIcon cachedIcon; 53 64 54 65 /** 55 66 * Constructs a new {@code PresetListEntry}, uninitialized. 56 * 67 * <p> 57 68 * Public default constructor is needed by {@link org.openstreetmap.josm.tools.XmlObjectParser.Parser#startElement} 58 69 */ 59 70 public PresetListEntry() { … … 73 84 74 85 /** 75 86 * Returns the contents displayed in the dropdown list. 76 * 87 * <p> 77 88 * This is the contents that would be displayed in the current view plus a short description to 78 89 * aid the user. The whole content is wrapped to {@code width}. 79 90 * … … 163 174 return tr("Clears the key ''{0}''.", key); 164 175 } 165 176 177 @Override 178 public Collection<String> regions() { 179 return this.regions; 180 } 181 182 @Override 183 public void realSetRegions(Collection<String> regions) { 184 this.regions = regions; 185 } 186 187 @Override 188 public boolean exclude_regions() { 189 return this.excludeRegions; 190 } 191 192 @Override 193 public void setExclude_regions(boolean excludeRegions) { 194 this.excludeRegions = excludeRegions; 195 } 196 166 197 // toString is mainly used to initialize the Editor 167 198 @Override 168 199 public String toString() { -
new file src/org/openstreetmap/josm/gui/tagging/presets/items/RegionSpecific.java
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 diff --git a/src/org/openstreetmap/josm/gui/tagging/presets/items/RegionSpecific.java b/src/org/openstreetmap/josm/gui/tagging/presets/items/RegionSpecific.java new file mode 100644
- + 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.gui.tagging.presets.items; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 import java.util.Arrays; 7 import java.util.Collection; 8 import java.util.Collections; 9 import java.util.Set; 10 import java.util.stream.Collectors; 11 12 import org.openstreetmap.josm.tools.Territories; 13 import org.openstreetmap.josm.tools.Utils; 14 import org.xml.sax.SAXException; 15 16 /** 17 * Indicates that this object may be specific to a region 18 * @since xxx 19 */ 20 public interface RegionSpecific { 21 /** 22 * Get the regions for the item 23 * @return The regions that the item is valid for 24 * @apiNote This is not {@code getRegions} just in case we decide to make the {@link RegionSpecific} record classes. 25 * @since xxx 26 */ 27 Collection<String> regions(); 28 29 /** 30 * Set the regions for the preset 31 * @param regions The region list (comma delimited) 32 * @throws SAXException if an unknown ISO 3166-2 is found 33 * @since xxx 34 */ 35 default void setRegions(String regions) throws SAXException { 36 Set<String> regionSet = Collections.unmodifiableSet(Arrays.stream(regions.split(",")) 37 .map(Utils::intern).collect(Collectors.toSet())); 38 for (String region : regionSet) { 39 if (!Territories.getKnownIso3166Codes().contains(region)) { 40 throw new SAXException(tr("Unknown ISO-3166 Code: {0}", region)); 41 } 42 } 43 this.realSetRegions(regionSet); 44 } 45 46 /** 47 * Set the regions for the preset 48 * @param regions The region collection 49 * @since xxx 50 */ 51 void realSetRegions(Collection<String> regions); 52 53 /** 54 * Get the exclude_regions for the preset 55 * @apiNote This is not {@code getExclude_regions} just in case we decide to make {@link RegionSpecific} a record class. 56 * @since xxx 57 */ 58 boolean exclude_regions(); 59 60 /** 61 * Set if the preset should not be used in the given region 62 * @param excludeRegions if true the function of regions is inverted 63 * @since xxx 64 */ 65 void setExclude_regions(boolean excludeRegions); 66 } -
src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 diff --git a/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java b/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java
a b 67 67 import org.openstreetmap.josm.gui.tagging.presets.items.PresetLink; 68 68 import org.openstreetmap.josm.gui.tagging.presets.items.Roles; 69 69 import org.openstreetmap.josm.gui.tagging.presets.items.Space; 70 import org.openstreetmap.josm.gui.tagging.presets.items.RegionSpecific; 70 71 import org.openstreetmap.josm.gui.util.GuiHelper; 71 72 import org.openstreetmap.josm.tools.GBC; 72 73 import org.openstreetmap.josm.tools.ImageProvider; … … 88 89 * It is also able to construct dialogs out of preset definitions. 89 90 * @since 294 90 91 */ 91 public class TaggingPreset extends AbstractAction implements ActiveLayerChangeListener, AdaptableAction, Predicate<IPrimitive> { 92 public class TaggingPreset extends AbstractAction implements ActiveLayerChangeListener, AdaptableAction, Predicate<IPrimitive>, 93 RegionSpecific { 92 94 93 95 /** The user pressed the "Apply" button */ 94 96 public static final int DIALOG_ANSWER_APPLY = 1; … … 142 144 */ 143 145 public transient Set<TaggingPresetType> types; 144 146 /** 147 * List of regions the preset is applicable for. 148 */ 149 private Collection<String> regions; 150 /** 151 * If true, invert the meaning of regions. 152 */ 153 private boolean excludeRegions; 154 /** 145 155 * The list of preset items 146 156 */ 147 157 public final transient List<TaggingPresetItem> data = new ArrayList<>(2); … … 349 359 } 350 360 } 351 361 362 @Override 363 public final Collection<String> regions() { 364 return this.regions != null || this.group == null ? this.regions : this.group.regions(); 365 } 366 367 @Override 368 public final void realSetRegions(Collection<String> regions) { 369 this.regions = regions; 370 } 371 372 @Override 373 public final boolean exclude_regions() { 374 return this.excludeRegions; 375 } 376 377 @Override 378 public final void setExclude_regions(boolean excludeRegions) { 379 this.excludeRegions = excludeRegions; 380 } 381 352 382 private static class PresetPanel extends JPanel { 353 383 private boolean hasElements; 354 384 -
src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetValidation.java
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 diff --git a/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetValidation.java b/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetValidation.java
a b 24 24 import org.openstreetmap.josm.data.validation.TestError; 25 25 import org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker; 26 26 import org.openstreetmap.josm.data.validation.tests.OpeningHourTest; 27 import org.openstreetmap.josm.data.validation.tests.TagChecker; 27 28 import org.openstreetmap.josm.gui.MainApplication; 29 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 28 30 import org.openstreetmap.josm.gui.util.GuiHelper; 29 31 import org.openstreetmap.josm.tools.Logging; 30 32 import org.openstreetmap.josm.tools.SubclassFilteredCollection; … … 55 57 try { 56 58 MapCSSTagChecker mapCSSTagChecker = OsmValidator.getTest(MapCSSTagChecker.class); 57 59 OpeningHourTest openingHourTest = OsmValidator.getTest(OpeningHourTest.class); 58 OsmValidator.initializeTests(Arrays.asList(mapCSSTagChecker, openingHourTest)); 60 TagChecker tagChecker = OsmValidator.getTest(TagChecker.class); 61 tagChecker.startTest(NullProgressMonitor.INSTANCE); //since initializeTest works if test is enabled 62 OsmValidator.initializeTests(Arrays.asList(mapCSSTagChecker, openingHourTest, tagChecker)); 63 59 64 60 65 List<TestError> errors = new ArrayList<>(); 61 66 openingHourTest.addErrorsForPrimitive(primitive, errors); 62 67 errors.addAll(mapCSSTagChecker.getErrorsForPrimitive(primitive, ValidatorPrefHelper.PREF_OTHER.get())); 68 tagChecker.check(primitive); 69 errors.addAll(tagChecker.getErrors()); 63 70 64 71 boolean visible = !errors.isEmpty(); 65 72 String toolTipText = "<html>" + Utils.joinAsHtmlUnorderedList(Utils.transform(errors, e -> -
test/unit/org/openstreetmap/josm/data/validation/tests/TagCheckerTest.java
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 diff --git a/test/unit/org/openstreetmap/josm/data/validation/tests/TagCheckerTest.java b/test/unit/org/openstreetmap/josm/data/validation/tests/TagCheckerTest.java
a b 228 228 assertFalse(errors.get(0).isFixable()); 229 229 } 230 230 231 @Test 232 void testRegionKey() throws IOException { 233 final List<TestError> errors = test(OsmUtils.createPrimitive("node highway=crossing crossing_ref=zebra")); 234 assertEquals(1, errors.size()); 235 assertEquals("Invalid region for this preset", errors.get(0).getMessage()); 236 assertEquals("Preset Pedestrian Crossing should not have the key crossing_ref", errors.get(0).getDescription()); 237 assertEquals(Severity.WARNING, errors.get(0).getSeverity()); 238 assertFalse(errors.get(0).isFixable()); 239 240 } 241 242 @Test 243 void testRegionTag() throws IOException { 244 final List<TestError> errors = test(OsmUtils.createPrimitive("relation type=waterway ref:gnis=123456")); 245 assertEquals(1, errors.size()); 246 assertEquals("Invalid region for this preset", errors.get(0).getMessage()); 247 assertEquals("Preset Waterway should not have the key ref:gnis", errors.get(0).getDescription()); 248 assertEquals(Severity.WARNING, errors.get(0).getSeverity()); 249 assertFalse(errors.get(0).isFixable()); 250 } 251 231 252 /** 232 253 * Key in presets but not in ignored.cfg. Caused a NPE with r14727. 233 254 * @throws IOException if any I/O error occurs -
test/unit/org/openstreetmap/josm/gui/tagging/presets/items/CheckGroupTest.java
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 diff --git a/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/CheckGroupTest.java b/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/CheckGroupTest.java
a b 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.gui.tagging.presets.items; 3 3 4 import static org.junit.jupiter.api.Assertions.assertEquals; 5 import static org.junit.jupiter.api.Assertions.assertFalse; 6 import static org.junit.jupiter.api.Assertions.assertTrue; 7 8 import javax.swing.JPanel; 9 10 import org.junit.jupiter.api.Test; 11 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport; 4 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItem; 5 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemTest; 12 6 13 7 /** 14 8 * Unit tests of {@link CheckGroup} class. 15 9 */ 16 class CheckGroupTest { 17 /** 18 * Unit test for {@link CheckGroup#addToPanel}. 19 */ 20 @Test 21 void testAddToPanel() { 22 CheckGroup cg = new CheckGroup(); 23 JPanel p = new JPanel(); 24 assertEquals(0, p.getComponentCount()); 25 assertFalse(cg.addToPanel(p, TaggingPresetItemGuiSupport.create(false))); 26 assertTrue(p.getComponentCount() > 0); 10 class CheckGroupTest implements TaggingPresetItemTest { 11 @Override 12 public TaggingPresetItem getInstance() { 13 return new CheckGroup(); 27 14 } 28 15 } -
test/unit/org/openstreetmap/josm/gui/tagging/presets/items/CheckTest.java
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 diff --git a/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/CheckTest.java b/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/CheckTest.java
a b 8 8 9 9 import org.junit.jupiter.api.Test; 10 10 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport; 11 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemTest; 11 12 import org.openstreetmap.josm.testutils.annotations.Main; 12 13 13 14 /** 14 15 * Unit tests of {@link Check} class. 15 16 */ 16 17 @Main 17 class CheckTest { 18 class CheckTest implements RegionSpecificTest, TaggingPresetItemTest { 19 @Override 20 public Check getInstance() { 21 final Check check = new Check(); 22 check.key = "crossing:island"; 23 return check; 24 } 25 18 26 /** 19 27 * Unit test for {@link Check#addToPanel}. 20 28 */ 29 @Override 21 30 @Test 22 void testAddToPanel() {31 public void testAddToPanel() { 23 32 JPanel p = new JPanel(); 24 33 assertEquals(0, p.getComponentCount()); 25 assertTrue( new Check().addToPanel(p, TaggingPresetItemGuiSupport.create(false)));34 assertTrue(getInstance().addToPanel(p, TaggingPresetItemGuiSupport.create(false))); 26 35 assertTrue(p.getComponentCount() > 0); 27 36 } 28 37 } -
test/unit/org/openstreetmap/josm/gui/tagging/presets/items/ComboTest.java
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 diff --git a/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/ComboTest.java b/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/ComboTest.java
a b 12 12 import org.openstreetmap.josm.data.osm.OsmPrimitive; 13 13 import org.openstreetmap.josm.data.osm.OsmUtils; 14 14 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport; 15 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemTest; 15 16 import org.openstreetmap.josm.testutils.annotations.BasicPreferences; 16 17 import org.openstreetmap.josm.testutils.annotations.I18n; 17 18 import org.openstreetmap.josm.testutils.annotations.Main; … … 22 23 @BasicPreferences 23 24 @I18n("de") 24 25 @Main 25 class ComboTest { 26 class ComboTest implements TaggingPresetItemTest { 27 @Override 28 public Combo getInstance() { 29 return new Combo(); 30 } 31 26 32 /** 27 * Unit test for {@link C ombo#addToPanel}.33 * Unit test for {@link Check#addToPanel}. 28 34 */ 35 @Override 29 36 @Test 30 void testAddToPanel() {37 public void testAddToPanel() { 31 38 JPanel p = new JPanel(); 32 39 assertEquals(0, p.getComponentCount()); 33 assertTrue( new Combo().addToPanel(p, TaggingPresetItemGuiSupport.create(false)));40 assertTrue(getInstance().addToPanel(p, TaggingPresetItemGuiSupport.create(false))); 34 41 assertTrue(p.getComponentCount() > 0); 35 42 } 36 43 … … 39 46 */ 40 47 @Test 41 48 void testUseLastAsDefault() { 42 Combo combo = new Combo();49 final Combo combo = getInstance(); 43 50 combo.key = "addr:country"; 44 51 combo.values_from = "java.util.Locale#getISOCountries"; 45 52 OsmPrimitive way = OsmUtils.createPrimitive("way"); … … 118 125 119 126 @Test 120 127 void testColor() { 121 Combo combo = new Combo();128 final Combo combo = getInstance(); 122 129 combo.key = "colour"; 123 130 combo.values = "red;green;blue;black"; 124 131 combo.values_context = "color"; -
test/unit/org/openstreetmap/josm/gui/tagging/presets/items/ItemSeparatorTest.java
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 diff --git a/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/ItemSeparatorTest.java b/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/ItemSeparatorTest.java
a b 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.gui.tagging.presets.items; 3 3 4 import static org.junit.jupiter.api.Assertions.assertEquals; 5 import static org.junit.jupiter.api.Assertions.assertFalse; 6 import static org.junit.jupiter.api.Assertions.assertTrue; 7 8 import javax.swing.JPanel; 9 10 import org.junit.jupiter.api.Test; 11 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport; 4 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemTest; 12 5 13 6 /** 14 7 * Unit tests of {@link ItemSeparator} class. 15 8 */ 16 class ItemSeparatorTest { 17 /** 18 * Unit test for {@link ItemSeparator#addToPanel}. 19 */ 20 @Test 21 void testAddToPanel() { 22 JPanel p = new JPanel(); 23 assertEquals(0, p.getComponentCount()); 24 assertFalse(new ItemSeparator().addToPanel(p, TaggingPresetItemGuiSupport.create(false))); 25 assertTrue(p.getComponentCount() > 0); 9 class ItemSeparatorTest implements TaggingPresetItemTest { 10 @Override 11 public ItemSeparator getInstance() { 12 return new ItemSeparator(); 26 13 } 27 14 } -
test/unit/org/openstreetmap/josm/gui/tagging/presets/items/KeyTest.java
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 diff --git a/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/KeyTest.java b/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/KeyTest.java
a b 8 8 9 9 import org.junit.jupiter.api.Test; 10 10 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport; 11 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemTest; 11 12 12 13 /** 13 14 * Unit tests of {@link Key} class. 14 15 */ 15 class KeyTest { 16 class KeyTest implements RegionSpecificTest, TaggingPresetItemTest { 17 @Override 18 public Key getInstance() { 19 final Key key = new Key(); 20 key.key = "highway"; 21 key.value = "residential"; 22 return key; 23 } 24 16 25 /** 17 26 * Unit test for {@link Key#addToPanel}. 18 27 */ 19 28 @Test 20 void testAddToPanel() { 29 @Override 30 public void testAddToPanel() { 21 31 JPanel p = new JPanel(); 22 32 assertEquals(0, p.getComponentCount()); 23 33 assertFalse(new Key().addToPanel(p, TaggingPresetItemGuiSupport.create(false))); -
test/unit/org/openstreetmap/josm/gui/tagging/presets/items/LabelTest.java
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 diff --git a/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/LabelTest.java b/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/LabelTest.java
a b 8 8 9 9 import org.junit.jupiter.api.Test; 10 10 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport; 11 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemTest; 11 12 12 13 /** 13 14 * Unit tests of {@link Label} class. 14 15 */ 15 class LabelTest { 16 class LabelTest implements TaggingPresetItemTest { 17 @Override 18 public Label getInstance() { 19 return new Label(); 20 } 21 16 22 /** 17 * Unit test for {@link Label#addToPanel}.23 * Unit test for {@link Check#addToPanel}. 18 24 */ 25 @Override 19 26 @Test 20 void testAddToPanel() {27 public void testAddToPanel() { 21 28 JPanel p = new JPanel(); 22 29 assertEquals(0, p.getComponentCount()); 23 assertTrue( new Label().addToPanel(p, TaggingPresetItemGuiSupport.create(false)));30 assertTrue(getInstance().addToPanel(p, TaggingPresetItemGuiSupport.create(false))); 24 31 assertTrue(p.getComponentCount() > 0); 25 32 } 26 33 } -
test/unit/org/openstreetmap/josm/gui/tagging/presets/items/LinkTest.java
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 diff --git a/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/LinkTest.java b/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/LinkTest.java
a b 9 9 10 10 import org.junit.jupiter.api.Test; 11 11 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport; 12 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemTest; 12 13 import org.openstreetmap.josm.spi.preferences.Config; 13 14 14 15 /** 15 16 * Unit tests of {@link Link} class. 16 17 */ 17 class LinkTest { 18 class LinkTest implements TaggingPresetItemTest { 19 @Override 20 public Link getInstance() { 21 return new Link(); 22 } 23 18 24 /** 19 25 * Unit test for {@link Link#addToPanel}. 20 26 */ 27 @Override 21 28 @Test 22 void testAddToPanel() {23 Link l = new Link();29 public void testAddToPanel() { 30 Link l = getInstance(); 24 31 JPanel p = new JPanel(); 25 32 assertEquals(0, p.getComponentCount()); 26 33 assertFalse(l.addToPanel(p, TaggingPresetItemGuiSupport.create(false))); -
test/unit/org/openstreetmap/josm/gui/tagging/presets/items/MultiSelectTest.java
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 diff --git a/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/MultiSelectTest.java b/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/MultiSelectTest.java
a b 8 8 9 9 import org.junit.jupiter.api.Test; 10 10 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport; 11 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemTest; 11 12 import org.openstreetmap.josm.testutils.annotations.Main; 12 13 13 14 /** 14 15 * Unit tests of {@link MultiSelect} class. 15 16 */ 16 17 @Main 17 class MultiSelectTest { 18 class MultiSelectTest implements TaggingPresetItemTest { 19 @Override 20 public MultiSelect getInstance() { 21 return new MultiSelect(); 22 } 23 18 24 /** 19 * Unit test for {@link MultiSelect#addToPanel}.25 * Unit test for {@link Check#addToPanel}. 20 26 */ 27 @Override 21 28 @Test 22 void testAddToPanel() {29 public void testAddToPanel() { 23 30 JPanel p = new JPanel(); 24 31 assertEquals(0, p.getComponentCount()); 25 assertTrue( new MultiSelect().addToPanel(p, TaggingPresetItemGuiSupport.create(false)));32 assertTrue(getInstance().addToPanel(p, TaggingPresetItemGuiSupport.create(false))); 26 33 assertTrue(p.getComponentCount() > 0); 27 34 } 28 35 } -
test/unit/org/openstreetmap/josm/gui/tagging/presets/items/OptionalTest.java
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 diff --git a/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/OptionalTest.java b/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/OptionalTest.java
a b 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.gui.tagging.presets.items; 3 3 4 import static org.junit.jupiter.api.Assertions.assertEquals; 5 import static org.junit.jupiter.api.Assertions.assertFalse; 6 import static org.junit.jupiter.api.Assertions.assertTrue; 7 8 import javax.swing.JPanel; 9 10 import org.junit.jupiter.api.Test; 11 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport; 4 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemTest; 12 5 13 6 /** 14 7 * Unit tests of {@link Optional} class. 15 8 */ 16 class OptionalTest { 17 /** 18 * Unit test for {@link Optional#addToPanel}. 19 */ 20 @Test 21 void testAddToPanel() { 22 JPanel p = new JPanel(); 23 assertEquals(0, p.getComponentCount()); 24 assertFalse(new Optional().addToPanel(p, TaggingPresetItemGuiSupport.create(false))); 25 assertTrue(p.getComponentCount() > 0); 9 class OptionalTest implements TaggingPresetItemTest { 10 @Override 11 public Optional getInstance() { 12 return new Optional(); 26 13 } 27 14 } -
test/unit/org/openstreetmap/josm/gui/tagging/presets/items/PresetLinkTest.java
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 diff --git a/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/PresetLinkTest.java b/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/PresetLinkTest.java
a b 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.gui.tagging.presets.items; 3 3 4 import static org.junit.jupiter.api.Assertions.assertEquals; 5 import static org.junit.jupiter.api.Assertions.assertFalse; 6 import static org.junit.jupiter.api.Assertions.assertTrue; 7 8 import javax.swing.JPanel; 9 10 import org.junit.jupiter.api.Test; 11 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport; 4 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemTest; 12 5 import org.openstreetmap.josm.testutils.annotations.TaggingPresets; 13 6 14 7 /** 15 8 * Unit tests of {@link PresetLink} class. 16 9 */ 17 10 @TaggingPresets 18 class PresetLinkTest { 19 /** 20 * Unit test for {@link PresetLink#addToPanel}. 21 */ 22 @Test 23 void testAddToPanel() { 24 PresetLink l = new PresetLink(); 25 l.preset_name = "River"; 26 JPanel p = new JPanel(); 27 assertEquals(0, p.getComponentCount()); 28 assertFalse(l.addToPanel(p, TaggingPresetItemGuiSupport.create(false))); 29 assertTrue(p.getComponentCount() > 0); 11 class PresetLinkTest implements TaggingPresetItemTest { 12 @Override 13 public PresetLink getInstance() { 14 PresetLink presetLink = new PresetLink(); 15 presetLink.preset_name = "River"; 16 return presetLink; 30 17 } 31 18 } -
new file test/unit/org/openstreetmap/josm/gui/tagging/presets/items/RegionSpecificTest.java
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 diff --git a/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/RegionSpecificTest.java b/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/RegionSpecificTest.java new file mode 100644
- + 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.gui.tagging.presets.items; 3 4 import static org.junit.jupiter.api.Assertions.assertAll; 5 import static org.junit.jupiter.api.Assertions.assertEquals; 6 import static org.junit.jupiter.api.Assertions.assertFalse; 7 import static org.junit.jupiter.api.Assertions.assertNotEquals; 8 import static org.junit.jupiter.api.Assertions.assertThrows; 9 10 import org.junit.jupiter.api.Test; 11 import org.openstreetmap.josm.testutils.annotations.Territories; 12 import org.xml.sax.SAXException; 13 14 /** 15 * Test class for {@link RegionSpecific} 16 */ 17 @Territories 18 interface RegionSpecificTest { 19 /** 20 * Get the test instance 21 * @return The instance to test 22 */ 23 RegionSpecific getInstance(); 24 25 @Test 26 default void testSetRegions() throws SAXException { 27 final RegionSpecific regionSpecific = getInstance(); 28 if ("java.lang.Record".equals(regionSpecific.getClass().getSuperclass().getCanonicalName())) { 29 assertThrows(UnsupportedOperationException.class, () -> regionSpecific.setRegions("US")); 30 } else { 31 assertFalse(regionSpecific.regions() != null && regionSpecific.regions().contains("US"), 32 "Using US as the test region for setting regions"); 33 regionSpecific.setRegions("US"); 34 assertAll(() -> assertEquals(1, regionSpecific.regions().size()), 35 () -> assertEquals("US", regionSpecific.regions().iterator().next())); 36 } 37 } 38 39 @Test 40 default void testSetExcludeRegions() { 41 final RegionSpecific regionSpecific = getInstance(); 42 if ("java.lang.Record".equals(regionSpecific.getClass().getSuperclass().getCanonicalName())) { 43 assertThrows(UnsupportedOperationException.class, () -> regionSpecific.setExclude_regions(true)); 44 } else { 45 final boolean oldExclude = regionSpecific.exclude_regions(); 46 regionSpecific.setExclude_regions(!oldExclude); 47 assertNotEquals(oldExclude, regionSpecific.exclude_regions()); 48 } 49 } 50 } -
test/unit/org/openstreetmap/josm/gui/tagging/presets/items/RolesTest.java
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 diff --git a/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/RolesTest.java b/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/RolesTest.java
a b 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.gui.tagging.presets.items; 3 3 4 import static org.junit.jupiter.api.Assertions.assertEquals; 5 import static org.junit.jupiter.api.Assertions.assertFalse; 6 import static org.junit.jupiter.api.Assertions.assertTrue; 7 8 import javax.swing.JPanel; 9 10 import org.junit.jupiter.api.Test; 11 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport; 4 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItem; 5 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemTest; 12 6 13 7 /** 14 8 * Unit tests of {@link Roles} class. 15 9 */ 16 class RolesTest { 17 /** 18 * Unit test for {@link Roles#addToPanel}. 19 */ 20 @Test 21 void testAddToPanel() { 22 JPanel p = new JPanel(); 23 assertEquals(0, p.getComponentCount()); 24 assertFalse(new Roles().addToPanel(p, TaggingPresetItemGuiSupport.create(false))); 25 assertTrue(p.getComponentCount() > 0); 10 class RolesTest implements TaggingPresetItemTest { 11 @Override 12 public TaggingPresetItem getInstance() { 13 return new Roles(); 26 14 } 27 15 } -
test/unit/org/openstreetmap/josm/gui/tagging/presets/items/SpaceTest.java
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 diff --git a/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/SpaceTest.java b/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/SpaceTest.java
a b 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.gui.tagging.presets.items; 3 3 4 import static org.junit.jupiter.api.Assertions.assertEquals; 5 import static org.junit.jupiter.api.Assertions.assertFalse; 6 import static org.junit.jupiter.api.Assertions.assertTrue; 7 8 import javax.swing.JPanel; 9 10 import org.junit.jupiter.api.Test; 11 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport; 4 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemTest; 12 5 13 6 /** 14 7 * Unit tests of {@link Space} class. 15 8 */ 16 class SpaceTest { 17 /** 18 * Unit test for {@link Space#addToPanel}. 19 */ 20 @Test 21 void testAddToPanel() { 22 JPanel p = new JPanel(); 23 assertEquals(0, p.getComponentCount()); 24 assertFalse(new Space().addToPanel(p, TaggingPresetItemGuiSupport.create(false))); 25 assertTrue(p.getComponentCount() > 0); 9 class SpaceTest implements TaggingPresetItemTest { 10 @Override 11 public Space getInstance() { 12 return new Space(); 26 13 } 27 14 } -
test/unit/org/openstreetmap/josm/gui/tagging/presets/items/TextTest.java
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 diff --git a/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/TextTest.java b/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/TextTest.java
a b 8 8 9 9 import org.junit.jupiter.api.Test; 10 10 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport; 11 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemTest; 11 12 import org.openstreetmap.josm.testutils.annotations.Main; 12 13 13 14 /** 14 15 * Unit tests of {@link Text} class. 15 16 */ 16 17 @Main 17 class TextTest { 18 class TextTest implements TaggingPresetItemTest { 19 @Override 20 public Text getInstance() { 21 return new Text(); 22 } 23 18 24 /** 19 * Unit test for {@link Text#addToPanel}.25 * Unit test for {@link Check#addToPanel}. 20 26 */ 27 @Override 21 28 @Test 22 void testAddToPanel() {29 public void testAddToPanel() { 23 30 JPanel p = new JPanel(); 24 31 assertEquals(0, p.getComponentCount()); 25 assertTrue( new Text().addToPanel(p, TaggingPresetItemGuiSupport.create(false)));32 assertTrue(getInstance().addToPanel(p, TaggingPresetItemGuiSupport.create(false))); 26 33 assertTrue(p.getComponentCount() > 0); 27 34 } 28 35 } -
new file test/unit/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetItemTest.java
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 diff --git a/test/unit/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetItemTest.java b/test/unit/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetItemTest.java new file mode 100644
- + 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.gui.tagging.presets; 3 4 import static org.junit.jupiter.api.Assertions.assertEquals; 5 import static org.junit.jupiter.api.Assertions.assertFalse; 6 import static org.junit.jupiter.api.Assertions.assertNotEquals; 7 8 import javax.swing.JPanel; 9 10 import org.junit.jupiter.api.Test; 11 12 /** 13 * Test class for {@link TaggingPresetItem} 14 */ 15 public interface TaggingPresetItemTest { 16 /** 17 * Get the instance to test 18 * 19 * @return The item to test 20 */ 21 TaggingPresetItem getInstance(); 22 23 /** 24 * Test method for {@link TaggingPresetItem#addToPanel(JPanel, TaggingPresetItemGuiSupport)} 25 */ 26 @Test 27 default void testAddToPanel() { 28 TaggingPresetItem item = getInstance(); 29 JPanel p = new JPanel(); 30 assertEquals(0, p.getComponentCount()); 31 assertFalse(item.addToPanel(p, TaggingPresetItemGuiSupport.create(false))); 32 assertNotEquals(0, p.getComponentCount()); 33 } 34 } -
test/unit/org/openstreetmap/josm/testutils/annotations/TaggingPresets.java
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 diff --git a/test/unit/org/openstreetmap/josm/testutils/annotations/TaggingPresets.java b/test/unit/org/openstreetmap/josm/testutils/annotations/TaggingPresets.java
a b 8 8 import java.lang.annotation.Target; 9 9 import java.util.Collection; 10 10 11 import org.junit.jupiter.api.extension.BeforeAllCallback; 11 12 import org.junit.jupiter.api.extension.BeforeEachCallback; 12 13 import org.junit.jupiter.api.extension.ExtendWith; 13 14 import org.junit.jupiter.api.extension.ExtensionContext; … … 24 25 @Retention(RetentionPolicy.RUNTIME) 25 26 @Target({ ElementType.METHOD, ElementType.TYPE }) 26 27 @BasicPreferences 28 @Territories 27 29 @ExtendWith(TaggingPresets.TaggingPresetsExtension.class) 28 30 public @interface TaggingPresets { 29 31 30 class TaggingPresetsExtension implements BeforeEachCallback {32 class TaggingPresetsExtension implements BeforeEachCallback, BeforeAllCallback { 31 33 private static int expectedHashcode = 0; 32 34 35 @Override 36 public void beforeAll(ExtensionContext extensionContext) throws Exception { 37 setup(); 38 } 39 33 40 @Override 34 41 public void beforeEach(ExtensionContext extensionContext) { 35 42 setup(); 36 43 } 37 44 38 45 /** 39 * Set up the tagging presets46 * Set up the tagging presets 40 47 */ 41 48 public static synchronized void setup() { 42 49 final Collection<TaggingPreset> oldPresets = org.openstreetmap.josm.gui.tagging.presets.TaggingPresets.getTaggingPresets();