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:dagger.android.processor.ContributesAndroidInjectorGenerator.java
private void generate(AndroidInjectorDescriptor descriptor) { ClassName moduleName = descriptor.enclosingModule().topLevelClassName() .peerClass(Joiner.on('_').join(descriptor.enclosingModule().simpleNames()) + "_" + CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, descriptor.methodName())); String baseName = descriptor.injectedType().simpleName(); ClassName subcomponentName = moduleName.nestedClass(baseName + "Subcomponent"); ClassName subcomponentBuilderName = subcomponentName.nestedClass("Builder"); TypeSpec module = TypeSpec.classBuilder(moduleName).addModifiers(PUBLIC, ABSTRACT) .addAnnotation(AnnotationSpec.builder(Module.class) .addMember("subcomponents", "$T.class", subcomponentName).build()) .addMethod(bindAndroidInjectorFactory(descriptor, subcomponentBuilderName)) .addType(subcomponent(descriptor, subcomponentName, subcomponentBuilderName)) .addMethod(MethodSpec.constructorBuilder().addModifiers(PRIVATE).build()).build(); try {/*from ww w. j a v a 2s. c o m*/ JavaFile.builder(moduleName.packageName(), module).skipJavaLangImports(true).build().writeTo(filer); } catch (IOException e) { throw new AssertionError(e); } }
From source file:com.github.jcustenborder.kafka.connect.utils.templates.model.SchemaData.java
String type(Schema schema) { String result;//from w w w. j a v a 2 s .com switch (schema.type()) { case ARRAY: result = String.format("Array of %s", type(schema.valueSchema())); break; case MAP: result = String.format("Map of %s, %s", type(schema.keySchema()), type(schema.valueSchema())); break; default: result = String.format(":ref:`schema-%s`", CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, schema.type().toString())); break; } return result; }
From source file:org.brooth.jeta.apt.processors.ObserverProcessor.java
public boolean process(TypeSpec.Builder builder, RoundContext context) { ClassName masterClassName = ClassName.get(context.metacodeContext().masterElement()); builder.addSuperinterface(/* w w w . ja va 2s. c o m*/ ParameterizedTypeName.get(ClassName.get(ObserverMetacode.class), masterClassName)); ClassName handlerClassName = ClassName.get(ObserverHandler.class); MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder("applyObservers").addAnnotation(Override.class) .addModifiers(Modifier.PUBLIC).returns(handlerClassName) .addParameter(masterClassName, "master", Modifier.FINAL).addParameter(Object.class, "observable") .addParameter(Class.class, "observableClass") .addStatement("$T handler = new $T()", handlerClassName, handlerClassName); for (Element element : context.elements()) { final Observe annotation = element.getAnnotation(Observe.class); String observableClass = MetacodeUtils.extractClassName(new Runnable() { public void run() { annotation.value(); } }); ClassName observableTypeName = ClassName.bestGuess(observableClass); ClassName metacodeTypeName = ClassName.bestGuess(MetacodeUtils.toMetacodeName(observableClass)); List<? extends VariableElement> params = ((ExecutableElement) element).getParameters(); if (params.size() != 1) throw new IllegalArgumentException("Observer method must have one parameter (event)"); TypeName eventTypeName = TypeName.get(params.get(0).asType()); if (eventTypeName instanceof ParameterizedTypeName) eventTypeName = ((ParameterizedTypeName) eventTypeName).rawType; String methodHashName = "get" + CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, CaseFormat.UPPER_CAMEL .to(CaseFormat.UPPER_UNDERSCORE, eventTypeName.toString()).replaceAll("\\.", "_")) + "Observers"; TypeSpec eventObserverTypeSpec = TypeSpec.anonymousClassBuilder("") .addSuperinterface(ParameterizedTypeName.get(ClassName.get(EventObserver.class), eventTypeName)) .addMethod(MethodSpec.methodBuilder("onEvent").addAnnotation(Override.class) .addModifiers(Modifier.PUBLIC).addParameter(eventTypeName, "event").returns(void.class) .addStatement("master.$N(event)", element.getSimpleName().toString()).build()) .build(); methodBuilder.beginControlFlow("if ($T.class == observableClass)", observableTypeName) .addStatement("handler.add($T.class, $T.class,\n$T.$L(($T) observable).\nregister($L))", observableTypeName, eventTypeName, metacodeTypeName, methodHashName, observableTypeName, eventObserverTypeSpec) .endControlFlow(); } methodBuilder.addStatement("return handler"); builder.addMethod(methodBuilder.build()); return false; }
From source file:org.embulk.cli.EmbulkNew.java
public boolean newPlugin() throws IOException { if (Files.exists(this.pluginBasePath)) { throw new IOException("./" + this.fullProjectName + " already exists. Please delete it first."); }//from w w w .j a va 2 s .co m Files.createDirectories(this.pluginBasePath); System.out.println("Creating " + this.fullProjectName + "/"); boolean success = false; try { // // Generate gemspec // final String author = getGitConfig("user.name", "YOUR_NAME"); final String email = getGitConfig("user.email", "YOUR_NAME"); final String expectedGitHubAccount = email.split("@")[0]; // variables used in Velocity templates final String rubyClassName = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name); final String javaClassName = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name) + CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, category) + "Plugin"; final String javaPackageName = "org.embulk." + embulkCategory + "." + name; final String displayName = getDisplayName(name); final String displayCategory = category.replace("_", " "); final HashMap<String, String> extraGuesses = new HashMap<String, String>(); final String description; switch (category) { case "input": description = String.format("Loads records from %s.", displayName); break; case "file_input": description = String.format("Reads files stored on %s.", displayName); break; case "parser": description = String.format("Parses %s files read by other file input plugins.", displayName); extraGuesses.put("embulk/data/new/ruby/parser_guess.rb.vm", String.format("%s/guess/%s.rb", pluginDirectory, name)); break; case "decoder": description = String.format("Decodes %s-encoded files read by other file input plugins.", displayName); extraGuesses.put("embulk/data/new/ruby/decoder_guess.rb.vm", String.format("%s/guess/%s.rb", pluginDirectory, name)); break; case "output": description = String.format("Dumps records to %s.", displayName); break; case "file_output": description = String.format("Stores files on %s.", displayName); break; case "formatter": description = String.format("Formats %s files for other file output plugins.", displayName); break; case "encoder": description = String.format("Encodes files using %s for other file output plugins.", displayName); break; case "filter": description = String.format("%s", displayName); break; default: throw new RuntimeException("FATAL: Invalid plugin category."); } // // Generate project repository // final VelocityContext velocityContext = createVelocityContext(author, category, description, displayName, displayCategory, email, embulkCategory, this.embulkVersion, expectedGitHubAccount, fullProjectName, javaClassName, javaPackageName, language, name, rubyClassName); copyTemplated("embulk/data/new/README.md.vm", "README.md", velocityContext); copy("embulk/data/new/LICENSE.txt", "LICENSE.txt"); copyTemplated("embulk/data/new/gitignore.vm", ".gitignore", velocityContext); switch (language) { case "ruby": copy("embulk/data/new/ruby/Rakefile", "Rakefile"); copy("embulk/data/new/ruby/Gemfile", "Gemfile"); copy("embulk/data/new/ruby/.ruby-version", ".ruby-version"); copyTemplated("embulk/data/new/ruby/gemspec.vm", fullProjectName + ".gemspec", velocityContext); copyTemplated(String.format("embulk/data/new/ruby/%s.rb.vm", category), this.pluginPath, velocityContext); break; case "java": copy("embulk/data/new/java/gradle/wrapper/gradle-wrapper.jar", "gradle/wrapper/gradle-wrapper.jar"); copy("embulk/data/new/java/gradle/wrapper/gradle-wrapper.properties", "gradle/wrapper/gradle-wrapper.properties"); copy("embulk/data/new/java/gradlew.bat", "gradlew.bat"); copy("embulk/data/new/java/gradlew", "gradlew"); setExecutable("gradlew"); copy("embulk/data/new/java/config/checkstyle/checkstyle.xml", "config/checkstyle/checkstyle.xml"); copy("embulk/data/new/java/config/checkstyle/default.xml", "config/checkstyle/default.xml"); copyTemplated("embulk/data/new/java/build.gradle.vm", "build.gradle", velocityContext); copyTemplated("embulk/data/new/java/plugin_loader.rb.vm", this.pluginPath, velocityContext); copyTemplated(String.format("embulk/data/new/java/%s.java.vm", category), String .format("src/main/java/%s/%s.java", javaPackageName.replaceAll("\\.", "/"), javaClassName), velocityContext); copyTemplated("embulk/data/new/java/test.java.vm", String.format("src/test/java/%s/Test%s.java", javaPackageName.replaceAll("\\.", "/"), javaClassName), velocityContext); break; } for (Map.Entry<String, String> entry : extraGuesses.entrySet()) { copyTemplated(entry.getKey(), entry.getValue(), velocityContext); } System.out.println(""); System.out.println("Plugin template is successfully generated."); switch (language) { case "ruby": System.out.println("Next steps:"); System.out.println(""); System.out.printf(" $ cd %s\n", fullProjectName); System.out .println(" $ bundle install # install one using rbenv & rbenv-build"); System.out.println(" $ bundle exec rake # build gem to be released"); System.out .println(" $ bundle exec embulk run config.yml # you can run plugin using this command"); break; case "java": System.out.println("Next steps:"); System.out.println(""); System.out.printf(" $ cd %s\n", fullProjectName); System.out.println(" $ ./gradlew package"); } success = true; System.out.println(""); } catch (Exception ex) { ex.printStackTrace(); } finally { if (!success) { System.out.println("Failed. Removing the directory created."); deleteDirectoryTree(Paths.get(fullProjectName)); } } return success; }
From source file:org.apache.brooklyn.util.javalang.Enums.java
/** checks that all accepted enum values are represented by the given set of explicit values */ public static void checkAllEnumeratedIgnoreCase(String contextMessage, Enum<?>[] enumValues, String... explicitValues) { MutableSet<String> explicitValuesSet = MutableSet .copyOf(Iterables.transform(Arrays.asList(explicitValues), StringFunctions.toLowerCase())); Set<Enum<?>> missingEnums = MutableSet.of(); for (Enum<?> e : enumValues) { if (explicitValuesSet.remove(e.name().toLowerCase())) continue; if (explicitValuesSet.remove(e.toString().toLowerCase())) continue; if (explicitValuesSet .remove(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, e.name()).toLowerCase())) continue; if (explicitValuesSet .remove(CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, e.toString()).toLowerCase())) continue; if (explicitValuesSet .remove(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, e.toString()).toLowerCase())) continue; if (explicitValuesSet .remove(CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, e.name()).toLowerCase())) continue; missingEnums.add(e);/* w w w.j a v a2 s . c o m*/ } if (!missingEnums.isEmpty() || !explicitValuesSet.isEmpty()) { throw new IllegalStateException("Not all options for " + contextMessage + " are enumerated; " + "leftover enums = " + missingEnums + "; " + "leftover values = " + explicitValuesSet); } }
From source file:com.spectralogic.ds3cli.Ds3Cli.java
private CliCommand getCommandExecutor() throws CommandException { final String commandName = this.args.getCommand(); final String commandCamel = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, commandName); final Iterator<CliCommand> implementations = getAllCommands(); while (implementations.hasNext()) { final CliCommand implementation = implementations.next(); final String className = implementation.getClass().getSimpleName(); if (className.equalsIgnoreCase(commandCamel)) { return implementation.withProvider(this.ds3Provider, this.fileUtils); }/* w ww. j a v a 2 s.co m*/ } throw new CommandException("No command class: " + commandName); }
From source file:org.zalando.jpa.eclipselink.customizer.databasemapping.support.EnumTypeConverter.java
protected void checkPgTypeName() { if (Strings.isNullOrEmpty(pgTypeName)) { pgTypeName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, enumClass.getSimpleName()); } }
From source file:com.salesforce.jprotoc.ProtoTypeMap.java
private static String getJavaOuterClassname(DescriptorProtos.FileDescriptorProto fileDescriptor, DescriptorProtos.FileOptions fileOptions) { if (fileOptions.hasJavaOuterClassname()) { return fileOptions.getJavaOuterClassname(); }/* w w w . ja v a 2s .c o m*/ // If the outer class name is not explicitly defined, then we take the proto filename, strip its extension, // and convert it from snake case to camel case. String filename = fileDescriptor.getName().substring(0, fileDescriptor.getName().length() - ".proto".length()); return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, filename); }
From source file:edu.berkeley.ground.postgres.dao.version.PostgresItemDao.java
@Override public T retrieveFromDatabase(long id) throws GroundException { return this.retrieve( String.format(SqlConstants.SELECT_STAR_ITEM_BY_ID, CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, this.getType().getSimpleName()), id), id);// www . j a v a2 s. c om }
From source file:ninja.utils.SwissKnife.java
/** * Returns the lower class name. Eg. A class named MyObject will become * "myObject".//from ww w .j a va2 s. c om * * @param object Object for which to return the lowerCamelCaseName * @return the lowerCamelCaseName of the Object */ public static String getRealClassNameLowerCamelCase(Object object) { return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, object.getClass().getSimpleName()); }