Example usage for com.google.common.base CaseFormat UPPER_CAMEL

List of usage examples for com.google.common.base CaseFormat UPPER_CAMEL

Introduction

In this page you can find the example usage for com.google.common.base CaseFormat UPPER_CAMEL.

Prototype

CaseFormat UPPER_CAMEL

To view the source code for com.google.common.base CaseFormat UPPER_CAMEL.

Click Source Link

Document

Java and C++ class naming convention, e.g., "UpperCamel".

Usage

From source file:com.opengamma.basics.value.ValueAdjustmentType.java

/**
 * Obtains the type from a unique name.//www.ja va 2s  .c om
 * 
 * @param uniqueName  the unique name
 * @return the type
 * @throws IllegalArgumentException if the name is not known
 */
@FromString
public static ValueAdjustmentType of(String uniqueName) {
    ArgChecker.notNull(uniqueName, "uniqueName");
    return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, uniqueName));
}

From source file:com.facebook.buck.python.PythonUtil.java

public static ImmutableMap<Path, SourcePath> getModules(BuildTarget target, SourcePathResolver resolver,
        String parameter, Path baseModule, SourceList items, PatternMatchedCollection<SourceList> platformItems,
        PythonPlatform pythonPlatform, Optional<VersionMatchedCollection<SourceList>> versionItems,
        Optional<ImmutableMap<BuildTarget, Version>> versions) {
    return ImmutableMap.<Path, SourcePath>builder()
            .putAll(PythonUtil.toModuleMap(target, resolver, parameter, baseModule, ImmutableList.of(items)))
            .putAll(PythonUtil.toModuleMap(target, resolver,
                    "platform" + CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, parameter), baseModule,
                    platformItems.getMatchingValues(pythonPlatform.getFlavor().toString())))
            .putAll(PythonUtil.toModuleMap(target, resolver,
                    "versioned" + CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, parameter), baseModule,
                    versions.isPresent() && versionItems.isPresent()
                            ? versionItems.get().getMatchingValues(versions.get())
                            : ImmutableList.of()))
            .build();//from  w  w w . j av  a2  s  . c o m
}

From source file:org.graylog.autovalue.WithBeanGetterExtension.java

private MethodSpec generateGetterMethod(String name, ExecutableElement element) {
    final TypeName returnType = ClassName.get(element.getReturnType());
    final String prefix = isBoolean(returnType) ? "is" : "get";
    final String getterName = CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, name);
    final MethodSpec.Builder builder = MethodSpec.methodBuilder(prefix + getterName)
            .addModifiers(Modifier.PUBLIC, Modifier.FINAL)
            .addAnnotation(AnnotationSpec.builder(JsonIgnore.class).build()).addStatement("return $N()", name)
            .returns(returnType);/*from ww  w  .jav a 2s. co  m*/

    // Copy all annotations but @JsonProperty, @JsonIgnore, and @Override to the new method.
    for (AnnotationMirror annotationMirror : element.getAnnotationMirrors()) {
        final TypeName annotationType = ClassName.get(annotationMirror.getAnnotationType());
        if (SKIP_ANNOTATIONS.contains(annotationType)) {
            continue;
        }
        builder.addAnnotation(AnnotationSpec.get(annotationMirror));
    }

    return builder.build();
}

From source file:com.contentful.generator.Generator.java

/**
 * Fetch content types from the given space and generate corresponding model classes.
 *
 * @param spaceId space id/*from  w  w  w.  ja  v  a2s  .c  om*/
 * @param pkg package name for generated classes
 * @param path package source root
 * @param client management api client instance
 */
public void generate(String spaceId, String pkg, String path, CMAClient client) {
    try {
        CMAArray<CMAContentType> contentTypes = client.contentTypes().fetchAll(spaceId);

        for (CMAContentType contentType : contentTypes.getItems()) {
            String name = contentType.getName();
            if (name != null) {
                String className = normalize(name, CaseFormat.UPPER_CAMEL);
                models.put(contentType.getResourceId(), className);
            }
        }

        for (CMAContentType contentType : contentTypes.getItems()) {
            String name = contentType.getName();
            if (name == null || name.isEmpty()) {
                printer.print("WARNING: Ignoring Content Type (id=" + "\"" + contentType.getResourceId() + "\""
                        + "), has no name.");
                continue;
            }

            JavaFile javaFile = generateModel(pkg, contentType, models.get(contentType.getResourceId()));

            fileHandler.write(javaFile, path);
        }
    } catch (Exception e) {
        printer.print("Failed to fetch content types, reason: " + e.getMessage());

        // Clean up any generated files
        String generatedPath = Joiner.on(File.separatorChar).join(path,
                Joiner.on(File.separatorChar).join(pkg.split("\\.")));

        for (String fileName : models.values()) {
            fileHandler.delete(new File(generatedPath + File.separator + fileName + ".java"));
        }

        throw new GeneratorException(e);
    }
}

From source file:org.seedstack.seed.core.internal.diagnostic.tool.ErrorCodePrinter.java

private String formatCamelCase(String value) {
    String result = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, value).replace("_", " ");
    return result.substring(0, 1).toUpperCase(Locale.ENGLISH) + result.substring(1);
}

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

private static HashSet<String> splitStringTermsToSet(String name) {
    // TODO(yulissa): Handle constants in the form of upper underscore
    String nameSplit = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, name);
    return Sets.newHashSet(Splitter.on('_').trimResults().omitEmptyStrings().splitToList(nameSplit));
}

From source file:fr.putnami.pwt.core.widget.client.util.StyleUtils.java

public static void initStyle(Widget w) {
    if (w != null && w.getElement() != null) {
        String widgetClassName = "p-"
                + CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, w.getClass().getSimpleName());
        w.getElement().addClassName(widgetClassName);
    }/*from  www. ja  va2s .  co  m*/
}

From source file:com.tactfactory.harmony.generator.BundleGenerator.java

/**
 * Generate the empty annotation./*from w  ww  .j a v  a2 s . c o m*/
 * @param bundleOwnerName Owner name
 * @param bundleName Bundle name
 * @param bundleNameSpace Bundle namespace
 */
private void generateAnnotation(final String bundleOwnerName, final String bundleName,
        final String bundleNameSpace) {

    final String tplPath = this.getAdapter().getAnnotationBundleTemplatePath() + "/TemplateAnnotation.java";
    final String genPath = this.getAdapter().getAnnotationBundlePath(bundleOwnerName, bundleNameSpace,
            bundleName) + "/" + CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, bundleName) + ".java";

    this.makeSource(tplPath, genPath, false);
}

From source file:com.facebook.buck.rules.modern.impl.DefaultClassInfo.java

DefaultClassInfo(Class<?> clazz, Optional<ClassInfo<? super T>> superInfo) {
    this.type = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, clazz.getSimpleName()).intern();
    this.superInfo = superInfo;

    Optional<Class<?>> immutableBase = findImmutableBase(clazz);
    ImmutableList.Builder<FieldInfo<?>> fieldsBuilder = ImmutableList.builder();
    if (immutableBase.isPresent()) {
        ImmutableMap<Field, Boolean> parameterFields = parameterFieldsFromFields(clazz);
        ImmutableMap<Field, Method> parameterMethods = findMethodsForFields(parameterFields.keySet(), clazz);
        parameterFields.forEach((field, isLazy) -> {
            Method method = parameterMethods.get(field);
            if (method == null) {
                return;
            }/*  w  w  w.java 2s  .c  o m*/
            AddToRuleKey addAnnotation = method.getAnnotation(AddToRuleKey.class);
            // TODO(cjhopman): Add @ExcludeFromRuleKey annotation and require that all fields are
            // either explicitly added or explicitly excluded.
            Optional<CustomFieldBehavior> customBehavior = Optional
                    .ofNullable(method.getDeclaredAnnotation(CustomFieldBehavior.class));
            if (addAnnotation != null && !addAnnotation.stringify()) {
                if (isLazy) {
                    throw new RuntimeException(
                            "@Value.Lazy fields cannot be @AddToRuleKey, change it to @Value.Derived.");
                }
                Nullable methodNullable = method.getAnnotation(Nullable.class);
                boolean methodOptional = Optional.class.isAssignableFrom(method.getReturnType());
                fieldsBuilder.add(
                        forFieldWithBehavior(field, methodNullable != null || methodOptional, customBehavior));
            } else {
                fieldsBuilder.add(excludedField(field, customBehavior));
            }
        });
    } else {
        for (final Field field : clazz.getDeclaredFields()) {
            // TODO(cjhopman): Make this a Precondition.
            if (!Modifier.isFinal(field.getModifiers())) {
                LOG.warn("All fields of a Buildable must be final (%s.%s)", clazz.getSimpleName(),
                        field.getName());
            }

            if (Modifier.isStatic(field.getModifiers())) {
                continue;
            }
            field.setAccessible(true);

            Optional<CustomFieldBehavior> customBehavior = Optional
                    .ofNullable(field.getDeclaredAnnotation(CustomFieldBehavior.class));
            AddToRuleKey addAnnotation = field.getAnnotation(AddToRuleKey.class);
            // TODO(cjhopman): Add @ExcludeFromRuleKey annotation and require that all fields are either
            // explicitly added or explicitly excluded.
            if (addAnnotation != null && !addAnnotation.stringify()) {
                fieldsBuilder.add(forFieldWithBehavior(field, field.getAnnotation(Nullable.class) != null,
                        customBehavior));
            } else {
                fieldsBuilder.add(excludedField(field, customBehavior));
            }
        }
    }

    if (clazz.isMemberClass()) {
        // TODO(cjhopman): This should also iterate over the outer class's class hierarchy.
        Class<?> outerClazz = clazz.getDeclaringClass();
        // I don't think this can happen, but if it does, this needs to be updated to handle it
        // correctly.
        Preconditions.checkArgument(
                !outerClazz.isAnonymousClass() && !outerClazz.isMemberClass() && !outerClazz.isLocalClass());
        for (final Field field : outerClazz.getDeclaredFields()) {
            field.setAccessible(true);
            if (!Modifier.isStatic(field.getModifiers())) {
                continue;
            }
            // TODO(cjhopman): Make this a Precondition.
            if (!Modifier.isFinal(field.getModifiers())) {
                LOG.warn("All static fields of a Buildable's outer class must be final (%s.%s)",
                        outerClazz.getSimpleName(), field.getName());
            }
        }
    }
    this.fields = fieldsBuilder.build();
}

From source file:datamine.storage.recordbuffers.idl.generator.RecordMetaWrapperGenerator.java

public static String getBaseClassName(String tableName) {
    return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, tableName) + "Metadata";
}