214 * version. The method returns {@code true} if the name consists |
214 * version. The method returns {@code true} if the name consists |
215 * of an initial character for which {@link |
215 * of an initial character for which {@link |
216 * Character#isJavaIdentifierStart(int)} returns {@code true}, |
216 * Character#isJavaIdentifierStart(int)} returns {@code true}, |
217 * followed only by characters for which {@link |
217 * followed only by characters for which {@link |
218 * Character#isJavaIdentifierPart(int)} returns {@code true}. |
218 * Character#isJavaIdentifierPart(int)} returns {@code true}. |
219 * This pattern matches regular identifiers, keywords, and the |
219 * This pattern matches regular identifiers, keywords, restricted |
220 * literals {@code "true"}, {@code "false"}, and {@code "null"}. |
220 * keywords, and the literals {@code "true"}, {@code "false"}, and |
|
221 * {@code "null"}. |
221 * The method returns {@code false} for all other strings. |
222 * The method returns {@code false} for all other strings. |
222 * |
223 * |
223 * @param name the string to check |
224 * @param name the string to check |
224 * @return {@code true} if this string is a |
225 * @return {@code true} if this string is a |
225 * syntactically valid identifier or keyword, {@code false} |
226 * syntactically valid identifier or keyword, {@code false} |
249 /** |
250 /** |
250 * Returns whether or not {@code name} is a syntactically valid |
251 * Returns whether or not {@code name} is a syntactically valid |
251 * qualified name in the latest source version. Unlike {@link |
252 * qualified name in the latest source version. Unlike {@link |
252 * #isIdentifier isIdentifier}, this method returns {@code false} |
253 * #isIdentifier isIdentifier}, this method returns {@code false} |
253 * for keywords, boolean literals, and the null literal. |
254 * for keywords, boolean literals, and the null literal. |
|
255 * This method returns {@code true} for <i>restricted |
|
256 * keywords</i>. |
254 * |
257 * |
255 * @param name the string to check |
258 * @param name the string to check |
256 * @return {@code true} if this string is a |
259 * @return {@code true} if this string is a |
257 * syntactically valid name, {@code false} otherwise. |
260 * syntactically valid name, {@code false} otherwise. |
|
261 * @jls 3.9 Keywords |
258 * @jls 6.2 Names and Identifiers |
262 * @jls 6.2 Names and Identifiers |
259 */ |
263 */ |
260 public static boolean isName(CharSequence name) { |
264 public static boolean isName(CharSequence name) { |
261 return isName(name, latest()); |
265 return isName(name, latest()); |
262 } |
266 } |
264 /** |
268 /** |
265 * Returns whether or not {@code name} is a syntactically valid |
269 * Returns whether or not {@code name} is a syntactically valid |
266 * qualified name in the given source version. Unlike {@link |
270 * qualified name in the given source version. Unlike {@link |
267 * #isIdentifier isIdentifier}, this method returns {@code false} |
271 * #isIdentifier isIdentifier}, this method returns {@code false} |
268 * for keywords, boolean literals, and the null literal. |
272 * for keywords, boolean literals, and the null literal. |
|
273 * This method returns {@code true} for <i>restricted |
|
274 * keywords</i>. |
269 * |
275 * |
270 * @param name the string to check |
276 * @param name the string to check |
271 * @param version the version to use |
277 * @param version the version to use |
272 * @return {@code true} if this string is a |
278 * @return {@code true} if this string is a |
273 * syntactically valid name, {@code false} otherwise. |
279 * syntactically valid name, {@code false} otherwise. |
|
280 * @jls 3.9 Keywords |
274 * @jls 6.2 Names and Identifiers |
281 * @jls 6.2 Names and Identifiers |
275 * @since 9 |
282 * @since 9 |
276 */ |
283 */ |
277 public static boolean isName(CharSequence name, SourceVersion version) { |
284 public static boolean isName(CharSequence name, SourceVersion version) { |
278 String id = name.toString(); |
285 String id = name.toString(); |
285 } |
292 } |
286 |
293 |
287 /** |
294 /** |
288 * Returns whether or not {@code s} is a keyword, boolean literal, |
295 * Returns whether or not {@code s} is a keyword, boolean literal, |
289 * or null literal in the latest source version. |
296 * or null literal in the latest source version. |
|
297 * This method returns {@code false} for <i>restricted |
|
298 * keywords</i>. |
290 * |
299 * |
291 * @param s the string to check |
300 * @param s the string to check |
292 * @return {@code true} if {@code s} is a keyword, or boolean |
301 * @return {@code true} if {@code s} is a keyword, or boolean |
293 * literal, or null literal, {@code false} otherwise. |
302 * literal, or null literal, {@code false} otherwise. |
294 * @jls 3.9 Keywords |
303 * @jls 3.9 Keywords |
300 } |
309 } |
301 |
310 |
302 /** |
311 /** |
303 * Returns whether or not {@code s} is a keyword, boolean literal, |
312 * Returns whether or not {@code s} is a keyword, boolean literal, |
304 * or null literal in the given source version. |
313 * or null literal in the given source version. |
|
314 * This method returns {@code false} for <i>restricted |
|
315 * keywords</i>. |
305 * |
316 * |
306 * @param s the string to check |
317 * @param s the string to check |
307 * @param version the version to use |
318 * @param version the version to use |
308 * @return {@code true} if {@code s} is a keyword, or boolean |
319 * @return {@code true} if {@code s} is a keyword, or boolean |
309 * literal, or null literal, {@code false} otherwise. |
320 * literal, or null literal, {@code false} otherwise. |