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:org.apache.brooklyn.api.objs.BrooklynObjectType.java
public String toCamelCase() { return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, this.name()); }
From source file:com.google.template.soy.types.proto.Protos.java
/** Performs camelcase translation. */ private static String computeJsExtensionName(FieldDescriptor field) { String name = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, field.getName()); return field.isRepeated() ? name + "List" : name; }
From source file:org.gradle.integtests.fixtures.executer.IntegrationTestBuildContext.java
public String getCurrentSubprojectName() { return CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL, getGradleHomeDir().getParentFile().getParentFile().getName()); }
From source file:com.shenit.commons.utils.ShenStrings.java
/** * To underscore format/*www . ja va 2 s . co m*/ * @param str * @return */ public static String underscore(String str) { if (str.indexOf(DELIMITER_UNDERSCORE) > 0) return str; return CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, str(str)); }
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 w w w . j ava 2s . com // 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.tactfactory.harmony.generator.BundleGenerator.java
/** * Generate the empty annotation./* ww w .ja v a2 s. c om*/ * @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:io.soliton.protobuf.json.Messages.java
/** * Converts a JSON object to a protobuf message * * @param builder the proto message type builder * @param input the JSON object to convert *//*from w w w. j a v a 2 s . co m*/ public static Message fromJson(Message.Builder builder, JsonObject input) throws Exception { Descriptors.Descriptor descriptor = builder.getDescriptorForType(); for (Map.Entry<String, JsonElement> entry : input.entrySet()) { String protoName = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, entry.getKey()); Descriptors.FieldDescriptor field = descriptor.findFieldByName(protoName); if (field == null) { throw new Exception("Can't find descriptor for field " + protoName); } if (field.isRepeated()) { if (!entry.getValue().isJsonArray()) { // fail } JsonArray array = entry.getValue().getAsJsonArray(); for (JsonElement item : array) { builder.addRepeatedField(field, parseField(field, item, builder)); } } else { builder.setField(field, parseField(field, entry.getValue(), builder)); } } return builder.build(); }
From source file:org.apache.beam.runners.core.construction.PipelineOptionsTranslation.java
/** Converts the provided {@link Struct} into {@link PipelineOptions}. */ public static PipelineOptions fromProto(Struct protoOptions) { try {/*ww w .j av a2 s . c om*/ Map<String, TreeNode> mapWithoutUrns = new HashMap<>(); TreeNode rootOptions = MAPPER.readTree(JsonFormat.printer().print(protoOptions)); Iterator<String> optionsKeys = rootOptions.fieldNames(); while (optionsKeys.hasNext()) { String optionKey = optionsKeys.next(); TreeNode optionValue = rootOptions.get(optionKey); mapWithoutUrns.put( CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, optionKey.substring("beam:option:".length(), optionKey.length() - ":v1".length())), optionValue); } return MAPPER.readValue(MAPPER.writeValueAsString(ImmutableMap.of("options", mapWithoutUrns)), PipelineOptions.class); } catch (IOException e) { throw new RuntimeException("Failed to read PipelineOptions from Protocol", e); } }
From source file:org.apache.brooklyn.util.javalang.coerce.EnumTypeCoercions.java
public static <E extends Enum<E>> Maybe<E> tryCoerce(String input, Class<E> targetType) { if (input == null) return null; if (targetType == null) return Maybe.absent("Null enum type"); if (!targetType.isEnum()) return Maybe.absent("Type '" + targetType + "' is not an enum"); List<String> options = ImmutableList.of(input, CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_UNDERSCORE, input), CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_UNDERSCORE, input), CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, input), CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, input)); for (String value : options) { try {// w ww.j av a2s . co m return Maybe.of(Enum.valueOf(targetType, value)); } catch (IllegalArgumentException iae) { continue; } } Maybe<E> result = Enums.valueOfIgnoreCase(targetType, input); if (result.isPresent()) return result; return Maybe.absent(new ClassCoercionException( "Invalid value '" + input + "' for " + JavaClassNames.simpleClassName(targetType) + "; expected one of " + Arrays.asList(Enums.values(targetType)))); }
From source file:com.google.errorprone.bugpatterns.SimpleDateFormatConstant.java
@Override public Description matchVariable(VariableTree tree, VisitorState state) { if (tree.getInitializer() == null) { return NO_MATCH; }// w ww .j a v a 2s . co m VarSymbol sym = ASTHelpers.getSymbol(tree); if (sym == null || sym.getKind() != ElementKind.FIELD) { return NO_MATCH; } String name = sym.getSimpleName().toString(); if (!(sym.isStatic() && sym.getModifiers().contains(Modifier.FINAL))) { return NO_MATCH; } if (!name.equals(name.toUpperCase())) { return NO_MATCH; } if (!isSameType(getType(tree), state.getTypeFromString("java.text.SimpleDateFormat"), state)) { return NO_MATCH; } return buildDescription(tree).addFix(threadLocalFix(tree, state, sym)) .addFix(renameVariable(tree, CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, tree.getName().toString()), state)) .build(); }