generate_objc_internal_header.py [plain text]
import logging
import string
from string import Template
from generator import Generator, ucfirst
from objc_generator import ObjCGenerator
from objc_generator_templates import ObjCGeneratorTemplates as ObjCTemplates
log = logging.getLogger('global')
class ObjCInternalHeaderGenerator(ObjCGenerator):
def __init__(self, *args, **kwargs):
ObjCGenerator.__init__(self, *args, **kwargs)
def output_filename(self):
return '%sInternal.h' % self.protocol_name()
def generate_output(self):
headers = set([
'"%s.h"' % self.protocol_name(),
'"%sJSONObjectPrivate.h"' % self.protocol_name(),
'<JavaScriptCore/InspectorValues.h>',
'<JavaScriptCore/AugmentableInspectorController.h>',
])
header_args = {
'includes': '\n'.join(['#import ' + header for header in sorted(headers)]),
}
event_domains = filter(self.should_generate_events_for_domain, self.domains_to_generate())
sections = []
sections.append(self.generate_license())
sections.append(Template(ObjCTemplates.GenericHeaderPrelude).substitute(None, **header_args))
sections.append('\n\n'.join(filter(None, map(self._generate_event_dispatcher_private_interfaces, event_domains))))
sections.append(Template(ObjCTemplates.GenericHeaderPostlude).substitute(None, **header_args))
return '\n\n'.join(sections)
def _generate_event_dispatcher_private_interfaces(self, domain):
lines = []
if len(self.events_for_domain(domain)):
objc_name = '%s%sDomainEventDispatcher' % (self.objc_prefix(), domain.domain_name)
lines.append('@interface %s (Private)' % objc_name)
lines.append('- (instancetype)initWithController:(Inspector::AugmentableInspectorController*)controller;')
lines.append('@end')
return '\n'.join(lines)