Changeset 20155 in osm for applications/editors/josm
- Timestamp:
- 2010-02-25T22:40:01+01:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/TagChecker.java
r19611 r20155 5 5 6 6 import java.awt.Dimension; 7 import java.awt.GridBagConstraints; 7 8 import java.awt.GridBagLayout; 8 9 import java.awt.event.ActionEvent; … … 41 42 import org.openstreetmap.josm.data.osm.Node; 42 43 import org.openstreetmap.josm.data.osm.OsmPrimitive; 44 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 43 45 import org.openstreetmap.josm.data.osm.OsmUtils; 44 46 import org.openstreetmap.josm.data.osm.Relation; … … 149 151 { 150 152 super(tr("Properties checker :"), 151 tr("This plugin checks for errors in property keys and values."));153 tr("This plugin checks for errors in property keys and values.")); 152 154 } 153 155 … … 327 329 /* for(String a : OsmPrimitive.getDirectionKeys()) 328 330 presetsValueData.add(a); 329 */331 */ 330 332 for(String a : Main.pref.getCollection(PreferenceEditor.PREFIX + ".knownkeys", 331 Arrays.asList(new String[]{"is_in", "int_ref", "fixme", "population"})))333 Arrays.asList(new String[]{"is_in", "int_ref", "fixme", "population"}))) 332 334 presetsValueData.add(a); 333 335 for(TaggingPreset p : presets) … … 431 433 { 432 434 errors.add( new TestError(this, Severity.ERROR, tr("Illegal tag/value combinations"), 433 tr("Illegal tag/value combinations"), tr("Illegal tag/value combinations"), 1272, p) );435 tr("Illegal tag/value combinations"), tr("Illegal tag/value combinations"), 1272, p) ); 434 436 withErrors.add(p, "TC"); 435 437 } 436 438 } 437 439 440 Map<String, String> keys = p.getKeys(); 438 441 for(CheckerData d : checkerData) 439 442 { 440 if(d.match(p ))443 if(d.match(p, keys)) 441 444 { 442 445 errors.add( new TestError(this, d.getSeverity(), tr("Illegal tag/value combinations"), 443 d.getDescription(), d.getDescriptionOrig(), d.getCode(), p) );446 d.getDescription(), d.getDescriptionOrig(), d.getCode(), p) ); 444 447 withErrors.add(p, "TC"); 445 448 } … … 456 459 translated the stuff before. Makes the ignore file language dependend. */ 457 460 errors.add( new TestError(this, Severity.WARNING, tr("Painting problem"), 458 s, s, PAINT, p) );461 s, s, PAINT, p) ); 459 462 withErrors.add(p, "P"); 460 463 } … … 471 474 { 472 475 errors.add( new TestError(this, Severity.WARNING, tr("Tags with empty values"), 473 tr(s, key), MessageFormat.format(s, key), EMPTY_VALUES, p) );476 tr(s, key), MessageFormat.format(s, key), EMPTY_VALUES, p) ); 474 477 withErrors.add(p, "EV"); 475 478 } … … 477 480 { 478 481 errors.add( new TestError(this, Severity.WARNING, tr("Invalid property key"), 479 tr(s, key), MessageFormat.format(s, key), INVALID_KEY, p) );482 tr(s, key), MessageFormat.format(s, key), INVALID_KEY, p) ); 480 483 withErrors.add(p, "IPK"); 481 484 } … … 483 486 { 484 487 errors.add( new TestError(this, Severity.WARNING, tr("Invalid white space in property key"), 485 tr(s, key), MessageFormat.format(s, key), INVALID_KEY_SPACE, p) );488 tr(s, key), MessageFormat.format(s, key), INVALID_KEY_SPACE, p) ); 486 489 withErrors.add(p, "IPK"); 487 490 } … … 489 492 { 490 493 errors.add( new TestError(this, Severity.OTHER, tr("Property values start or end with white space"), 491 tr(s, key), MessageFormat.format(s, key), INVALID_SPACE, p) );494 tr(s, key), MessageFormat.format(s, key), INVALID_SPACE, p) ); 492 495 withErrors.add(p, "SPACE"); 493 496 } … … 495 498 { 496 499 errors.add( new TestError(this, Severity.OTHER, tr("Property values contain HTML entity"), 497 tr(s, key), MessageFormat.format(s, key), INVALID_HTML, p) );500 tr(s, key), MessageFormat.format(s, key), INVALID_HTML, p) ); 498 501 withErrors.add(p, "HTML"); 499 502 } … … 523 526 String i = marktr("Key ''{0}'' not in presets."); 524 527 errors.add( new TestError(this, Severity.OTHER, tr("Presets do not contain property key"), 525 tr(i, key), MessageFormat.format(i, key), INVALID_VALUE, p) );528 tr(i, key), MessageFormat.format(i, key), INVALID_VALUE, p) ); 526 529 withErrors.add(p, "UPK"); 527 530 } … … 546 549 String i = marktr("Value ''{0}'' for key ''{1}'' not in presets."); 547 550 errors.add( new TestError(this, Severity.OTHER, tr("Presets do not contain property value"), 548 tr(i, prop.getValue(), key), MessageFormat.format(i, prop.getValue(), key), INVALID_VALUE, p) );551 tr(i, prop.getValue(), key), MessageFormat.format(i, prop.getValue(), key), INVALID_VALUE, p) ); 549 552 withErrors.add(p, "UPV"); 550 553 } 551 554 } 552 555 } 553 554 555 556 557 558 559 560 561 562 556 if (checkFixmes && value != null && value.length() > 0) { 557 if ((value.toLowerCase().contains("FIXME") 558 || value.contains("check and delete") 559 || key.contains("todo") || key.toLowerCase().contains("fixme")) 560 && !withErrors.contains(p, "FIXME")) { 561 errors.add(new TestError(this, Severity.OTHER, 562 tr("FIXMES"), FIXME, p)); 563 withErrors.add(p, "FIXME"); 564 } 565 } 563 566 } 564 567 } … … 600 603 { 601 604 GBC a = GBC.eol(); 602 a.anchor = G BC.EAST;605 a.anchor = GridBagConstraints.EAST; 603 606 604 607 testPanel.add( new JLabel(name), GBC.eol().insets(3,0,0,0) ); … … 637 640 tr("TagChecker source"), 638 641 JOptionPane.QUESTION_MESSAGE 639 642 ); 640 643 if (source != null) 641 644 ((DefaultListModel)Sources.getModel()).addElement(source); … … 668 671 tr("Information"), 669 672 JOptionPane.INFORMATION_MESSAGE 670 673 ); 671 674 } 672 675 } … … 703 706 704 707 testPanel.add(new JLabel(tr("Data sources")), GBC.eol().insets(23,0,0,0)); 705 testPanel.add(new JScrollPane(Sources), GBC.eol().insets(23,0,0,0).fill(G BC.HORIZONTAL));708 testPanel.add(new JScrollPane(Sources), GBC.eol().insets(23,0,0,0).fill(GridBagConstraints.HORIZONTAL)); 706 709 final JPanel buttonPanel = new JPanel(new GridBagLayout()); 707 testPanel.add(buttonPanel, GBC.eol().fill(G BC.HORIZONTAL));710 testPanel.add(buttonPanel, GBC.eol().fill(GridBagConstraints.HORIZONTAL)); 708 711 buttonPanel.add(addSrcButton, GBC.std().insets(0,5,0,0)); 709 712 buttonPanel.add(editSrcButton, GBC.std().insets(5,5,5,0)); … … 837 840 { 838 841 commands.add( new ChangePropertyKeyCommand(Collections.singleton(primitives.get(i)), 839 key, replacementKey) );842 key, replacementKey) ); 840 843 } 841 844 } … … 879 882 private String description; 880 883 private List<CheckerElement> data = new ArrayList<CheckerElement>(); 881 private Integer type = 0;882 private Integercode;884 private OsmPrimitiveType type; 885 private int code; 883 886 protected Severity severity; 884 protected static int NODE = 1;885 protected static int WAY = 2;886 protected static int RELATION = 3;887 protected static int ALL = 4;888 887 protected static int TAG_CHECK_ERROR = 1250; 889 888 protected static int TAG_CHECK_WARN = 1260; … … 915 914 else 916 915 tag = n.startsWith("/") ? getPattern(n) : n; 917 noMatch = m.group(2).equals("!="); 918 n = m.group(3).trim(); 919 if(n.equals("*")) 920 valueAll = true; 921 else if(n.equals("BOOLEAN_TRUE")) 922 { 923 valueBool = true; 924 value = OsmUtils.trueval; 925 } 926 else if(n.equals("BOOLEAN_FALSE")) 927 { 928 valueBool = true; 929 value = OsmUtils.falseval; 930 } 931 else 932 value = n.startsWith("/") ? getPattern(n) : n; 933 } 934 public boolean match(OsmPrimitive osm) 935 { 936 for(Entry<String, String> prop: osm.getKeys().entrySet()) 937 { 916 noMatch = m.group(2).equals("!="); 917 n = m.group(3).trim(); 918 if(n.equals("*")) 919 valueAll = true; 920 else if(n.equals("BOOLEAN_TRUE")) 921 { 922 valueBool = true; 923 value = OsmUtils.trueval; 924 } 925 else if(n.equals("BOOLEAN_FALSE")) 926 { 927 valueBool = true; 928 value = OsmUtils.falseval; 929 } 930 else 931 value = n.startsWith("/") ? getPattern(n) : n; 932 } 933 public boolean match(OsmPrimitive osm, Map<String, String> keys) { 934 for(Entry<String, String> prop: keys.entrySet()) { 938 935 String key = prop.getKey(); 939 936 String val = valueBool ? OsmUtils.getNamedOsmBoolean(prop.getValue()) : prop.getValue(); 940 937 if((tagAll || (tag instanceof Pattern ? ((Pattern)tag).matcher(key).matches() : key.equals(tag))) 941 && (valueAll || (value instanceof Pattern ? ((Pattern)value).matcher(val).matches() : val.equals(value))))938 && (valueAll || (value instanceof Pattern ? ((Pattern)value).matcher(val).matches() : val.equals(value)))) 942 939 return !noMatch; 943 940 } … … 962 959 String[] n = str.split(" *: *", 3); 963 960 if(n[0].equals("way")) 964 type = WAY;961 type = OsmPrimitiveType.WAY; 965 962 else if(n[0].equals("node")) 966 type = NODE;963 type = OsmPrimitiveType.NODE; 967 964 else if(n[0].equals("relation")) 968 type = RELATION;965 type = OsmPrimitiveType.RELATION; 969 966 else if(n[0].equals("*")) 970 type = ALL;971 if(type == 0 || n.length != 3)967 type = null; 968 else 972 969 return tr("Could not find element type"); 970 if (n.length != 3) 971 return tr("Incorrect number of parameters"); 972 973 973 if(n[1].equals("W")) 974 974 { … … 1005 1005 return null; 1006 1006 } 1007 public boolean match(OsmPrimitive osm) 1008 { 1009 if(osm.getKeys() == null || (type == NODE && !(osm instanceof Node)) 1010 || (type == RELATION && !(osm instanceof Relation)) || (type == WAY && !(osm instanceof Way))) 1007 public boolean match(OsmPrimitive osm, Map<String, String> keys) 1008 { 1009 if (type != null && OsmPrimitiveType.from(osm) != type) 1011 1010 return false; 1012 for(CheckerElement ce : data) 1013 {1014 if(!ce.match(osm ))1011 1012 for(CheckerElement ce : data) { 1013 if(!ce.match(osm, keys)) 1015 1014 return false; 1016 1015 } … … 1029 1028 return severity; 1030 1029 } 1031 public int getCode() 1032 { 1033 return code + type; 1030 1031 public int getCode() { 1032 if (type == null) { 1033 return code; 1034 } else { 1035 return code + type.ordinal() + 1; 1036 } 1034 1037 } 1035 1038 } -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/util/AgregatePrimitivesVisitor.java
r17540 r20155 2 2 3 3 import java.util.Collection; 4 import java.util. LinkedList;4 import java.util.HashSet; 5 5 6 6 import org.openstreetmap.josm.data.osm.Node; … … 21 21 { 22 22 /** Aggregated data */ 23 Collection<OsmPrimitive> aggregatedData; 24 25 /** 26 * Constructor 27 */ 28 public AgregatePrimitivesVisitor() 29 { 30 aggregatedData = new LinkedList<OsmPrimitive>(); 31 } 23 final Collection<OsmPrimitive> aggregatedData = new HashSet<OsmPrimitive>(); 32 24 33 25 /**
Note:
See TracChangeset
for help on using the changeset viewer.