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.ballerinalang.composer.service.workspace.rest.datamodel.BLangFileRestService.java
public static JsonElement generateJSON(Node node, Map<String, Node> anonStructs) throws InvocationTargetException, IllegalAccessException { if (node == null) { return JsonNull.INSTANCE; }/*from w w w. j a v a 2s. c o m*/ Set<Method> methods = ClassUtils.getAllInterfaces(node.getClass()).stream() .flatMap(aClass -> Arrays.stream(aClass.getMethods())).collect(Collectors.toSet()); JsonObject nodeJson = new JsonObject(); JsonArray wsJsonArray = new JsonArray(); Set<Whitespace> ws = node.getWS(); if (ws != null && !ws.isEmpty()) { for (Whitespace whitespace : ws) { JsonObject wsJson = new JsonObject(); wsJson.addProperty("ws", whitespace.getWs()); wsJson.addProperty("i", whitespace.getIndex()); wsJson.addProperty("text", whitespace.getPrevious()); wsJson.addProperty("static", whitespace.isStatic()); wsJsonArray.add(wsJson); } nodeJson.add("ws", wsJsonArray); } Diagnostic.DiagnosticPosition position = node.getPosition(); if (position != null) { JsonObject positionJson = new JsonObject(); positionJson.addProperty("startColumn", position.getStartColumn()); positionJson.addProperty("startLine", position.getStartLine()); positionJson.addProperty("endColumn", position.getEndColumn()); positionJson.addProperty("endLine", position.getEndLine()); nodeJson.add("position", positionJson); } /* Virtual props */ JsonArray type = getType(node); if (type != null) { nodeJson.add(SYMBOL_TYPE, type); } if (node.getKind() == NodeKind.INVOCATION) { assert node instanceof BLangInvocation : node.getClass(); BLangInvocation invocation = (BLangInvocation) node; if (invocation.symbol != null && invocation.symbol.kind != null) { nodeJson.addProperty(INVOCATION_TYPE, invocation.symbol.kind.toString()); } } for (Method m : methods) { String name = m.getName(); if (name.equals("getWS") || name.equals("getPosition")) { continue; } String jsonName; if (name.startsWith("get")) { jsonName = toJsonName(name, 3); } else if (name.startsWith("is")) { jsonName = toJsonName(name, 2); } else { continue; } Object prop = m.invoke(node); /* Literal class - This class is escaped in backend to address cases like "ss\"" and 8.0 and null */ if (node.getKind() == NodeKind.LITERAL && "value".equals(jsonName)) { if (prop instanceof String) { nodeJson.addProperty(jsonName, '"' + StringEscapeUtils.escapeJava((String) prop) + '"'); nodeJson.addProperty(UNESCAPED_VALUE, String.valueOf(prop)); } else { nodeJson.addProperty(jsonName, String.valueOf(prop)); } continue; } if (node.getKind() == NodeKind.USER_DEFINED_TYPE && jsonName.equals("typeName")) { IdentifierNode typeNode = (IdentifierNode) prop; Node structNode; if (typeNode.getValue().startsWith("$anonStruct$") && (structNode = anonStructs.remove(typeNode.getValue())) != null) { JsonObject anonStruct = generateJSON(structNode, anonStructs).getAsJsonObject(); anonStruct.addProperty("anonStruct", true); nodeJson.add("anonStruct", anonStruct); continue; } } if (prop instanceof List && jsonName.equals("types")) { // Currently we don't need any Symbols for the UI. So skipping for now. continue; } /* Node classes */ if (prop instanceof Node) { nodeJson.add(jsonName, generateJSON((Node) prop, anonStructs)); } else if (prop instanceof List) { List listProp = (List) prop; JsonArray listPropJson = new JsonArray(); nodeJson.add(jsonName, listPropJson); for (Object listPropItem : listProp) { if (listPropItem instanceof Node) { /* Remove top level anon func and struct */ if (node.getKind() == NodeKind.COMPILATION_UNIT) { if (listPropItem instanceof BLangStruct && ((BLangStruct) listPropItem).isAnonymous) { anonStructs.put(((BLangStruct) listPropItem).getName().getValue(), ((BLangStruct) listPropItem)); continue; } if (listPropItem instanceof BLangFunction && (((BLangFunction) listPropItem)).name.value.startsWith("$lambda$")) { continue; } } listPropJson.add(generateJSON((Node) listPropItem, anonStructs)); } else { logger.debug("Can't serialize " + jsonName + ", has a an array of " + listPropItem); } } /* Runtime model classes */ } else if (prop instanceof Set && jsonName.equals("flags")) { Set flags = (Set) prop; for (Flag flag : Flag.values()) { nodeJson.addProperty(StringUtils.lowerCase(flag.toString()), flags.contains(flag)); } } else if (prop instanceof Set) { // TODO : limit this else if to getInputs getOutputs of transform. Set vars = (Set) prop; JsonArray listVarJson = new JsonArray(); nodeJson.add(jsonName, listVarJson); for (Object obj : vars) { listVarJson.add(obj.toString()); } } else if (prop instanceof NodeKind) { String kindName = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, prop.toString()); nodeJson.addProperty(jsonName, kindName); } else if (prop instanceof OperatorKind) { nodeJson.addProperty(jsonName, prop.toString()); /* Generic classes */ } else if (prop instanceof String) { nodeJson.addProperty(jsonName, (String) prop); } else if (prop instanceof Number) { nodeJson.addProperty(jsonName, (Number) prop); } else if (prop instanceof Boolean) { nodeJson.addProperty(jsonName, (Boolean) prop); } else if (prop instanceof Enum) { nodeJson.addProperty(jsonName, StringUtils.lowerCase(((Enum) prop).name())); } else if (prop != null) { nodeJson.addProperty(jsonName, prop.toString()); String message = "Node " + node.getClass().getSimpleName() + " contains unknown type prop: " + jsonName + " of type " + prop.getClass(); logger.error(message); } } return nodeJson; }
From source file:com.google.api.codegen.transformer.SampleTransformer.java
/** * Creates a region tag from the spec, replacing any {@code %m}, {@code %c}, and {@code %v} * placeholders with the method name, calling form name, and value set id, respectively. *///from w ww. j a v a 2 s . co m private static String regionTagFromSpec(String spec, String methodName, CallingForm callingForm, String valueSetId) { final String DEFAULT_REGION_SPEC = "sample"; if (Strings.isNullOrEmpty(spec)) { spec = DEFAULT_REGION_SPEC; } return spec.replace("%m", CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, methodName)) .replace("%c", callingForm.toLowerCamel()).replace("%v", valueSetId); }
From source file:com.tactfactory.harmony.platform.android.AndroidProjectAdapter.java
@Override public List<IUpdater> getDatabaseFiles() { List<IUpdater> result = new ArrayList<IUpdater>(); String applicationName = CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, this.adapter.getApplicationMetadata().getName()); String templatePath = this.adapter.getTemplateSourceDataPath(); String filePath = String.format("%s%s/%s/", this.adapter.getSourcePath(), this.adapter.getApplicationMetadata().getProjectNameSpace(), this.adapter.getData()); result.add(new SourceFile(templatePath + "TemplateSQLiteOpenHelper.java", String.format("%s%sSQLiteOpenHelper.java", filePath, applicationName), false)); result.add(new SourceFile(templatePath + "base/TemplateSQLiteOpenHelperBase.java", String.format("%sbase/%sSQLiteOpenHelperBase.java", filePath, applicationName), true)); result.add(new SourceFile(templatePath + "base/ApplicationSQLiteAdapterBase.java", filePath + "base/SQLiteAdapterBase.java", true)); result.add(new SourceFile(templatePath + "ApplicationSQLiteAdapter.java", filePath + "SQLiteAdapter.java", false));//from w w w .j av a2 s. c o m result.add(new SourceFile(templatePath + "data-package-info.java", filePath + "package-info.java", true)); result.add(new SourceFile(templatePath + "base/data-package-info.java", filePath + "base/package-info.java", true)); return result; }
From source file:com.geemvc.taglib.form.FormTagSupport.java
public String getName() { if (name == null) name = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, handlerMethod().getName()); return name; }
From source file:org.abstractmeta.reflectify.plugin.ReflectifyGenerator.java
protected void generateMethodInvokers(JavaTypeBuilder typeBuilder, List<JavaMethod> methods, Type reflectifyType) {// ww w . j a v a 2s . c om Map<String, Integer> methodCounter = new HashMap<String, Integer>(); JavaMethodBuilder methodBuilder = new JavaMethodBuilder(); methodBuilder.addAnnotation(new SuppressWarningsImpl("unchecked")); methodBuilder.addModifier("protected").setName("registerMethodInvokers").setResultType(void.class); methodBuilder.addParameter("methods", new ParameterizedTypeImpl(null, Map.class, String.class, new ParameterizedTypeImpl(null, List.class, new ParameterizedTypeImpl(null, MethodInvoker.class, reflectifyType, Object.class)))); methodBuilder.addBody("\n"); for (JavaMethod method : methods) { if (!method.getModifiers().contains("public")) { continue; } String methodName = method.getName(); String methodInvokerTypeNamePostfix = getOccurrence(methodCounter, methodName); String methodInvokerClassName = StringUtil.format(CaseFormat.UPPER_CAMEL, methodName, "invoker" + methodInvokerTypeNamePostfix, CaseFormat.LOWER_CAMEL); boolean exceptionHandling = method.getExceptionTypes() != null && !method.getExceptionTypes().isEmpty(); buildMethodInvokerType(methodBuilder, methodName, methodInvokerClassName, ReflectUtil.getObjectType(method.getResultType()), method.getParameterTypes(), reflectifyType, exceptionHandling); methodBuilder.addBody(String.format( String.format("register(methods, \"%s\", new %s());", methodName, methodInvokerClassName))); } typeBuilder.addMethod(methodBuilder.build()); }
From source file:com.cinchapi.concourse.importer.cli.ImportCli.java
/** * Given an alias (or fully qualified class name) attempt to load a "custom" * importer that is not already defined in the {@link #importers built-in} * collection./*from w w w .j av a2s . c om*/ * * @param alias a conventional alias (FileTypeImporter --> file-type) or a * fully qualified class name * @return the {@link Class} that corresponds to the custom importer * @throws ClassNotFoundException */ @SuppressWarnings("unchecked") private static Class<? extends Importer> getCustomImporterClass(String alias) throws ClassNotFoundException { try { return (Class<? extends Importer>) Class.forName(alias); } catch (ClassNotFoundException e) { // Attempt to determine the correct class name from the alias by // loading the server's classpath. For the record, this is hella // slow. Reflections.log = null; // turn off reflection logging Reflections reflections = new Reflections(); char firstChar = alias.charAt(0); for (Class<? extends Importer> clazz : reflections.getSubTypesOf(Importer.class)) { String name = clazz.getSimpleName(); if (name.length() == 0) { // Skip anonymous subclasses continue; } char nameFirstChar = name.charAt(0); if (!Modifier.isAbstract(clazz.getModifiers()) && (nameFirstChar == Character.toUpperCase(firstChar) || nameFirstChar == Character.toLowerCase(firstChar))) { String expected = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, clazz.getSimpleName()) .replaceAll("-importer", ""); if (alias.equals(expected)) { return clazz; } } } throw e; } }
From source file:com.attribyte.relay.wp.WPSupplier.java
@Override public void init(final Properties props, final Optional<ByteString> savedState, final Logger logger) throws Exception { if (isInit.compareAndSet(false, true)) { this.logger = logger; logger.info("Initializing WP supplier..."); final long siteId = Long.parseLong(props.getProperty("siteId", "0")); if (siteId < 1L) { throw new Exception("A 'siteId' must be specified"); }/* w ww . j av a 2s. co m*/ final Set<String> cachedTaxonomies = ImmutableSet.of(TAG_TAXONOMY, CATEGORY_TAXONOMY); final Duration taxonomyCacheTimeout = Duration.ofMinutes(30); //TODO: Configure final Duration userCacheTimeout = Duration.ofMinutes(30); //TODO: Configure initPools(props, logger); this.db = new DB(defaultConnectionPool, siteId, cachedTaxonomies, taxonomyCacheTimeout, userCacheTimeout); Properties siteProps = new InitUtil("site.", props, false).getProperties(); Site overrideSite = new Site(siteProps); this.site = this.db.selectSite().overrideWith(overrideSite); logger.info( String.format("Initialized site %d - %s", this.site.id, Strings.nullToEmpty(this.site.title))); if (savedState.isPresent()) { startMeta = PostMeta.fromBytes(savedState.get()); } else { startMeta = PostMeta.ZERO; } this.selectSleepMillis = Integer.parseInt(props.getProperty("selectSleepMillis", "30000")); this.selectAll = props.getProperty("selectAll", "false").equalsIgnoreCase("true"); if (this.selectAll) { this.stopId = this.db.selectMaxPostId(); } else { this.stopId = 0L; } String supplyIdsFileStr = props.getProperty("supplyIdsFile", ""); if (!supplyIdsFileStr.isEmpty()) { this.selectAll = true; File supplyIdsFile = new File(supplyIdsFileStr); logger.info(String.format("Using 'supplyIdsFile', '%s'", supplyIdsFile.getAbsolutePath())); this.supplyIds = Lists.newArrayListWithExpectedSize(1024); List<String> lines = Files.readLines(supplyIdsFile, Charsets.UTF_8); for (String line : lines) { line = line.trim(); if (line.isEmpty() || line.startsWith("#")) { continue; } Long id = Longs.tryParse(line); if (id != null) { this.supplyIds.add(id); logger.info(String.format("Adding supplied id, '%d'", id)); } } } else { this.supplyIds = null; } this.maxSelected = Integer.parseInt(props.getProperty("maxSelected", "500")); String allowedStatusStr = props.getProperty("allowedStatus", "").trim(); if (!allowedStatusStr.isEmpty()) { if (allowedStatusStr.equalsIgnoreCase("all")) { this.allowedStatus = ALL_STATUS; } else { this.allowedStatus = ImmutableSet .copyOf(Splitter.on(',').omitEmptyStrings().splitToList(allowedStatusStr).stream() .map(Post.Status::fromString).collect(Collectors.toSet())); } } else { this.allowedStatus = DEFAULT_ALLOWED_STATUS; } String allowedTypesStr = props.getProperty("allowedTypes", "").trim(); if (!allowedStatusStr.isEmpty()) { this.allowedTypes = ImmutableSet .copyOf(Splitter.on(',').omitEmptyStrings().splitToList(allowedTypesStr)).stream() .map(Post.Type::fromString).collect(Collectors.toSet()); } else { this.allowedTypes = DEFAULT_ALLOWED_TYPES; } String allowedPostMetaStr = props.getProperty("allowedPostMeta", "").trim(); if (!allowedPostMetaStr.isEmpty()) { this.allowedPostMeta = ImmutableSet .copyOf(Splitter.on(',').omitEmptyStrings().splitToList(allowedPostMetaStr)); } else { this.allowedPostMeta = ImmutableSet.of(); } String allowedImageMetaStr = props.getProperty("allowedImageMeta", "").trim(); if (!allowedImageMetaStr.isEmpty()) { this.allowedImageMeta = ImmutableSet .copyOf(Splitter.on(',').omitEmptyStrings().splitToList(allowedImageMetaStr)); } else { this.allowedImageMeta = ImmutableSet.of(); } String allowedUserMetaStr = props.getProperty("allowedUserMeta", "").trim(); if (!allowedUserMetaStr.isEmpty()) { this.allowedUserMeta = ImmutableSet .copyOf(Splitter.on(',').omitEmptyStrings().splitToList(allowedUserMetaStr)); } else { this.allowedUserMeta = ImmutableSet.of(); } String metaNameCaseFormat = props.getProperty("metaNameCaseFormat", "").trim().toLowerCase(); switch (metaNameCaseFormat) { case "lower_camel": this.metaNameCaseFormat = CaseFormat.LOWER_CAMEL; break; case "lower_hyphen": this.metaNameCaseFormat = CaseFormat.LOWER_HYPHEN; break; case "upper_camel": this.metaNameCaseFormat = CaseFormat.UPPER_CAMEL; break; case "upper_underscore": this.metaNameCaseFormat = CaseFormat.UPPER_UNDERSCORE; break; default: this.metaNameCaseFormat = null; } this.excerptOutputField = props.getProperty("excerptOutputField", "summary").toLowerCase().trim(); this.stopOnLostMessage = props.getProperty("stopOnLostMessage", "false").equalsIgnoreCase("true"); this.logReplicationMessage = props.getProperty("logReplicationMessage", "false") .equalsIgnoreCase("true"); this.originId = props.getProperty("originId", ""); Properties dusterProps = new InitUtil("duster.", props, false).getProperties(); if (dusterProps.size() > 0) { this.httpClient = new JettyClient(); this.httpClient.init("http.", props, logger); this.dusterClient = new DusterClient(dusterProps, httpClient, logger); logger.info("Duster is enabled..."); } else { logger.info("Duster is disabled..."); } if (!props.getProperty("contentTransformer", "").trim().isEmpty()) { this.contentTransformer = (ContentTransformer) (Class .forName(props.getProperty("contentTransformer")).newInstance()); this.contentTransformer.init(props); } else if (props.getProperty("cleanShortcodes", "true").equalsIgnoreCase("true")) { this.contentTransformer = new ShortcodeCleaner(); } if (!props.getProperty("postTransformer", "").trim().isEmpty()) { this.postTransformer = (PostTransformer) (Class.forName(props.getProperty("postTransformer")) .newInstance()); this.postTransformer.init(props); } else { this.postTransformer = null; } if (!props.getProperty("postFilter", "").trim().isEmpty()) { this.postFilter = (PostFilter) (Class.forName(props.getProperty("postFilter")).newInstance()); this.postFilter.init(props); } else { this.postFilter = null; } String dbDir = props.getProperty("metadb.dir", "").trim(); if (dbDir.isEmpty()) { this.metaDB = null; } else { logger.info(String.format("Initializing meta db, '%s'...", dbDir)); File metaDir = new File(dbDir); if (!metaDir.exists()) { throw new Exception(String.format("The 'metadb.dir' must exist ('%s')", dbDir)); } this.metaDB = new PostMetaDB(metaDir); } Long modifiedOffsetHours = Longs.tryParse(props.getProperty("modifiedOffsetHours", "0")); this.modifiedOffsetMillis = modifiedOffsetHours != null ? modifiedOffsetHours * 3600 * 1000L : 0L; if (this.modifiedOffsetMillis != 0L) { logger.info(String.format("Set modified select offset to %d millis", this.modifiedOffsetMillis)); } this.replicateScheduledState = props.getProperty("replicateScheduledState", "true") .equalsIgnoreCase("true"); this.replicatePendingState = props.getProperty("replicatePendingState", "false") .equalsIgnoreCase("true"); logger.info("Initialized WP supplier..."); } }
From source file:org.openehr.adl.am.AmObjectFactory.java
public static Class<? extends RmObject> getRmClass(@Nonnull String rmTypeName) throws ClassNotFoundException { int genericsTypeIndex = rmTypeName.indexOf('<'); String name = genericsTypeIndex == -1 ? rmTypeName : rmTypeName.substring(0, genericsTypeIndex); String className = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name); //noinspection unchecked return (Class<RmObject>) Class.forName(RM_PACKAGE_NAME + '.' + className); }
From source file:com.jwebmp.core.htmlbuilder.javascript.JavaScriptPart.java
/** * Renders the fields (getDeclaredFields()) as a map of html attributes * * @return/*from w ww . j ava2s.c o m*/ */ public Map<String, String> toAttributes() { Map<String, String> map = new LinkedHashMap<>(); Field[] fields = getClass().getDeclaredFields(); for (Field field : fields) { if (Modifier.isFinal(field.getModifiers()) || Modifier.isStatic(field.getModifiers())) { continue; } field.setAccessible(true); try { Object result = field.get(this); if (result != null) { if (JavaScriptPart.class.isAssignableFrom(result.getClass())) { map.put(CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, field.getName()), ((JavaScriptPart) result).toString(true)); } else { map.put(CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, field.getName()), result.toString()); } } } catch (Exception e) { JavaScriptPart.log.log(Level.WARNING, "Cant format as attributes", e); } } return map; }
From source file:dagger.internal.codegen.MembersInjectorGenerator.java
private static String injectionSiteDelegateMethodName(Element injectionSiteElement) { return "inject" + CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, injectionSiteElement.getSimpleName().toString()); }