< prev index next >
src/java.base/share/classes/jdk/internal/module/Checks.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -24,11 +24,11 @@
*/
package jdk.internal.module;
/**
- * Utility class for checking module name and binary names.
+ * Utility class for checking module, package, and class names.
*/
public final class Checks {
private Checks() { }
@@ -56,12 +56,10 @@
if (last == -1) {
String id = name.substring(off);
throw new IllegalArgumentException(name + ": Invalid module name"
+ ": '" + id + "' is not a Java identifier");
}
- //if (!Character.isJavaIdentifierStart(last))
- // throw new IllegalArgumentException(name + ": Module name ends in digit");
return name;
}
/**
* Returns {@code true} if the given name is a legal module name.
@@ -75,56 +73,76 @@
off = next+1;
}
int last = isJavaIdentifier(name, off, name.length() - off);
if (last == -1)
return false;
- //if (!Character.isJavaIdentifierStart(last))
- // return false;
return true;
}
/**
* Checks a name to ensure that it's a legal package name.
*
* @throws IllegalArgumentException if name is null or not a legal
* package name
*/
public static String requirePackageName(String name) {
- return requireBinaryName("package name", name);
+ return requireTypeName("package name", name);
}
/**
- * Checks a name to ensure that it's a legal type name.
+ * Returns {@code true} if the given name is a legal package name.
+ */
+ public static boolean isPackageName(String name) {
+ return isTypeName(name);
+ }
+
+ /**
+ * Checks a name to ensure that it's a legal qualified class name
*
* @throws IllegalArgumentException if name is null or not a legal
- * type name
+ * qualified class name
*/
public static String requireServiceTypeName(String name) {
- return requireBinaryName("service type name", name);
+ return requireQualifiedClassName("service type name", name);
}
/**
- * Checks a name to ensure that it's a legal type name.
+ * Checks a name to ensure that it's a legal qualified class name.
*
* @throws IllegalArgumentException if name is null or not a legal
- * type name
+ * qualified class name
*/
public static String requireServiceProviderName(String name) {
- return requireBinaryName("service provider name", name);
+ return requireQualifiedClassName("service provider name", name);
+ }
+
+ /**
+ * Checks a name to ensure that it's a legal qualified class name in
+ * a named package.
+ *
+ * @throws IllegalArgumentException if name is null or not a legal
+ * qualified class name in a named package
+ */
+ public static String requireQualifiedClassName(String what, String name) {
+ requireTypeName(what, name);
+ if (name.indexOf('.') == -1)
+ throw new IllegalArgumentException(name + ": is not a qualified name of"
+ + " a Java class in a named package");
+ return name;
}
/**
- * Returns {@code true} if the given name is a legal binary name.
+ * Returns {@code true} if the given name is a legal class name.
*/
- public static boolean isJavaIdentifier(String name) {
- return isBinaryName(name);
+ public static boolean isClassName(String name) {
+ return isTypeName(name);
}
/**
- * Returns {@code true} if the given name is a legal binary name.
+ * Returns {@code true} if the given name is a legal type name.
*/
- public static boolean isBinaryName(String name) {
+ private static boolean isTypeName(String name) {
int next;
int off = 0;
while ((next = name.indexOf('.', off)) != -1) {
if (isJavaIdentifier(name, off, (next - off)) == -1)
return false;
@@ -133,16 +151,16 @@
int count = name.length() - off;
return (isJavaIdentifier(name, off, count) != -1);
}
/**
- * Checks if the given name is a legal binary name.
+ * Checks if the given name is a legal type name.
*
* @throws IllegalArgumentException if name is null or not a legal
- * binary name
+ * type name
*/
- public static String requireBinaryName(String what, String name) {
+ private static String requireTypeName(String what, String name) {
if (name == null)
throw new IllegalArgumentException("Null " + what);
int next;
int off = 0;
while ((next = name.indexOf('.', off)) != -1) {
< prev index next >