Example usage for org.eclipse.jdt.internal.core.util Messages convention_unit_notJavaName

List of usage examples for org.eclipse.jdt.internal.core.util Messages convention_unit_notJavaName

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core.util Messages convention_unit_notJavaName.

Prototype

String convention_unit_notJavaName

To view the source code for org.eclipse.jdt.internal.core.util Messages convention_unit_notJavaName.

Click Source Link

Usage

From source file:com.codenvy.ide.ext.java.server.core.JavaConventions.java

License:Open Source License

/**
 * Validate the given compilation unit name for the given source and compliance levels.
 * <p>/*w  ww  .jav a2  s  .  c  om*/
 * A compilation 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 org.eclipse.jdt.core.JavaCore#getJavaLikeExtensions() Java-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>
 * </p>
 * @param name the name of a compilation 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 compilation unit name, otherwise a status
 *      object indicating what is wrong with the name
 * @since 3.3
 */
public static IStatus validateCompilationUnitName(String name, String sourceLevel, String complianceLevel) {
    if (name == null) {
        return new Status(IStatus.ERROR, org.eclipse.jdt.core.JavaCore.PLUGIN_ID, -1,
                Messages.convention_unit_nullName, null);
    }
    if (!org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(name)) {
        return new Status(IStatus.ERROR, org.eclipse.jdt.core.JavaCore.PLUGIN_ID, -1,
                Messages.convention_unit_notJavaName, null);
    }
    String identifier;
    int index;
    index = name.lastIndexOf('.');
    if (index == -1) {
        return new Status(IStatus.ERROR, org.eclipse.jdt.core.JavaCore.PLUGIN_ID, -1,
                Messages.convention_unit_notJavaName, null);
    }
    identifier = name.substring(0, index);
    // JSR-175 metadata strongly recommends "package-info.java" 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;
}

From source file:com.codenvy.ide.ext.java.server.dom.JavaConventions.java

License:Open Source License

/**
 * Validate the given compilation unit name for the given source and compliance levels.
 * <p>/*from www  . j a v  a 2s.  c om*/
 * A compilation 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 org.eclipse.jdt.core.JavaCore#getJavaLikeExtensions() Java-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>
 * </p>
 * @param name the name of a compilation 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 compilation unit name, otherwise a status
 *      object indicating what is wrong with the name
 * @since 3.3
 */
public static IStatus validateCompilationUnitName(String name, String sourceLevel, String complianceLevel) {
    if (name == null) {
        return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.convention_unit_nullName, null);
    }
    if (!Util.isJavaLikeFileName(name)) {
        return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.convention_unit_notJavaName, null);
    }
    String identifier;
    int index;
    index = name.lastIndexOf('.');
    if (index == -1) {
        return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.convention_unit_notJavaName, null);
    }
    identifier = name.substring(0, index);
    // JSR-175 metadata strongly recommends "package-info.java" 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;
}

From source file:com.codenvy.ide.ext.java.server.internal.core.PackageFragment.java

License:Open Source License

/**
 * @see org.eclipse.jdt.core.IPackageFragment#getCompilationUnit(String)
 * @exception IllegalArgumentException if the name does not end with ".java"
 *///from  w w  w . j a  v  a  2 s.  c  o m
public ICompilationUnit getCompilationUnit(String cuName) {
    if (!Util.isJavaLikeFileName(cuName)) {
        throw new IllegalArgumentException(Messages.convention_unit_notJavaName);
    }
    return new CompilationUnit(this, manager, cuName, DefaultWorkingCopyOwner.PRIMARY);
}

From source file:org.eclipse.jdt.internal.core.PackageFragment.java

License:Open Source License

/**
 * @see IPackageFragment#getCompilationUnit(String)
 * @exception IllegalArgumentException if the name does not end with ".java"
 *///w  w w  .  j  a va  2  s  .co  m
public ICompilationUnit getCompilationUnit(String cuName) {
    if (!org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(cuName)) {
        throw new IllegalArgumentException(Messages.convention_unit_notJavaName);
    }
    // GROOVY start
    /* old {
    return new CompilationUnit(this, cuName, DefaultWorkingCopyOwner.PRIMARY);
    } new */
    return LanguageSupportFactory.newCompilationUnit(this, cuName, DefaultWorkingCopyOwner.PRIMARY);
    // GROOVY end
}