/** The name of the field. */ public String getFieldName(FieldModel field) { return publicFieldName(field.getNameAsParameterName()); }
/** * The name of a variable to hold a value for the given proto message field (such as a flattened * parameter). */ public String getVariableName(FieldModel field) { return localVarName(field.getNameAsParameterName()); }
/** The function name to get the given field. */ public String getFieldGetFunctionName(FieldModel field) { return getFieldGetFunctionName(field, field.getNameAsParameterName()); }
/** The key to use in a dictionary for the given field. */ public String getFieldKey(FieldModel field) { return keyName(field.getNameAsParameterName()); }
/** The function name to add an element to a map or repeated field. */ public String getFieldAddFunctionName(FieldModel field) { if (field.isMap()) { return publicMethodName(Name.from("put").join(field.getNameAsParameterName())); } else if (field.isRepeated()) { return publicMethodName(Name.from("add").join(field.getNameAsParameterName())); } else { return publicMethodName(Name.from("set").join(field.getNameAsParameterName())); } }
/** * The function name to get the count of elements in the given field. * * @throws IllegalArgumentException if the field is not a repeated field. */ public String getFieldCountGetFunctionName(FieldModel field) { if (field.isRepeated()) { return publicMethodName(Name.from("get").join(field.getNameAsParameterName()).join("count")); } else { throw new IllegalArgumentException( "Non-repeated field " + field.getSimpleName() + " has no count function."); } }
/** The function name to set the given field. */ public String getFieldSetFunctionName(FieldModel field) { return getFieldSetFunctionName( field.getNameAsParameterName(), MapType.ofMap(field.isMap()), Cardinality.ofRepeated(field.isRepeated())); }
/** The function name to set a field that is a resource name class. */ public String getResourceNameFieldSetFunctionName(FieldConfig fieldConfig) { FieldModel type = fieldConfig.getField(); Name identifier = fieldConfig.getField().getNameAsParameterName(); Name resourceName = getResourceTypeNameObject(fieldConfig.getResourceNameConfig()); if (type.isMap()) { return getNotImplementedString("SurfaceNamer.getResourceNameFieldSetFunctionName:map-type"); } else if (type.isRepeated()) { return publicMethodName( Name.from("add", "all").join(identifier).join("with").join(resourceName).join("list")); } else { return publicMethodName(Name.from("set").join(identifier).join("with").join(resourceName)); } }
/** The function name to get a field that is a resource name class. */ public String getResourceNameFieldGetFunctionName(FieldConfig fieldConfig) { FieldModel type = fieldConfig.getField(); Name identifier = fieldConfig.getField().getNameAsParameterName(); Name resourceName = getResourceTypeNameObject(fieldConfig.getResourceNameConfig()); if (type.isMap()) { return getNotImplementedString("SurfaceNamer.getResourceNameFieldGetFunctionName:map-type"); } else if (type.isRepeated()) { return publicMethodName( Name.from("get").join(identifier).join("list_as").join(resourceName).join("list")); } else { return publicMethodName(Name.from("get").join(identifier).join("as").join(resourceName)); } }