def Enum(self, parent_section, scope, obj):
        """Generates the code for an Enum definition.

    Args:
      parent_section: the main section of the parent scope.
      scope: the parent scope.
      obj: the Enum definition.
    """
        section = self.GetSectionFromAttributes(parent_section, obj)
        type_string = 'number'
        id_prefix = js_utils.GetFullyQualifiedScopePrefix(scope)
        self.Documentation(parent_section, obj, '\n@enum {%s}' % type_string)
        section.EmitCode('%s%s = {' % (id_prefix, obj.name))
        count = 0
        for ii in range(0, len(obj.values)):
            value = obj.values[ii]
            comma = ','
            if ii == len(obj.values) - 1:
                comma = ''
            if value.value is None:
                section.EmitCode('%s: %d%s' % (value.name, count, comma))
            else:
                section.EmitCode('%s: %s%s' % (value.name, value.value, comma))
                count = int(value.value)
            count += 1
        section.EmitCode('};')
    def Variable(self, parent_section, scope, obj):
        """Generates the code for a Variable definition.

    This function will generate the member/global variable declaration, as well
    as the setter/getter functions if specified in the attributes.

    Args:
      parent_section: the main section of the parent scope.
      scope: the parent scope.
      obj: the Variable definition.
    """
        member_section = self.GetSectionFromAttributes(parent_section, obj)

        bm = obj.type_defn.binding_model
        id_prefix = js_utils.GetFullyQualifiedScopePrefix(scope)
        proto = 'prototype.'
        # Note: There is no static in javascript
        field_name = naming.Normalize(obj.name, naming.Java)
        extra = ''
        if 'getter' in obj.attributes and 'setter' not in obj.attributes:
            extra = '\n\nThis property is read-only.'
        elif 'getter' not in obj.attributes and 'setter' in obj.attributes:
            extra = '\n\nThis property is write-only.'
        type_string = '\n@type {%s}' % js_utils.GetFullyQualifiedTypeName(
            obj.type_defn)
        self.Documentation(member_section, obj, extra + type_string)
        undef = ''
        if gflags.FLAGS['properties-equal-undefined'].value:
            undef = ' = undefined'
        member_section.EmitCode('%s%s%s%s;' %
                                (id_prefix, proto, field_name, undef))
    def Class(self, parent_section, scope, obj):
        """Generates the code for a Class definition.

    This function will recursively generate the code for all the definitions
    inside the class. These definitions will be output into one of 3 sections
    (private, protected, public), depending on their attributes. These
    individual sections will only be output if they are not empty.

    Args:
      parent_section: the main section of the parent scope.
      scope: the parent scope.
      obj: the Class definition.
    """
        section = self.GetSectionFromAttributes(parent_section,
                                                obj).CreateSection(obj.name)
        id_prefix = js_utils.GetFullyQualifiedScopePrefix(scope)
        if 'marshaled' in obj.attributes and not ('no_marshaled_docs'
                                                  in obj.attributes):
            found = False
            for member_defn in obj.defn_list:
                if member_defn.name == 'marshaled':
                    if isinstance(member_defn, syntax_tree.Variable):
                        type_name = js_utils.GetFullyQualifiedTypeName(
                            member_defn.type_defn)
                        self.Documentation(section, obj,
                                           '\n@type {%s}' % type_name)
                        section.EmitCode('%s%s = goog.typedef;' %
                                         (id_prefix, obj.name))
                        found = True
                        break
            if not found:
                log.SourceError(
                    obj.source,
                    ('no marshaled function found for %s' % obj.name))
        else:
            extends = ''
            if obj.base_type:
                base = js_utils.GetFullyQualifiedTypeName(obj.base_type)
                if base[0] == '!':
                    base = base[1:]
                extends = '\n@extends {%s}' % base
            self.Documentation(section, obj, '\n@constructor' + extends)
            section.EmitCode('%s%s = function() { };' % (id_prefix, obj.name))

        public_section = section.CreateSection('public:')
        protected_section = section.CreateSection('protected:')
        private_section = section.CreateSection('private:')
        self.DefinitionList(section, obj, obj.defn_list)
    def OverloadedFunction(self, parent_section, scope, func_array):
        """Generates the code for an Overloaded Function.

    Args:
      parent_section: the main section of the parent scope.
      scope: the parent scope.
      func_array: an array of function definition objects.
    """
        # merge the params.
        params = []
        min_params = len(func_array[0].params)
        for func in func_array:
            if len(func.params) < min_params:
                min_params = len(func.params)
            index = 0
            # we only take the comment from the first function that documents
            # a parameter at this position.
            comments, param_comments = js_utils.GetCommentsForParams(func)
            for param in func.params:
                if len(params) <= index:
                    params.append({
                        'orig_name': param.name,
                        'new_name': param.name,
                        'docs': param_comments[param.name],
                        'params': [{
                            'param': param,
                            'func': func
                        }]
                    })
                else:
                    params[index]['params'].append({
                        'param': param,
                        'func': func
                    })
                index += 1

        # rename the params.
        index = 0
        opt = ''
        for param in params:
            if index >= min_params:
                opt = 'opt_'
            param['new_name'] = '%sparam%d' % (opt, index + 1)
            index += 1

        # generate param comments.
        param_comments = []
        for param in params:
            if len(param['params']) == 1:
                param_string = js_utils.GetFunctionParamType(
                    param['params'][0]['func'],
                    param['params'][0]['param'].name)
            else:
                union_strings = set()
                for option in param['params']:
                    union_strings.add(
                        js_utils.GetFunctionParamType(option['func'],
                                                      option['param'].name))
                param_string = '|'.join(union_strings)
                if len(union_strings) > 1:
                    param_string = '(' + param_string + ')'
            param_comments += [
                '@param {%s} %s %s' %
                (param_string, param['new_name'], param['docs'])
            ]

        first_func = func_array[0]

        # use just the first function's comments.
        func_comments = (js_utils.GetCommentsForParams(first_func)[0] +
                         '\n'.join(param_comments))

        first_func.attributes['__docs'] = func_comments
        section = self.GetSectionFromAttributes(parent_section, first_func)
        self.Documentation(section, first_func, '')

        param_strings = []
        for param in params:
            param_strings += [param['new_name']]

        param_string = ', '.join(param_strings)
        id_prefix = js_utils.GetFullyQualifiedScopePrefix(scope)
        proto = 'prototype.'
        prototype = '%s%s%s = function(%s) { };' % (
            id_prefix, proto, naming.Normalize(first_func.name,
                                               naming.Java), param_string)
        section.EmitCode(prototype)