/** * Validate the given javaScript unit name for the given source and compliance levels. * * <p>A javaScript unit name must obey the following rules: * * <ul> * <li>it must not be null * <li>it must be suffixed by a dot ('.') followed by one of the {@link * JavaScriptCore#getJavaScriptLikeExtensions() JavaScript-like extensions} * <li>its prefix must be a valid identifier * <li>it must not contain any characters or substrings that are not valid on the file system on * which workspace root is located. * </ul> * * @param name the name of a javaScript unit * @param sourceLevel the source level * @param complianceLevel the compliance level * @return a status object with code <code>IStatus.OK</code> if the given name is valid as a * javaScript unit name, otherwise a status object indicating what is wrong with the name */ public static IStatus validateCompilationUnitName( String name, String sourceLevel, String complianceLevel) { if (name == null) { return new Status( IStatus.ERROR, JavaScriptCore.PLUGIN_ID, -1, Messages.convention_unit_nullName, null); } if (!org.eclipse.wst.jsdt.internal.core.util.Util.isJavaLikeFileName(name)) { return new Status( IStatus.ERROR, JavaScriptCore.PLUGIN_ID, -1, Messages.convention_unit_notJavaName, null); } // String identifier; int index; index = name.lastIndexOf('.'); if (index == -1) { return new Status( IStatus.ERROR, JavaScriptCore.PLUGIN_ID, -1, Messages.convention_unit_notJavaName, null); } // identifier = name.substring(0, index); // JSR-175 metadata strongly recommends "package-info.js" as the // file in which to store package annotations and // the package-level spec (replaces package.html) // if (!identifier.equals(PACKAGE_INFO)) { // IStatus status = validateIdentifier(identifier, sourceLevel, complianceLevel); // if (!status.isOK()) { // return status; // } // } // IStatus status = ResourcesPlugin.getWorkspace().validateName(name, IResource.FILE); // if (!status.isOK()) { // return status; // } return JavaModelStatus.VERIFIED_OK; }