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.abstractmeta.reflectify.plugin.ReflectifyGenerator.java
private void buildArgumentSetter(JavaTypeBuilder nestedClassBuilder, JavaMethodBuilder parameterSetterMethod, String methodName, List<Type> genericParameterTypes, Type reflectifyType) { List<String> parameterSimpleTypeNames = new ArrayList<String>(); if (genericParameterTypes != null && genericParameterTypes.size() > 0) { parameterSetterMethod.addBody("\nswitch(parameterIndex) {"); for (int i = 0; i < genericParameterTypes.size(); i++) { Type fileType = ReflectUtil.getObjectType(genericParameterTypes.get(i)); parameterSimpleTypeNames.add(ReflectUtil.getRawClass(fileType).getSimpleName()); String fieldName = "parameter" + i; nestedClassBuilder.addField( new JavaFieldBuilder().setName(fieldName).setType(genericParameterTypes.get(i)).build()); String parameterSetterClassName = StringUtil.format(CaseFormat.UPPER_CAMEL, fieldName, "Setter", CaseFormat.LOWER_CAMEL); JavaTypeBuilder parameterSetterClass = parameterSetterMethod.addNestedJavaType(); parameterSetterClass.setSuperType(AbstractType.class); parameterSetterClass.setName(parameterSetterClassName) .addSuperInterface(new ParameterizedTypeImpl(null, ParameterSetter.class, fileType)); JavaMethodBuilder methodBuilder = new JavaMethodBuilder().addModifier("public").setName("set") .setResultType(void.class); methodBuilder.addParameter("value", fileType); methodBuilder.addBody(fieldName + " = value;"); parameterSetterClass.addMethod(methodBuilder.build()); parameterSetterMethod.addBody(" case " + i + ": return (ParameterSetter<RP>) new " + parameterSetterClassName + "();"); }// w w w .j av a2 s .co m nestedClassBuilder.addImportType(ArrayIndexOutOfBoundsException.class); parameterSetterMethod.addBody("}"); } nestedClassBuilder.addImportType(ArrayIndexOutOfBoundsException.class); String ownerType; if (reflectifyType instanceof TypeNameWrapper) { ownerType = TypeNameWrapper.class.cast(reflectifyType).getTypeName(); } else { ownerType = ReflectUtil.getRawClass(reflectifyType).getSimpleName(); } parameterSetterMethod.addBody( String.format("throw new %s(\"Invalid index parameter \" + parameterIndex + \" for %s.%s(%s)\");", ArrayIndexOutOfBoundsException.class.getSimpleName(), ownerType, methodName, Joiner.on(", ").join(parameterSimpleTypeNames))); }
From source file:bio.gcat.Utilities.java
public static String camelCase(String text) { return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, text); }
From source file:org.abstractmeta.reflectify.plugin.ReflectifyGenerator.java
protected void generateAccessors(JavaTypeBuilder typeBuilder, List<JavaMethod> methods, Type reflectifyType) { JavaMethodBuilder methodBuilder = new JavaMethodBuilder(); methodBuilder.addModifier("protected").setName("registerAccessors").setResultType(void.class); methodBuilder.addParameter("accessors", new ParameterizedTypeImpl(null, Map.class, String.class, new ParameterizedTypeImpl(null, Accessor.class, reflectifyType, Object.class))); methodBuilder.addBody("\n"); for (JavaMethod method : methods) { if (!method.getModifiers().contains("public")) { continue; }//from w w w.j a va 2 s .co m String methodName = method.getName(); if (!((methodName.startsWith("get") || methodName.startsWith("is")) && method.getParameterTypes().size() == 0)) { continue; } String fieldName = ReflectUtil.extractFieldNameFromMethodName(method.getName()); Type fieldType = ReflectUtil.getObjectType(method.getResultType()); Class fieldRawClass = ReflectUtil.getRawClass(fieldType); JavaTypeBuilder nestedClassBuilder = methodBuilder.addNestedJavaType(); String accessorClassName = StringUtil.format(CaseFormat.UPPER_CAMEL, fieldName, "accessor", CaseFormat.LOWER_CAMEL); nestedClassBuilder.setName(accessorClassName); nestedClassBuilder .addSuperInterface(new ParameterizedTypeImpl(null, Accessor.class, reflectifyType, fieldType)); JavaMethodBuilder accessorBuilder = new JavaMethodBuilder(); accessorBuilder.addModifier("public").setName("get").setResultType(fieldType); accessorBuilder.addParameter("instance", reflectifyType); accessorBuilder.addBody("return instance." + methodName + "();"); String fieldSimpleName; if (fieldRawClass.isArray()) { fieldSimpleName = JavaTypeUtil.getSimpleClassName(fieldRawClass.getComponentType().getName(), true) + " []"; } else { fieldSimpleName = JavaTypeUtil.getSimpleClassName(fieldRawClass.getName(), true); } nestedClassBuilder.addMethod(accessorBuilder.build()); methodBuilder.addBody("register(accessors, \"" + fieldName + "\", " + fieldSimpleName + ".class , new " + accessorClassName + "());"); } typeBuilder.addMethod(methodBuilder.build()); }
From source file:io.soliton.shapeshifter.NamedSchema.java
/** * Returns the external name of a given field of this schema. * * @param name the name of the field to look up *///from w ww .j a v a2s . c o m public String getPropertyName(String name) { Preconditions.checkArgument(has(name)); if (substitutions.containsKey(name)) { name = substitutions.get(name); } return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name); }
From source file:org.jooby.camel.Camel.java
@SuppressWarnings({ "rawtypes", "unchecked" }) private <T> T configure(final T source, final Config config) { List<Method> methods = Lists.newArrayList(source.getClass().getMethods()); config.entrySet().forEach(o -> {// ww w . ja v a 2s . c o m String key = o.getKey(); String setter = "set" + CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, key); Object raw = o.getValue().unwrapped(); Optional<Method> result = methods.stream().filter(m -> m.getName().equals(setter)).findFirst(); if (result.isPresent()) { Method method = result.get(); Class type = method.getParameterTypes()[0]; Object value = cast(type, raw); Try.run(() -> method.invoke(source, value)).onFailure(ex -> { throw new IllegalArgumentException("Bad option: <" + raw + "> for: " + method, ex); }); } else { log.error("Unknown option camel.{} = {}", key, raw); } }); return source; }
From source file:iterator.Explorer.java
/** @see Subscriber#updated(IFS) */ @Override//from ww w. jav a 2 s . c o m @Subscribe public void updated(IFS updated) { ifs = updated; System.err.println("Updated: " + ifs); String name = CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, Optional.fromNullable(ifs.getName()).or(IFS.UNTITLED)); setTitle(name); if (!ifs.isEmpty()) { save.setEnabled(true); saveAs.setEnabled(true); } repaint(); }
From source file:org.abstractmeta.reflectify.plugin.ReflectifyGenerator.java
protected void generateMutators(JavaTypeBuilder typeBuilder, List<JavaMethod> methods, Type reflectifyType) { JavaMethodBuilder methodBuilder = new JavaMethodBuilder(); methodBuilder.addModifier("protected").setName("registerMutators").setResultType(void.class); methodBuilder.addParameter("mutators", new ParameterizedTypeImpl(null, Map.class, String.class, new ParameterizedTypeImpl(null, Mutator.class, reflectifyType, Object.class))); methodBuilder.addBody("\n"); for (JavaMethod method : methods) { if (!method.getModifiers().contains("public")) { continue; }// w w w. j a v a 2 s .com String methodName = method.getName(); if (!methodName.startsWith("set") || method.getParameterTypes().size() != 1) { continue; } String fieldName = ReflectUtil.extractFieldNameFromMethodName(method.getName()); Type fieldType = ReflectUtil.getObjectType(method.getParameterTypes().get(0)); JavaTypeBuilder nestedClassBuilder = methodBuilder.addNestedJavaType(); String accessorClassName = StringUtil.format(CaseFormat.UPPER_CAMEL, fieldName, "mutator", CaseFormat.LOWER_CAMEL); nestedClassBuilder.setName(accessorClassName); nestedClassBuilder .addSuperInterface(new ParameterizedTypeImpl(null, Mutator.class, reflectifyType, fieldType)); JavaMethodBuilder accessorBuilder = new JavaMethodBuilder(); accessorBuilder.addModifier("public").setName("set").setResultType(void.class); accessorBuilder.addParameter("instance", reflectifyType).addParameter("value", fieldType); accessorBuilder.addBody("instance." + methodName + "(value);"); nestedClassBuilder.addMethod(accessorBuilder.build()); methodBuilder.addBody("register(mutators, \"" + fieldName + "\", new " + accessorClassName + "());"); } typeBuilder.addMethod(methodBuilder.build()); }
From source file:com.google.template.soy.jssrc.internal.GenJsCodeVisitorAssistantForMsgs.java
/** * Private helper for visitGoogMsgDefNode(). * Converts a Soy placeholder name (in upper underscore format) into a JS variable name (in lower * camel case format) used by goog.getMsg(). If the original name has a numeric suffix, it will * be preserved with an underscore.//from w w w . ja v a 2s . c o m * * For example, the following transformations happen: * <li> N : n * <li> NUM_PEOPLE : numPeople * <li> PERSON_2 : person_2 * <li>GENDER_OF_THE_MAIN_PERSON_3 : genderOfTheMainPerson_3 * * @param placeholderName The placeholder name to convert. * @return The generated goog.getMsg name for the given (standard) Soy name. */ private static String genGoogMsgPlaceholderName(String placeholderName) { Matcher suffixMatcher = UNDERSCORE_NUMBER_SUFFIX.matcher(placeholderName); if (suffixMatcher.find()) { String base = placeholderName.substring(0, suffixMatcher.start()); String suffix = suffixMatcher.group(); return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, base) + suffix; } else { return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, placeholderName); } }
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"; }/* w w w .j a va 2s. com*/ 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:brooklyn.util.task.BasicExecutionManager.java
/** invoked in a task's thread when a task is starting to run (may be some time after submitted), * but before doing any of the task's work, so that we can update bookkeeping and notify callbacks */ protected void internalBeforeStart(Map<?, ?> flags, Task<?> task) { activeTaskCount.incrementAndGet();/*from w w w . j av a2s .c o m*/ //set thread _before_ start time, so we won't get a null thread when there is a start-time if (log.isTraceEnabled()) log.trace("" + this + " beforeStart, task: " + task); if (!task.isCancelled()) { Thread thread = Thread.currentThread(); ((TaskInternal<?>) task).setThread(thread); if (RENAME_THREADS) { threadOriginalName.set(thread.getName()); String newThreadName = "brooklyn-" + CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL, task.getDisplayName().replace(" ", "")) + "-" + task.getId().substring(0, 8); thread.setName(newThreadName); } PerThreadCurrentTaskHolder.perThreadCurrentTask.set(task); ((TaskInternal<?>) task).setStartTimeUtc(System.currentTimeMillis()); } ExecutionUtils.invoke(flags.get("newTaskStartCallback"), task); }