(self, element, import_manager=None)
return
Handles imports for the specified element.

    Args:
      element: (Property|Parameter) The property we want to set the import for.
      import_manager: The import manager to import into if not the implied one.
Handles imports for the specified element.
Handles imports for the specified element .
def _HandleImports(self, element, import_manager=None):
    """Handles imports for the specified element.

    Args:
      element: (Property|Parameter) The property we want to set the import for.
      import_manager: The import manager to import into if not the implied one.

    """
    # If this is a reference then resolve it so we can check the details.
    element = getattr(element, 'referenced_schema', element)

    # Get the parent of this Property/Parameter.
    if isinstance(element, data_types.ComplexDataType):
      parent = element
      data_type = element
    else:
      parent = element.schema
      data_type = element.data_type

    # If this is a reference then resolve it so we can check the details.
    data_type = getattr(data_type, 'referenced_schema', data_type)

    if not import_manager:
      if self._InnerModelClassesSupported():
        # If inner classes are supported find the top level parent to set
        # imports for.
        while parent.parent:
          parent = parent.parent
      import_manager = cpp_import_manager.CppImportManager.ForElement(parent)

    # For collections, we have to get the imports for the first non-collection
    # up the base_type chain.
    while isinstance(data_type, (data_types.ArrayDataType,
                                 data_types.MapDataType)):
      data_type = data_type._base_type  # pylint: disable=protected-access
      # TODO(user): This should be handled within the core.
      data_type = getattr(data_type, 'referenced_schema', data_type)

    # If we are a reference to a schema that does not resolve, do not fail.
    # Our kitchen sink test API does this. Well formed APIs should not.
    if not data_type:
      return

    json_type = data_type.json_type
    json_format = data_type.values.get('format')
    if json_type == 'object':
      if not data_type.parent:
        import_manager.AddDataType(data_type)
      return

    datatype_and_imports = (
        self.language_model.type_map.get((json_type, json_format)))
    if datatype_and_imports:
      import_definition = datatype_and_imports[1]
      # Import all required imports.
      for required_import in import_definition.imports:
        if required_import:
          import_manager.AddImport(required_import)
      # Set all template values, if specified.
      for template_value in import_definition.template_values:
        element.SetTemplateValue(template_value, True)
    elif data_type:
      if not data_type.parent:
        import_manager.AddDataType(data_type)
    return
def _HandleImports ( self , element , import_manager = None ) : # If this is a reference then resolve it so we can check the details. element = getattr ( element , 'referenced_schema' , element ) # Get the parent of this Property/Parameter. if isinstance ( element , data_types . ComplexDataType ) : parent = element data_type = element else : parent = element . schema data_type = element . data_type # If this is a reference then resolve it so we can check the details. data_type = getattr ( data_type , 'referenced_schema' , data_type ) if not import_manager : if self . _InnerModelClassesSupported ( ) : # If inner classes are supported find the top level parent to set # imports for. while parent . parent : parent = parent . parent import_manager = cpp_import_manager . CppImportManager . ForElement ( parent ) # For collections, we have to get the imports for the first non-collection # up the base_type chain. while isinstance ( data_type , ( data_types . ArrayDataType , data_types . MapDataType ) ) : data_type = data_type . _base_type # pylint: disable=protected-access # TODO(user): This should be handled within the core. data_type = getattr ( data_type , 'referenced_schema' , data_type ) # If we are a reference to a schema that does not resolve, do not fail. # Our kitchen sink test API does this. Well formed APIs should not. if not data_type : return json_type = data_type . json_type json_format = data_type . values . get ( 'format' ) if json_type == 'object' : if not data_type . parent : import_manager . AddDataType ( data_type ) return datatype_and_imports = ( self . language_model . type_map . get ( ( json_type , json_format ) ) ) if datatype_and_imports : import_definition = datatype_and_imports [ 1 ] # Import all required imports. for required_import in import_definition . imports : if required_import : import_manager . AddImport ( required_import ) # Set all template values, if specified. for template_value in import_definition . template_values : element . SetTemplateValue ( template_value , True ) elif data_type : if not data_type . parent : import_manager . AddDataType ( data_type ) return