Changeset 12656 in josm for trunk/src/org
- Timestamp:
- 2017-08-26T00:40:19+02:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 added
- 24 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java
r12643 r12656 46 46 import org.openstreetmap.josm.actions.JosmAction; 47 47 import org.openstreetmap.josm.actions.ParameterizedAction; 48 import org.openstreetmap.josm.actions.search.SearchCompiler.ParseError;49 48 import org.openstreetmap.josm.data.osm.DataSet; 50 49 import org.openstreetmap.josm.data.osm.Filter; 51 50 import org.openstreetmap.josm.data.osm.OsmPrimitive; 51 import org.openstreetmap.josm.data.osm.search.SearchParseError; 52 import org.openstreetmap.josm.data.osm.search.SearchCompiler; 52 53 import org.openstreetmap.josm.gui.ExtendedDialog; 53 54 import org.openstreetmap.josm.gui.MainApplication; … … 380 381 SearchCompiler.compile(ss); 381 382 return true; 382 } catch (ParseError | MapCSSException e) { 383 } catch (SearchParseError | MapCSSException e) { 383 384 return false; 384 385 } … … 418 419 SearchCompiler.compile(ss); 419 420 super.buttonAction(buttonIndex, evt); 420 } catch (ParseError e) { 421 } catch (SearchParseError e) { 421 422 Logging.debug(e); 422 423 JOptionPane.showMessageDialog( … … 828 829 } 829 830 subMonitor.finishTask(); 830 } catch (ParseError e) { 831 } catch (SearchParseError e) { 831 832 Logging.debug(e); 832 833 JOptionPane.showMessageDialog( -
trunk/src/org/openstreetmap/josm/data/gpx/WayPoint.java
r12620 r12656 8 8 import java.util.Objects; 9 9 10 import org.openstreetmap.josm.actions.search.SearchCompiler.Match;11 10 import org.openstreetmap.josm.data.coor.EastNorth; 12 11 import org.openstreetmap.josm.data.coor.ILatLon; 13 12 import org.openstreetmap.josm.data.coor.LatLon; 13 import org.openstreetmap.josm.data.osm.search.SearchCompiler.Match; 14 14 import org.openstreetmap.josm.data.projection.Projecting; 15 15 import org.openstreetmap.josm.tools.Logging; -
trunk/src/org/openstreetmap/josm/data/osm/FilterMatcher.java
r12630 r12656 7 7 8 8 import org.openstreetmap.josm.actions.search.SearchAction.SearchMode; 9 import org.openstreetmap.josm. actions.search.SearchCompiler;10 import org.openstreetmap.josm. actions.search.SearchCompiler.Match;11 import org.openstreetmap.josm. actions.search.SearchCompiler.Not;12 import org.openstreetmap.josm. actions.search.SearchCompiler.ParseError;9 import org.openstreetmap.josm.data.osm.search.SearchParseError; 10 import org.openstreetmap.josm.data.osm.search.SearchCompiler; 11 import org.openstreetmap.josm.data.osm.search.SearchCompiler.Match; 12 import org.openstreetmap.josm.data.osm.search.SearchCompiler.Not; 13 13 import org.openstreetmap.josm.gui.MainApplication; 14 14 import org.openstreetmap.josm.gui.MapFrame; … … 79 79 private final boolean isInverted; 80 80 81 FilterInfo(Filter filter) throws ParseError { 81 FilterInfo(Filter filter) throws SearchParseError { 82 82 if (filter.mode == SearchMode.remove || filter.mode == SearchMode.in_selection) { 83 83 isDelete = true; … … 98 98 * Clears the current filters, and adds the given filters 99 99 * @param filters the filters to add 100 * @throws ParseError if the search expression in one of the filters cannot be parsed 101 */ 102 public void update(Collection<Filter> filters) throws ParseError { 100 * @throws SearchParseError if the search expression in one of the filters cannot be parsed 101 */ 102 public void update(Collection<Filter> filters) throws SearchParseError { 103 103 reset(); 104 104 for (Filter filter : filters) { … … 118 118 * Adds a filter to the currently used filters 119 119 * @param filter the filter to add 120 * @throws ParseError if the search expression in the filter cannot be parsed 121 */ 122 public void add(final Filter filter) throws ParseError { 120 * @throws SearchParseError if the search expression in the filter cannot be parsed 121 */ 122 public void add(final Filter filter) throws SearchParseError { 123 123 if (!filter.enable) { 124 124 return; … … 330 330 * @param filters filters to add to the resulting filter matcher 331 331 * @return a new {@code FilterMatcher} containing the given filters 332 * @throws ParseError if the search expression in a filter cannot be parsed 332 * @throws SearchParseError if the search expression in a filter cannot be parsed 333 333 * @since 12383 334 334 */ 335 public static FilterMatcher of(Filter... filters) throws ParseError { 335 public static FilterMatcher of(Filter... filters) throws SearchParseError { 336 336 FilterMatcher result = new FilterMatcher(); 337 337 for (Filter filter : filters) { -
trunk/src/org/openstreetmap/josm/data/osm/FilterModel.java
r12636 r12656 17 17 18 18 import org.openstreetmap.josm.Main; 19 import org.openstreetmap.josm.actions.search.SearchCompiler.ParseError;20 19 import org.openstreetmap.josm.data.osm.Filter.FilterPreferenceEntry; 20 import org.openstreetmap.josm.data.osm.search.SearchParseError; 21 21 import org.openstreetmap.josm.gui.MainApplication; 22 22 import org.openstreetmap.josm.gui.layer.OsmDataLayer; … … 52 52 try { 53 53 filterMatcher.add(filter); 54 } catch (ParseError e) { 54 } catch (SearchParseError e) { 55 55 Logging.error(e); 56 56 JOptionPane.showMessageDialog( -
trunk/src/org/openstreetmap/josm/data/osm/FilterWorker.java
r12388 r12656 5 5 import java.util.Collections; 6 6 7 import org.openstreetmap.josm.actions.search.SearchCompiler.ParseError;8 7 import org.openstreetmap.josm.data.osm.FilterMatcher.FilterType; 8 import org.openstreetmap.josm.data.osm.search.SearchParseError; 9 9 import org.openstreetmap.josm.tools.SubclassFilteredCollection; 10 10 … … 28 28 * @param filters the filters 29 29 * @return true, if the filter state (normal / disabled / hidden) of any primitive has changed in the process 30 * @throws ParseError if the search expression in a filter cannot be parsed 30 * @throws SearchParseError if the search expression in a filter cannot be parsed 31 31 * @since 12383 32 32 */ 33 public static boolean executeFilters(Collection<OsmPrimitive> all, Filter... filters) throws ParseError { 33 public static boolean executeFilters(Collection<OsmPrimitive> all, Filter... filters) throws SearchParseError { 34 34 return executeFilters(all, FilterMatcher.of(filters)); 35 35 } -
trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r12620 r12656 21 21 22 22 import org.openstreetmap.josm.Main; 23 import org.openstreetmap.josm. actions.search.SearchCompiler;24 import org.openstreetmap.josm. actions.search.SearchCompiler.Match;25 import org.openstreetmap.josm. actions.search.SearchCompiler.ParseError;23 import org.openstreetmap.josm.data.osm.search.SearchParseError; 24 import org.openstreetmap.josm.data.osm.search.SearchCompiler; 25 import org.openstreetmap.josm.data.osm.search.SearchCompiler.Match; 26 26 import org.openstreetmap.josm.data.osm.visitor.Visitor; 27 27 import org.openstreetmap.josm.gui.mappaint.StyleCache; … … 761 761 try { 762 762 return SearchCompiler.compile(Main.pref.get(prefName, defaultValue)); 763 } catch (ParseError e) { 763 } catch (SearchParseError e) { 764 764 Logging.log(Logging.LEVEL_ERROR, "Unable to compile pattern for " + prefName + ", trying default pattern:", e); 765 765 } … … 767 767 try { 768 768 return SearchCompiler.compile(defaultValue); 769 } catch (ParseError e2) { 769 } catch (SearchParseError e2) { 770 770 throw new AssertionError("Unable to compile default pattern for direction keys: " + e2.getMessage(), e2); 771 771 } -
trunk/src/org/openstreetmap/josm/data/osm/search/PushbackTokenizer.java
r12651 r12656 1 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm. actions.search;2 package org.openstreetmap.josm.data.osm.search; 3 3 4 4 import static org.openstreetmap.josm.tools.I18n.marktr; … … 11 11 import java.util.Objects; 12 12 13 import org.openstreetmap.josm.actions.search.SearchCompiler.ParseError;14 13 import org.openstreetmap.josm.tools.JosmRuntimeException; 15 14 … … 17 16 * This class is used to parse a search string and split it into tokens. 18 17 * It provides methods to parse numbers and extract strings. 18 * @since 12656 (moved from actions.search package) 19 19 */ 20 20 public class PushbackTokenizer { … … 300 300 * @param errorMessage The error if the number cannot be read 301 301 * @return The number that was found 302 * @throws ParseError if there is no number 303 */ 304 public long readNumber(String errorMessage) throws ParseError { 302 * @throws SearchParseError if there is no number 303 */ 304 public long readNumber(String errorMessage) throws SearchParseError { 305 305 if ((nextToken() == Token.KEY) && (currentNumber != null)) 306 306 return currentNumber; 307 307 else 308 throw new ParseError(errorMessage); 308 throw new SearchParseError(errorMessage); 309 309 } 310 310 … … 321 321 * @param errorMessage The error if the input is malformed 322 322 * @return The range that was found 323 * @throws ParseError If the input is not as expected for a range 324 */ 325 public Range readRange(String errorMessage) throws ParseError { 323 * @throws SearchParseError If the input is not as expected for a range 324 */ 325 public Range readRange(String errorMessage) throws SearchParseError { 326 326 if (nextToken() != Token.KEY || (currentNumber == null && currentRange == null)) { 327 throw new ParseError(errorMessage); 327 throw new SearchParseError(errorMessage); 328 328 } else if (!isRange && currentNumber != null) { 329 329 if (currentNumber >= 0) { … … 337 337 return new Range(currentNumber, currentRange); 338 338 } else { 339 throw new ParseError(errorMessage); 339 throw new SearchParseError(errorMessage); 340 340 } 341 341 } -
trunk/src/org/openstreetmap/josm/data/osm/search/SearchCompiler.java
r12651 r12656 1 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm. actions.search;2 package org.openstreetmap.josm.data.osm.search; 3 3 4 4 import static org.openstreetmap.josm.tools.I18n.marktr; … … 24 24 25 25 import org.openstreetmap.josm.Main; 26 import org.openstreetmap.josm.actions.search.PushbackTokenizer.Range; 27 import org.openstreetmap.josm.actions.search.PushbackTokenizer.Token; 26 import org.openstreetmap.josm.actions.search.SearchAction; 28 27 import org.openstreetmap.josm.data.Bounds; 29 28 import org.openstreetmap.josm.data.coor.LatLon; … … 36 35 import org.openstreetmap.josm.data.osm.Tagged; 37 36 import org.openstreetmap.josm.data.osm.Way; 37 import org.openstreetmap.josm.data.osm.search.PushbackTokenizer.Range; 38 import org.openstreetmap.josm.data.osm.search.PushbackTokenizer.Token; 38 39 import org.openstreetmap.josm.gui.MainApplication; 39 40 import org.openstreetmap.josm.gui.mappaint.Environment; … … 53 54 54 55 /** 55 Implements a google-like search. 56 <br> 57 Grammar: 58 <pre> 59 expression = 60 fact | expression 61 fact expression 62 fact 63 64 fact = 65 ( expression ) 66 -fact 67 term? 68 term=term 69 term:term 70 term 71 </pre> 72 73 @author Imi 56 * Implements a google-like search. 57 * <br> 58 * Grammar: 59 * <pre> 60 * expression = 61 * fact | expression 62 * fact expression 63 * fact 64 * 65 * fact = 66 * ( expression ) 67 * -fact 68 * term? 69 * term=term 70 * term:term 71 * term 72 * </pre> 73 * 74 * @author Imi 75 * @since 12656 (moved from actions.search package) 74 76 */ 75 77 public class SearchCompiler { … … 126 128 127 129 @Override 128 public Match get(String keyword, PushbackTokenizer tokenizer) throws ParseError { 130 public Match get(String keyword, PushbackTokenizer tokenizer) throws SearchParseError { 129 131 switch(keyword) { 130 132 case "modified": … … 198 200 minDate = DateUtils.fromString(rangeA1.isEmpty() ? "1980" : rangeA1).getTime(); 199 201 } catch (UncheckedParseException ex) { 200 throw new ParseError(tr("Cannot parse timestamp ''{0}''", rangeA1), ex); 202 throw new SearchParseError(tr("Cannot parse timestamp ''{0}''", rangeA1), ex); 201 203 } 202 204 try { … … 204 206 maxDate = rangeA2.isEmpty() ? System.currentTimeMillis() : DateUtils.fromString(rangeA2).getTime(); 205 207 } catch (UncheckedParseException ex) { 206 throw new ParseError(tr("Cannot parse timestamp ''{0}''", rangeA2), ex); 208 throw new SearchParseError(tr("Cannot parse timestamp ''{0}''", rangeA2), ex); 207 209 } 208 210 return new TimestampRange(minDate, maxDate); 209 211 } else { 210 throw new ParseError("<html>" + tr("Expecting {0} after {1}", "<i>min</i>/<i>max</i>", "<i>timestamp</i>")); 212 throw new SearchParseError("<html>" + tr("Expecting {0} after {1}", "<i>min</i>/<i>max</i>", "<i>timestamp</i>")); 211 213 } 212 214 } 213 215 } else { 214 throw new ParseError("<html>" + tr("Expecting {0} after {1}", "<code>:</code>", "<i>" + keyword + "</i>")); 216 throw new SearchParseError("<html>" + tr("Expecting {0} after {1}", "<code>:</code>", "<i>" + keyword + "</i>")); 215 217 } 216 218 } … … 252 254 253 255 public interface SimpleMatchFactory extends MatchFactory { 254 Match get(String keyword, PushbackTokenizer tokenizer) throws ParseError; 256 Match get(String keyword, PushbackTokenizer tokenizer) throws SearchParseError; 255 257 } 256 258 257 259 public interface UnaryMatchFactory extends MatchFactory { 258 UnaryMatch get(String keyword, Match matchOperand, PushbackTokenizer tokenizer) throws ParseError; 260 UnaryMatch get(String keyword, Match matchOperand, PushbackTokenizer tokenizer) throws SearchParseError; 259 261 } 260 262 261 263 public interface BinaryMatchFactory extends MatchFactory { 262 AbstractBinaryMatch get(String keyword, Match lhs, Match rhs, PushbackTokenizer tokenizer) throws ParseError; 264 AbstractBinaryMatch get(String keyword, Match lhs, Match rhs, PushbackTokenizer tokenizer) throws SearchParseError; 263 265 } 264 266 265 267 /** 266 268 * Base class for all search criteria. If the criterion only depends on an object's tags, 267 * inherit from {@link org.openstreetmap.josm. actions.search.SearchCompiler.TaggedMatch}.269 * inherit from {@link org.openstreetmap.josm.data.osm.search.SearchCompiler.TaggedMatch}. 268 270 */ 269 271 public abstract static class Match implements Predicate<OsmPrimitive> { … … 536 538 } 537 539 538 Id(PushbackTokenizer tokenizer) throws ParseError { 540 Id(PushbackTokenizer tokenizer) throws SearchParseError { 539 541 this(tokenizer.readRange(tr("Range of primitive ids expected"))); 540 542 } … … 559 561 } 560 562 561 ChangesetId(PushbackTokenizer tokenizer) throws ParseError { 563 ChangesetId(PushbackTokenizer tokenizer) throws SearchParseError { 562 564 this(tokenizer.readRange(tr("Range of changeset ids expected"))); 563 565 } … … 582 584 } 583 585 584 Version(PushbackTokenizer tokenizer) throws ParseError { 586 Version(PushbackTokenizer tokenizer) throws SearchParseError { 585 587 this(tokenizer.readRange(tr("Range of versions expected"))); 586 588 } … … 607 609 private final boolean caseSensitive; 608 610 609 KeyValue(String key, String value, boolean regexSearch, boolean caseSensitive) throws ParseError { 611 KeyValue(String key, String value, boolean regexSearch, boolean caseSensitive) throws SearchParseError { 610 612 this.caseSensitive = caseSensitive; 611 613 if (regexSearch) { … … 615 617 this.keyPattern = Pattern.compile(key, searchFlags); 616 618 } catch (PatternSyntaxException e) { 617 throw new ParseError(tr(rxErrorMsg, e.getPattern(), e.getIndex(), e.getMessage()), e); 619 throw new SearchParseError(tr(rxErrorMsg, e.getPattern(), e.getIndex(), e.getMessage()), e); 618 620 } catch (IllegalArgumentException e) { 619 throw new ParseError(tr(rxErrorMsgNoPos, key, e.getMessage()), e); 621 throw new SearchParseError(tr(rxErrorMsgNoPos, key, e.getMessage()), e); 620 622 } 621 623 try { 622 624 this.valuePattern = Pattern.compile(value, searchFlags); 623 625 } catch (PatternSyntaxException e) { 624 throw new ParseError(tr(rxErrorMsg, e.getPattern(), e.getIndex(), e.getMessage()), e); 626 throw new SearchParseError(tr(rxErrorMsg, e.getPattern(), e.getIndex(), e.getMessage()), e); 625 627 } catch (IllegalArgumentException | StringIndexOutOfBoundsException e) { 626 throw new ParseError(tr(rxErrorMsgNoPos, value, e.getMessage()), e); 628 throw new SearchParseError(tr(rxErrorMsgNoPos, value, e.getMessage()), e); 627 629 } 628 630 this.key = key; … … 771 773 * @param key key 772 774 * @param value value 773 * @throws ParseError if a parse error occurs 775 * @throws SearchParseError if a parse error occurs 774 776 */ 775 public ExactKeyValue(boolean regexp, String key, String value) throws ParseError { 777 public ExactKeyValue(boolean regexp, String key, String value) throws SearchParseError { 776 778 if ("".equals(key)) 777 throw new ParseError(tr("Key cannot be empty when tag operator is used. Sample use: key=value")); 779 throw new SearchParseError(tr("Key cannot be empty when tag operator is used. Sample use: key=value")); 778 780 this.key = key; 779 781 this.value = value == null ? "" : value; … … 812 814 keyPattern = Pattern.compile(key, regexFlags(false)); 813 815 } catch (PatternSyntaxException e) { 814 throw new ParseError(tr(rxErrorMsg, e.getPattern(), e.getIndex(), e.getMessage()), e); 816 throw new SearchParseError(tr(rxErrorMsg, e.getPattern(), e.getIndex(), e.getMessage()), e); 815 817 } catch (IllegalArgumentException e) { 816 throw new ParseError(tr(rxErrorMsgNoPos, key, e.getMessage()), e); 818 throw new SearchParseError(tr(rxErrorMsgNoPos, key, e.getMessage()), e); 817 819 } 818 820 } else { … … 823 825 valuePattern = Pattern.compile(this.value, regexFlags(false)); 824 826 } catch (PatternSyntaxException e) { 825 throw new ParseError(tr(rxErrorMsg, e.getPattern(), e.getIndex(), e.getMessage()), e); 827 throw new SearchParseError(tr(rxErrorMsg, e.getPattern(), e.getIndex(), e.getMessage()), e); 826 828 } catch (IllegalArgumentException e) { 827 throw new ParseError(tr(rxErrorMsgNoPos, value, e.getMessage()), e); 829 throw new SearchParseError(tr(rxErrorMsgNoPos, value, e.getMessage()), e); 828 830 } 829 831 } else { … … 893 895 private final boolean caseSensitive; 894 896 895 Any(String s, boolean regexSearch, boolean caseSensitive) throws ParseError { 897 Any(String s, boolean regexSearch, boolean caseSensitive) throws SearchParseError { 896 898 s = Normalizer.normalize(s, Normalizer.Form.NFC); 897 899 this.caseSensitive = caseSensitive; … … 900 902 this.searchRegex = Pattern.compile(s, regexFlags(caseSensitive)); 901 903 } catch (PatternSyntaxException e) { 902 throw new ParseError(tr(rxErrorMsg, e.getPattern(), e.getIndex(), e.getMessage()), e); 904 throw new SearchParseError(tr(rxErrorMsg, e.getPattern(), e.getIndex(), e.getMessage()), e); 903 905 } catch (IllegalArgumentException | StringIndexOutOfBoundsException e) { 904 906 // StringIndexOutOfBoundsException catched because of https://bugs.openjdk.java.net/browse/JI-9044959 905 907 // See #13870: To remove after we switch to a version of Java which resolves this bug 906 throw new ParseError(tr(rxErrorMsgNoPos, s, e.getMessage()), e); 908 throw new SearchParseError(tr(rxErrorMsgNoPos, s, e.getMessage()), e); 907 909 } 908 910 this.search = s; … … 959 961 private final OsmPrimitiveType type; 960 962 961 ExactType(String type) throws ParseError { 963 ExactType(String type) throws SearchParseError { 962 964 this.type = OsmPrimitiveType.from(type); 963 965 if (this.type == null) 964 throw new ParseError(tr("Unknown primitive type: {0}. Allowed values are node, way or relation", type)); 966 throw new SearchParseError(tr("Unknown primitive type: {0}. Allowed values are node, way or relation", type)); 965 967 } 966 968 … … 1048 1050 private final boolean modulo; 1049 1051 1050 Nth(PushbackTokenizer tokenizer, boolean modulo) throws ParseError { 1052 Nth(PushbackTokenizer tokenizer, boolean modulo) throws SearchParseError { 1051 1053 this((int) tokenizer.readNumber(tr("Positive integer expected")), modulo); 1052 1054 } … … 1131 1133 } 1132 1134 1133 NodeCountRange(PushbackTokenizer tokenizer) throws ParseError { 1135 NodeCountRange(PushbackTokenizer tokenizer) throws SearchParseError { 1134 1136 this(tokenizer.readRange(tr("Range of numbers expected"))); 1135 1137 } … … 1160 1162 } 1161 1163 1162 WayCountRange(PushbackTokenizer tokenizer) throws ParseError { 1164 WayCountRange(PushbackTokenizer tokenizer) throws SearchParseError { 1163 1165 this(tokenizer.readRange(tr("Range of numbers expected"))); 1164 1166 } … … 1189 1191 } 1190 1192 1191 TagCountRange(PushbackTokenizer tokenizer) throws ParseError { 1193 TagCountRange(PushbackTokenizer tokenizer) throws SearchParseError { 1192 1194 this(tokenizer.readRange(tr("Range of numbers expected"))); 1193 1195 } … … 1414 1416 } 1415 1417 1416 AreaSize(PushbackTokenizer tokenizer) throws ParseError { 1418 AreaSize(PushbackTokenizer tokenizer) throws SearchParseError { 1417 1419 this(tokenizer.readRange(tr("Range of numbers expected"))); 1418 1420 } … … 1439 1441 } 1440 1442 1441 WayLength(PushbackTokenizer tokenizer) throws ParseError { 1443 WayLength(PushbackTokenizer tokenizer) throws SearchParseError { 1442 1444 this(tokenizer.readRange(tr("Range of numbers expected"))); 1443 1445 } … … 1571 1573 private final List<TaggingPreset> presets; 1572 1574 1573 Preset(String presetName) throws ParseError { 1575 Preset(String presetName) throws SearchParseError { 1574 1576 1575 1577 if (presetName == null || presetName.isEmpty()) { 1576 throw new ParseError("The name of the preset is required"); 1578 throw new SearchParseError("The name of the preset is required"); 1577 1579 } 1578 1580 … … 1593 1595 1594 1596 if (this.presets.isEmpty()) { 1595 throw new ParseError(tr("Unknown preset name: ") + presetName); 1597 throw new SearchParseError(tr("Unknown preset name: ") + presetName); 1596 1598 } 1597 1599 } … … 1624 1626 } 1625 1627 1626 public static class ParseError extends Exception {1627 public ParseError(String msg) {1628 super(msg);1629 }1630 1631 public ParseError(String msg, Throwable cause) {1632 super(msg, cause);1633 }1634 1635 public ParseError(Token expected, Token found) {1636 this(tr("Unexpected token. Expected {0}, found {1}", expected, found));1637 }1638 }1639 1640 1628 /** 1641 1629 * Compiles the search expression. 1642 1630 * @param searchStr the search expression 1643 1631 * @return a {@link Match} object for the expression 1644 * @throws ParseError if an error has been encountered while compiling 1632 * @throws SearchParseError if an error has been encountered while compiling 1645 1633 * @see #compile(org.openstreetmap.josm.actions.search.SearchAction.SearchSetting) 1646 1634 */ 1647 public static Match compile(String searchStr) throws ParseError { 1635 public static Match compile(String searchStr) throws SearchParseError { 1648 1636 return new SearchCompiler(false, false, 1649 1637 new PushbackTokenizer( … … 1656 1644 * @param setting the settings to use 1657 1645 * @return a {@link Match} object for the expression 1658 * @throws ParseError if an error has been encountered while compiling 1646 * @throws SearchParseError if an error has been encountered while compiling 1659 1647 * @see #compile(String) 1660 1648 */ 1661 public static Match compile(SearchAction.SearchSetting setting) throws ParseError { 1649 public static Match compile(SearchAction.SearchSetting setting) throws SearchParseError { 1662 1650 if (setting.mapCSSSearch) { 1663 1651 return compileMapCSS(setting.text); … … 1669 1657 } 1670 1658 1671 static Match compileMapCSS(String mapCSS) throws ParseError { 1659 static Match compileMapCSS(String mapCSS) throws SearchParseError { 1672 1660 try { 1673 1661 final List<Selector> selectors = new MapCSSParser(new StringReader(mapCSS)).selectors(); … … 1684 1672 }; 1685 1673 } catch (ParseException e) { 1686 throw new ParseError(tr("Failed to parse MapCSS selector"), e); 1674 throw new SearchParseError(tr("Failed to parse MapCSS selector"), e); 1687 1675 } 1688 1676 } … … 1692 1680 * 1693 1681 * @return match determined by search string 1694 * @throws org.openstreetmap.josm. actions.search.SearchCompiler.ParseError if search expression cannot be parsed1695 */ 1696 public Match parse() throws ParseError { 1682 * @throws org.openstreetmap.josm.data.osm.search.SearchParseError if search expression cannot be parsed 1683 */ 1684 public Match parse() throws SearchParseError { 1697 1685 Match m = Optional.ofNullable(parseExpression()).orElse(Always.INSTANCE); 1698 1686 if (!tokenizer.readIfEqual(Token.EOF)) 1699 throw new ParseError(tr("Unexpected token: {0}", tokenizer.nextToken())); 1687 throw new SearchParseError(tr("Unexpected token: {0}", tokenizer.nextToken())); 1700 1688 Logging.debug("Parsed search expression is {0}", m); 1701 1689 return m; … … 1706 1694 * 1707 1695 * @return match determined by parsing expression 1708 * @throws ParseError if search expression cannot be parsed 1709 */ 1710 private Match parseExpression() throws ParseError { 1696 * @throws SearchParseError if search expression cannot be parsed 1697 */ 1698 private Match parseExpression() throws SearchParseError { 1711 1699 // Step 1: parse the whole expression and build a list of factors and logical tokens 1712 1700 List<Object> list = parseExpressionStep1(); … … 1716 1704 } 1717 1705 1718 private List<Object> parseExpressionStep1() throws ParseError { 1706 private List<Object> parseExpressionStep1() throws SearchParseError { 1719 1707 Match factor; 1720 1708 String token = null; … … 1739 1727 } 1740 1728 } else if (errorMessage != null) { 1741 throw new ParseError(errorMessage); 1729 throw new SearchParseError(errorMessage); 1742 1730 } 1743 1731 } while (factor != null); … … 1777 1765 * 1778 1766 * @return match determined by parsing factor string 1779 * @throws ParseError if search expression cannot be parsed 1780 */ 1781 private Match parseFactor() throws ParseError { 1767 * @throws SearchParseError if search expression cannot be parsed 1768 */ 1769 private Match parseFactor() throws SearchParseError { 1782 1770 if (tokenizer.readIfEqual(Token.LEFT_PARENT)) { 1783 1771 Match expression = parseExpression(); 1784 1772 if (!tokenizer.readIfEqual(Token.RIGHT_PARENT)) 1785 throw new ParseError(Token.RIGHT_PARENT, tokenizer.nextToken()); 1773 throw new SearchParseError(Token.RIGHT_PARENT, tokenizer.nextToken()); 1786 1774 return expression; 1787 1775 } else if (tokenizer.readIfEqual(Token.NOT)) { … … 1827 1815 } 1828 1816 1829 private Match parseFactor(String errorMessage) throws ParseError { 1830 return Optional.ofNullable(parseFactor()).orElseThrow(() -> new ParseError(errorMessage)); 1817 private Match parseFactor(String errorMessage) throws SearchParseError { 1818 return Optional.ofNullable(parseFactor()).orElseThrow(() -> new SearchParseError(errorMessage)); 1831 1819 } 1832 1820 … … 1874 1862 } 1875 1863 } 1876 -
trunk/src/org/openstreetmap/josm/data/validation/Test.java
r12636 r12656 15 15 import javax.swing.JPanel; 16 16 17 import org.openstreetmap.josm.actions.search.SearchCompiler.NotOutsideDataSourceArea;18 17 import org.openstreetmap.josm.command.Command; 19 18 import org.openstreetmap.josm.command.DeleteCommand; … … 22 21 import org.openstreetmap.josm.data.osm.Relation; 23 22 import org.openstreetmap.josm.data.osm.Way; 23 import org.openstreetmap.josm.data.osm.search.SearchCompiler.NotOutsideDataSourceArea; 24 24 import org.openstreetmap.josm.data.osm.visitor.AbstractVisitor; 25 25 import org.openstreetmap.josm.gui.MainApplication; -
trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java
r12643 r12656 41 41 import org.openstreetmap.josm.actions.relation.SelectMembersAction; 42 42 import org.openstreetmap.josm.actions.relation.SelectRelationAction; 43 import org.openstreetmap.josm.actions.search.SearchCompiler;44 43 import org.openstreetmap.josm.data.osm.DataSet; 45 44 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 50 49 import org.openstreetmap.josm.data.osm.event.DatasetEventManager; 51 50 import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode; 51 import org.openstreetmap.josm.data.osm.search.SearchCompiler; 52 52 import org.openstreetmap.josm.data.osm.event.NodeMovedEvent; 53 53 import org.openstreetmap.josm.data.osm.event.PrimitivesAddedEvent; -
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
r12641 r12656 61 61 import org.openstreetmap.josm.actions.relation.SelectRelationAction; 62 62 import org.openstreetmap.josm.actions.search.SearchAction.SearchSetting; 63 import org.openstreetmap.josm.actions.search.SearchCompiler;64 63 import org.openstreetmap.josm.command.ChangeCommand; 65 64 import org.openstreetmap.josm.command.ChangePropertyCommand; … … 78 77 import org.openstreetmap.josm.data.osm.event.DatasetEventManager; 79 78 import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode; 79 import org.openstreetmap.josm.data.osm.search.SearchCompiler; 80 80 import org.openstreetmap.josm.data.osm.event.SelectionEventManager; 81 81 import org.openstreetmap.josm.data.preferences.StringProperty; -
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/RecentTagCollection.java
r12615 r12656 9 9 10 10 import org.openstreetmap.josm.actions.search.SearchAction; 11 import org.openstreetmap.josm.actions.search.SearchCompiler;12 11 import org.openstreetmap.josm.data.osm.Tag; 12 import org.openstreetmap.josm.data.osm.search.SearchParseError; 13 import org.openstreetmap.josm.data.osm.search.SearchCompiler; 13 14 import org.openstreetmap.josm.data.preferences.CollectionProperty; 14 15 … … 81 82 } 82 83 83 public void setTagsToIgnore(SearchAction.SearchSetting tagsToIgnore) throws Search Compiler.ParseError {84 public void setTagsToIgnore(SearchAction.SearchSetting tagsToIgnore) throws SearchParseError { 84 85 setTagsToIgnore(tagsToIgnore.text.isEmpty() ? SearchCompiler.Never.INSTANCE : SearchCompiler.compile(tagsToIgnore)); 85 86 } 86 87 87 public SearchAction.SearchSetting ignoreTag(Tag tagToIgnore, SearchAction.SearchSetting settingToUpdate) throws Search Compiler.ParseError {88 public SearchAction.SearchSetting ignoreTag(Tag tagToIgnore, SearchAction.SearchSetting settingToUpdate) throws SearchParseError { 88 89 final String forTag = SearchCompiler.buildSearchStringForTag(tagToIgnore.getKey(), tagToIgnore.getValue()); 89 90 settingToUpdate.text = settingToUpdate.text.isEmpty() -
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/SearchBasedRowFilter.java
r9536 r12656 5 5 import javax.swing.table.TableModel; 6 6 7 import org.openstreetmap.josm.actions.search.SearchCompiler;8 7 import org.openstreetmap.josm.data.osm.Tag; 8 import org.openstreetmap.josm.data.osm.search.SearchCompiler; 9 9 10 10 /** 11 11 * A {@link RowFilter} implementation which matches tags w.r.t. the specified filter's 12 * {@link org.openstreetmap.josm. actions.search.SearchCompiler.Match#match(org.openstreetmap.josm.data.osm.Tagged)} method.12 * {@link org.openstreetmap.josm.data.osm.search.SearchCompiler.Match#match(org.openstreetmap.josm.data.osm.Tagged)} method. 13 13 * 14 14 * <p>An {@link javax.swing.RowFilter.Entry}'s column 0 is considered as key, and column 1 is considered as value.</p> -
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelper.java
r12641 r12656 64 64 import org.openstreetmap.josm.actions.JosmAction; 65 65 import org.openstreetmap.josm.actions.search.SearchAction; 66 import org.openstreetmap.josm.actions.search.SearchCompiler;67 66 import org.openstreetmap.josm.command.ChangePropertyCommand; 68 67 import org.openstreetmap.josm.command.Command; … … 70 69 import org.openstreetmap.josm.data.osm.OsmPrimitive; 71 70 import org.openstreetmap.josm.data.osm.Tag; 71 import org.openstreetmap.josm.data.osm.search.SearchParseError; 72 import org.openstreetmap.josm.data.osm.search.SearchCompiler; 72 73 import org.openstreetmap.josm.data.preferences.BooleanProperty; 73 74 import org.openstreetmap.josm.data.preferences.CollectionProperty; … … 335 336 tagsToIgnore = searchSetting; 336 337 recentTags.setTagsToIgnore(tagsToIgnore); 337 } catch (Search Compiler.ParseError parseError) {338 } catch (SearchParseError parseError) { 338 339 warnAboutParseError(parseError); 339 340 tagsToIgnore = new SearchAction.SearchSetting(); … … 343 344 } 344 345 345 private static void warnAboutParseError(Search Compiler.ParseError parseError) {346 private static void warnAboutParseError(SearchParseError parseError) { 346 347 Logging.warn(parseError); 347 348 JOptionPane.showMessageDialog( … … 1009 1010 PROPERTY_TAGS_TO_IGNORE.put(tagsToIgnore.writeToString()); 1010 1011 } 1011 } catch (Search Compiler.ParseError parseError) {1012 } catch (SearchParseError parseError) { 1012 1013 throw new IllegalStateException(parseError); 1013 1014 } … … 1031 1032 recentTags.setTagsToIgnore(tagsToIgnore); 1032 1033 PROPERTY_TAGS_TO_IGNORE.put(tagsToIgnore.writeToString()); 1033 } catch (Search Compiler.ParseError parseError) {1034 } catch (SearchParseError parseError) { 1034 1035 warnAboutParseError(parseError); 1035 1036 } -
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/Marker.java
r12620 r12656 23 23 import javax.swing.ImageIcon; 24 24 25 import org.openstreetmap.josm.actions.search.SearchCompiler.Match;26 25 import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent; 27 26 import org.openstreetmap.josm.data.coor.CachedLatLon; … … 30 29 import org.openstreetmap.josm.data.gpx.GpxConstants; 31 30 import org.openstreetmap.josm.data.gpx.WayPoint; 31 import org.openstreetmap.josm.data.osm.search.SearchCompiler.Match; 32 32 import org.openstreetmap.josm.data.preferences.CachedProperty; 33 33 import org.openstreetmap.josm.data.preferences.IntegerProperty; -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ConditionFactory.java
r12218 r12656 15 15 import java.util.regex.PatternSyntaxException; 16 16 17 import org.openstreetmap.josm.actions.search.SearchCompiler.InDataSourceArea;18 17 import org.openstreetmap.josm.data.osm.Node; 19 18 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 22 21 import org.openstreetmap.josm.data.osm.Tag; 23 22 import org.openstreetmap.josm.data.osm.Way; 23 import org.openstreetmap.josm.data.osm.search.SearchCompiler.InDataSourceArea; 24 24 import org.openstreetmap.josm.data.osm.visitor.paint.relations.MultipolygonCache; 25 25 import org.openstreetmap.josm.gui.mappaint.Cascade; -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java
r12620 r12656 24 24 import java.util.zip.CRC32; 25 25 26 import org.openstreetmap.josm.actions.search.SearchCompiler;27 import org.openstreetmap.josm.actions.search.SearchCompiler.Match;28 import org.openstreetmap.josm.actions.search.SearchCompiler.ParseError;29 26 import org.openstreetmap.josm.data.coor.LatLon; 30 27 import org.openstreetmap.josm.data.osm.Node; 31 28 import org.openstreetmap.josm.data.osm.OsmPrimitive; 32 29 import org.openstreetmap.josm.data.osm.Way; 30 import org.openstreetmap.josm.data.osm.search.SearchParseError; 31 import org.openstreetmap.josm.data.osm.search.SearchCompiler; 32 import org.openstreetmap.josm.data.osm.search.SearchCompiler.Match; 33 33 import org.openstreetmap.josm.gui.mappaint.Cascade; 34 34 import org.openstreetmap.josm.gui.mappaint.Environment; … … 676 676 try { 677 677 m = SearchCompiler.compile(searchStr); 678 } catch (ParseError ex) { 678 } catch (SearchParseError ex) { 679 679 Logging.trace(ex); 680 680 return null; -
trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java
r12641 r12656 34 34 import org.openstreetmap.josm.Main; 35 35 import org.openstreetmap.josm.actions.AdaptableAction; 36 import org.openstreetmap.josm.actions.search.SearchCompiler;37 import org.openstreetmap.josm.actions.search.SearchCompiler.Match;38 36 import org.openstreetmap.josm.command.ChangePropertyCommand; 39 37 import org.openstreetmap.josm.command.Command; … … 44 42 import org.openstreetmap.josm.data.osm.RelationMember; 45 43 import org.openstreetmap.josm.data.osm.Tag; 44 import org.openstreetmap.josm.data.osm.search.SearchCompiler; 45 import org.openstreetmap.josm.data.osm.search.SearchCompiler.Match; 46 import org.openstreetmap.josm.data.osm.search.SearchParseError; 46 47 import org.openstreetmap.josm.gui.ExtendedDialog; 47 48 import org.openstreetmap.josm.gui.MainApplication; … … 246 247 try { 247 248 this.nameTemplateFilter = SearchCompiler.compile(filter); 248 } catch (Search Compiler.ParseError e) {249 } catch (SearchParseError e) { 249 250 Logging.error("Error while parsing" + filter + ": " + e.getMessage()); 250 251 throw new SAXException(e); -
trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/Roles.java
r12615 r12656 14 14 15 15 import org.openstreetmap.josm.actions.search.SearchAction; 16 import org.openstreetmap.josm.actions.search.SearchCompiler;17 16 import org.openstreetmap.josm.data.osm.OsmPrimitive; 18 17 import org.openstreetmap.josm.data.osm.Tag; 18 import org.openstreetmap.josm.data.osm.search.SearchParseError; 19 import org.openstreetmap.josm.data.osm.search.SearchCompiler; 19 20 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItem; 20 21 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetType; … … 82 83 searchSetting.regexSearch = true; 83 84 this.memberExpression = SearchCompiler.compile(searchSetting); 84 } catch (Search Compiler.ParseError ex) {85 } catch (SearchParseError ex) { 85 86 throw new SAXException(tr("Illegal member expression: {0}", ex.getMessage()), ex); 86 87 } -
trunk/src/org/openstreetmap/josm/gui/widgets/CompileSearchTextDecorator.java
r12620 r12656 9 9 import javax.swing.text.JTextComponent; 10 10 11 import org.openstreetmap.josm.actions.search.SearchCompiler; 11 import org.openstreetmap.josm.data.osm.search.SearchParseError; 12 import org.openstreetmap.josm.data.osm.search.SearchCompiler; 12 13 import org.openstreetmap.josm.tools.Logging; 13 14 … … 43 44 textComponent.setToolTipText(originalToolTipText); 44 45 filter = SearchCompiler.compile(textComponent.getText()); 45 } catch (Search Compiler.ParseError ex) {46 } catch (SearchParseError ex) { 46 47 textComponent.setBackground(new Color(255, 224, 224)); 47 48 textComponent.setToolTipText(ex.getMessage()); -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/LoadAndZoomHandler.java
r12636 r12656 16 16 import org.openstreetmap.josm.actions.downloadtasks.DownloadTask; 17 17 import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler; 18 import org.openstreetmap.josm.actions.search.SearchCompiler;19 18 import org.openstreetmap.josm.data.Bounds; 20 19 import org.openstreetmap.josm.data.coor.LatLon; … … 24 23 import org.openstreetmap.josm.data.osm.Relation; 25 24 import org.openstreetmap.josm.data.osm.SimplePrimitiveId; 25 import org.openstreetmap.josm.data.osm.search.SearchParseError; 26 import org.openstreetmap.josm.data.osm.search.SearchCompiler; 26 27 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 27 28 import org.openstreetmap.josm.gui.MainApplication; … … 202 203 zoom(filteredPrimitives, bbox); 203 204 }); 204 } catch (Search Compiler.ParseError ex) {205 } catch (SearchParseError ex) { 205 206 Logging.error(ex); 206 207 throw new RequestHandlerErrorException(ex); -
trunk/src/org/openstreetmap/josm/tools/template_engine/ContextSwitchTemplate.java
r11974 r12656 9 9 import java.util.List; 10 10 11 import org.openstreetmap.josm.actions.search.SearchCompiler.And;12 import org.openstreetmap.josm.actions.search.SearchCompiler.Child;13 import org.openstreetmap.josm.actions.search.SearchCompiler.Match;14 import org.openstreetmap.josm.actions.search.SearchCompiler.Not;15 import org.openstreetmap.josm.actions.search.SearchCompiler.Or;16 import org.openstreetmap.josm.actions.search.SearchCompiler.Parent;17 11 import org.openstreetmap.josm.data.osm.Node; 18 12 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 20 14 import org.openstreetmap.josm.data.osm.RelationMember; 21 15 import org.openstreetmap.josm.data.osm.Way; 16 import org.openstreetmap.josm.data.osm.search.SearchCompiler.And; 17 import org.openstreetmap.josm.data.osm.search.SearchCompiler.Child; 18 import org.openstreetmap.josm.data.osm.search.SearchCompiler.Match; 19 import org.openstreetmap.josm.data.osm.search.SearchCompiler.Not; 20 import org.openstreetmap.josm.data.osm.search.SearchCompiler.Or; 21 import org.openstreetmap.josm.data.osm.search.SearchCompiler.Parent; 22 22 23 23 /** -
trunk/src/org/openstreetmap/josm/tools/template_engine/ParseError.java
r8540 r12656 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import org.openstreetmap.josm.data.osm.search.SearchParseError; 6 7 import org.openstreetmap.josm.tools.template_engine.Tokenizer.Token; 7 8 import org.openstreetmap.josm.tools.template_engine.Tokenizer.TokenType; … … 22 23 } 23 24 24 public ParseError(int position, org.openstreetmap.josm.actions.search.SearchCompiler.ParseError e) {25 public ParseError(int position, SearchParseError e) { 25 26 super(tr("Error while parsing search expression on position {0}", position), e); 26 27 unexpectedToken = null; -
trunk/src/org/openstreetmap/josm/tools/template_engine/SearchExpressionCondition.java
r10305 r12656 2 2 package org.openstreetmap.josm.tools.template_engine; 3 3 4 import org.openstreetmap.josm. actions.search.SearchCompiler.Match;4 import org.openstreetmap.josm.data.osm.search.SearchCompiler.Match; 5 5 6 6 public class SearchExpressionCondition implements TemplateEntry { -
trunk/src/org/openstreetmap/josm/tools/template_engine/TemplateEngineDataProvider.java
r8510 r12656 4 4 import java.util.Collection; 5 5 6 import org.openstreetmap.josm. actions.search.SearchCompiler.Match;6 import org.openstreetmap.josm.data.osm.search.SearchCompiler.Match; 7 7 8 8 public interface TemplateEngineDataProvider { -
trunk/src/org/openstreetmap/josm/tools/template_engine/TemplateParser.java
r11929 r12656 9 9 import java.util.List; 10 10 11 import org.openstreetmap.josm.actions.search.SearchCompiler; 12 import org.openstreetmap.josm.actions.search.SearchCompiler.Match; 11 import org.openstreetmap.josm.data.osm.search.SearchCompiler; 12 import org.openstreetmap.josm.data.osm.search.SearchCompiler.Match; 13 import org.openstreetmap.josm.data.osm.search.SearchParseError; 13 14 import org.openstreetmap.josm.tools.template_engine.Tokenizer.Token; 14 15 import org.openstreetmap.josm.tools.template_engine.Tokenizer.TokenType; … … 102 103 result.getEntries().add(new SearchExpressionCondition( 103 104 SearchCompiler.compile(searchText), condition)); 104 } catch (Search Compiler.ParseError e) {105 } catch (SearchParseError e) { 105 106 throw new ParseError(searchExpression.getPosition(), e); 106 107 } … … 133 134 Match match = SearchCompiler.compile(searchText); 134 135 result = new ContextSwitchTemplate(match, template, searchExpression.getPosition()); 135 } catch (Search Compiler.ParseError e) {136 } catch (SearchParseError e) { 136 137 throw new ParseError(searchExpression.getPosition(), e); 137 138 }
Note:
See TracChangeset
for help on using the changeset viewer.