List of usage examples for com.google.common.base CaseFormat UPPER_CAMEL
CaseFormat UPPER_CAMEL
To view the source code for com.google.common.base CaseFormat UPPER_CAMEL.
Click Source Link
From source file:org.jooby.assets.AssetProcessor.java
public String name() { return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, getClass().getSimpleName()); }
From source file:com.google.javascript.jscomp.PolymerPass.java
/** * Validates the class definition and if valid, destructively extracts the class definition from * the AST.//from ww w . j a v a 2 s .co m */ private ClassDefinition extractClassDefinition(Node callNode) { Node descriptor = NodeUtil.getArgumentForCallOrNew(callNode, 0); if (descriptor == null || !descriptor.isObjectLit()) { // report bad class definition compiler.report(JSError.make(callNode, POLYMER_DESCRIPTOR_NOT_VALID)); return null; } int paramCount = callNode.getChildCount() - 1; if (paramCount != 1) { compiler.report(JSError.make(callNode, POLYMER_UNEXPECTED_PARAMS)); return null; } Node elName = NodeUtil.getFirstPropMatchingKey(descriptor, "is"); if (elName == null) { compiler.report(JSError.make(callNode, POLYMER_MISSING_IS)); return null; } String elNameString = CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, elName.getString()); elNameString += "Element"; Node target; if (NodeUtil.isNameDeclaration(callNode.getParent().getParent())) { target = IR.name(callNode.getParent().getString()); } else if (callNode.getParent().isAssign()) { target = callNode.getParent().getFirstChild().cloneTree(); } else { target = IR.name(elNameString); } target.useSourceInfoIfMissingFrom(callNode); JSDocInfo classInfo = NodeUtil.getBestJSDocInfo(target); JSDocInfo ctorInfo = null; Node constructor = NodeUtil.getFirstPropMatchingKey(descriptor, "factoryImpl"); if (constructor == null) { constructor = IR.function(IR.name(""), IR.paramList(), IR.block()); constructor.useSourceInfoFromForTree(callNode); } else { ctorInfo = NodeUtil.getBestJSDocInfo(constructor); } Node baseClass = NodeUtil.getFirstPropMatchingKey(descriptor, "extends"); String nativeBaseElement = baseClass == null ? null : baseClass.getString(); Node behaviorArray = NodeUtil.getFirstPropMatchingKey(descriptor, "behaviors"); List<BehaviorDefinition> behaviors = extractBehaviors(behaviorArray); List<MemberDefinition> allProperties = new LinkedList<>(); for (BehaviorDefinition behavior : behaviors) { overwriteMembersIfPresent(allProperties, behavior.props); } overwriteMembersIfPresent(allProperties, extractProperties(descriptor)); ClassDefinition def = new ClassDefinition(target, descriptor, classInfo, new MemberDefinition(ctorInfo, null, constructor), nativeBaseElement, allProperties, behaviors); return def; }
From source file:org.apache.metron.parsers.regex.RegularExpressionsParser.java
private void convertCamelCaseToUnderScore(Map<String, Object> json) { Map<String, String> oldKeyNewKeyMap = new HashMap<>(); for (Map.Entry<String, Object> entry : json.entrySet()) { if (capitalLettersPattern.matcher(entry.getKey()).matches()) { oldKeyNewKeyMap.put(entry.getKey(), CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, entry.getKey())); }//from w ww.j a v a2 s . c o m } oldKeyNewKeyMap.forEach((oldKey, newKey) -> json.put(newKey, json.remove(oldKey))); }
From source file:com.tactfactory.harmony.platform.winphone.WinphoneProjectAdapter.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 = this.adapter.getSourcePath(); result.add(new SourceFile(templatePath + "TemplateApplicationBase.cs", filePath + applicationName + "ApplicationBase.cs", true)); result.add(new ProjectUpdater(FileType.Compile, applicationName + "ApplicationBase.cs")); result.add(new SourceFile(templatePath + "TemplateApplication.xaml.cs", filePath + applicationName + "Application.xaml.cs")); result.add(new ProjectUpdater(FileType.Compile, applicationName + "Application.xaml.cs", applicationName + "Application.xaml")); result.add(new SourceFile(templatePath + "TemplateApplication.xaml", filePath + applicationName + "Application.xaml")); result.add(new ProjectUpdater(FileType.ApplicationDefinition, applicationName + "Application.xaml")); return result; }
From source file:com.shieldsbetter.sbomg.ViewModelGenerator.java
private static void outfitModelWithList(ModelClass dest, String contextName, Set<String> listOptions, Object elDesc) {/*from ww w .j ava 2s.c o m*/ boolean immutableFlag = listOptions.contains("immutable"); boolean replaceableFlag = listOptions.contains("replaceable"); ListElementTypeData elTypeData = outfitModelWithListElementType(dest, contextName, elDesc); String elTypeRaw = elTypeData.getRawTypeName(); TypeName elType = ClassName.get("", elTypeRaw); String slotTypeRaw = contextName + "Key"; TypeName slotType = ClassName.get("", slotTypeRaw); TypeSpec.Builder keyType = TypeSpec.classBuilder(slotTypeRaw) .addModifiers(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL) .addMethod(MethodSpec.constructorBuilder().addModifiers(Modifier.PRIVATE) .addParameter(elType, "value").addStatement("myValue = value").build()) .addMethod(MethodSpec.methodBuilder("getValue").addModifiers(Modifier.PRIVATE).returns(elType) .addStatement("return myValue").build()); if (elTypeData.isFinal() || immutableFlag) { keyType.addField(elType, "myValue", Modifier.PRIVATE, Modifier.FINAL); } else { keyType.addField(elType, "myValue", Modifier.PRIVATE); keyType.addMethod(MethodSpec.methodBuilder("setValue").addModifiers(Modifier.PRIVATE) .addParameter(elType, "value").addStatement("myValue = value").build()); } dest.addType(keyType.build()); FieldSpec.Builder field = FieldSpec .builder(ParameterizedTypeName.get(ClassName.get("java.util", "List"), slotType), "my" + contextName + "List", Modifier.PRIVATE) .initializer("new $T<>()", ClassName.get("java.util", "LinkedList")); if (!replaceableFlag) { field.addModifiers(Modifier.FINAL); } dest.addField(field.build()); dest.addRootMethod("get" + contextName + "Element", elType, ImmutableList.of(ImmutablePair.of("index", TypeName.INT)), CodeBlock.builder().addStatement("return my$LList.get(index).getValue()", contextName).build()); dest.addRootMethod("get" + contextName + "Element", elType, ImmutableList.of(ImmutablePair.of("key", slotType)), CodeBlock.builder().addStatement("int index = my$LList.indexOf(key)", contextName) .addStatement("return my$LList.get(index).getValue()", contextName).build()); // TODO: Fix this. The generated field contians keys not elements. /* dest.addRootMethod("contains" + contextName + "Element", TypeName.BOOLEAN, ImmutableList.of( ImmutablePair.of("element", elType)), renderCodeBlock(LIST_CONTAINS_VALUE_METHOD_TEMPL, "fieldName", contextName, "valueParam", "element")); */ if (contextName.isEmpty()) { String parentInterfaceName = elTypeRaw; if (elTypeData.isInnerClass()) { parentInterfaceName = dest.getName() + "." + parentInterfaceName; } dest.addImplements(ParameterizedTypeName.get(ClassName.get("", "Iterable"), ClassName.get("", parentInterfaceName))); dest.addOverriddenRootMethod("iterator", ParameterizedTypeName.get(ClassName.get(Iterator.class), elType), ImmutableList.of(), renderCodeBlock(LIST_ITERATOR_TEMPL, "elementType", elTypeRaw, "contextName", contextName, "baseIterable", "my" + contextName + "List")); } else { // Gross workaround here. JavaPoet doesn't provide any way to // include a random non-static import. So we render out a template // that happens to include an unresolved $T, then replace it with // the type we want to import. dest.addRootMethod(CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, contextName), ParameterizedTypeName.get(ClassName.get("", "Iterable"), elType), ImmutableList.of(), CodeBlock.of( renderTemplate(RETURN_LIST_METHOD_TEMPL, "elementType", elTypeRaw, "iteratorCode", renderTemplate(LIST_ITERATOR_TEMPL, "elementType", elTypeRaw, "contextName", contextName, "baseIterable", "my" + contextName + "List")), ParameterizedTypeName.get(ClassName.get(Iterator.class), elType))); } if (immutableFlag) { String elementParam = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, contextName + "Elements"); dest.addInitializationParameter(elementParam, ParameterizedTypeName.get(ClassName.get("", "Iterable"), elType)); CodeBlock.Builder init = CodeBlock.builder().beginControlFlow("for ($T e : $L)", elType, elementParam) .addStatement("$LKey k = new $LKey(e);", contextName, contextName) .addStatement("my$LList.add(k)", contextName); if (!elTypeData.isLeaf()) { init.addStatement("subscribeIfNotNull(k)"); } init.endControlFlow(); dest.addInitializationCode(init.build()); } if (replaceableFlag) { dest.addListenerEvent(contextName + "Replaced", ImmutableList.of(ImmutablePair.of("newValue", ParameterizedTypeName.get(ClassName.get("java.util", "List"), elType)))); dest.addRootMethod("replace" + contextName, TypeName.VOID, ImmutableList.of(ImmutablePair.of("elements", ParameterizedTypeName.get(ClassName.get("", "Iterable"), elType))), renderCodeBlock(REPLACE_LIST_METHOD_TEMPL, "contextName", contextName, "elementType", elTypeRaw, "parentType", dest.getName(), "elementsParam", "elements", "leafFlag", elTypeData.isLeaf())); dest.addBuildCode(CodeBlock.builder().beginControlFlow("") .addStatement("List<$T> valueList = new $T<>()", elType, LinkedList.class) .beginControlFlow("for ($T s : my$LList)", slotType, contextName) .addStatement("valueList.add(s.getValue())").endControlFlow() .addStatement("l.on$LReplaced(this, " + "$T.unmodifiableList(valueList))", contextName, Collections.class) .endControlFlow().build()); } if (!elTypeData.isLeaf()) { dest.addField(FieldSpec .builder( ParameterizedTypeName.get(ClassName.get("java.util", "Map"), slotType, ClassName.get("", elTypeRaw + ".Subscription")), "my" + contextName + "Subscriptions", Modifier.PRIVATE, Modifier.FINAL) .initializer("new $T<>()", ClassName.get("java.util", "HashMap")).build()); dest.addListenerEvent(contextName + "Updated", ImmutableList.of(ImmutablePair.of("updatedElement", elType), ImmutablePair.of("index", TypeName.INT), ImmutablePair.of("key", slotType), ImmutablePair.of("event", ClassName.get("", elTypeRaw + ".Event")))); dest.addRootMethod(MethodSpec.methodBuilder("subscribeIfNotNull").returns(TypeName.VOID) .addModifiers(Modifier.PRIVATE).addParameter(slotType, "key", Modifier.FINAL) .addCode(renderCodeBlock(SUBSCRIBE_IF_NOT_NULL_TEMPL, "keyParam", "key", "fieldName", contextName, "fieldType", elTypeRaw, "parentType", dest.getName())) .build()); } if (!immutableFlag) { if (!replaceableFlag) { dest.addBuildCode(CodeBlock.builder().beginControlFlow("").addStatement("int i = 0") .beginControlFlow("for ($T s : my$LList)", slotType, contextName) .addStatement("l.on$LAdded(this, s.getValue(), i, s)", contextName).addStatement("i++") .endControlFlow().endControlFlow().build()); } dest.addListenerEvent(contextName + "Added", ImmutableList.of(ImmutablePair.of("addedElement", elType), ImmutablePair.of("index", TypeName.INT), ImmutablePair.of("key", slotType))); dest.addRootMethod("add" + contextName, slotType, ImmutableList.of(ImmutablePair.of("newElement", elType)), renderCodeBlock(LIST_ADD_METHOD_TEMPL, "valueParam", "newElement", "fieldName", contextName, "fieldType", elTypeRaw, "leafFlag", elTypeData.isLeaf(), "parentType", dest.getName())); dest.addListenerEvent(contextName + "Removed", ImmutableList.of(ImmutablePair.of("removedElement", elType), ImmutablePair.of("index", TypeName.INT), ImmutablePair.of("key", slotType))); dest.addRootMethod("remove" + contextName, TypeName.VOID, ImmutableList.of(ImmutablePair.of("index", TypeName.INT)), renderCodeBlock( LIST_REMOVE_METHOD_BY_INDEX_TEMPL, "indexParam", "index", "fieldName", contextName)); dest.addRootMethod("remove" + contextName, TypeName.VOID, ImmutableList.of(ImmutablePair.of("key", slotType)), renderCodeBlock(LIST_REMOVE_METHOD_BY_KEY_TEMPL, "keyParam", "key", "fieldName", contextName)); dest.addRootMethod(MethodSpec.methodBuilder("remove" + contextName).addModifiers(Modifier.PRIVATE) .returns(TypeName.VOID).addParameter(TypeName.INT, "index", Modifier.FINAL) .addParameter(slotType, "key", Modifier.FINAL) .addCode(renderCodeBlock(LIST_REMOVE_METHOD_CORE_TEMPL, "fieldName", contextName, "keyParam", "key", "indexParam", "index", "leafFlag", elTypeData.isLeaf(), "parentType", dest.getName())) .build()); dest.addRootMethod("clear" + contextName, TypeName.VOID, ImmutableList.<ImmutablePair<String, TypeName>>of(), renderCodeBlock(LIST_CLEAR_METHOD_TEMPL, "fieldName", contextName)); if (!elTypeData.isFinal()) { dest.addListenerEvent(contextName + "Set", ImmutableList.of(ImmutablePair.of("oldValue", elType), ImmutablePair.of("newValue", elType), ImmutablePair.of("index", TypeName.INT), ImmutablePair.of("key", slotType))); dest.addRootMethod("set" + contextName, TypeName.VOID, ImmutableList.of(ImmutablePair.of("index", TypeName.INT), ImmutablePair.of("newValue", elType)), renderCodeBlock(LIST_SET_METHOD_BY_INDEX_TEMPL, "fieldName", contextName, "indexParam", "index", "valueParam", "newValue")); dest.addRootMethod("set" + contextName, TypeName.VOID, ImmutableList.of(ImmutablePair.of("key", slotType), ImmutablePair.of("newValue", elType)), renderCodeBlock(LIST_SET_METHOD_BY_KEY_TEMPL, "keyParam", "key", "fieldName", contextName, "valueParam", "newValue")); dest.addRootMethod(MethodSpec.methodBuilder("set" + contextName).returns(TypeName.VOID) .addModifiers(Modifier.PRIVATE).addParameter(TypeName.INT, "index", Modifier.FINAL) .addParameter(slotType, "key", Modifier.FINAL).addParameter(elType, "value", Modifier.FINAL) .addCode(renderCodeBlock(LIST_SET_METHOD_CORE_TEMPL, "keyParam", "key", "indexParam", "index", "valueParam", "value", "leafFlag", elTypeData.isLeaf(), "fieldName", contextName, "fieldType", elTypeRaw, "parentType", dest.getName())) .build()); } } }
From source file:org.jooby.livereload.LiveReload.java
@SuppressWarnings("unchecked") @Override//from www . jav a 2s. com public void configure(final Env env, final Config conf, final Binder binder) throws Throwable { boolean enabled = conf.hasPath("livereload.enabled") ? conf.getBoolean("livereload.enabled") : "dev".equals(env.name()); if (enabled) { Router router = env.router(); /** * Livereload client: */ String livereloadjs = "/" + LiveReload.class.getPackage().getName().replace(".", "/") + "/livereload.js"; router.assets("/livereload.js", livereloadjs); /** {{liveReload}} local variable */ router.use("*", (req, rsp) -> req.set("liveReload", template(req))).name("livereload"); String serverName = CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, conf.getString("application.name")); Queue<WebSocket> broadcast = new ConcurrentLinkedQueue<>(); AtomicBoolean first = new AtomicBoolean(true); /** * Websocket: */ router.ws("/livereload", ws -> { // add to broadcast broadcast.add(ws); ws.onMessage(msg -> { Map<String, Object> cmd = msg.to(Map.class); log.debug("command: {}", cmd); Map<String, Object> rsp = handshake(cmd, serverName, V7); if (rsp != null) { log.debug("sending: {}", rsp); ws.send(rsp); } else { log.trace("ignoring command: {}", cmd); // resync app state after a jooby:run restart if (first.compareAndSet(true, false)) { int counter = Integer.parseInt(System.getProperty("joobyRun.counter", "0")); if (counter > 0) { ws.send(reload("/", true)); } } } }); // remove from broadcast ws.onClose(reason -> broadcast.remove(ws)); }).consumes(MediaType.json).produces(MediaType.json); if (paths.isEmpty()) { Path basedir = Paths.get(System.getProperty("user.dir")); Path assetsDir; if (conf.hasPath("assets.outputDir")) { assetsDir = Paths.get(conf.getString("assets.outputDir")); } else { assetsDir = basedir.resolve("public"); } register(basedir.resolve("public"), "**/*.html", "**/*.ftl", "**/*.hbs", "**/*.jade"); register(assetsDir, "**/*.css", "**/*.scss", "**/*.sass", "**/*.less", "**/*.js", "**/*.coffee", "**/*.ts"); register(basedir.resolve("target"), "**/*.class", "**/*.conf", "**/*.properties"); register(basedir.resolve("build"), "**/*.class", "**/*.conf", "**/*.properties"); } if (paths.size() > 0) { FileWatcher watcher = new FileWatcher(); paths.forEach(it -> watcher.register((Path) it[0], (kind, path) -> { Path relative = relative(paths, path.toAbsolutePath()); log.debug("file changed {}: {}", relative, File.separator); Map<String, Object> reload = reload( Route.normalize("/" + relative.toString().replace(File.separator, "/")), css.test(relative)); for (WebSocket ws : broadcast) { try { log.debug("sending: {}", reload); ws.send(reload); } catch (Exception x) { log.debug("execution of {} resulted in exception", reload, x); } } }, options -> ((List<String>) it[1]).forEach(options::includes))); watcher.configure(env, conf, binder); } else { log.warn("File watcher is off"); } } }
From source file:net.phonex.intellij.android.dbmodel.CodeGenerator.java
private String getFieldName(String varName) { return "FIELD_" + CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, varName); }
From source file:org.jooby.internal.mvc.MvcRoutes.java
private static String attrName(final Annotation annotation, final Method attr) { String name = attr.getName(); if (name.equals("value")) { return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, annotation.annotationType().getSimpleName()); }// w w w . ja va 2s . c o m return annotation.annotationType().getSimpleName() + "." + name; }
From source file:com.google.api.codegen.DiscoveryImporter.java
private static String lowerCamelToUpperCamel(String s) { return CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, s); }
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 a 2 s. c o 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))); }