Changeset 12656 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2017-08-26T00:40:19+02:00 (7 years ago)
Author:
Don-vip
Message:

see #15182 - move SearchCompiler from actions.search to data.osm.search

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  
    4646import org.openstreetmap.josm.actions.JosmAction;
    4747import org.openstreetmap.josm.actions.ParameterizedAction;
    48 import org.openstreetmap.josm.actions.search.SearchCompiler.ParseError;
    4948import org.openstreetmap.josm.data.osm.DataSet;
    5049import org.openstreetmap.josm.data.osm.Filter;
    5150import org.openstreetmap.josm.data.osm.OsmPrimitive;
     51import org.openstreetmap.josm.data.osm.search.SearchParseError;
     52import org.openstreetmap.josm.data.osm.search.SearchCompiler;
    5253import org.openstreetmap.josm.gui.ExtendedDialog;
    5354import org.openstreetmap.josm.gui.MainApplication;
     
    380381                    SearchCompiler.compile(ss);
    381382                    return true;
    382                 } catch (ParseError | MapCSSException e) {
     383                } catch (SearchParseError | MapCSSException e) {
    383384                    return false;
    384385                }
     
    418419                        SearchCompiler.compile(ss);
    419420                        super.buttonAction(buttonIndex, evt);
    420                     } catch (ParseError e) {
     421                    } catch (SearchParseError e) {
    421422                        Logging.debug(e);
    422423                        JOptionPane.showMessageDialog(
     
    828829                }
    829830                subMonitor.finishTask();
    830             } catch (ParseError e) {
     831            } catch (SearchParseError e) {
    831832                Logging.debug(e);
    832833                JOptionPane.showMessageDialog(
  • trunk/src/org/openstreetmap/josm/data/gpx/WayPoint.java

    r12620 r12656  
    88import java.util.Objects;
    99
    10 import org.openstreetmap.josm.actions.search.SearchCompiler.Match;
    1110import org.openstreetmap.josm.data.coor.EastNorth;
    1211import org.openstreetmap.josm.data.coor.ILatLon;
    1312import org.openstreetmap.josm.data.coor.LatLon;
     13import org.openstreetmap.josm.data.osm.search.SearchCompiler.Match;
    1414import org.openstreetmap.josm.data.projection.Projecting;
    1515import org.openstreetmap.josm.tools.Logging;
  • trunk/src/org/openstreetmap/josm/data/osm/FilterMatcher.java

    r12630 r12656  
    77
    88import 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;
     9import org.openstreetmap.josm.data.osm.search.SearchParseError;
     10import org.openstreetmap.josm.data.osm.search.SearchCompiler;
     11import org.openstreetmap.josm.data.osm.search.SearchCompiler.Match;
     12import org.openstreetmap.josm.data.osm.search.SearchCompiler.Not;
    1313import org.openstreetmap.josm.gui.MainApplication;
    1414import org.openstreetmap.josm.gui.MapFrame;
     
    7979        private final boolean isInverted;
    8080
    81         FilterInfo(Filter filter) throws ParseError {
     81        FilterInfo(Filter filter) throws SearchParseError {
    8282            if (filter.mode == SearchMode.remove || filter.mode == SearchMode.in_selection) {
    8383                isDelete = true;
     
    9898     * Clears the current filters, and adds the given filters
    9999     * @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 {
    103103        reset();
    104104        for (Filter filter : filters) {
     
    118118     * Adds a filter to the currently used filters
    119119     * @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 {
    123123        if (!filter.enable) {
    124124            return;
     
    330330     * @param filters filters to add to the resulting filter matcher
    331331     * @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
    333333     * @since 12383
    334334     */
    335     public static FilterMatcher of(Filter... filters) throws ParseError {
     335    public static FilterMatcher of(Filter... filters) throws SearchParseError {
    336336        FilterMatcher result = new FilterMatcher();
    337337        for (Filter filter : filters) {
  • trunk/src/org/openstreetmap/josm/data/osm/FilterModel.java

    r12636 r12656  
    1717
    1818import org.openstreetmap.josm.Main;
    19 import org.openstreetmap.josm.actions.search.SearchCompiler.ParseError;
    2019import org.openstreetmap.josm.data.osm.Filter.FilterPreferenceEntry;
     20import org.openstreetmap.josm.data.osm.search.SearchParseError;
    2121import org.openstreetmap.josm.gui.MainApplication;
    2222import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     
    5252            try {
    5353                filterMatcher.add(filter);
    54             } catch (ParseError e) {
     54            } catch (SearchParseError e) {
    5555                Logging.error(e);
    5656                JOptionPane.showMessageDialog(
  • trunk/src/org/openstreetmap/josm/data/osm/FilterWorker.java

    r12388 r12656  
    55import java.util.Collections;
    66
    7 import org.openstreetmap.josm.actions.search.SearchCompiler.ParseError;
    87import org.openstreetmap.josm.data.osm.FilterMatcher.FilterType;
     8import org.openstreetmap.josm.data.osm.search.SearchParseError;
    99import org.openstreetmap.josm.tools.SubclassFilteredCollection;
    1010
     
    2828     * @param filters the filters
    2929     * @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
    3131     * @since 12383
    3232     */
    33     public static boolean executeFilters(Collection<OsmPrimitive> all, Filter... filters) throws ParseError {
     33    public static boolean executeFilters(Collection<OsmPrimitive> all, Filter... filters) throws SearchParseError {
    3434        return executeFilters(all, FilterMatcher.of(filters));
    3535    }
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r12620 r12656  
    2121
    2222import 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;
     23import org.openstreetmap.josm.data.osm.search.SearchParseError;
     24import org.openstreetmap.josm.data.osm.search.SearchCompiler;
     25import org.openstreetmap.josm.data.osm.search.SearchCompiler.Match;
    2626import org.openstreetmap.josm.data.osm.visitor.Visitor;
    2727import org.openstreetmap.josm.gui.mappaint.StyleCache;
     
    761761        try {
    762762            return SearchCompiler.compile(Main.pref.get(prefName, defaultValue));
    763         } catch (ParseError e) {
     763        } catch (SearchParseError e) {
    764764            Logging.log(Logging.LEVEL_ERROR, "Unable to compile pattern for " + prefName + ", trying default pattern:", e);
    765765        }
     
    767767        try {
    768768            return SearchCompiler.compile(defaultValue);
    769         } catch (ParseError e2) {
     769        } catch (SearchParseError e2) {
    770770            throw new AssertionError("Unable to compile default pattern for direction keys: " + e2.getMessage(), e2);
    771771        }
  • trunk/src/org/openstreetmap/josm/data/osm/search/PushbackTokenizer.java

    r12651 r12656  
    11// License: GPL. For details, see LICENSE file.
    2 package org.openstreetmap.josm.actions.search;
     2package org.openstreetmap.josm.data.osm.search;
    33
    44import static org.openstreetmap.josm.tools.I18n.marktr;
     
    1111import java.util.Objects;
    1212
    13 import org.openstreetmap.josm.actions.search.SearchCompiler.ParseError;
    1413import org.openstreetmap.josm.tools.JosmRuntimeException;
    1514
     
    1716 * This class is used to parse a search string and split it into tokens.
    1817 * It provides methods to parse numbers and extract strings.
     18 * @since 12656 (moved from actions.search package)
    1919 */
    2020public class PushbackTokenizer {
     
    300300     * @param errorMessage The error if the number cannot be read
    301301     * @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 {
    305305        if ((nextToken() == Token.KEY) && (currentNumber != null))
    306306            return currentNumber;
    307307        else
    308             throw new ParseError(errorMessage);
     308            throw new SearchParseError(errorMessage);
    309309    }
    310310
     
    321321     * @param errorMessage The error if the input is malformed
    322322     * @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 {
    326326        if (nextToken() != Token.KEY || (currentNumber == null && currentRange == null)) {
    327             throw new ParseError(errorMessage);
     327            throw new SearchParseError(errorMessage);
    328328        } else if (!isRange && currentNumber != null) {
    329329            if (currentNumber >= 0) {
     
    337337            return new Range(currentNumber, currentRange);
    338338        } else {
    339             throw new ParseError(errorMessage);
     339            throw new SearchParseError(errorMessage);
    340340        }
    341341    }
  • trunk/src/org/openstreetmap/josm/data/osm/search/SearchCompiler.java

    r12651 r12656  
    11// License: GPL. For details, see LICENSE file.
    2 package org.openstreetmap.josm.actions.search;
     2package org.openstreetmap.josm.data.osm.search;
    33
    44import static org.openstreetmap.josm.tools.I18n.marktr;
     
    2424
    2525import org.openstreetmap.josm.Main;
    26 import org.openstreetmap.josm.actions.search.PushbackTokenizer.Range;
    27 import org.openstreetmap.josm.actions.search.PushbackTokenizer.Token;
     26import org.openstreetmap.josm.actions.search.SearchAction;
    2827import org.openstreetmap.josm.data.Bounds;
    2928import org.openstreetmap.josm.data.coor.LatLon;
     
    3635import org.openstreetmap.josm.data.osm.Tagged;
    3736import org.openstreetmap.josm.data.osm.Way;
     37import org.openstreetmap.josm.data.osm.search.PushbackTokenizer.Range;
     38import org.openstreetmap.josm.data.osm.search.PushbackTokenizer.Token;
    3839import org.openstreetmap.josm.gui.MainApplication;
    3940import org.openstreetmap.josm.gui.mappaint.Environment;
     
    5354
    5455/**
    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)
    7476 */
    7577public class SearchCompiler {
     
    126128
    127129        @Override
    128         public Match get(String keyword, PushbackTokenizer tokenizer) throws ParseError {
     130        public Match get(String keyword, PushbackTokenizer tokenizer) throws SearchParseError {
    129131            switch(keyword) {
    130132            case "modified":
     
    198200                                minDate = DateUtils.fromString(rangeA1.isEmpty() ? "1980" : rangeA1).getTime();
    199201                            } 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);
    201203                            }
    202204                            try {
     
    204206                                maxDate = rangeA2.isEmpty() ? System.currentTimeMillis() : DateUtils.fromString(rangeA2).getTime();
    205207                            } 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);
    207209                            }
    208210                            return new TimestampRange(minDate, maxDate);
    209211                        } 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>"));
    211213                        }
    212214                    }
    213215                } 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>"));
    215217                }
    216218            }
     
    252254
    253255    public interface SimpleMatchFactory extends MatchFactory {
    254         Match get(String keyword, PushbackTokenizer tokenizer) throws ParseError;
     256        Match get(String keyword, PushbackTokenizer tokenizer) throws SearchParseError;
    255257    }
    256258
    257259    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;
    259261    }
    260262
    261263    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;
    263265    }
    264266
    265267    /**
    266268     * 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}.
    268270     */
    269271    public abstract static class Match implements Predicate<OsmPrimitive> {
     
    536538        }
    537539
    538         Id(PushbackTokenizer tokenizer) throws ParseError {
     540        Id(PushbackTokenizer tokenizer) throws SearchParseError {
    539541            this(tokenizer.readRange(tr("Range of primitive ids expected")));
    540542        }
     
    559561        }
    560562
    561         ChangesetId(PushbackTokenizer tokenizer) throws ParseError {
     563        ChangesetId(PushbackTokenizer tokenizer) throws SearchParseError {
    562564            this(tokenizer.readRange(tr("Range of changeset ids expected")));
    563565        }
     
    582584        }
    583585
    584         Version(PushbackTokenizer tokenizer) throws ParseError {
     586        Version(PushbackTokenizer tokenizer) throws SearchParseError {
    585587            this(tokenizer.readRange(tr("Range of versions expected")));
    586588        }
     
    607609        private final boolean caseSensitive;
    608610
    609         KeyValue(String key, String value, boolean regexSearch, boolean caseSensitive) throws ParseError {
     611        KeyValue(String key, String value, boolean regexSearch, boolean caseSensitive) throws SearchParseError {
    610612            this.caseSensitive = caseSensitive;
    611613            if (regexSearch) {
     
    615617                    this.keyPattern = Pattern.compile(key, searchFlags);
    616618                } 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);
    618620                } catch (IllegalArgumentException e) {
    619                     throw new ParseError(tr(rxErrorMsgNoPos, key, e.getMessage()), e);
     621                    throw new SearchParseError(tr(rxErrorMsgNoPos, key, e.getMessage()), e);
    620622                }
    621623                try {
    622624                    this.valuePattern = Pattern.compile(value, searchFlags);
    623625                } 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);
    625627                } catch (IllegalArgumentException | StringIndexOutOfBoundsException e) {
    626                     throw new ParseError(tr(rxErrorMsgNoPos, value, e.getMessage()), e);
     628                    throw new SearchParseError(tr(rxErrorMsgNoPos, value, e.getMessage()), e);
    627629                }
    628630                this.key = key;
     
    771773         * @param key key
    772774         * @param value value
    773          * @throws ParseError if a parse error occurs
     775         * @throws SearchParseError if a parse error occurs
    774776         */
    775         public ExactKeyValue(boolean regexp, String key, String value) throws ParseError {
     777        public ExactKeyValue(boolean regexp, String key, String value) throws SearchParseError {
    776778            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"));
    778780            this.key = key;
    779781            this.value = value == null ? "" : value;
     
    812814                    keyPattern = Pattern.compile(key, regexFlags(false));
    813815                } 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);
    815817                } catch (IllegalArgumentException e) {
    816                     throw new ParseError(tr(rxErrorMsgNoPos, key, e.getMessage()), e);
     818                    throw new SearchParseError(tr(rxErrorMsgNoPos, key, e.getMessage()), e);
    817819                }
    818820            } else {
     
    823825                    valuePattern = Pattern.compile(this.value, regexFlags(false));
    824826                } 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);
    826828                } catch (IllegalArgumentException e) {
    827                     throw new ParseError(tr(rxErrorMsgNoPos, value, e.getMessage()), e);
     829                    throw new SearchParseError(tr(rxErrorMsgNoPos, value, e.getMessage()), e);
    828830                }
    829831            } else {
     
    893895        private final boolean caseSensitive;
    894896
    895         Any(String s, boolean regexSearch, boolean caseSensitive) throws ParseError {
     897        Any(String s, boolean regexSearch, boolean caseSensitive) throws SearchParseError {
    896898            s = Normalizer.normalize(s, Normalizer.Form.NFC);
    897899            this.caseSensitive = caseSensitive;
     
    900902                    this.searchRegex = Pattern.compile(s, regexFlags(caseSensitive));
    901903                } 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);
    903905                } catch (IllegalArgumentException | StringIndexOutOfBoundsException e) {
    904906                    // StringIndexOutOfBoundsException catched because of https://bugs.openjdk.java.net/browse/JI-9044959
    905907                    // 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);
    907909                }
    908910                this.search = s;
     
    959961        private final OsmPrimitiveType type;
    960962
    961         ExactType(String type) throws ParseError {
     963        ExactType(String type) throws SearchParseError {
    962964            this.type = OsmPrimitiveType.from(type);
    963965            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));
    965967        }
    966968
     
    10481050        private final boolean modulo;
    10491051
    1050         Nth(PushbackTokenizer tokenizer, boolean modulo) throws ParseError {
     1052        Nth(PushbackTokenizer tokenizer, boolean modulo) throws SearchParseError {
    10511053            this((int) tokenizer.readNumber(tr("Positive integer expected")), modulo);
    10521054        }
     
    11311133        }
    11321134
    1133         NodeCountRange(PushbackTokenizer tokenizer) throws ParseError {
     1135        NodeCountRange(PushbackTokenizer tokenizer) throws SearchParseError {
    11341136            this(tokenizer.readRange(tr("Range of numbers expected")));
    11351137        }
     
    11601162        }
    11611163
    1162         WayCountRange(PushbackTokenizer tokenizer) throws ParseError {
     1164        WayCountRange(PushbackTokenizer tokenizer) throws SearchParseError {
    11631165            this(tokenizer.readRange(tr("Range of numbers expected")));
    11641166        }
     
    11891191        }
    11901192
    1191         TagCountRange(PushbackTokenizer tokenizer) throws ParseError {
     1193        TagCountRange(PushbackTokenizer tokenizer) throws SearchParseError {
    11921194            this(tokenizer.readRange(tr("Range of numbers expected")));
    11931195        }
     
    14141416        }
    14151417
    1416         AreaSize(PushbackTokenizer tokenizer) throws ParseError {
     1418        AreaSize(PushbackTokenizer tokenizer) throws SearchParseError {
    14171419            this(tokenizer.readRange(tr("Range of numbers expected")));
    14181420        }
     
    14391441        }
    14401442
    1441         WayLength(PushbackTokenizer tokenizer) throws ParseError {
     1443        WayLength(PushbackTokenizer tokenizer) throws SearchParseError {
    14421444            this(tokenizer.readRange(tr("Range of numbers expected")));
    14431445        }
     
    15711573        private final List<TaggingPreset> presets;
    15721574
    1573         Preset(String presetName) throws ParseError {
     1575        Preset(String presetName) throws SearchParseError {
    15741576
    15751577            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");
    15771579            }
    15781580
     
    15931595
    15941596            if (this.presets.isEmpty()) {
    1595                 throw new ParseError(tr("Unknown preset name: ") + presetName);
     1597                throw new SearchParseError(tr("Unknown preset name: ") + presetName);
    15961598            }
    15971599        }
     
    16241626    }
    16251627
    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 
    16401628    /**
    16411629     * Compiles the search expression.
    16421630     * @param searchStr the search expression
    16431631     * @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
    16451633     * @see #compile(org.openstreetmap.josm.actions.search.SearchAction.SearchSetting)
    16461634     */
    1647     public static Match compile(String searchStr) throws ParseError {
     1635    public static Match compile(String searchStr) throws SearchParseError {
    16481636        return new SearchCompiler(false, false,
    16491637                new PushbackTokenizer(
     
    16561644     * @param setting the settings to use
    16571645     * @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
    16591647     * @see #compile(String)
    16601648     */
    1661     public static Match compile(SearchAction.SearchSetting setting) throws ParseError {
     1649    public static Match compile(SearchAction.SearchSetting setting) throws SearchParseError {
    16621650        if (setting.mapCSSSearch) {
    16631651            return compileMapCSS(setting.text);
     
    16691657    }
    16701658
    1671     static Match compileMapCSS(String mapCSS) throws ParseError {
     1659    static Match compileMapCSS(String mapCSS) throws SearchParseError {
    16721660        try {
    16731661            final List<Selector> selectors = new MapCSSParser(new StringReader(mapCSS)).selectors();
     
    16841672            };
    16851673        } 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);
    16871675        }
    16881676    }
     
    16921680     *
    16931681     * @return match determined by search string
    1694      * @throws org.openstreetmap.josm.actions.search.SearchCompiler.ParseError if search expression cannot be parsed
    1695      */
    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 {
    16971685        Match m = Optional.ofNullable(parseExpression()).orElse(Always.INSTANCE);
    16981686        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()));
    17001688        Logging.debug("Parsed search expression is {0}", m);
    17011689        return m;
     
    17061694     *
    17071695     * @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 {
    17111699        // Step 1: parse the whole expression and build a list of factors and logical tokens
    17121700        List<Object> list = parseExpressionStep1();
     
    17161704    }
    17171705
    1718     private List<Object> parseExpressionStep1() throws ParseError {
     1706    private List<Object> parseExpressionStep1() throws SearchParseError {
    17191707        Match factor;
    17201708        String token = null;
     
    17391727                }
    17401728            } else if (errorMessage != null) {
    1741                 throw new ParseError(errorMessage);
     1729                throw new SearchParseError(errorMessage);
    17421730            }
    17431731        } while (factor != null);
     
    17771765     *
    17781766     * @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 {
    17821770        if (tokenizer.readIfEqual(Token.LEFT_PARENT)) {
    17831771            Match expression = parseExpression();
    17841772            if (!tokenizer.readIfEqual(Token.RIGHT_PARENT))
    1785                 throw new ParseError(Token.RIGHT_PARENT, tokenizer.nextToken());
     1773                throw new SearchParseError(Token.RIGHT_PARENT, tokenizer.nextToken());
    17861774            return expression;
    17871775        } else if (tokenizer.readIfEqual(Token.NOT)) {
     
    18271815    }
    18281816
    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));
    18311819    }
    18321820
     
    18741862    }
    18751863}
    1876 
  • trunk/src/org/openstreetmap/josm/data/validation/Test.java

    r12636 r12656  
    1515import javax.swing.JPanel;
    1616
    17 import org.openstreetmap.josm.actions.search.SearchCompiler.NotOutsideDataSourceArea;
    1817import org.openstreetmap.josm.command.Command;
    1918import org.openstreetmap.josm.command.DeleteCommand;
     
    2221import org.openstreetmap.josm.data.osm.Relation;
    2322import org.openstreetmap.josm.data.osm.Way;
     23import org.openstreetmap.josm.data.osm.search.SearchCompiler.NotOutsideDataSourceArea;
    2424import org.openstreetmap.josm.data.osm.visitor.AbstractVisitor;
    2525import org.openstreetmap.josm.gui.MainApplication;
  • trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java

    r12643 r12656  
    4141import org.openstreetmap.josm.actions.relation.SelectMembersAction;
    4242import org.openstreetmap.josm.actions.relation.SelectRelationAction;
    43 import org.openstreetmap.josm.actions.search.SearchCompiler;
    4443import org.openstreetmap.josm.data.osm.DataSet;
    4544import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    5049import org.openstreetmap.josm.data.osm.event.DatasetEventManager;
    5150import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode;
     51import org.openstreetmap.josm.data.osm.search.SearchCompiler;
    5252import org.openstreetmap.josm.data.osm.event.NodeMovedEvent;
    5353import org.openstreetmap.josm.data.osm.event.PrimitivesAddedEvent;
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    r12641 r12656  
    6161import org.openstreetmap.josm.actions.relation.SelectRelationAction;
    6262import org.openstreetmap.josm.actions.search.SearchAction.SearchSetting;
    63 import org.openstreetmap.josm.actions.search.SearchCompiler;
    6463import org.openstreetmap.josm.command.ChangeCommand;
    6564import org.openstreetmap.josm.command.ChangePropertyCommand;
     
    7877import org.openstreetmap.josm.data.osm.event.DatasetEventManager;
    7978import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode;
     79import org.openstreetmap.josm.data.osm.search.SearchCompiler;
    8080import org.openstreetmap.josm.data.osm.event.SelectionEventManager;
    8181import org.openstreetmap.josm.data.preferences.StringProperty;
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/RecentTagCollection.java

    r12615 r12656  
    99
    1010import org.openstreetmap.josm.actions.search.SearchAction;
    11 import org.openstreetmap.josm.actions.search.SearchCompiler;
    1211import org.openstreetmap.josm.data.osm.Tag;
     12import org.openstreetmap.josm.data.osm.search.SearchParseError;
     13import org.openstreetmap.josm.data.osm.search.SearchCompiler;
    1314import org.openstreetmap.josm.data.preferences.CollectionProperty;
    1415
     
    8182    }
    8283
    83     public void setTagsToIgnore(SearchAction.SearchSetting tagsToIgnore) throws SearchCompiler.ParseError {
     84    public void setTagsToIgnore(SearchAction.SearchSetting tagsToIgnore) throws SearchParseError {
    8485        setTagsToIgnore(tagsToIgnore.text.isEmpty() ? SearchCompiler.Never.INSTANCE : SearchCompiler.compile(tagsToIgnore));
    8586    }
    8687
    87     public SearchAction.SearchSetting ignoreTag(Tag tagToIgnore, SearchAction.SearchSetting settingToUpdate) throws SearchCompiler.ParseError {
     88    public SearchAction.SearchSetting ignoreTag(Tag tagToIgnore, SearchAction.SearchSetting settingToUpdate) throws SearchParseError {
    8889        final String forTag = SearchCompiler.buildSearchStringForTag(tagToIgnore.getKey(), tagToIgnore.getValue());
    8990        settingToUpdate.text = settingToUpdate.text.isEmpty()
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/SearchBasedRowFilter.java

    r9536 r12656  
    55import javax.swing.table.TableModel;
    66
    7 import org.openstreetmap.josm.actions.search.SearchCompiler;
    87import org.openstreetmap.josm.data.osm.Tag;
     8import org.openstreetmap.josm.data.osm.search.SearchCompiler;
    99
    1010/**
    1111 * 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.
    1313 *
    1414 * <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  
    6464import org.openstreetmap.josm.actions.JosmAction;
    6565import org.openstreetmap.josm.actions.search.SearchAction;
    66 import org.openstreetmap.josm.actions.search.SearchCompiler;
    6766import org.openstreetmap.josm.command.ChangePropertyCommand;
    6867import org.openstreetmap.josm.command.Command;
     
    7069import org.openstreetmap.josm.data.osm.OsmPrimitive;
    7170import org.openstreetmap.josm.data.osm.Tag;
     71import org.openstreetmap.josm.data.osm.search.SearchParseError;
     72import org.openstreetmap.josm.data.osm.search.SearchCompiler;
    7273import org.openstreetmap.josm.data.preferences.BooleanProperty;
    7374import org.openstreetmap.josm.data.preferences.CollectionProperty;
     
    335336                tagsToIgnore = searchSetting;
    336337                recentTags.setTagsToIgnore(tagsToIgnore);
    337             } catch (SearchCompiler.ParseError parseError) {
     338            } catch (SearchParseError parseError) {
    338339                warnAboutParseError(parseError);
    339340                tagsToIgnore = new SearchAction.SearchSetting();
     
    343344    }
    344345
    345     private static void warnAboutParseError(SearchCompiler.ParseError parseError) {
     346    private static void warnAboutParseError(SearchParseError parseError) {
    346347        Logging.warn(parseError);
    347348        JOptionPane.showMessageDialog(
     
    10091010                        PROPERTY_TAGS_TO_IGNORE.put(tagsToIgnore.writeToString());
    10101011                    }
    1011                 } catch (SearchCompiler.ParseError parseError) {
     1012                } catch (SearchParseError parseError) {
    10121013                    throw new IllegalStateException(parseError);
    10131014                }
     
    10311032                    recentTags.setTagsToIgnore(tagsToIgnore);
    10321033                    PROPERTY_TAGS_TO_IGNORE.put(tagsToIgnore.writeToString());
    1033                 } catch (SearchCompiler.ParseError parseError) {
     1034                } catch (SearchParseError parseError) {
    10341035                    warnAboutParseError(parseError);
    10351036                }
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/Marker.java

    r12620 r12656  
    2323import javax.swing.ImageIcon;
    2424
    25 import org.openstreetmap.josm.actions.search.SearchCompiler.Match;
    2625import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent;
    2726import org.openstreetmap.josm.data.coor.CachedLatLon;
     
    3029import org.openstreetmap.josm.data.gpx.GpxConstants;
    3130import org.openstreetmap.josm.data.gpx.WayPoint;
     31import org.openstreetmap.josm.data.osm.search.SearchCompiler.Match;
    3232import org.openstreetmap.josm.data.preferences.CachedProperty;
    3333import org.openstreetmap.josm.data.preferences.IntegerProperty;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ConditionFactory.java

    r12218 r12656  
    1515import java.util.regex.PatternSyntaxException;
    1616
    17 import org.openstreetmap.josm.actions.search.SearchCompiler.InDataSourceArea;
    1817import org.openstreetmap.josm.data.osm.Node;
    1918import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    2221import org.openstreetmap.josm.data.osm.Tag;
    2322import org.openstreetmap.josm.data.osm.Way;
     23import org.openstreetmap.josm.data.osm.search.SearchCompiler.InDataSourceArea;
    2424import org.openstreetmap.josm.data.osm.visitor.paint.relations.MultipolygonCache;
    2525import org.openstreetmap.josm.gui.mappaint.Cascade;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java

    r12620 r12656  
    2424import java.util.zip.CRC32;
    2525
    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;
    2926import org.openstreetmap.josm.data.coor.LatLon;
    3027import org.openstreetmap.josm.data.osm.Node;
    3128import org.openstreetmap.josm.data.osm.OsmPrimitive;
    3229import org.openstreetmap.josm.data.osm.Way;
     30import org.openstreetmap.josm.data.osm.search.SearchParseError;
     31import org.openstreetmap.josm.data.osm.search.SearchCompiler;
     32import org.openstreetmap.josm.data.osm.search.SearchCompiler.Match;
    3333import org.openstreetmap.josm.gui.mappaint.Cascade;
    3434import org.openstreetmap.josm.gui.mappaint.Environment;
     
    676676            try {
    677677                m = SearchCompiler.compile(searchStr);
    678             } catch (ParseError ex) {
     678            } catch (SearchParseError ex) {
    679679                Logging.trace(ex);
    680680                return null;
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java

    r12641 r12656  
    3434import org.openstreetmap.josm.Main;
    3535import org.openstreetmap.josm.actions.AdaptableAction;
    36 import org.openstreetmap.josm.actions.search.SearchCompiler;
    37 import org.openstreetmap.josm.actions.search.SearchCompiler.Match;
    3836import org.openstreetmap.josm.command.ChangePropertyCommand;
    3937import org.openstreetmap.josm.command.Command;
     
    4442import org.openstreetmap.josm.data.osm.RelationMember;
    4543import org.openstreetmap.josm.data.osm.Tag;
     44import org.openstreetmap.josm.data.osm.search.SearchCompiler;
     45import org.openstreetmap.josm.data.osm.search.SearchCompiler.Match;
     46import org.openstreetmap.josm.data.osm.search.SearchParseError;
    4647import org.openstreetmap.josm.gui.ExtendedDialog;
    4748import org.openstreetmap.josm.gui.MainApplication;
     
    246247        try {
    247248            this.nameTemplateFilter = SearchCompiler.compile(filter);
    248         } catch (SearchCompiler.ParseError e) {
     249        } catch (SearchParseError e) {
    249250            Logging.error("Error while parsing" + filter + ": " + e.getMessage());
    250251            throw new SAXException(e);
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/Roles.java

    r12615 r12656  
    1414
    1515import org.openstreetmap.josm.actions.search.SearchAction;
    16 import org.openstreetmap.josm.actions.search.SearchCompiler;
    1716import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1817import org.openstreetmap.josm.data.osm.Tag;
     18import org.openstreetmap.josm.data.osm.search.SearchParseError;
     19import org.openstreetmap.josm.data.osm.search.SearchCompiler;
    1920import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItem;
    2021import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetType;
     
    8283                searchSetting.regexSearch = true;
    8384                this.memberExpression = SearchCompiler.compile(searchSetting);
    84             } catch (SearchCompiler.ParseError ex) {
     85            } catch (SearchParseError ex) {
    8586                throw new SAXException(tr("Illegal member expression: {0}", ex.getMessage()), ex);
    8687            }
  • trunk/src/org/openstreetmap/josm/gui/widgets/CompileSearchTextDecorator.java

    r12620 r12656  
    99import javax.swing.text.JTextComponent;
    1010
    11 import org.openstreetmap.josm.actions.search.SearchCompiler;
     11import org.openstreetmap.josm.data.osm.search.SearchParseError;
     12import org.openstreetmap.josm.data.osm.search.SearchCompiler;
    1213import org.openstreetmap.josm.tools.Logging;
    1314
     
    4344            textComponent.setToolTipText(originalToolTipText);
    4445            filter = SearchCompiler.compile(textComponent.getText());
    45         } catch (SearchCompiler.ParseError ex) {
     46        } catch (SearchParseError ex) {
    4647            textComponent.setBackground(new Color(255, 224, 224));
    4748            textComponent.setToolTipText(ex.getMessage());
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/LoadAndZoomHandler.java

    r12636 r12656  
    1616import org.openstreetmap.josm.actions.downloadtasks.DownloadTask;
    1717import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler;
    18 import org.openstreetmap.josm.actions.search.SearchCompiler;
    1918import org.openstreetmap.josm.data.Bounds;
    2019import org.openstreetmap.josm.data.coor.LatLon;
     
    2423import org.openstreetmap.josm.data.osm.Relation;
    2524import org.openstreetmap.josm.data.osm.SimplePrimitiveId;
     25import org.openstreetmap.josm.data.osm.search.SearchParseError;
     26import org.openstreetmap.josm.data.osm.search.SearchCompiler;
    2627import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
    2728import org.openstreetmap.josm.gui.MainApplication;
     
    202203                    zoom(filteredPrimitives, bbox);
    203204                });
    204             } catch (SearchCompiler.ParseError ex) {
     205            } catch (SearchParseError ex) {
    205206                Logging.error(ex);
    206207                throw new RequestHandlerErrorException(ex);
  • trunk/src/org/openstreetmap/josm/tools/template_engine/ContextSwitchTemplate.java

    r11974 r12656  
    99import java.util.List;
    1010
    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;
    1711import org.openstreetmap.josm.data.osm.Node;
    1812import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    2014import org.openstreetmap.josm.data.osm.RelationMember;
    2115import org.openstreetmap.josm.data.osm.Way;
     16import org.openstreetmap.josm.data.osm.search.SearchCompiler.And;
     17import org.openstreetmap.josm.data.osm.search.SearchCompiler.Child;
     18import org.openstreetmap.josm.data.osm.search.SearchCompiler.Match;
     19import org.openstreetmap.josm.data.osm.search.SearchCompiler.Not;
     20import org.openstreetmap.josm.data.osm.search.SearchCompiler.Or;
     21import org.openstreetmap.josm.data.osm.search.SearchCompiler.Parent;
    2222
    2323/**
  • trunk/src/org/openstreetmap/josm/tools/template_engine/ParseError.java

    r8540 r12656  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import org.openstreetmap.josm.data.osm.search.SearchParseError;
    67import org.openstreetmap.josm.tools.template_engine.Tokenizer.Token;
    78import org.openstreetmap.josm.tools.template_engine.Tokenizer.TokenType;
     
    2223    }
    2324
    24     public ParseError(int position, org.openstreetmap.josm.actions.search.SearchCompiler.ParseError e) {
     25    public ParseError(int position, SearchParseError e) {
    2526        super(tr("Error while parsing search expression on position {0}", position), e);
    2627        unexpectedToken = null;
  • trunk/src/org/openstreetmap/josm/tools/template_engine/SearchExpressionCondition.java

    r10305 r12656  
    22package org.openstreetmap.josm.tools.template_engine;
    33
    4 import org.openstreetmap.josm.actions.search.SearchCompiler.Match;
     4import org.openstreetmap.josm.data.osm.search.SearchCompiler.Match;
    55
    66public class SearchExpressionCondition implements TemplateEntry {
  • trunk/src/org/openstreetmap/josm/tools/template_engine/TemplateEngineDataProvider.java

    r8510 r12656  
    44import java.util.Collection;
    55
    6 import org.openstreetmap.josm.actions.search.SearchCompiler.Match;
     6import org.openstreetmap.josm.data.osm.search.SearchCompiler.Match;
    77
    88public interface TemplateEngineDataProvider {
  • trunk/src/org/openstreetmap/josm/tools/template_engine/TemplateParser.java

    r11929 r12656  
    99import java.util.List;
    1010
    11 import org.openstreetmap.josm.actions.search.SearchCompiler;
    12 import org.openstreetmap.josm.actions.search.SearchCompiler.Match;
     11import org.openstreetmap.josm.data.osm.search.SearchCompiler;
     12import org.openstreetmap.josm.data.osm.search.SearchCompiler.Match;
     13import org.openstreetmap.josm.data.osm.search.SearchParseError;
    1314import org.openstreetmap.josm.tools.template_engine.Tokenizer.Token;
    1415import org.openstreetmap.josm.tools.template_engine.Tokenizer.TokenType;
     
    102103                    result.getEntries().add(new SearchExpressionCondition(
    103104                            SearchCompiler.compile(searchText), condition));
    104                 } catch (SearchCompiler.ParseError e) {
     105                } catch (SearchParseError e) {
    105106                    throw new ParseError(searchExpression.getPosition(), e);
    106107                }
     
    133134                Match match = SearchCompiler.compile(searchText);
    134135                result = new ContextSwitchTemplate(match, template, searchExpression.getPosition());
    135             } catch (SearchCompiler.ParseError e) {
     136            } catch (SearchParseError e) {
    136137                throw new ParseError(searchExpression.getPosition(), e);
    137138            }
Note: See TracChangeset for help on using the changeset viewer.