use of com.google.api.codegen.metacode.InitCodeNode in project toolkit by googleapis.
the class InitCodeTransformer method getInitCodeNodes.
public List<InitCodeNode> getInitCodeNodes(MethodContext methodContext, InitCodeContext initCodeContext) {
InitCodeNode root = InitCodeNode.createTree(initCodeContext);
List<InitCodeNode> orderedItems = root.listInInitializationOrder();
if (initCodeContext.outputType() == InitCodeOutputType.FieldList) {
// Remove the request object for flattened method
orderedItems.remove(orderedItems.size() - 1);
}
return orderedItems;
}
use of com.google.api.codegen.metacode.InitCodeNode in project toolkit by googleapis.
the class InitCodeTransformer method generateRequestAssertViews.
/**
* Generates assert views for the test of the tested method and its fields.
*/
List<ClientTestAssertView> generateRequestAssertViews(MethodContext methodContext, InitCodeContext initContext) {
InitCodeNode rootNode = InitCodeNode.createTree(initContext.cloneWithEmptySymbolTable());
List<ClientTestAssertView> assertViews = new ArrayList<>();
SurfaceNamer namer = methodContext.getNamer();
// Add request fields checking
for (InitCodeNode fieldItemTree : rootNode.getChildren().values()) {
FieldConfig fieldConfig = fieldItemTree.getFieldConfig();
String getterMethod = namer.getFieldGetFunctionName(methodContext.getFeatureConfig(), fieldConfig);
String expectedValueIdentifier = getVariableName(methodContext, fieldItemTree);
String expectedTransformFunction = null;
String actualTransformFunction = null;
if (methodContext.getFeatureConfig().useResourceNameFormatOption(fieldConfig)) {
if (fieldConfig.requiresParamTransformationFromAny()) {
expectedTransformFunction = namer.getToStringMethod();
actualTransformFunction = namer.getToStringMethod();
} else if (fieldConfig.requiresParamTransformation()) {
if (methodContext.getFeatureConfig().useResourceNameConverters(fieldConfig)) {
expectedTransformFunction = namer.getToStringMethod();
} else {
expectedTransformFunction = namer.getResourceOneofCreateMethod(methodContext.getTypeTable(), fieldConfig);
}
} else if (methodContext.getFeatureConfig().useResourceNameConverters(fieldConfig)) {
if (fieldConfig.getField().isRepeated()) {
actualTransformFunction = namer.getResourceTypeParseListMethodName(methodContext.getTypeTable(), fieldConfig);
} else if (fieldConfig.getResourceNameConfig().getResourceNameType() == ResourceNameType.ONEOF) {
actualTransformFunction = namer.getResourceTypeParentParseMethod(methodContext, fieldConfig);
} else {
actualTransformFunction = namer.getResourceTypeParseMethodName(methodContext.getTypeTable(), fieldConfig);
}
}
}
boolean isMap = fieldConfig.getField().isMap();
boolean isArray = fieldConfig.getField().isRepeated() && !isMap;
boolean isFloatingPointNumber = fieldConfig.getField().getType().isFloatType() || fieldConfig.getField().getType().isDoubleType();
TypeModel fieldType = fieldItemTree.getType();
String messageTypeName = null;
if (fieldType.isMessage()) {
messageTypeName = methodContext.getTypeTable().getFullNameForMessageType(fieldType);
}
assertViews.add(createAssertView(expectedValueIdentifier, expectedTransformFunction, actualTransformFunction, isMap, isArray, isFloatingPointNumber, getterMethod, messageTypeName));
}
return assertViews;
}
Aggregations