< prev index next >

src/java.base/share/classes/jdk/internal/module/Checks.java

Print this page
rev 52979 : 8215281: Use String.isEmpty() when applicable in java.base
Reviewed-by: TBD

*** 61,86 **** } return name; } /** - * Returns {@code true} if the given name is a legal module name. - */ - public static boolean isModuleName(String name) { - int next; - int off = 0; - while ((next = name.indexOf('.', off)) != -1) { - String id = name.substring(off, next); - if (!isJavaIdentifier(id)) - return false; - off = next+1; - } - String last = name.substring(off); - return isJavaIdentifier(last); - } - - /** * Checks a name to ensure that it's a legal package name. * * @throws IllegalArgumentException if name is null or not a legal * package name */ --- 61,70 ----
*** 179,202 **** } return name; } /** ! * Returns true if the given char sequence is a legal Java identifier, * otherwise false. */ ! private static boolean isJavaIdentifier(CharSequence cs) { ! if (cs.length() == 0 || RESERVED.contains(cs)) return false; ! int first = Character.codePointAt(cs, 0); if (!Character.isJavaIdentifierStart(first)) return false; int i = Character.charCount(first); ! while (i < cs.length()) { ! int cp = Character.codePointAt(cs, i); if (!Character.isJavaIdentifierPart(cp)) return false; i += Character.charCount(cp); } --- 163,186 ---- } return name; } /** ! * Returns true if the given string is a legal Java identifier, * otherwise false. */ ! private static boolean isJavaIdentifier(String str) { ! if (str.isEmpty() || RESERVED.contains(str)) return false; ! int first = Character.codePointAt(str, 0); if (!Character.isJavaIdentifierStart(first)) return false; int i = Character.charCount(first); ! while (i < str.length()) { ! int cp = Character.codePointAt(str, i); if (!Character.isJavaIdentifierPart(cp)) return false; i += Character.charCount(cp); }
< prev index next >