From 2175f32677ad58b229ec4e53a9c010f00dacb80f Mon Sep 17 00:00:00 2001 From: Hixie Date: Thu, 19 Feb 2015 16:00:32 -0800 Subject: [PATCH] Specs: fix a raft of syntax errors caught by actually running a syntax checker... Review URL: https://codereview.chromium.org/943843002 --- specs/elements.md | 48 ++++++++++++++----------- specs/gestures.md | 90 +++++++++++++++++++++++++++++++---------------- specs/modules.md | 2 +- specs/pointer.md | 12 ++++--- specs/script.md | 2 ++ 5 files changed, 98 insertions(+), 56 deletions(-) diff --git a/specs/elements.md b/specs/elements.md index f2c5ec15622..140b4391aac 100644 --- a/specs/elements.md +++ b/specs/elements.md @@ -17,14 +17,14 @@ abstract class Node extends EventTarget { external Root get owner; // O(1) external ParentNode get parentNode; // O(1) - Element get parentElement => { + Element get parentElement { if (parentNode is Element) return parentNode as Element; return null; } external Node get previousSibling; // O(1) - Element get previousElementSibling => { + Element get previousElementSibling { var result = previousSibling; while (result != null && result is! Element) result = result.previousSibling; @@ -32,7 +32,7 @@ abstract class Node extends EventTarget { } external Node get nextSibling; // O(1) - Element get nextElementSibling => { + Element get nextElementSibling { var result = nextSibling; while (result != null && result is! Element) result = result.nextSibling; @@ -53,7 +53,7 @@ abstract class Node extends EventTarget { }); } - void _insertAfter(Node node); // O(N) in number of arguments plus all their descendants + external void _insertAfter(Node node); // O(N) in number of arguments plus all their descendants // node must be Text or Element, parentNode must be non-null void insertAfter(List nodes) { var lastNode = this; @@ -119,7 +119,7 @@ abstract class Node extends EventTarget { abstract class ParentNode extends Node { external Node get firstChild; // O(1) - Element get firstElementChild => { + Element get firstElementChild { var result = firstChild; while (result != null && result is! Element) result = result.nextSibling; @@ -127,7 +127,7 @@ abstract class ParentNode extends Node { } external Node get lastChild; // O(1) - Element get lastElementChild => { + Element get lastElementChild { var result = lastChild; while (result != null && result is! Element) result = result.previousSibling; @@ -143,7 +143,7 @@ abstract class ParentNode extends Node { external void _appendChild(Node node); // O(N) in number of descendants // node must be Text or Element - void appendChild(Node node) { + void appendChild(node) { if (node is String) node = new Text(node); _appendChild(node); @@ -154,7 +154,7 @@ abstract class ParentNode extends Node { external void _prependChild(Node node); // O(N) in number of descendants // node must be Text or Element - void prependChild(Node node) { + void prependChild(node) { if (node is String) node = new Text(node); _prependChild(node); @@ -168,7 +168,7 @@ abstract class ParentNode extends Node { } external void removeChildren(); // O(N) in number of descendants - void setChild(Node node) { + void setChild(node) { removeChildren(); appendChild(node); } @@ -191,15 +191,15 @@ class tagname extends AutomaticMetadata { final String name; void init(DeclarationMirror target, Module module) { assert(target is ClassMirror); - if (!target.isSubclassOf(reflectClass(Element))) - throw Error('@tagname can only be used on descendants of Element'); + if (!(target as ClassMirror).isSubclassOf(reflectClass(Element))) + throw new UnsupportedError('@tagname can only be used on descendants of Element'); module.registerElement(name, (target as ClassMirror).reflectedType); } } // @hasShadow annotation for registering elements class _HasShadow { - const HasShadow(); + const _HasShadow(); } const hasShadow = const _HasShadow(); @@ -207,8 +207,11 @@ abstract class Element extends ParentNode { Element({Map attributes: null, List children: null, Module hostModule: null}) { // O(M+N), M = number of attributes, N = number of children nodes plus all their descendants - var shadowClass = reflectClass(hasShadow); - bool needsShadow = reflect(this).type.metadata.singleWhere((mirror) => mirror.type == hasShadowClass); + var shadowClass = reflectClass(hasShadow.runtimeType); + var shadowAnnotations = reflect(this).type.metadata.where((mirror) => mirror.type == shadowClass); + if (shadowAnnotations.length > 2) + throw new StateError('@hasShadow specified multiple times on ' + currentMirrorSystem().getName(reflectClass(this.runtimeType).simpleName)); + bool needsShadow = shadowAnnotations.length == 1; if (children != null) children = children.map((node) => node is String ? new Text(node) : node).toList(); this._initElement(attributes, children, hostModule, needsShadow); @@ -222,7 +225,7 @@ abstract class Element extends ParentNode { String get tagName { // O(N) in number of annotations on the class // throws a StateError if the class doesn't have an @tagname annotation var tagnameClass = reflectClass(tagname); - return (reflectClass(this.runtimeType).metadata.singleWhere((mirror) => mirror.type == tagnameClass).reflectee as tagname).value; + return (reflectClass(this.runtimeType).metadata.singleWhere((mirror) => mirror.type == tagnameClass).reflectee as tagname).name; } external bool hasAttribute(String name); // O(N) in number of attributes @@ -235,7 +238,7 @@ abstract class Element extends ParentNode { // Returns a new Array and new Attr instances every time. external List getAttributes(); // O(N) in number of attributes - external final Root shadowRoot; // O(1) + external Root get shadowRoot; // O(1) // returns the shadow root void endTagParsedCallback() { } @@ -270,8 +273,14 @@ class Fragment extends ParentNode { } class Root extends ParentNode { - external Root ({List children, Element host}); // O(N) in number of children nodes arguments plus all their descendants - // children must be String, Text, or Element + Root({List children: null, this.host}) { // O(N) in number of children nodes plus all their descendants + if (children != null) + children = children.map((node) => node is String ? new Text(node) : node).toList(); + this._initRoot(children); + } + external void _initRoot(List children); + // appends the given children nodes + // children must be Text or Element final Element host; @@ -280,8 +289,7 @@ class Root extends ParentNode { } class ApplicationRoot extends Root { - external ApplicationRoot ({List children}) : Root(children: children); // O(N) in number of children nodes arguments plus all their descendants - // children must be String, Text, or Element + ApplicationRoot ({List children}) : super(children: children); // O(N) in number of children nodes arguments plus all their descendants @override Type getLayoutManager() => rootLayoutManager; // O(1) diff --git a/specs/gestures.md b/specs/gestures.md index f272f84b2f9..e600705fb8f 100644 --- a/specs/gestures.md +++ b/specs/gestures.md @@ -112,19 +112,20 @@ abstract class Gesture extends EventTarget { if (returnValue.cancel) { assert(returnValue.choose == false); if (wasActive) - module.application.cancelGesture(this); + module.application.gestureManager.cancelGesture(this); // if we never became active, then we never called addGesture() below _active = false; } else if (active == true) { if (wasActive == false || event is PointerDownEvent) - module.application.addGesture(event, this); + module.application.gestureManager.addGesture(event, this); if (returnValue.choose == true) - module.application.chooseGesture(this); + module.application.gestureManager.chooseGesture(this); } _ready = returnValue.finished; } } +/* ``` Subclasses should override ``processEvent()``: - as the events are received, they get examined to see if they @@ -136,10 +137,9 @@ Subclasses should override ``processEvent()``: - doing anything with the event or target other than reading state is a contract violation - you are allowed to call sendEvent() at any time during a - processEventInternal() call, or after a call to - processEventInternal(), assuming that the last such call returned - valid=true, until the next call to processEventInternal() or - cancel(). + processEvent() call, or after a call to processEvent(), assuming + that the last such call returned valid=true, until the next call to + processEvent() or cancel(). - set forceChoose=true on the return value if you are confident that this is the gesture the user meant, even if it's possible that another gesture is still claiming it's valid (e.g. a long @@ -151,6 +151,7 @@ Subclasses should override ``processEvent()``: "cancel" events if cancel() is called ```dart +*/ class PointerState { PointerState({this.gestures, this.chosen}) { @@ -251,6 +252,7 @@ class GestureManager { } } +/* ``` @@ -263,13 +265,15 @@ SKY MODULE ``` diff --git a/specs/modules.md b/specs/modules.md index 3a8d3fe6b26..25f8e62d034 100644 --- a/specs/modules.md +++ b/specs/modules.md @@ -100,7 +100,7 @@ abstract class AbstractModule extends EventTarget { // if it's already loaded, the future will resolve immediately // if loading fails, the future will have an error - List getImports(); // O(N) + external List getImports(); // O(N) // returns the Module objects of all the imported modules external void registerElement(String tagname, Type elementClass); // O(1) diff --git a/specs/pointer.md b/specs/pointer.md index 5001f3d5b6f..2fe6bfeb9ad 100644 --- a/specs/pointer.md +++ b/specs/pointer.md @@ -434,6 +434,7 @@ class PointerMovedEvent extends PointerEvent { PointerMovedEvent = PointerEvent; bool get bubbles => false; } +/* ``` Wheel events @@ -470,12 +471,13 @@ Note: The only wheels that are supported are mouse wheels and physical dials. Track balls are not reported as mouse wheels. ```dart +*/ class WheelEvent extends Event { - Event({ this.wheel, - this.delta: 0.0, - this.pointer, - this.x, this.y, - }): super(); + WheelEvent({ this.wheel, + this.delta: 0.0, + this.pointer, + this.x, this.y + }): super(); final int wheel; final double delta; // revolutions (or fractions thereof) diff --git a/specs/script.md b/specs/script.md index 6bb5c28cc26..857f2c00f1c 100644 --- a/specs/script.md +++ b/specs/script.md @@ -22,6 +22,8 @@ argument's default value. The following definitions are exposed in ``dart:sky``: ```dart +import 'dart:mirrors'; + abstract class AutomaticMetadata { const AutomaticMetadata(); void init(DeclarationMirror target, Module module);