Search in sources :

Example 11 with InitCodeNode

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;
}
Also used : InitCodeNode(com.google.api.codegen.metacode.InitCodeNode)

Example 12 with InitCodeNode

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;
}
Also used : ClientTestAssertView(com.google.api.codegen.viewmodel.testing.ClientTestAssertView) InitCodeNode(com.google.api.codegen.metacode.InitCodeNode) FieldConfig(com.google.api.codegen.config.FieldConfig) ArrayList(java.util.ArrayList) TypeModel(com.google.api.codegen.config.TypeModel)

Aggregations

InitCodeNode (com.google.api.codegen.metacode.InitCodeNode)12 ArrayList (java.util.ArrayList)7 FieldConfig (com.google.api.codegen.config.FieldConfig)4 InitCodeLineView (com.google.api.codegen.viewmodel.InitCodeLineView)3 ListInitCodeLineView (com.google.api.codegen.viewmodel.ListInitCodeLineView)3 MapInitCodeLineView (com.google.api.codegen.viewmodel.MapInitCodeLineView)3 ReadFileInitCodeLineView (com.google.api.codegen.viewmodel.ReadFileInitCodeLineView)3 SimpleInitCodeLineView (com.google.api.codegen.viewmodel.SimpleInitCodeLineView)3 StructureInitCodeLineView (com.google.api.codegen.viewmodel.StructureInitCodeLineView)3 TypeModel (com.google.api.codegen.config.TypeModel)2 Scanner (com.google.api.codegen.util.Scanner)2 FieldSettingView (com.google.api.codegen.viewmodel.FieldSettingView)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ArrayDeque (java.util.ArrayDeque)2 HashMap (java.util.HashMap)2 BatchingConfig (com.google.api.codegen.config.BatchingConfig)1 FieldModel (com.google.api.codegen.config.FieldModel)1 GrpcStreamingConfig (com.google.api.codegen.config.GrpcStreamingConfig)1 InterfaceModel (com.google.api.codegen.config.InterfaceModel)1 MethodContext (com.google.api.codegen.config.MethodContext)1