mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Add support for named arguments to our bindings generation.
This doesn't yet support having both named and optional arguments, but once I have an example of that it should be trivial to add. I also cleaned up the generation a little so the generated dart file looks nicer. :) R=abarth@chromium.org BUG= Review URL: https://codereview.chromium.org/923093003
This commit is contained in:
parent
24b3a12e95
commit
9aba803749
@ -55,6 +55,7 @@ ImplementedAs=*
|
||||
InitializedByEventConstructor
|
||||
Iterable
|
||||
LegacyTreatAsPartialInterface
|
||||
Named
|
||||
NamedConstructor=*
|
||||
NoImplHeader
|
||||
NoInterfaceObject
|
||||
@ -70,9 +71,9 @@ ReflectInvalid=*
|
||||
ReflectMissing=*
|
||||
ReflectOnly=*
|
||||
Replaceable
|
||||
SetterCallWith=ExecutionContext|ScriptArguments|ActiveWindow|FirstWindow
|
||||
SetWrapperReferenceFrom=*
|
||||
SetWrapperReferenceTo=*
|
||||
SetterCallWith=ExecutionContext|ScriptArguments|ActiveWindow|FirstWindow
|
||||
SpecialWrapFor=*
|
||||
TreatNullAs=NullString|EmptyString
|
||||
TreatReturnedNullStringAs=Null|Undefined
|
||||
|
||||
@ -125,6 +125,7 @@ def argument_context(interface, method, argument, index):
|
||||
'local_cpp_type': local_cpp_type,
|
||||
# FIXME: check that the default value's type is compatible with the argument's
|
||||
'default_value': default_value,
|
||||
'is_named': 'Named' in extended_attributes,
|
||||
'dart_default_value': dart_default_value,
|
||||
'enum_validation_expression': idl_type.enum_validation_expression,
|
||||
'preprocessed_type': preprocessed_type,
|
||||
|
||||
@ -5,23 +5,24 @@
|
||||
// WARNING: Do not edit - generated code.
|
||||
part of sky.core;
|
||||
|
||||
abstract class {{interface_name}} extends {{ parent_interface if parent_interface else 'NativeFieldWrapperClass2' }} {
|
||||
|
||||
{% macro args_macro(args) -%}
|
||||
{%- for arg in args -%}
|
||||
{%- if arg.is_optional and (loop.first or not args[arg.index-1].is_optional) -%}
|
||||
[
|
||||
{{ '{' if arg.is_named else '[' }}
|
||||
{%- endif -%}
|
||||
{{ arg.dart_type }} {{ arg.name }}
|
||||
{%- if arg.is_optional %} = {{ arg.dart_default_value }}
|
||||
{%- if loop.last -%}]{%- endif -%}
|
||||
{#- TODO(eseidel): This does not support having both optional and named arguments! -#}
|
||||
{%- if loop.last -%}{{ '}' if arg.is_named else ']' }}{%- endif -%}
|
||||
{%- endif -%}
|
||||
{%- if not loop.last %}, {% endif %}
|
||||
{%- endfor -%}
|
||||
{%- endmacro %}
|
||||
{%- endmacro -%}
|
||||
|
||||
abstract class {{interface_name}} extends {{ parent_interface if parent_interface else 'NativeFieldWrapperClass2' }} {
|
||||
// Constructors
|
||||
{# TODO(eseidel): We only ever have one constructor. #}
|
||||
{% for constructor in constructors %}
|
||||
{%- for constructor in constructors -%}
|
||||
static {{interface_name}} _constructor({{ args_macro(constructor.arguments) }}) native "{{interface_name}}_constructorCallback";
|
||||
factory {{interface_name}}({{ args_macro(constructor.arguments) }}) => _constructor(
|
||||
{%- for arg in constructor.arguments -%}
|
||||
@ -30,6 +31,7 @@ abstract class {{interface_name}} extends {{ parent_interface if parent_interfac
|
||||
);
|
||||
{% endfor %}
|
||||
|
||||
// Attributes
|
||||
{% for attribute in attributes %}
|
||||
{{ attribute.dart_type }} get {{ attribute.name }} native "{{interface_name}}_{{ attribute.name }}_Getter";
|
||||
{% if not attribute.is_read_only %}
|
||||
@ -37,7 +39,8 @@ abstract class {{interface_name}} extends {{ parent_interface if parent_interfac
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
// Methods
|
||||
{% for method in methods %}
|
||||
{{method.dart_type}} {{method.name}}({{ args_macro(method.arguments)}} ) native "{{interface_name}}_{{ method.name }}_Callback";
|
||||
{{method.dart_type}} {{method.name}}({{ args_macro(method.arguments)}}) native "{{interface_name}}_{{ method.name }}_Callback";
|
||||
{% endfor %}
|
||||
}
|
||||
|
||||
@ -3,8 +3,7 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
interface Node : EventTarget {
|
||||
// TODO(abarth): This should actually be a named argument.
|
||||
Node cloneNode(optional boolean deep);
|
||||
Node cloneNode([Named] optional boolean deep = true);
|
||||
|
||||
readonly attribute ParentNode owner;
|
||||
readonly attribute ParentNode parentNode;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user