Example usage for org.eclipse.jdt.internal.compiler.parser ScannerHelper isUpperCase

List of usage examples for org.eclipse.jdt.internal.compiler.parser ScannerHelper isUpperCase

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.parser ScannerHelper isUpperCase.

Prototype

public static boolean isUpperCase(char c) 

Source Link

Usage

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

License:Open Source License

/**
 * Validate the given package name for the given source and compliance levels.
 * <p>//from w  ww.j a va 2s.com
 * The syntax of a package name corresponds to PackageName as
 * defined by PackageDeclaration (JLS2 7.4). For example, <code>"java.lang"</code>.
 * <p>
 * Note that the given name must be a non-empty package name (that is, attempting to
 * validate the default package will return an error status.)
 * Also it must not contain any characters or substrings that are not valid
 * on the file system on which workspace root is located.
 *
 * @param name the name of a package
 * @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 package name, otherwise a status
 *      object indicating what is wrong with the name
 * @since 3.3
 */
public static IStatus validatePackageName(String name, String sourceLevel, String complianceLevel) {

    if (name == null) {
        return new Status(IStatus.ERROR, org.eclipse.jdt.core.JavaCore.PLUGIN_ID, -1,
                Messages.convention_package_nullName, null);
    }
    int length;
    if ((length = name.length()) == 0) {
        return new Status(IStatus.ERROR, org.eclipse.jdt.core.JavaCore.PLUGIN_ID, -1,
                Messages.convention_package_emptyName, null);
    }
    if (name.charAt(0) == DOT || name.charAt(length - 1) == DOT) {
        return new Status(IStatus.ERROR, org.eclipse.jdt.core.JavaCore.PLUGIN_ID, -1,
                Messages.convention_package_dotName, null);
    }
    if (CharOperation.isWhitespace(name.charAt(0))
            || CharOperation.isWhitespace(name.charAt(name.length() - 1))) {
        return new Status(IStatus.ERROR, org.eclipse.jdt.core.JavaCore.PLUGIN_ID, -1,
                Messages.convention_package_nameWithBlanks, null);
    }
    int dot = 0;
    while (dot != -1 && dot < length - 1) {
        if ((dot = name.indexOf(DOT, dot + 1)) != -1 && dot < length - 1 && name.charAt(dot + 1) == DOT) {
            return new Status(IStatus.ERROR, org.eclipse.jdt.core.JavaCore.PLUGIN_ID, -1,
                    Messages.convention_package_consecutiveDotsName, null);
        }
    }
    //      IWorkspace workspace = ResourcesPlugin.getWorkspace();
    StringTokenizer st = new StringTokenizer(name, "."); //$NON-NLS-1$
    boolean firstToken = true;
    IStatus warningStatus = null;
    while (st.hasMoreTokens()) {
        String typeName = st.nextToken();
        typeName = typeName.trim(); // grammar allows spaces
        char[] scannedID = scannedIdentifier(typeName, sourceLevel, complianceLevel);
        if (scannedID == null) {
            return new Status(IStatus.ERROR, org.eclipse.jdt.core.JavaCore.PLUGIN_ID, -1,
                    Messages.bind(Messages.convention_illegalIdentifier, typeName), null);
        }
        //         IStatus status = workspace.validateName(new String(scannedID), IResource.FOLDER);
        //         if (!status.isOK()) {
        //            return status;
        //         }
        if (firstToken && scannedID.length > 0 && ScannerHelper.isUpperCase(scannedID[0])) {
            if (warningStatus == null) {
                warningStatus = new Status(IStatus.WARNING, org.eclipse.jdt.core.JavaCore.PLUGIN_ID, -1,
                        Messages.convention_package_uppercaseName, null);
            }
        }
        firstToken = false;
    }
    if (warningStatus != null) {
        return warningStatus;
    }
    return JavaModelStatus.VERIFIED_OK;
}

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

License:Open Source License

private static boolean validateCamelCasePattern(String stringPattern) {
    if (stringPattern == null)
        return true;
    // verify sting pattern validity
    int length = stringPattern.length();
    boolean validCamelCase = true;
    boolean lowerCamelCase = false;
    int uppercase = 0;
    for (int i = 0; i < length && validCamelCase; i++) {
        char ch = stringPattern.charAt(i);
        validCamelCase = i == 0 ? ScannerHelper.isJavaIdentifierStart(ch)
                : ScannerHelper.isJavaIdentifierPart(ch);
        // at least one uppercase character is need in CamelCase pattern
        // (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=136313)
        if (ScannerHelper.isUpperCase(ch))
            uppercase++;/*from  w w w. j ava 2 s .  c  o  m*/
        if (i == 0)
            lowerCamelCase = uppercase == 0;
    }
    if (validCamelCase) {
        validCamelCase = lowerCamelCase ? uppercase > 0 : uppercase > 1;
    }
    return validCamelCase;
}