Skip to content

Commit

Permalink
More descriptive names
Browse files Browse the repository at this point in the history
  • Loading branch information
liach committed Nov 2, 2024
1 parent dae377a commit 469077d
Showing 1 changed file with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,24 +174,23 @@ public static ClassDesc parseReferenceTypeDesc(String descriptor) {
}

/**
* Validates the correctness of a path-based name, which is a class or
* interface name or a package name.
* Validates the correctness of a class or interface name or a package name.
* In particular checks for the presence of invalid characters,
* consecutive, leading, or trailing separator char,
* and the empty string for class or interface names.
* consecutive, leading, or trailing separator char, for both non-internal
* and internal forms, and the empty string for class or interface names.
*
* @param name the name
* @param usesSlash {@code true} means {@code /} is the separator char,
* otherwise {@code .} is the separator char
* @param allowsEmpty {@code true} means the empty string is a valid name
* @param slashSeparator {@code true} means {@code /} is the separator char
* (internal form); otherwise {@code .} is the separator char
* @param allowEmpty {@code true} means the empty string is a valid name
* @return the name passed if valid
* @throws IllegalArgumentException if the name is invalid
* @throws NullPointerException if name is {@code null}
*/
private static String validatePathBasedName(String name, boolean usesSlash, boolean allowsEmpty) {
private static String validateClassOrPackageName(String name, boolean slashSeparator, boolean allowEmpty) {
int len = name.length(); // implicit null check
// empty name special rule
if (allowsEmpty && len == 0)
if (allowEmpty && len == 0)
return name;
// state variable for detection of illegal states of
// empty name, consecutive, leading, or trailing separators
Expand All @@ -206,7 +205,7 @@ private static String validatePathBasedName(String name, boolean usesSlash, bool
if (foundSlash || ch == '.') {
// reject the other separator char
// reject consecutive or leading separators
if (foundSlash != usesSlash || i == afterSeparator)
if (foundSlash != slashSeparator || i == afterSeparator)
throw invalidClassName(name);
afterSeparator = i + 1;
}
Expand All @@ -228,7 +227,7 @@ private static String validatePathBasedName(String name, boolean usesSlash, bool
* @throws NullPointerException if class name is {@code null}
*/
public static String validateBinaryClassName(String name) {
return validatePathBasedName(name, false, false);
return validateClassOrPackageName(name, false, false);
}

/**
Expand All @@ -242,7 +241,7 @@ public static String validateBinaryClassName(String name) {
* @throws NullPointerException if class name is {@code null}
*/
public static String validateInternalClassName(String name) {
return validatePathBasedName(name, true, false);
return validateClassOrPackageName(name, true, false);
}

/**
Expand All @@ -256,7 +255,7 @@ public static String validateInternalClassName(String name) {
* @throws NullPointerException if the package name is {@code null}
*/
public static String validateBinaryPackageName(String name) {
return validatePathBasedName(name, false, true);
return validateClassOrPackageName(name, false, true);
}

/**
Expand All @@ -270,7 +269,7 @@ public static String validateBinaryPackageName(String name) {
* @throws NullPointerException if the package name is {@code null}
*/
public static String validateInternalPackageName(String name) {
return validatePathBasedName(name, true, true);
return validateClassOrPackageName(name, true, true);
}

/**
Expand Down

0 comments on commit 469077d

Please sign in to comment.