本文整理汇总了Python中objc_generator.ObjCGenerator类的典型用法代码示例。如果您正苦于以下问题:Python ObjCGenerator类的具体用法?Python ObjCGenerator怎么用?Python ObjCGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ObjCGenerator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _generate_init_method_for_required_members
def _generate_init_method_for_required_members(self, domain, declaration, required_members):
pairs = []
for member in required_members:
objc_type = self.objc_type_for_member(declaration, member)
var_name = ObjCGenerator.identifier_to_objc_identifier(member.member_name)
pairs.append('%s:(%s)%s' % (var_name, objc_type, var_name))
pairs[0] = ucfirst(pairs[0])
lines = []
lines.append('- (instancetype)initWith%s' % ' '.join(pairs))
lines.append('{')
lines.append(' if (!(self = [super init]))')
lines.append(' return nil;')
lines.append('')
required_pointer_members = filter(lambda member: ObjCGenerator.is_type_objc_pointer_type(member.type), required_members)
if required_pointer_members:
for member in required_pointer_members:
var_name = ObjCGenerator.identifier_to_objc_identifier(member.member_name)
lines.append(' THROW_EXCEPTION_FOR_REQUIRED_PROPERTY(%s, @"%s");' % (var_name, var_name))
objc_array_class = self.objc_class_for_array_type(member.type)
if objc_array_class and objc_array_class.startswith(self.objc_prefix()):
lines.append(' THROW_EXCEPTION_FOR_BAD_TYPE_IN_ARRAY(%s, [%s class]);' % (var_name, objc_array_class))
lines.append('')
for member in required_members:
var_name = ObjCGenerator.identifier_to_objc_identifier(member.member_name)
lines.append(' self.%s = %s;' % (var_name, var_name))
lines.append('')
lines.append(' return self;')
lines.append('}')
return '\n'.join(lines)
示例2: generate_output
def generate_output(self):
headers = set([
'<WebInspector/RWIProtocolJSONObject.h>',
])
header_args = {
'includes': '\n'.join(['#import ' + header for header in sorted(headers)]),
}
domains = self.domains_to_generate()
type_domains = filter(ObjCGenerator.should_generate_domain_types_filter(self.model()), domains)
command_domains = filter(ObjCGenerator.should_generate_domain_command_handler_filter(self.model()), domains)
event_domains = filter(ObjCGenerator.should_generate_domain_event_dispatcher_filter(self.model()), domains)
# FIXME: <https://webkit.org/b/138222> Web Inspector: Reduce unnecessary enums/types generated in ObjC Protocol Interfaces
# Currently we generate enums/types for all types in the type_domains. For the built-in
# JSC domains (Debugger, Runtime) this produces extra unused types. We only need to
# generate these types if they are referenced by the command_domains or event_domains.
sections = []
sections.append(self.generate_license())
sections.append(Template(ObjCTemplates.HeaderPrelude).substitute(None, **header_args))
sections.append('\n'.join(filter(None, map(self._generate_forward_declarations, type_domains))))
sections.append('\n'.join(filter(None, map(self._generate_enums, type_domains))))
sections.append('\n'.join(filter(None, map(self._generate_types, type_domains))))
sections.append('\n\n'.join(filter(None, map(self._generate_command_protocols, command_domains))))
sections.append('\n\n'.join(filter(None, map(self._generate_event_interfaces, event_domains))))
sections.append(Template(ObjCTemplates.HeaderPostlude).substitute(None))
return '\n\n'.join(sections)
示例3: _generate_event
def _generate_event(self, domain, event):
lines = []
lines.append(self._generate_event_signature(domain, event))
lines.append('{')
lines.append(' const FrontendRouter& router = _controller->frontendRouter();')
lines.append('')
required_pointer_parameters = filter(lambda parameter: not parameter.is_optional and ObjCGenerator.is_type_objc_pointer_type(parameter.type), event.event_parameters)
for parameter in required_pointer_parameters:
var_name = ObjCGenerator.identifier_to_objc_identifier(parameter.parameter_name)
lines.append(' THROW_EXCEPTION_FOR_REQUIRED_PARAMETER(%s, @"%s");' % (var_name, var_name))
objc_array_class = self.objc_class_for_array_type(parameter.type)
if objc_array_class and objc_array_class.startswith(self.objc_prefix()):
lines.append(' THROW_EXCEPTION_FOR_BAD_TYPE_IN_ARRAY(%s, [%s class]);' % (var_name, objc_array_class))
optional_pointer_parameters = filter(lambda parameter: parameter.is_optional and ObjCGenerator.is_type_objc_pointer_type(parameter.type), event.event_parameters)
for parameter in optional_pointer_parameters:
var_name = ObjCGenerator.identifier_to_objc_identifier(parameter.parameter_name)
lines.append(' THROW_EXCEPTION_FOR_BAD_OPTIONAL_PARAMETER(%s, @"%s");' % (var_name, var_name))
objc_array_class = self.objc_class_for_array_type(parameter.type)
if objc_array_class and objc_array_class.startswith(self.objc_prefix()):
lines.append(' THROW_EXCEPTION_FOR_BAD_TYPE_IN_OPTIONAL_ARRAY(%s, [%s class]);' % (var_name, objc_array_class))
if required_pointer_parameters or optional_pointer_parameters:
lines.append('')
lines.append(' Ref<InspectorObject> jsonMessage = InspectorObject::create();')
lines.append(' jsonMessage->setString(ASCIILiteral("method"), ASCIILiteral("%s.%s"));' % (domain.domain_name, event.event_name))
if event.event_parameters:
lines.extend(self._generate_event_out_parameters(domain, event))
lines.append(' router.sendEvent(jsonMessage->toJSONString());')
lines.append('}')
return '\n'.join(lines)
开发者ID:Comcast,项目名称:WebKitForWayland,代码行数:33,代码来源:generate_objc_frontend_dispatcher_implementation.py
示例4: _generate_conversions_for_command
def _generate_conversions_for_command(self, domain, command):
lines = []
if command.call_parameters:
lines.append('')
def in_param_expression(param_name, parameter):
_type = parameter.type
if isinstance(_type, AliasedType):
_type = _type.aliased_type # Fall through to enum or primitive.
if isinstance(_type, EnumType):
_type = _type.primitive_type # Fall through to primitive.
if isinstance(_type, PrimitiveType):
return '*%s' % param_name if parameter.is_optional else param_name
return '%s.copyRef()' % param_name
for parameter in command.call_parameters:
in_param_name = 'in_%s' % parameter.parameter_name
objc_in_param_name = 'o_%s' % in_param_name
objc_type = ObjCGenerator.objc_type_for_param(domain, command.command_name, parameter, False)
param_expression = in_param_expression(in_param_name, parameter)
import_expression = ObjCGenerator.objc_protocol_import_expression_for_parameter(param_expression, domain, command.command_name, parameter)
if not parameter.is_optional:
lines.append(' %s = %s;' % (join_type_and_name(objc_type, objc_in_param_name), import_expression))
else:
lines.append(' %s;' % join_type_and_name(objc_type, objc_in_param_name))
lines.append(' if (%s)' % in_param_name)
lines.append(' %s = %s;' % (objc_in_param_name, import_expression))
if lines:
lines.append('')
return '\n'.join(lines)
示例5: _generate_event
def _generate_event(self, domain, event):
lines = []
lines.append(self._generate_event_signature(domain, event))
lines.append('{')
lines.append(' InspectorFrontendChannel* frontendChannel = _controller->frontendChannel();')
lines.append(' if (!frontendChannel)')
lines.append(' return;')
lines.append('')
required_pointer_parameters = filter(lambda parameter: not parameter.is_optional and ObjCGenerator.is_type_objc_pointer_type(parameter.type), event.event_parameters)
for parameter in required_pointer_parameters:
var_name = ObjCGenerator.identifier_to_objc_identifier(parameter.parameter_name)
lines.append(' THROW_EXCEPTION_FOR_REQUIRED_PARAMETER(%s, @"%s");' % (var_name, var_name))
optional_pointer_parameters = filter(lambda parameter: parameter.is_optional and ObjCGenerator.is_type_objc_pointer_type(parameter.type), event.event_parameters)
for parameter in optional_pointer_parameters:
var_name = ObjCGenerator.identifier_to_objc_identifier(parameter.parameter_name)
lines.append(' THROW_EXCEPTION_FOR_BAD_OPTIONAL_PARAMETER(%s, @"%s");' % (var_name, var_name))
if required_pointer_parameters or optional_pointer_parameters:
lines.append('')
lines.append(' RefPtr<InspectorObject> jsonMessage = InspectorObject::create();')
lines.append(' jsonMessage->setString(ASCIILiteral("method"), ASCIILiteral("%s.%s"));' % (domain.domain_name, event.event_name))
if event.event_parameters:
lines.extend(self._generate_event_out_parameters(domain, event))
lines.append(' frontendChannel->sendMessageToFrontend(jsonMessage->toJSONString());')
lines.append('}')
return '\n'.join(lines)
示例6: generate_output
def generate_output(self):
secondary_headers = [
'"%sInternal.h"' % ObjCGenerator.OBJC_PREFIX,
'"%sBackendDispatchers.h"' % ObjCGenerator.OBJC_PREFIX,
"<JavaScriptCore/AlternateDispatchableAgent.h>",
"<JavaScriptCore/AugmentableInspectorController.h>",
"<JavaScriptCore/InspectorAlternateBackendDispatchers.h>",
"<JavaScriptCore/InspectorBackendDispatchers.h>",
]
header_args = {
"primaryInclude": '"%sConfiguration.h"' % ObjCGenerator.OBJC_PREFIX,
"secondaryIncludes": "\n".join(["#import %s" % header for header in secondary_headers]),
}
self._command_filter = ObjCGenerator.should_generate_domain_command_handler_filter(self.model())
self._event_filter = ObjCGenerator.should_generate_domain_event_dispatcher_filter(self.model())
domains = self.domains_to_generate()
sections = []
sections.append(self.generate_license())
sections.append(Template(ObjCTemplates.ImplementationPrelude).substitute(None, **header_args))
sections.append(self._generate_configuration_implementation_for_domains(domains))
sections.append(Template(ObjCTemplates.ImplementationPostlude).substitute(None, **header_args))
return "\n\n".join(sections)
示例7: _generate_conversions_for_command
def _generate_conversions_for_command(self, domain, command):
lines = []
if command.call_parameters:
lines.append("")
def in_param_expression(param_name, parameter):
_type = parameter.type
if isinstance(_type, AliasedType):
_type = _type.aliased_type # Fall through to enum or primitive.
if isinstance(_type, EnumType):
_type = _type.primitive_type # Fall through to primitive.
if isinstance(_type, PrimitiveType):
if _type.raw_name() in ["array", "any", "object"]:
return "&%s" % param_name if not parameter.is_optional else param_name
return "*%s" % param_name if parameter.is_optional else param_name
return "&%s" % param_name if not parameter.is_optional else param_name
for parameter in command.call_parameters:
in_param_name = "in_%s" % parameter.parameter_name
objc_in_param_name = "o_%s" % in_param_name
objc_type = ObjCGenerator.objc_type_for_param(domain, command.command_name, parameter, False)
param_expression = in_param_expression(in_param_name, parameter)
import_expression = ObjCGenerator.objc_protocol_import_expression_for_parameter(
param_expression, domain, command.command_name, parameter
)
if not parameter.is_optional:
lines.append(" %s = %s;" % (join_type_and_name(objc_type, objc_in_param_name), import_expression))
else:
lines.append(" %s;" % join_type_and_name(objc_type, objc_in_param_name))
lines.append(" if (%s)" % in_param_name)
lines.append(" %s = %s;" % (objc_in_param_name, import_expression))
if lines:
lines.append("")
return "\n".join(lines)
示例8: _generate_init_method_for_required_members
def _generate_init_method_for_required_members(self, domain, declaration, required_members):
pairs = []
for member in required_members:
objc_type = ObjCGenerator.objc_type_for_member(declaration, member)
var_name = ObjCGenerator.identifier_to_objc_identifier(member.member_name)
pairs.append('%s:(%s)%s' % (var_name, objc_type, var_name))
pairs[0] = ucfirst(pairs[0])
return '- (instancetype)initWith%s;' % ' '.join(pairs)
示例9: _generate_setter_for_member
def _generate_setter_for_member(self, domain, declaration, member):
objc_type = ObjCGenerator.objc_type_for_member(declaration, member)
var_name = ObjCGenerator.identifier_to_objc_identifier(member.member_name)
setter_method = ObjCGenerator.objc_setter_method_for_member(declaration, member)
conversion_expression = ObjCGenerator.objc_to_protocol_expression_for_member(declaration, member, var_name)
lines = []
lines.append('- (void)set%s:(%s)%s' % (ucfirst(var_name), objc_type, var_name))
lines.append('{')
lines.append(' [super %s:%s forKey:@"%s"];' % (setter_method, conversion_expression, member.member_name))
lines.append('}')
return '\n'.join(lines)
示例10: _generate_dealloc
def _generate_dealloc(self, domains):
lines = []
lines.append('- (void)dealloc')
lines.append('{')
for domain in domains:
if domain.commands and self._command_filter(domain):
lines.append(' [_%sHandler release];' % ObjCGenerator.variable_name_prefix_for_domain(domain))
if domain.events and self._event_filter(domain):
lines.append(' [_%sEventDispatcher release];' % ObjCGenerator.variable_name_prefix_for_domain(domain))
lines.append(' [super dealloc];')
lines.append('}')
return lines
示例11: _generate_ivars
def _generate_ivars(self, domains):
lines = []
for domain in domains:
if self.should_generate_commands_for_domain(domain):
objc_class_name = '%s%sDomainHandler' % (self.objc_prefix(), domain.domain_name)
ivar_name = '_%sHandler' % ObjCGenerator.variable_name_prefix_for_domain(domain)
lines.append(' id<%s> %s;' % (objc_class_name, ivar_name))
if self.should_generate_events_for_domain(domain):
objc_class_name = '%s%sDomainEventDispatcher' % (self.objc_prefix(), domain.domain_name)
ivar_name = '_%sEventDispatcher' % ObjCGenerator.variable_name_prefix_for_domain(domain)
lines.append(' %s *%s;' % (objc_class_name, ivar_name))
return lines
示例12: _generate_getter_for_member
def _generate_getter_for_member(self, domain, declaration, member):
objc_type = self.objc_type_for_member(declaration, member)
var_name = ObjCGenerator.identifier_to_objc_identifier(member.member_name)
getter_method = ObjCGenerator.objc_getter_method_for_member(declaration, member)
basic_expression = '[super %s:@"%s"]' % (getter_method, member.member_name)
conversion_expression = self.protocol_to_objc_expression_for_member(declaration, member, basic_expression)
lines = []
lines.append('- (%s)%s' % (objc_type, var_name))
lines.append('{')
lines.append(' return %s;' % conversion_expression)
lines.append('}')
return '\n'.join(lines)
示例13: _generate_ivars
def _generate_ivars(self, domains):
lines = []
for domain in domains:
if domain.commands and self._command_filter(domain):
objc_class_name = "%s%sDomainHandler" % (ObjCGenerator.OBJC_PREFIX, domain.domain_name)
ivar_name = "_%sHandler" % ObjCGenerator.variable_name_prefix_for_domain(domain)
lines.append(" id<%s> %s;" % (objc_class_name, ivar_name))
if domain.events and self._event_filter(domain):
objc_class_name = "%s%sDomainEventDispatcher" % (ObjCGenerator.OBJC_PREFIX, domain.domain_name)
ivar_name = "_%sEventDispatcher" % ObjCGenerator.variable_name_prefix_for_domain(domain)
lines.append(" %s *%s;" % (objc_class_name, ivar_name))
return lines
示例14: _generate_setter_for_member
def _generate_setter_for_member(self, domain, declaration, member):
objc_type = self.objc_type_for_member(declaration, member)
var_name = ObjCGenerator.identifier_to_objc_identifier(member.member_name)
setter_method = ObjCGenerator.objc_setter_method_for_member(declaration, member)
conversion_expression = self.objc_to_protocol_expression_for_member(declaration, member, var_name)
lines = []
lines.append('- (void)set%s:(%s)%s' % (ucfirst(var_name), objc_type, var_name))
lines.append('{')
objc_array_class = self.objc_class_for_array_type(member.type)
if objc_array_class and objc_array_class.startswith(self.objc_prefix()):
lines.append(' THROW_EXCEPTION_FOR_BAD_TYPE_IN_ARRAY(%s, [%s class]);' % (var_name, objc_array_class))
lines.append(' [super %s:%s forKey:@"%s"];' % (setter_method, conversion_expression, member.member_name))
lines.append('}')
return '\n'.join(lines)
示例15: _generate_success_block_for_command
def _generate_success_block_for_command(self, domain, command):
lines = []
if command.return_parameters:
success_block_parameters = []
for parameter in command.return_parameters:
objc_type = self.objc_type_for_param(domain, command.command_name, parameter)
var_name = ObjCGenerator.identifier_to_objc_identifier(parameter.parameter_name)
success_block_parameters.append(join_type_and_name(objc_type, var_name))
lines.append(' id successCallback = ^(%s) {' % ', '.join(success_block_parameters))
else:
lines.append(' id successCallback = ^{')
if command.return_parameters:
lines.append(' Ref<JSON::Object> resultObject = JSON::Object::create();')
required_pointer_parameters = filter(lambda parameter: not parameter.is_optional and ObjCGenerator.is_type_objc_pointer_type(parameter.type), command.return_parameters)
for parameter in required_pointer_parameters:
var_name = ObjCGenerator.identifier_to_objc_identifier(parameter.parameter_name)
lines.append(' THROW_EXCEPTION_FOR_REQUIRED_PARAMETER(%s, @"%s");' % (var_name, var_name))
objc_array_class = self.objc_class_for_array_type(parameter.type)
if objc_array_class and objc_array_class.startswith(self.objc_prefix()):
lines.append(' THROW_EXCEPTION_FOR_BAD_TYPE_IN_ARRAY(%s, [%s class]);' % (var_name, objc_array_class))
optional_pointer_parameters = filter(lambda parameter: parameter.is_optional and ObjCGenerator.is_type_objc_pointer_type(parameter.type), command.return_parameters)
for parameter in optional_pointer_parameters:
var_name = ObjCGenerator.identifier_to_objc_identifier(parameter.parameter_name)
lines.append(' THROW_EXCEPTION_FOR_BAD_OPTIONAL_PARAMETER(%s, @"%s");' % (var_name, var_name))
objc_array_class = self.objc_class_for_array_type(parameter.type)
if objc_array_class and objc_array_class.startswith(self.objc_prefix()):
lines.append(' THROW_EXCEPTION_FOR_BAD_TYPE_IN_OPTIONAL_ARRAY(%s, [%s class]);' % (var_name, objc_array_class))
for parameter in command.return_parameters:
keyed_set_method = CppGenerator.cpp_setter_method_for_type(parameter.type)
var_name = ObjCGenerator.identifier_to_objc_identifier(parameter.parameter_name)
var_expression = '*%s' % var_name if parameter.is_optional else var_name
export_expression = self.objc_protocol_export_expression_for_variable(parameter.type, var_expression)
if not parameter.is_optional:
lines.append(' resultObject->%s(ASCIILiteral("%s"), %s);' % (keyed_set_method, parameter.parameter_name, export_expression))
else:
lines.append(' if (%s)' % var_name)
lines.append(' resultObject->%s(ASCIILiteral("%s"), %s);' % (keyed_set_method, parameter.parameter_name, export_expression))
lines.append(' backendDispatcher()->sendResponse(requestId, WTFMove(resultObject), false);')
else:
lines.append(' backendDispatcher()->sendResponse(requestId, JSON::Object::create(), false);')
lines.append(' };')
return '\n'.join(lines)