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.shieldsbetter.sbomg.ViewModelGenerator.java

private static void outfitModel(ModelClass dest, String contextName, Set<String> options, Object modelDesc) {
    boolean finalFlag = options.contains("final");
    boolean leafFlag = options.contains("leaf");

    String fieldName = contextName;
    if (fieldName.isEmpty()) {
        fieldName = "Value";
    }/*from   w  w  w . j a  va2  s.  c  o m*/

    if (modelDesc instanceof String) {
        String fieldTypeString = (String) modelDesc;
        TypeName fieldType = typeName(fieldTypeString);

        FieldSpec.Builder fieldBuild = FieldSpec.builder(fieldType, "my" + fieldName, Modifier.PRIVATE);

        dest.addRootMethod("get" + fieldName, fieldType, ImmutableList.of(),
                CodeBlock.builder().addStatement("return my$L", fieldName).build());

        if (!leafFlag) {
            dest.addListenerEvent(contextName + "Updated",
                    ImmutableList.of(ImmutablePair.of("value", fieldType),
                            ImmutablePair.of("event", ClassName.get("", fieldTypeString + ".Event"))));
        }

        if (finalFlag) {
            fieldBuild.addModifiers(Modifier.FINAL);

            String paramName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, fieldName);
            dest.addInitializationParameter(paramName, fieldType);
            dest.addInitializationCode(
                    CodeBlock.builder().addStatement("my$L = $L", fieldName, paramName).build());

            if (!leafFlag) {
                dest.addInitializationCode(renderCodeBlock(SUBSCRIBE_TEMPL, "finalFlag", finalFlag, "fieldName",
                        fieldName, "fieldType", fieldTypeString, "parentType", dest.getName()));
            }
        } else {
            String subscribeCode;
            if (leafFlag) {
                subscribeCode = "";
            } else {
                FieldSpec.Builder subscriptionField = FieldSpec.builder(
                        ClassName.get("", fieldTypeString + ".Subscription"), "my" + fieldName + "Subscription",
                        Modifier.PRIVATE);
                dest.addField(subscriptionField.build());

                subscribeCode = renderTemplate(SUBSCRIBE_TEMPL, "finalFlag", finalFlag, "fieldName", fieldName,
                        "fieldType", fieldTypeString, "parentType", dest.getName());
            }

            dest.addBuildCode(
                    CodeBlock.builder().addStatement("l.on$LSet(this, my$L)", contextName, fieldName).build());

            dest.addListenerEvent(contextName + "Set",
                    ImmutableList.of(ImmutablePair.of("newValue", fieldType)));

            dest.addRootMethod("set" + contextName, TypeName.VOID,
                    ImmutableList.of(ImmutablePair.of("newValue", fieldType)),
                    renderCodeBlock(SET_METHOD_TEMPL, "parentType", dest.getName(), "fieldName", fieldName,
                            "valueParam", "newValue", "leafFlag", leafFlag, "contextName", contextName,
                            "afterUnsubscribe", subscribeCode));
        }

        dest.addField(fieldBuild.build());
    } else if (modelDesc instanceof List) {
        List listDesc = (List) modelDesc;

        switch (listDesc.size()) {
        case 1: {
            outfitModelWithList(dest, contextName, options, listDesc.get(0));
            break;
        }
        case 2: {
            outfitModelWithList(dest, contextName, options, listDesc);
            break;
        }
        default: {
            throw new RuntimeException();
        }
        }
    } else if (modelDesc instanceof Map) {
        Map<String, Object> mapDesc = (Map<String, Object>) modelDesc;
        for (Map.Entry<String, Object> field : mapDesc.entrySet()) {
            outfitModel(dest, contextName + field.getKey(), field.getValue());
        }
    } else {
        throw new RuntimeException(modelDesc.getClass().getSimpleName());
    }
}

From source file:dagger2.internal.codegen.ComponentGenerator.java

private void writeSubcomponentWithoutBuilder(ExecutableElement subcomponentFactoryMethod, BindingGraph subgraph,
        ClassWriter subcomponentWriter, ConstructorWriter constructorWriter,
        Map<TypeElement, MemberSelect> componentContributionFields,
        ImmutableList.Builder<Snippet> subcomponentConstructorParameters, MethodWriter componentMethod,
        ExecutableType resolvedMethod) {
    List<? extends VariableElement> params = subcomponentFactoryMethod.getParameters();
    List<? extends TypeMirror> paramTypes = resolvedMethod.getParameterTypes();
    for (int i = 0; i < params.size(); i++) {
        VariableElement moduleVariable = params.get(i);
        TypeElement moduleTypeElement = MoreTypes.asTypeElement(paramTypes.get(i));
        TypeName moduleType = TypeNames.forTypeMirror(paramTypes.get(i));
        verify(subgraph.transitiveModules().containsKey(moduleTypeElement));
        componentMethod.addParameter(moduleType, moduleVariable.getSimpleName().toString());
        if (!componentContributionFields.containsKey(moduleTypeElement)) {
            String preferredModuleName = CaseFormat.UPPER_CAMEL.to(LOWER_CAMEL,
                    moduleTypeElement.getSimpleName().toString());
            FieldWriter contributionField = subcomponentWriter.addField(moduleTypeElement, preferredModuleName);
            contributionField.addModifiers(PRIVATE, FINAL);
            String actualModuleName = contributionField.name();
            constructorWriter.addParameter(moduleType, actualModuleName);
            constructorWriter.body().addSnippet(Snippet.format(
                    Joiner.on('\n').join("if (%s == null) {", "  throw new NullPointerException();", "}"),
                    actualModuleName));//from  w  w  w . ja  v a2 s. co m
            constructorWriter.body().addSnippet(Snippet.format("this.%1$s = %1$s;", actualModuleName));
            MemberSelect moduleSelect = MemberSelect.instanceSelect(subcomponentWriter.name(),
                    Snippet.format(actualModuleName));
            componentContributionFields.put(moduleTypeElement, moduleSelect);
            subcomponentConstructorParameters.add(Snippet.format("%s", moduleVariable.getSimpleName()));
        }
    }

    SetView<TypeElement> uninitializedModules = Sets.difference(subgraph.transitiveModules().keySet(),
            componentContributionFields.keySet());
    for (TypeElement moduleType : uninitializedModules) {
        String preferredModuleName = CaseFormat.UPPER_CAMEL.to(LOWER_CAMEL,
                moduleType.getSimpleName().toString());
        FieldWriter contributionField = subcomponentWriter.addField(moduleType, preferredModuleName);
        contributionField.addModifiers(PRIVATE, FINAL);
        String actualModuleName = contributionField.name();
        constructorWriter.body().addSnippet(
                Snippet.format("this.%s = new %s();", actualModuleName, ClassName.fromTypeElement(moduleType)));
        MemberSelect moduleSelect = MemberSelect.instanceSelect(subcomponentWriter.name(),
                Snippet.format(actualModuleName));
        componentContributionFields.put(moduleType, moduleSelect);
    }

    componentMethod.body().addSnippet("return new %s(%s);", subcomponentWriter.name(),
            Snippet.makeParametersSnippet(subcomponentConstructorParameters.build()));
}

From source file:org.eclipse.xtext.xtext.ui.editor.quickfix.XtextGrammarQuickfixProvider.java

@Fix(INVALID_TERMINALRULE_NAME)
public void fixTerminalRuleName(final Issue issue, IssueResolutionAcceptor acceptor) {
    if (issue.getData().length == 1) {
        final String upperCase = CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, issue.getData()[0])
                .toString();//w  w  w  . j  a  va 2  s  .c om
        acceptor.accept(issue, "Change name to " + upperCase, "Change name to " + upperCase, "upcase.png",
                new IModification() {

                    @Override
                    public void apply(IModificationContext context) throws Exception {
                        final IXtextDocument xtextDocument = context.getXtextDocument();
                        xtextDocument.replace(issue.getOffset(), issue.getLength(), upperCase);
                        xtextDocument.modify(new IUnitOfWork.Void<XtextResource>() {
                            @Override
                            public void process(XtextResource state) throws Exception {
                                final EObject terminalRule = state
                                        .getEObject(issue.getUriToProblem().fragment());
                                Iterable<RuleCall> candidates = Iterables.filter(Iterables
                                        .filter(Lists.newArrayList(state.getAllContents()), RuleCall.class),
                                        new Predicate<RuleCall>() {
                                            @Override
                                            public boolean apply(RuleCall ruleCall) {
                                                return ruleCall.getRule() == terminalRule;
                                            }
                                        });
                                for (RuleCall ruleCall : candidates) {
                                    List<INode> nodes = NodeModelUtils.findNodesForFeature(ruleCall,
                                            XtextPackage.eINSTANCE.getRuleCall_Rule());
                                    for (INode node : nodes) {
                                        ITextRegion textRegion = node.getTextRegion();
                                        xtextDocument.replace(textRegion.getOffset(), textRegion.getLength(),
                                                upperCase);
                                    }
                                }
                            }
                        });
                    }
                });
    }
}

From source file:com.twitter.elephanttwin.retrieval.BlockIndexedFileInputFormat.java

/**
 * return the right method name based on the input column name.<br>
 *  Works with both Thrift and Protocol classes.
 *//*  w  w  w . j  a  va2  s . c om*/
public static String getCamelCaseMethodName(String columnName, Class<?> c) {
    if (TBase.class.isAssignableFrom(c))
        return "get" + columnName.substring(0, 1).toUpperCase() + columnName.substring(1);
    else if (Message.class.isAssignableFrom(c)) {
        return "get" + CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, columnName);
    }
    throw new RuntimeException("only Thrift and Protocol Buffer value classes are supported");
}

From source file:org.trinity.foundation.api.render.binding.BinderImpl.java

protected String toGetterMethodName(final String prefix, final String propertyName) {
    checkNotNull(prefix);//from w  w w. j  a v a2 s . c  o m
    checkNotNull(propertyName);

    return prefix + CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, propertyName);
}

From source file:org.jooby.assets.AssetCompiler.java

private static Map<String, String> bind(final Config conf, final List<String> names) {
    Map<String, String> map = new LinkedHashMap<>();
    names.forEach(name -> {//from   w ww  . ja va  2 s  . co m
        String clazz = AssetCompiler.class.getPackage().getName() + "."
                + CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, name);
        if (conf.hasPath(name + ".class")) {
            clazz = conf.getString(name + ".class");
        }
        map.put(name, clazz);
    });

    return map;
}

From source file:com.tactfactory.harmony.platform.android.AndroidProjectAdapter.java

@Override
public List<IUpdater> getApplicationFiles() {
    List<IUpdater> result = new ArrayList<IUpdater>();

    String applicationName = CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL,
            this.adapter.getApplicationMetadata().getName());

    String templatePath = this.adapter.getTemplateSourcePath();

    String filePath = String.format("%s%s/", this.adapter.getSourcePath(),
            this.adapter.getApplicationMetadata().getProjectNameSpace());

    //Create base classes for Fixtures loaders
    result.add(new SourceFile(templatePath + "TemplateApplicationBase.java",
            filePath + applicationName + "ApplicationBase.java", true));

    result.add(new SourceFile(templatePath + "TemplateApplication.java",
            filePath + applicationName + "Application.java"));

    return result;
}

From source file:org.apache.abdera2.activities.extra.Extra.java

static String get_name(Method obj) {
    String name = null;//  w  ww . j  a v  a  2 s.c  om
    if (obj.isAnnotationPresent(Name.class))
        name = obj.getAnnotation(Name.class).value();
    else {
        name = obj.getName();
        if (name.startsWith("get") || name.startsWith("set"))
            name = name.substring(3);
        name = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, name);
    }
    return name;
}

From source file:com.tactfactory.harmony.platform.android.AndroidProjectAdapter.java

@Override
public List<IUpdater> getProviderFiles() {
    List<IUpdater> result = new ArrayList<IUpdater>();

    String nameProvider = CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL,
            this.adapter.getApplicationMetadata().getName() + "Provider");

    String templatePath = this.adapter.getTemplateSourceProviderPath();
    String filePath = String.format("%s%s/%s/", this.adapter.getSourcePath(),
            this.adapter.getApplicationMetadata().getProjectNameSpace(), this.adapter.getProvider());

    result.add(new SourceFile(templatePath + "utils/base/ApplicationProviderUtilsBase.java",
            filePath + "utils/base/ProviderUtilsBase.java", true));

    result.add(new SourceFile(templatePath + "utils/ApplicationProviderUtils.java",
            filePath + "utils/ProviderUtils.java", false));

    result.add(new SourceFile(templatePath + "TemplateProvider.java", filePath + nameProvider + ".java"));
    result.add(new SourceFile(templatePath + "base/TemplateProviderBase.java",
            filePath + "base/" + nameProvider + "Base.java", true));
    result.add(new SourceFile(templatePath + "base/ProviderAdapterBase.java",
            filePath + "base/ProviderAdapterBase.java", true));
    result.add(new SourceFile(templatePath + "ProviderAdapter.java", filePath + "ProviderAdapter.java", false));

    // Package infos
    result.add(new SourceFile(templatePath + "provider-package-info.java", filePath + "package-info.java"));
    result.add(new SourceFile(templatePath + "base/provider-package-info.java",
            filePath + "base/package-info.java"));

    result.add(new SourceFile(templatePath + "utils/base/package-info.java",
            filePath + "utils/base/package-info.java"));
    result.add(new SourceFile(templatePath + "utils/package-info.java", filePath + "utils/package-info.java"));

    String providerNamespace = this.adapter.getApplicationMetadata().getProjectNameSpace().replace('/', '.')
            + "." + this.adapter.getProvider();

    result.add(new ManifestProviderAndroid(this.adapter, providerNamespace, nameProvider));

    return result;
}

From source file:com.google.javascript.jscomp.PolymerPass.java

/**
 * @return The PolymerElement type string for a class definition.
 *//*www .  j  a v a  2 s .c om*/
private static String getPolymerElementType(final ClassDefinition cls) {
    return SimpleFormat.format("Polymer%sElement", cls.nativeBaseElement == null ? ""
            : CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, cls.nativeBaseElement));
}