Changeset 8811 in josm for trunk/src/org


Ignore:
Timestamp:
2015-10-01T21:06:10+02:00 (5 years ago)
Author:
simon04
Message:

see #11916 - Refactoring of SearchAction/SearchCompiler

Location:
trunk/src/org/openstreetmap/josm
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java

    r8540 r8811  
    286286                if (buttonIndex == 0) {
    287287                    try {
    288                         SearchCompiler.compile(hcbSearchString.getText(), caseSensitive.isSelected(), regexSearch.isSelected());
     288                        SearchSetting ss = new SearchSetting();
     289                        ss.text = hcbSearchString.getText();
     290                        ss.caseSensitive = caseSensitive.isSelected();
     291                        ss.regexSearch = regexSearch.isSelected();
     292                        SearchCompiler.compile(ss);
    289293                        super.buttonAction(buttonIndex, evt);
    290294                    } catch (ParseError e) {
     
    454458        int foundMatches = 0;
    455459        try {
    456             String searchText = s.text;
    457             SearchCompiler.Match matcher = SearchCompiler.compile(searchText, s.caseSensitive, s.regexSearch);
     460            SearchCompiler.Match matcher = SearchCompiler.compile(s);
    458461
    459462            if (s.mode == SearchMode.replace) {
     
    508511    public static void getSelection(SearchSetting s, Collection<OsmPrimitive> all, Property<OsmPrimitive, Boolean> p) {
    509512        try {
    510             String searchText = s.text;
    511513            if (s instanceof Filter && ((Filter) s).inverted) {
    512                 searchText = String.format("-(%s)", searchText);
    513             }
    514             SearchCompiler.Match matcher = SearchCompiler.compile(searchText, s.caseSensitive, s.regexSearch);
     514                s = new SearchSetting(s);
     515                s.text = String.format("-(%s)", s.text);
     516            }
     517            SearchCompiler.Match matcher = SearchCompiler.compile(s);
    515518
    516519            for (OsmPrimitive osm : all) {
     
    540543
    541544    public static void search(String search, SearchMode mode) {
    542         search(new SearchSetting(search, mode, false, false, false));
     545        final SearchSetting searchSetting = new SearchSetting();
     546        searchSetting.text = search;
     547        searchSetting.mode = mode;
     548        search(searchSetting);
    543549    }
    544550
     
    579585
    580586    public static class SearchSetting {
    581         public String text;
    582         public SearchMode mode;
     587        public String text = "";
     588        public SearchMode mode = SearchMode.replace;
    583589        public boolean caseSensitive;
    584590        public boolean regexSearch;
     
    589595         */
    590596        public SearchSetting() {
    591             this("", SearchMode.replace, false /* case insensitive */,
    592                     false /* no regexp */, false /* only useful primitives */);
    593         }
    594 
    595         public SearchSetting(String text, SearchMode mode, boolean caseSensitive,
    596                 boolean regexSearch, boolean allElements) {
    597             this.caseSensitive = caseSensitive;
    598             this.regexSearch = regexSearch;
    599             this.allElements = allElements;
    600             this.mode = mode;
    601             this.text = text;
    602597        }
    603598
    604599        public SearchSetting(SearchSetting original) {
    605             this(original.text, original.mode, original.caseSensitive,
    606                     original.regexSearch, original.allElements);
     600            text = original.text;
     601            mode = original.mode;
     602            caseSensitive = original.caseSensitive;
     603            regexSearch = original.regexSearch;
     604            allElements = original.allElements;
    607605        }
    608606
     
    612610                    /*case sensitive*/  trc("search", "CS") :
    613611                        /*case insensitive*/  trc("search", "CI");
    614                     String rx = regexSearch ? ", " +
     612            String rx = regexSearch ? ", " +
    615613                            /*regex search*/ trc("search", "RX") : "";
    616                     String all = allElements ? ", " +
     614            String all = allElements ? ", " +
    617615                            /*all elements*/ trc("search", "A") : "";
    618                     return "\"" + text + "\" (" + cs + rx + all + ", " + mode + ")";
     616            return "\"" + text + "\" (" + cs + rx + all + ", " + mode + ")";
    619617        }
    620618
  • trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java

    r8781 r8811  
    14021402    }
    14031403
    1404     public static Match compile(String searchStr, boolean caseSensitive, boolean regexSearch) throws ParseError {
    1405         return new SearchCompiler(caseSensitive, regexSearch,
     1404    /**
     1405     * Compiles the search expression.
     1406     * @param searchStr the search expression
     1407     * @return a {@link Match} object for the expression
     1408     * @throws ParseError if an error has been encountered while compiling
     1409     * @see #compile(org.openstreetmap.josm.actions.search.SearchAction.SearchSetting)
     1410     */
     1411    public static Match compile(String searchStr) throws ParseError {
     1412        return new SearchCompiler(false, false,
    14061413                new PushbackTokenizer(
    14071414                        new PushbackReader(new StringReader(searchStr))))
    1408         .parse();
     1415                .parse();
     1416    }
     1417
     1418    /**
     1419     * Compiles the search expression.
     1420     * @param setting the settings to use
     1421     * @return a {@link Match} object for the expression
     1422     * @throws ParseError if an error has been encountered while compiling
     1423     * @see #compile(String)
     1424     */
     1425    public static Match compile(SearchAction.SearchSetting setting) throws ParseError {
     1426        return new SearchCompiler(setting.caseSensitive, setting.regexSearch,
     1427                new PushbackTokenizer(
     1428                        new PushbackReader(new StringReader(setting.text))))
     1429                .parse();
    14091430    }
    14101431
  • trunk/src/org/openstreetmap/josm/data/osm/Filter.java

    r7083 r8811  
    2222     */
    2323    public Filter() {
    24         super("", SearchMode.add, false, false, false);
    25     }
    26 
    27     public Filter(String text, SearchMode mode, boolean caseSensitive,
    28             boolean regexSearch, boolean allElements) {
    29         super(text, mode, caseSensitive, regexSearch, allElements);
     24        super();
     25        mode = SearchMode.add;
    3026    }
    3127
    3228    public Filter(FilterPreferenceEntry e) {
    33         super(e.text, SearchMode.add, false, false, false);
     29        this();
     30        text = e.text;
    3431        if ("replace".equals(e.mode)) {
    3532            mode = SearchMode.replace;
  • trunk/src/org/openstreetmap/josm/data/osm/FilterMatcher.java

    r8510 r8811  
    8484            }
    8585
    86             Match compiled = SearchCompiler.compile(filter.text, filter.caseSensitive, filter.regexSearch);
     86            Match compiled = SearchCompiler.compile(filter);
    8787            this.match = filter.inverted ? new Not(compiled) : compiled;
    8888            this.isInverted = filter.inverted;
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r8767 r8811  
    795795
    796796        try {
    797             reversedDirectionKeys = SearchCompiler.compile(Main.pref.get("tags.reversed_direction", reversedDirectionDefault), false, false);
     797            reversedDirectionKeys = SearchCompiler.compile(Main.pref.get("tags.reversed_direction", reversedDirectionDefault));
    798798        } catch (ParseError e) {
    799799            Main.error("Unable to compile pattern for tags.reversed_direction, trying default pattern: " + e.getMessage());
    800800
    801801            try {
    802                 reversedDirectionKeys = SearchCompiler.compile(reversedDirectionDefault, false, false);
     802                reversedDirectionKeys = SearchCompiler.compile(reversedDirectionDefault);
    803803            } catch (ParseError e2) {
    804804                throw new AssertionError("Unable to compile default pattern for direction keys: " + e2.getMessage(), e2);
     
    806806        }
    807807        try {
    808             directionKeys = SearchCompiler.compile(Main.pref.get("tags.direction", directionDefault), false, false);
     808            directionKeys = SearchCompiler.compile(Main.pref.get("tags.direction", directionDefault));
    809809        } catch (ParseError e) {
    810810            Main.error("Unable to compile pattern for tags.direction, trying default pattern: " + e.getMessage());
    811811
    812812            try {
    813                 directionKeys = SearchCompiler.compile(directionDefault, false, false);
     813                directionKeys = SearchCompiler.compile(directionDefault);
    814814            } catch (ParseError e2) {
    815815                throw new AssertionError("Unable to compile default pattern for direction keys: " + e2.getMessage(), e2);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java

    r8540 r8811  
    289289                    f.setBackground(UIManager.getColor("TextField.background"));
    290290                    f.setToolTipText(tr("Relation list filter"));
    291                     model.setFilter(SearchCompiler.compile(filter.getText(), false, false));
     291                    model.setFilter(SearchCompiler.compile(filter.getText()));
    292292                } catch (SearchCompiler.ParseError ex) {
    293293                    f.setBackground(new Color(255, 224, 224));
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    r8693 r8811  
    13231323            }
    13241324
    1325             SearchSetting ss = new SearchSetting(s.toString(), SearchMode.replace, true, false, false);
     1325            final SearchSetting ss = new SearchSetting();
     1326            ss.text = s.toString();
     1327            ss.caseSensitive = true;
    13261328            org.openstreetmap.josm.actions.search.SearchAction.searchWithoutHistory(ss);
    13271329        }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java

    r8795 r8811  
    664664            Match m;
    665665            try {
    666                 m = SearchCompiler.compile(searchStr, false, false);
     666                m = SearchCompiler.compile(searchStr);
    667667            } catch (ParseError ex) {
    668668                return null;
  • trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java

    r8710 r8811  
    202202    public void setName_template_filter(String filter) throws SAXException {
    203203        try {
    204             this.nameTemplateFilter = SearchCompiler.compile(filter, false, false);
     204            this.nameTemplateFilter = SearchCompiler.compile(filter);
    205205        } catch (org.openstreetmap.josm.actions.search.SearchCompiler.ParseError e) {
    206206            Main.error("Error while parsing" + filter + ": " + e.getMessage());
  • trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetItems.java

    r8786 r8811  
    5252
    5353import org.openstreetmap.josm.Main;
     54import org.openstreetmap.josm.actions.search.SearchAction;
    5455import org.openstreetmap.josm.actions.search.SearchCompiler;
    5556import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    204205        public void setMember_expression(String member_expression) throws SAXException {
    205206            try {
    206                 this.memberExpression = SearchCompiler.compile(member_expression, true, true);
     207                final SearchAction.SearchSetting searchSetting = new SearchAction.SearchSetting();
     208                searchSetting.text = member_expression;
     209                searchSetting.caseSensitive = true;
     210                searchSetting.regexSearch = true;
     211                this.memberExpression = SearchCompiler.compile(searchSetting);
    207212            } catch (SearchCompiler.ParseError ex) {
    208213                throw new SAXException(tr("Illegal member expression: {0}", ex.getMessage()), ex);
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/LoadAndZoomHandler.java

    r8510 r8811  
    196196        } else if (args.containsKey("search") && PermissionPrefWithDefault.CHANGE_SELECTION.isAllowed()) {
    197197            try {
    198                 final SearchCompiler.Match search = SearchCompiler.compile(args.get("search"), false, false);
     198                final SearchCompiler.Match search = SearchCompiler.compile(args.get("search"));
    199199                Main.worker.submit(new Runnable() {
    200200                    @Override
  • trunk/src/org/openstreetmap/josm/tools/template_engine/TemplateParser.java

    r8509 r8811  
    9090                try {
    9191                    result.getEntries().add(new SearchExpressionCondition(
    92                             SearchCompiler.compile(searchExpression.getText(), false, false), condition));
     92                            SearchCompiler.compile(searchExpression.getText()), condition));
    9393                } catch (org.openstreetmap.josm.actions.search.SearchCompiler.ParseError e) {
    9494                    throw new ParseError(searchExpression.getPosition(), e);
     
    119119        else {
    120120            try {
    121                 Match match = SearchCompiler.compile(searchExpression.getText(), false, false);
     121                Match match = SearchCompiler.compile(searchExpression.getText());
    122122                result = new ContextSwitchTemplate(match, template, searchExpression.getPosition());
    123123            } catch (org.openstreetmap.josm.actions.search.SearchCompiler.ParseError e) {
Note: See TracChangeset for help on using the changeset viewer.