parameters: (self, ctxt, location, field_name, field_type)
return_statement: return None
docstring: Find the type or struct a field refers to or log an error.
docstring_summary: Find the type or struct a field refers to or log an error.
docstring_tokens: Find the type or struct a field refers to or log an error .
function: def resolve_field_type(self, ctxt, location, field_name, field_type):
          # type: (errors.ParserContext, common.SourceLocation, str, FieldType) -> Optional[Union[Enum, Struct, Type]]
          """Find the type or struct a field refers to or log an error."""
          # pylint: disable=too-many-return-statements,too-many-branches,too-many-locals
  
          if isinstance(field_type, FieldTypeVariant):
              variant = VariantType(field_type.file_name, field_type.line, field_type.column)
              variant.bson_serialization_type = []
              for alternative in field_type.variant:
                  alternative_type = self.resolve_field_type(ctxt, location, field_name, alternative)
                  if not alternative_type:
                      # There was an error.
                      return None
  
                  if isinstance(alternative_type, Enum):
                      ctxt.add_variant_enum_error(location, field_name, alternative_type.name)
                      return None
  
                  if isinstance(alternative_type, Struct):
                      if variant.variant_struct_type:
                          ctxt.add_variant_structs_error(location, field_name)
                          continue
  
                      variant.variant_struct_type = alternative_type
                      bson_serialization_type = ["object"]
                  else:
                      variant.variant_types.append(alternative_type)
                      if isinstance(alternative_type, ArrayType):
                          base_type = cast(Type, alternative_type.element_type)
                      else:
                          base_type = cast(Type, alternative_type)
  
                      bson_serialization_type = []
                      # If alternative_type is an array, element type could be Struct or Type.
                      if isinstance(base_type, Type):
                          bson_serialization_type = cast(Type, base_type).bson_serialization_type
  
                  variant.bson_serialization_type.extend(bson_serialization_type)
  
              return variant
  
          if isinstance(field_type, FieldTypeArray):
              element_type = self.resolve_field_type(ctxt, location, field_name,
                                                     field_type.element_type)
              if not element_type:
                  ctxt.add_unknown_type_error(location, field_name, field_type.element_type.type_name)
                  return None
  
              if isinstance(element_type, Enum):
                  ctxt.add_array_enum_error(location, field_name)
                  return None
  
              return ArrayType(element_type)
  
          assert isinstance(field_type, FieldTypeSingle)
          type_name = field_type.type_name
          if type_name.startswith('array<'):
              # The caller should've already stripped "array<...>" from type_name, this may be an
              # illegal nested array like "array<array<...>>".
              ctxt.add_bad_array_type_name_error(location, field_name, type_name)
              return None
  
          for command in self.commands:
              if command.name == type_name:
                  return command
  
          for idl_enum in self.enums:
              if idl_enum.name == type_name:
                  return idl_enum
  
          for struct in self.structs:
              if struct.name == type_name:
                  return struct
  
          for idltype in self.types:
              if idltype.name == type_name:
                  return idltype
  
          ctxt.add_unknown_type_error(location, field_name, type_name)
  
          return None
function_tokens: def resolve_field_type ( self , ctxt , location , field_name , field_type ) : # type: (errors.ParserContext, common.SourceLocation, str, FieldType) -> Optional[Union[Enum, Struct, Type]] # pylint: disable=too-many-return-statements,too-many-branches,too-many-locals if isinstance ( field_type , FieldTypeVariant ) : variant = VariantType ( field_type . file_name , field_type . line , field_type . column ) variant . bson_serialization_type = [ ] for alternative in field_type . variant : alternative_type = self . resolve_field_type ( ctxt , location , field_name , alternative ) if not alternative_type : # There was an error. return None if isinstance ( alternative_type , Enum ) : ctxt . add_variant_enum_error ( location , field_name , alternative_type . name ) return None if isinstance ( alternative_type , Struct ) : if variant . variant_struct_type : ctxt . add_variant_structs_error ( location , field_name ) continue variant . variant_struct_type = alternative_type bson_serialization_type = [ "object" ] else : variant . variant_types . append ( alternative_type ) if isinstance ( alternative_type , ArrayType ) : base_type = cast ( Type , alternative_type . element_type ) else : base_type = cast ( Type , alternative_type ) bson_serialization_type = [ ] # If alternative_type is an array, element type could be Struct or Type. if isinstance ( base_type , Type ) : bson_serialization_type = cast ( Type , base_type ) . bson_serialization_type variant . bson_serialization_type . extend ( bson_serialization_type ) return variant if isinstance ( field_type , FieldTypeArray ) : element_type = self . resolve_field_type ( ctxt , location , field_name , field_type . element_type ) if not element_type : ctxt . add_unknown_type_error ( location , field_name , field_type . element_type . type_name ) return None if isinstance ( element_type , Enum ) : ctxt . add_array_enum_error ( location , field_name ) return None return ArrayType ( element_type ) assert isinstance ( field_type , FieldTypeSingle ) type_name = field_type . type_name if type_name . startswith ( 'array<' ) : # The caller should've already stripped "array<...>" from type_name, this may be an # illegal nested array like "array<array<...>>". ctxt . add_bad_array_type_name_error ( location , field_name , type_name ) return None for command in self . commands : if command . name == type_name : return command for idl_enum in self . enums : if idl_enum . name == type_name : return idl_enum for struct in self . structs : if struct . name == type_name : return struct for idltype in self . types : if idltype . name == type_name : return idltype ctxt . add_unknown_type_error ( location , field_name , type_name ) return None