List of usage examples for com.google.common.base CaseFormat LOWER_CAMEL
CaseFormat LOWER_CAMEL
To view the source code for com.google.common.base CaseFormat LOWER_CAMEL.
Click Source Link
From source file:dagger.internal.codegen.SourceFiles.java
private static String factoryPrefix(ContributionBinding binding) { switch (binding.bindingKind()) { case INJECTION: return ""; case PROVISION: case PRODUCTION: return CaseFormat.LOWER_CAMEL.to(UPPER_CAMEL, binding.bindingElement().get().getSimpleName().toString()); default:/*from w ww .jav a 2s. c om*/ throw new IllegalArgumentException(); } }
From source file:com.google.api.codegen.util.Name.java
/** Returns the identifier in lower-camel format. */ public String toLowerCamel() { return toCamel(CaseFormat.LOWER_CAMEL); }
From source file:com.google.cloud.Identity.java
/** * Returns the string value associated with the identity. Used primarily for converting from * {@code Identity} objects to strings for protobuf-generated policies. *///from ww w .j av a2s .c o m public String strValue() { String protobufString = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, type.toString()); if (value == null) { return protobufString; } else { return protobufString + ":" + value; } }
From source file:org.abstractmeta.reflectify.plugin.ReflectifyGenerator.java
private void generateProviders(JavaTypeBuilder typeBuilder, JavaType sourceType, Type reflectifyType) { Map<String, Integer> providerCounter = new HashMap<String, Integer>(); JavaMethodBuilder methodBuilder = new JavaMethodBuilder(); methodBuilder.addModifier("protected").setName("registerProviders").setResultType(void.class); methodBuilder.addParameter("providers", new ParameterizedTypeImpl(null, List.class, new ParameterizedTypeImpl(null, Reflectify.Provider.class, reflectifyType))); methodBuilder.addBody("\n"); if (sourceType.getConstructors() == null) { return;/*from ww w .ja v a 2 s . co m*/ } if (sourceType.getModifiers().contains("abstract")) { return; } for (JavaConstructor constructor : sourceType.getConstructors()) { String sourceTypeSimpleName = JavaTypeUtil.getSimpleClassName(sourceType.getName(), true); String constructorCounterPostfix = getOccurrence(providerCounter, JavaTypeUtil.getSimpleClassName(sourceType.getName(), false)); String providerClassName = StringUtil.format(CaseFormat.UPPER_CAMEL, JavaTypeUtil.getSimpleClassName(sourceType.getName(), false), "provider" + constructorCounterPostfix, CaseFormat.LOWER_CAMEL); JavaTypeBuilder providerClassBuilder = methodBuilder.addNestedJavaType(); providerClassBuilder.setName(providerClassName) .addSuperInterface(new ParameterizedTypeImpl(null, Reflectify.Provider.class, reflectifyType)); String parameters = Joiner.on(", ").join(getArgumentClasses(constructor.getParameterTypes())); if (!parameters.isEmpty()) parameters = ", " + parameters; providerClassBuilder.addConstructor(new JavaConstructorBuilder().setName(providerClassName) .addBody(String.format("super(%s.class%s);", sourceTypeSimpleName, parameters)).build()); providerClassBuilder.setSuperType(AbstractProvider.class); buildArgumentSetterClasses(providerClassBuilder, reflectifyType, sourceTypeSimpleName, constructor.getParameterTypes()); methodBuilder.addBody(String.format(String.format("providers.add(new %s());", providerClassName))); JavaMethodBuilder getMethodProvider = new JavaMethodBuilder().addModifier("public").setName("get") .setResultType(reflectifyType); String constructorParameters = Joiner.on(", ") .join(getArgumentSetterMethodArgumentNames(constructor.getParameterTypes())); boolean exceptionHandling = constructor.getExceptionTypes() != null && !constructor.getExceptionTypes().isEmpty(); if (exceptionHandling) { getMethodProvider.addBody("try {"); } getMethodProvider.addBody((exceptionHandling ? " " : "") + String.format("return new %s(%s);", sourceTypeSimpleName, constructorParameters)); if (exceptionHandling) { getMethodProvider.addBody("} catch(Exception e) {"); getMethodProvider.addBody(String.format( " throw new RuntimeException(\"Failed to instantiate %s\", e);", sourceTypeSimpleName)); getMethodProvider.addBody("}"); } providerClassBuilder.addMethod(getMethodProvider.build()); } typeBuilder.addMethod(methodBuilder.build()); }
From source file:io.soliton.shapeshifter.NamedSchema.java
/** * Returns a {@code Schema} that will serialize and parse {@link Message} * corresponding to the given {@link Descriptor}. * * @param descriptor a descriptor of message. * @see Message#getDescriptorForType()/*from w ww . j a v a2 s .c om*/ */ public static NamedSchema of(Descriptor descriptor, String name) { Preconditions.checkNotNull(descriptor, "The descriptor should not be null"); Preconditions.checkNotNull(name, "The name should not be null"); Preconditions.checkArgument(!name.isEmpty(), "The name should not be empty"); return new NamedSchema(descriptor, name, ImmutableSet.<String>of(), ImmutableMap.<String, String>of(), CaseFormat.LOWER_CAMEL, ImmutableMap.<String, String>of(), ImmutableMap.<String, FormatTransformer>of(), ImmutableMap.<String, FieldDescriptor>of(), ImmutableMap.<String, String>of(), ImmutableMap.<String, String>of(), ImmutableMap.<String, String>of(), false); }
From source file:ninja.template.TemplateEngineFreemarker.java
@Override public void invoke(Context context, Result result) { Object object = result.getRenderable(); Map map;/*from ww w. j a va 2 s . c o m*/ // if the object is null we simply render an empty map... if (object == null) { map = Maps.newHashMap(); } else if (object instanceof Map) { map = (Map) object; } else { // We are getting an arbitrary Object and put that into // the root of freemarker // If you are rendering something like Results.ok().render(new MyObject()) // Assume MyObject has a public String name field. // You can then access the fields in the template like that: // ${myObject.publicField} String realClassNameLowerCamelCase = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, object.getClass().getSimpleName()); map = Maps.newHashMap(); map.put(realClassNameLowerCamelCase, object); } // set language from framework. You can access // it in the templates as ${lang} Optional<String> language = lang.getLanguage(context, Optional.of(result)); if (language.isPresent()) { map.put("lang", language.get()); } // put all entries of the session cookie to the map. // You can access the values by their key in the cookie if (!context.getSession().isEmpty()) { map.put("session", context.getSession().getData()); } map.put("contextPath", context.getContextPath()); ////////////////////////////////////////////////////////////////////// // A method that renders i18n messages and can also render messages with // placeholders directly in your template: // E.g.: ${i18n("mykey", myPlaceholderVariable)} ////////////////////////////////////////////////////////////////////// map.put("i18n", new TemplateEngineFreemarkerI18nMethod(messages, context, result)); Optional<String> requestLang = lang.getLanguage(context, Optional.of(result)); Locale locale = lang.getLocaleFromStringOrDefault(requestLang); map.put("prettyTime", new TemplateEngineFreemarkerPrettyTimeMethod(locale)); map.put("reverseRoute", templateEngineFreemarkerReverseRouteMethod); map.put("assetsAt", templateEngineFreemarkerAssetsAtMethod); map.put("webJarsAt", templateEngineFreemarkerWebJarsAtMethod); map.put("authenticityToken", new TemplateEngineFreemarkerAuthenticityTokenDirective(context)); map.put("authenticityForm", new TemplateEngineFreemarkerAuthenticityFormDirective(context)); /////////////////////////////////////////////////////////////////////// // Convenience method to translate possible flash scope keys. // !!! If you want to set messages with placeholders please do that // !!! in your controller. We only can set simple messages. // Eg. A message like "errorMessage=my name is: {0}" => translate in controller and pass directly. // A message like " errorMessage=An error occurred" => use that as errorMessage. // // get keys via ${flash.KEYNAME} ////////////////////////////////////////////////////////////////////// Map<String, String> translatedFlashCookieMap = Maps.newHashMap(); for (Entry<String, String> entry : context.getFlashScope().getCurrentFlashCookieData().entrySet()) { String messageValue = null; Optional<String> messageValueOptional = messages.get(entry.getValue(), context, Optional.of(result)); if (!messageValueOptional.isPresent()) { messageValue = entry.getValue(); } else { messageValue = messageValueOptional.get(); } // new way translatedFlashCookieMap.put(entry.getKey(), messageValue); } // now we can retrieve flash cookie messages via ${flash.MESSAGE_KEY} map.put("flash", translatedFlashCookieMap); // Specify the data source where the template files come from. // Here I set a file directory for it: String templateName = templateEngineHelper.getTemplateForResult(context.getRoute(), result, this.fileSuffix); Template freemarkerTemplate = null; try { freemarkerTemplate = cfg.getTemplate(templateName); // Fully buffer the response so in the case of a template error we can // return the applications 500 error message. Without fully buffering // we can't guarantee we haven't flushed part of the response to the // client. StringWriter buffer = new StringWriter(64 * 1024); freemarkerTemplate.process(map, buffer); ResponseStreams responseStreams = context.finalizeHeaders(result); try (Writer writer = responseStreams.getWriter()) { writer.write(buffer.toString()); } } catch (Exception cause) { // delegate rendering exception handling back to Ninja throwRenderingException(context, result, cause, templateName); } }
From source file:com.google.api.codegen.util.Name.java
private String toCamel(CaseFormat caseFormat) { StringBuffer buffer = new StringBuffer(); boolean firstPiece = true; for (NamePiece namePiece : namePieces) { if (firstPiece && caseFormat.equals(CaseFormat.LOWER_CAMEL)) { buffer.append(namePiece.caseFormat.to(CaseFormat.LOWER_CAMEL, namePiece.identifier)); } else {// w w w. j av a 2s . c om CaseFormat toCaseFormat = CaseFormat.UPPER_CAMEL; if (namePiece.casingMode.equals(CasingMode.UPPER_CAMEL_TO_SQUASHED_UPPERCASE)) { toCaseFormat = CaseFormat.UPPER_UNDERSCORE; } buffer.append(namePiece.caseFormat.to(toCaseFormat, namePiece.identifier)); } firstPiece = false; } return buffer.toString(); }
From source file:com.dangdang.ddframe.job.event.rdb.JobEventRdbSearch.java
private String buildWhere(final String tableName, final Collection<String> tableFields, final Condition condition) { StringBuilder sqlBuilder = new StringBuilder(); sqlBuilder.append(" WHERE 1=1"); if (null != condition.getFields() && !condition.getFields().isEmpty()) { for (String each : condition.getFields().keySet()) { String lowerUnderscore = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, each); if (null != condition.getFields().get(each) && tableFields.contains(lowerUnderscore)) { sqlBuilder.append(" AND ").append(lowerUnderscore).append("=?"); }/*w w w . j a v a 2 s . co m*/ } } if (null != condition.getStartTime()) { sqlBuilder.append(" AND ").append(getTableTimeField(tableName)).append(">=?"); } if (null != condition.getEndTime()) { sqlBuilder.append(" AND ").append(getTableTimeField(tableName)).append("<=?"); } return sqlBuilder.toString(); }
From source file:com.contentful.generator.Generator.java
static MethodSpec fieldGetter(FieldSpec fieldSpec) { String methodName = normalize(fieldSpec.name, CaseFormat.LOWER_CAMEL); return MethodSpec.methodBuilder(methodName).returns(fieldSpec.type).addModifiers(Modifier.PUBLIC) .addStatement("return $N", fieldSpec).build(); }
From source file:com.google.polymer.HtmlRenamer.java
private static void renameAllAttributeKeys(ImmutableMap<String, String> renameMap, Element element) { Attributes attributes = element.attributes(); for (Attribute attribute : attributes) { String key = attribute.getKey(); // Polymer events are referenced as strings. As a result they do not participate in renaming. // Additionally, it is not valid to have a Polymer property start with "on". if (!key.startsWith("on-")) { String renamedProperty = renameMap.get(CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL, key)); if (renamedProperty != null) { attribute.setKey(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, renamedProperty)); }/*from www .j a v a 2s .c o m*/ } } }