Example usage for com.google.common.base Ascii isLowerCase

List of usage examples for com.google.common.base Ascii isLowerCase

Introduction

In this page you can find the example usage for com.google.common.base Ascii isLowerCase.

Prototype

public static boolean isLowerCase(char c) 

Source Link

Document

Indicates whether c is one of the twenty-six lowercase ASCII alphabetic characters between 'a' and 'z' inclusive.

Usage

From source file:org.sfs.util.NullSafeAscii.java

public static boolean isLowerCase(char c) {
    return Ascii.isLowerCase(c);
}

From source file:org.immutables.value.processor.meta.ImportRewriteDisabler.java

private static boolean shouldDisableFor(Reporter reporter, Element element) {
    while (element != null) {
        if (element.getKind() == ElementKind.PACKAGE) {
            for (String segment : DOT_SPLITTER.split(((PackageElement) element).getQualifiedName())) {
                if (!segment.isEmpty() && Ascii.isUpperCase(segment.charAt(0))) {
                    reporter.warning(WARNING_START + " uppercase package names");
                    return true;
                }//  w w w  . ja va 2s .  c  o m
            }
        }
        if (element.getKind().isClass() || element.getKind().isInterface()) {
            if (Ascii.isLowerCase(element.getSimpleName().charAt(0))) {
                reporter.warning(WARNING_START + " lowercase class names");
                return true;
            }
        }
        element = element.getEnclosingElement();
    }
    return false;
}

From source file:com.squareup.javapoet.ClassName.java

/**
 * Returns a new {@link ClassName} instance for the given fully-qualified class name string. This
 * method assumes that the input is ASCII and follows typical Java style (lowercase package
 * names, UpperCamelCase class names) and may produce incorrect results or throw
 * {@link IllegalArgumentException} otherwise. For that reason, {@link #get(Class)} and
 * {@link #get(Class)} should be preferred as they can correctly create {@link ClassName}
 * instances without such restrictions.//w w  w  .j a v a  2  s  . c  om
 */
public static ClassName bestGuess(String classNameString) {
    List<String> names = new ArrayList<>();

    // Add the package name, like "java.util.concurrent", or "" for no package.
    int p = 0;
    while (p < classNameString.length() && Ascii.isLowerCase(classNameString.charAt(p))) {
        p = classNameString.indexOf('.', p) + 1;
        checkArgument(p != 0, "couldn't make a guess for %s", classNameString);
    }
    names.add(p != 0 ? classNameString.substring(0, p - 1) : "");

    // Add the class names, like "Map" and "Entry".
    for (String part : Splitter.on('.').split(classNameString.substring(p))) {
        checkArgument(!part.isEmpty() && Ascii.isUpperCase(part.charAt(0)), "couldn't make a guess for %s",
                classNameString);
        names.add(part);
    }

    checkArgument(names.size() >= 2, "couldn't make a guess for %s", classNameString);
    return new ClassName(names);
}

From source file:dagger2.internal.codegen.writer.ClassName.java

/**
 * Returns a new {@link ClassName} instance for the given fully-qualified class name string. This
 * method assumes that the input is ASCII and follows typical Java style (lower-case package
 * names, upper-camel-case class names) and may produce incorrect results or throw
 * {@link IllegalArgumentException} otherwise. For that reason, {@link #fromClass(Class)} and
 * {@link #fromClass(Class)} should be preferred as they can correctly create {@link ClassName}
 * instances without such restrictions./*  w  w  w.  j  a v a2s  . c  o  m*/
 */
public static ClassName bestGuessFromString(String classNameString) {
    checkNotNull(classNameString);
    List<String> parts = Splitter.on('.').splitToList(classNameString);
    int firstClassPartIndex = -1;
    for (int i = 0; i < parts.size(); i++) {
        String part = parts.get(i);
        checkArgument(SourceVersion.isIdentifier(part));
        char firstChar = part.charAt(0);
        if (Ascii.isLowerCase(firstChar)) {
            // looks like a package part
            if (firstClassPartIndex >= 0) {
                throw new IllegalArgumentException("couldn't make a guess for " + classNameString);
            }
        } else if (Ascii.isUpperCase(firstChar)) {
            // looks like a class part
            if (firstClassPartIndex < 0) {
                firstClassPartIndex = i;
            }
        } else {
            throw new IllegalArgumentException("couldn't make a guess for " + classNameString);
        }
    }
    int lastIndex = parts.size() - 1;
    return new ClassName(Joiner.on('.').join(parts.subList(0, firstClassPartIndex)),
            firstClassPartIndex == lastIndex ? ImmutableList.<String>of()
                    : ImmutableList.copyOf(parts.subList(firstClassPartIndex, lastIndex)),
            parts.get(lastIndex));
}

From source file:com.google.errorprone.bugpatterns.TypeParameterNaming.java

private static String suggestedNameFollowedWithT(String identifier) {
    Preconditions.checkArgument(!identifier.isEmpty());

    // Some early checks:
    // TFoo => FooT
    if (identifier.length() > 2 && identifier.charAt(0) == 'T' && Ascii.isUpperCase(identifier.charAt(1))
            && Ascii.isLowerCase(identifier.charAt(2))) {
        // splitToLowercaseTerms thinks "TFooBar" is ["tfoo", "bar"], so we remove "t", have it parse
        // as ["foo", "bar"], then staple "t" back on the end.
        ImmutableList<String> tokens = NamingConventions.splitToLowercaseTerms(identifier.substring(1));
        return Streams.concat(tokens.stream(), Stream.of("T")).map(TypeParameterNaming::upperCamelToken)
                .collect(Collectors.joining());
    }//  w  w w  .ja v a 2 s.co  m

    ImmutableList<String> tokens = NamingConventions.splitToLowercaseTerms(identifier);

    // UPPERCASE => UppercaseT
    if (tokens.size() == 1) {
        String token = tokens.get(0);
        if (Ascii.toUpperCase(token).equals(identifier)) {
            return upperCamelToken(token) + "T";
        }
    }

    // FooType => FooT
    if (Iterables.getLast(tokens).equals("type")) {
        return Streams.concat(tokens.subList(0, tokens.size() - 1).stream(), Stream.of("T"))
                .map(TypeParameterNaming::upperCamelToken).collect(Collectors.joining());
    }

    return identifier + "T";
}