Changeset 18195 in josm for trunk/src/org
- Timestamp:
- 2021-09-07T23:46:34+02:00 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/search/SearchCompiler.java
r17787 r18195 291 291 return match(object); 292 292 } 293 294 /** 295 * Check if this is a valid match object 296 * @return {@code this}, for easy chaining 297 * @throws SearchParseError If the match is not valid 298 */ 299 public Match validate() throws SearchParseError { 300 // Default to no-op 301 return this; 302 } 293 303 } 294 304 … … 861 871 return false; 862 872 return true; 873 } 874 875 @Override 876 public Match validate() throws SearchParseError { 877 if (this.referenceValue == null) { 878 final String referenceType; 879 if (this.compareMode == +1) { 880 referenceType = ">"; 881 } else if (this.compareMode == -1) { 882 referenceType = "<"; 883 } else { 884 referenceType = "<unknown>"; 885 } 886 throw new SearchParseError(tr("Reference value for ''{0}'' expected", referenceType)); 887 } 888 return this; 863 889 } 864 890 } … … 2109 2135 String key = tokenizer.getText(); 2110 2136 if (tokenizer.readIfEqual(Token.EQUALS)) { 2111 return new ExactKeyValue(regexSearch, caseSensitive, key, tokenizer.readTextOrNumber()) ;2137 return new ExactKeyValue(regexSearch, caseSensitive, key, tokenizer.readTextOrNumber()).validate(); 2112 2138 } else if (tokenizer.readIfEqual(Token.TILDE)) { 2113 return new ExactKeyValue(true, caseSensitive, key, tokenizer.readTextOrNumber()) ;2139 return new ExactKeyValue(true, caseSensitive, key, tokenizer.readTextOrNumber()).validate(); 2114 2140 } else if (tokenizer.readIfEqual(Token.LESS_THAN)) { 2115 return new ValueComparison(key, tokenizer.readTextOrNumber(), -1) ;2141 return new ValueComparison(key, tokenizer.readTextOrNumber(), -1).validate(); 2116 2142 } else if (tokenizer.readIfEqual(Token.GREATER_THAN)) { 2117 return new ValueComparison(key, tokenizer.readTextOrNumber(), +1) ;2143 return new ValueComparison(key, tokenizer.readTextOrNumber(), +1).validate(); 2118 2144 } else if (tokenizer.readIfEqual(Token.COLON)) { 2119 2145 // see if we have a Match that takes a data parameter … … 2124 2150 UnaryMatchFactory unaryFactory = unaryMatchFactoryMap.get(key); 2125 2151 if (unaryFactory != null) 2126 return unaryFactory.get(key, parseFactor(), tokenizer) ;2152 return unaryFactory.get(key, parseFactor(), tokenizer).validate(); 2127 2153 2128 2154 // key:value form where value is a string (may be OSM key search) 2129 2155 final String value = tokenizer.readTextOrNumber(); 2130 return new KeyValue(key, value != null ? value : "", regexSearch, caseSensitive) ;2156 return new KeyValue(key, value != null ? value : "", regexSearch, caseSensitive).validate(); 2131 2157 } else if (tokenizer.readIfEqual(Token.QUESTION_MARK)) 2132 2158 return new BooleanMatch(key, false); … … 2134 2160 SimpleMatchFactory factory = simpleMatchFactoryMap.get(key); 2135 2161 if (factory != null) 2136 return factory.get(key, caseSensitive, regexSearch, null) ;2162 return factory.get(key, caseSensitive, regexSearch, null).validate(); 2137 2163 2138 2164 UnaryMatchFactory unaryFactory = unaryMatchFactoryMap.get(key); 2139 2165 if (unaryFactory != null) 2140 return unaryFactory.get(key, parseFactor(), null) ;2166 return unaryFactory.get(key, parseFactor(), null).validate(); 2141 2167 2142 2168 // match string in any key or value 2143 return new Any(key, regexSearch, caseSensitive) ;2169 return new Any(key, regexSearch, caseSensitive).validate(); 2144 2170 } 2145 2171 } else
Note:
See TracChangeset
for help on using the changeset viewer.