/** * The name of the class that holds a sample for an API method, constructed from {@code parts}. */ public String getApiSampleClassName(String... parts) { return publicClassName(Name.anyLower(parts)); }
private static Name getChildSuggestedName( Name parentName, InitCodeLineType parentType, InitCodeNode child) { switch (parentType) { case StructureInitLine: return Name.anyLower(child.key); case MapInitLine: return parentName.join("item"); case ListInitLine: return parentName.join("element"); default: throw new IllegalArgumentException("Cannot generate child name for " + parentType); } }
/** The function name to format the entity for the given collection. */ public String getFormatFunctionName( InterfaceConfig interfaceConfig, SingleResourceNameConfig resourceNameConfig) { return staticFunctionName(Name.anyLower("format", resourceNameConfig.getEntityName(), "name")); }
private RestPlaceholderConfigView generateRestPlaceholderConfigView( SurfaceNamer namer, String var) { RestPlaceholderConfigView.Builder placeholderView = RestPlaceholderConfigView.newBuilder(); ImmutableList.Builder<String> getters = ImmutableList.builder(); for (String getter : var.split("\\.")) { getters.add( namer.getFieldGetFunctionName( Name.anyLower(getter), SurfaceNamer.MapType.NOT_MAP, SurfaceNamer.Cardinality.NOT_REPEATED)); } placeholderView.name(var); placeholderView.getters(getters.build()); return placeholderView.build(); }
private Name identifierFromSampleArgumentName(InitCodeContext context, String argName) { Name name = Name.anyLower(argName); Preconditions.checkArgument( !context.symbolTable().contains(name), "sample_argument_name \"%s\" is already in use.", name); return context.symbolTable().getNewSymbol(name); }
public PhpPackageMetadataNamer(String packageName, String domainLayerLocation) { String basePackageName = PhpPackageUtil.getBasePackageName(packageName); String[] packagePieces = PhpPackageUtil.splitPackageName(basePackageName); this.serviceName = Name.upperCamel(packagePieces); // To build metadata identifier, update pieces to be lowercase, so each piece is treated as a // single piece in the Name object for (int i = 0; i < packagePieces.length; i++) { packagePieces[i] = packagePieces[i].toLowerCase(); } Name composerVendor; Name composerPackage; // The metadataIdentifier for composer is formatted as "vendor/package". If a // domainLayerLocation is provided, set that as the vendor. Otherwise, take the first piece of // packagePieces to use as the vendor. if (domainLayerLocation != null && !domainLayerLocation.isEmpty()) { composerVendor = Name.anyCamel(domainLayerLocation); composerPackage = Name.anyLower(packagePieces); } else if (packagePieces.length == 1) { composerVendor = Name.anyLower(packagePieces[0]); composerPackage = composerVendor; } else { composerVendor = Name.anyLower(packagePieces[0]); composerPackage = Name.from(); for (int i = 1; i < packagePieces.length; i++) { composerPackage = composerPackage.join(Name.anyLower(packagePieces[i])); } } metadataIdenfifier = composerVendor.toSeparatedString("-") + "/" + composerPackage.toSeparatedString("-"); }
protected Name getResourceTypeNameObject(ResourceNameConfig resourceNameConfig) { String entityName = resourceNameConfig.getEntityName(); ResourceNameType resourceNameType = resourceNameConfig.getResourceNameType(); // Proto annotations use UpperCamelCase for resource names, // and GAPIC config uses lower_snake_case, so we have to support both formats. Function<String, Name> formatNameFunc; if (entityName.length() > 0 && Character.isUpperCase(entityName.charAt(0))) { formatNameFunc = Name::upperCamel; } else { formatNameFunc = Name::anyLower; } switch (resourceNameType) { case ANY: return getAnyResourceTypeName(); case FIXED: return Name.anyLower(entityName).join("name_fixed"); case ONEOF: // Remove suffix "_oneof". This allows the collection oneof config to "share" an entity name // with a collection config. entityName = StringUtil.removeSuffix(entityName, "_oneof"); return formatNameFunc.apply(entityName).join("name_oneof"); case SINGLE: return formatNameFunc.apply(entityName).join("name"); case NONE: default: throw new UnsupportedOperationException("unexpected entity name type"); } }
/** Apply {@code sampleParamConfig} to this node. */ private void resolveSampleParamConfig( InitCodeContext context, SampleParameterConfig sampleParamConfig) { if (sampleParamConfig.readFromFile()) { setupReadFileNode(context, sampleParamConfig); } else if (sampleParamConfig.isSampleArgument()) { Name argName = Name.anyLower(sampleParamConfig.sampleArgumentName()); if (!argName.equals(identifier)) { identifier = identifierFromSampleArgumentName(context, sampleParamConfig.sampleArgumentName()); } } }
identifierFromSampleArgumentName(context, sampleParamConfig.sampleArgumentName()); } else { childIdentifier = context.symbolTable().getNewSymbol(Name.anyLower(LOCAL_DEFAULT_FILENAME));
} else { fieldSetting.fieldSetFunction( namer.getFieldSetFunctionName(item.getType(), Name.anyLower(item.getVarName()))); namer.getFieldAddFunctionName(item.getType(), Name.anyLower(item.getVarName()))); fieldSetting.fieldGetFunction( namer.getFieldGetFunctionName(item.getType(), Name.anyLower(item.getVarName()))); fieldSetting.fieldName(context.getNamer().publicFieldName(Name.anyLower(item.getVarName())));
break; case Variable: value = namer.localVarReference(Name.anyLower(value)); break; default:
break; case Variable: value = context.getNamer().localVarReference(Name.anyLower(value)); break; default: