Changeset 17336 in josm
- Timestamp:
- 2020-11-23T19:59:45+01:00 (4 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/download/OverpassQueryWizardDialog.java
r16359 r17336 91 91 private Optional<String> tryParseSearchTerm(String searchTerm) { 92 92 try { 93 return Optional.of(SearchCompilerQueryWizard. getInstance().constructQuery(searchTerm));93 return Optional.of(SearchCompilerQueryWizard.constructQuery(searchTerm)); 94 94 } catch (UncheckedParseException | IllegalStateException ex) { 95 95 Logging.error(ex); -
trunk/src/org/openstreetmap/josm/tools/SearchCompilerQueryWizard.java
r16358 r17336 26 26 public final class SearchCompilerQueryWizard { 27 27 28 private static final SearchCompilerQueryWizard instance = new SearchCompilerQueryWizard();29 30 /**31 * Replies the unique instance of this class.32 *33 * @return the unique instance of this class34 */35 public static SearchCompilerQueryWizard getInstance() {36 return instance;37 }38 39 28 private SearchCompilerQueryWizard() { 40 29 // private constructor for utility class … … 47 36 * @throws UncheckedParseException when the parsing fails 48 37 */ 49 public String constructQuery(final String search) {38 public static String constructQuery(final String search) { 50 39 try { 51 40 Matcher matcher = Pattern.compile("\\s+GLOBAL\\s*$", Pattern.CASE_INSENSITIVE).matcher(search); … … 74 63 } 75 64 } 76 65 77 66 final Match match = SearchCompiler.compile(search); 78 67 return constructQuery(match, "[bbox:{{bbox}}];", ""); … … 82 71 } 83 72 84 private String constructQuery(final Match match, final String bounds, final String queryLineSuffix) {73 private static String constructQuery(final Match match, final String bounds, final String queryLineSuffix) { 85 74 final List<Match> normalized = normalizeToDNF(match); 86 75 final List<String> queryLines = new ArrayList<>(); … … 136 125 case EXACT: 137 126 return "[" + quote(key) + (negated ? "!=" : "=") + quote(value) + "]"; 127 case ANY_KEY: // *=value 128 // fall through 138 129 case EXACT_REGEXP: 139 130 final Matcher matcher = Pattern.compile("/(?<regex>.*)/(?<flags>i)?").matcher(value); … … 141 132 ? quote(matcher.group("regex")) + Optional.ofNullable(matcher.group("flags")).map(f -> "," + f).orElse("") 142 133 : quote(value); 134 if (mode == SearchCompiler.ExactKeyValue.Mode.ANY_KEY) 135 return "[~\"^.*$\"" + (negated ? "!~" : "~") + valueQuery + "]"; 143 136 return "[" + quote(key) + (negated ? "!~" : "~") + valueQuery + "]"; 144 137 case MISSING_KEY: -
trunk/test/unit/org/openstreetmap/josm/io/OverpassDownloadReaderTest.java
r17333 r17336 59 59 60 60 private String getExpandedQuery(String search) { 61 final String query = SearchCompilerQueryWizard. getInstance().constructQuery(search);61 final String query = SearchCompilerQueryWizard.constructQuery(search); 62 62 final String request = new OverpassDownloadReader(new Bounds(1, 2, 3, 4), null, query) 63 63 .getRequestForBbox(1, 2, 3, 4) -
trunk/test/unit/org/openstreetmap/josm/tools/SearchCompilerQueryWizardTest.java
r17275 r17336 24 24 25 25 private static String constructQuery(String s) { 26 return SearchCompilerQueryWizard. getInstance().constructQuery(s);26 return SearchCompilerQueryWizard.constructQuery(s); 27 27 } 28 28 … … 241 241 "type:relation and type=multipolygon and -landuse=* and -\"area:highway\"=*"); 242 242 } 243 244 /** 245 * Test for ticket <a href="https://josm.openstreetmap.de/ticket/20037>#20037</a> 246 */ 247 @Test 248 void testTicket20037() { 249 assertQueryEquals( 250 " node[~\"^.*$\"~\"forward\"];\n" + 251 " node[~\"^.*$\"~\"backward\"];\n", 252 "type:node AND (*=forward OR *=backward)"); 253 } 243 254 }
Note:
See TracChangeset
for help on using the changeset viewer.