Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Commit

Permalink
doc(annotation): added documentation to annotations library.
Browse files Browse the repository at this point in the history
  • Loading branch information
mhevery committed Apr 8, 2014
1 parent 2b1e2f5 commit b4c92ec
Show file tree
Hide file tree
Showing 24 changed files with 641 additions and 589 deletions.
549 changes: 17 additions & 532 deletions lib/core/annotation.dart

Large diffs are not rendered by default.

567 changes: 567 additions & 0 deletions lib/core/annotation_src.dart

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions lib/core/registry_dynamic.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
library angular.core_dynamic;

import 'dart:mirrors';
import 'package:angular/core/annotation.dart';
import 'package:angular/core/annotation_src.dart';
import 'package:angular/core/registry.dart';

export 'package:angular/core/registry.dart' show
MetadataExtractor;

var _fieldMetadataCache = new Map<Type, Map<String, AttrFieldAnnotation>>();
var _fieldMetadataCache = new Map<Type, Map<String, AbstractNgFieldAnnotation>>();

class DynamicMetadataExtractor implements MetadataExtractor {
final _fieldAnnotations = [
Expand All @@ -30,38 +30,38 @@ class DynamicMetadataExtractor implements MetadataExtractor {
}

map(Type type, obj) {
if (obj is NgAnnotation) {
if (obj is AbstractNgAnnotation) {
return mapDirectiveAnnotation(type, obj);
} else {
return obj;
}
}

NgAnnotation mapDirectiveAnnotation(Type type, NgAnnotation annotation) {
AbstractNgAnnotation mapDirectiveAnnotation(Type type, AbstractNgAnnotation annotation) {
var match;
var fieldMetadata = fieldMetadataExtractor(type);
if (fieldMetadata.isNotEmpty) {
var newMap = annotation.map == null ? {} : new Map.from(annotation.map);
fieldMetadata.forEach((String fieldName, AttrFieldAnnotation ann) {
fieldMetadata.forEach((String fieldName, AbstractNgFieldAnnotation ann) {
var attrName = ann.attrName;
if (newMap.containsKey(attrName)) {
throw 'Mapping for attribute $attrName is already defined (while '
'processing annottation for field $fieldName of $type)';
}
newMap[attrName] = '${ann.mappingSpec}$fieldName';
newMap[attrName] = '${mappingSpec(ann)}$fieldName';
});
annotation = annotation.cloneWithNewMap(newMap);
annotation = cloneWithNewMap(annotation, newMap);
}
return annotation;
}


Map<String, AttrFieldAnnotation> fieldMetadataExtractor(Type type) =>
Map<String, AbstractNgFieldAnnotation> fieldMetadataExtractor(Type type) =>
_fieldMetadataCache.putIfAbsent(type, () => _fieldMetadataExtractor(type));

Map<String, AttrFieldAnnotation> _fieldMetadataExtractor(Type type) {
Map<String, AbstractNgFieldAnnotation> _fieldMetadataExtractor(Type type) {
ClassMirror cm = reflectType(type);
final fields = <String, AttrFieldAnnotation>{};
final fields = <String, AbstractNgFieldAnnotation>{};
cm.declarations.forEach((Symbol name, DeclarationMirror decl) {
if (decl is VariableMirror ||
decl is MethodMirror && (decl.isGetter || decl.isSetter)) {
Expand All @@ -76,7 +76,7 @@ class DynamicMetadataExtractor implements MetadataExtractor {
throw 'Attribute annotation for $fieldName is defined more '
'than once in $type';
}
fields[fieldName] = meta.reflectee as AttrFieldAnnotation;
fields[fieldName] = meta.reflectee as AbstractNgFieldAnnotation;
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion lib/core_dom/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ typedef ApplyMapping(NodeAttrs attrs, Scope scope, Object dst,
class DirectiveRef {
final dom.Node element;
final Type type;
final NgAnnotation annotation;
final AbstractNgAnnotation annotation;
final String value;
final mappings = new List<ApplyMapping>();

Expand Down
2 changes: 1 addition & 1 deletion lib/core_dom/directive_map.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
part of angular.core.dom_internal;

@NgInjectableService()
class DirectiveMap extends AnnotationsMap<NgAnnotation> {
class DirectiveMap extends AnnotationsMap<AbstractNgAnnotation> {
DirectiveSelectorFactory _directiveSelectorFactory;
DirectiveSelector _selector;
DirectiveSelector get selector {
Expand Down
4 changes: 2 additions & 2 deletions lib/core_dom/element_binder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ElementBinder {
final bool hasTemplate = false;

bool get shouldCompileChildren =>
childMode == NgAnnotation.COMPILE_CHILDREN;
childMode == AbstractNgAnnotation.COMPILE_CHILDREN;

var _directiveCache;
List<DirectiveRef> get _usableDirectiveRefs {
Expand Down Expand Up @@ -199,7 +199,7 @@ class ElementBinder {
..factory(ElementProbe, (_) => probe);

directiveRefs.forEach((DirectiveRef ref) {
NgAnnotation annotation = ref.annotation;
AbstractNgAnnotation annotation = ref.annotation;
var visibility = ref.annotation.visibility;
if (ref.annotation is NgController) {
scope = scope.createChild(new PrototypeMap(scope.context));
Expand Down
8 changes: 4 additions & 4 deletions lib/core_dom/element_binder_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ElementBinderBuilder {
DirectiveRef component;

// Can be either COMPILE_CHILDREN or IGNORE_CHILDREN
String childMode = NgAnnotation.COMPILE_CHILDREN;
String childMode = AbstractNgAnnotation.COMPILE_CHILDREN;


ElementBinderBuilder(this._factory, this._parser);
Expand All @@ -43,15 +43,15 @@ class ElementBinderBuilder {
var annotation = ref.annotation;
var children = annotation.children;

if (annotation.children == NgAnnotation.TRANSCLUDE_CHILDREN) {
if (annotation.children == AbstractNgAnnotation.TRANSCLUDE_CHILDREN) {
template = ref;
} else if (annotation is NgComponent) {
component = ref;
} else {
decorators.add(ref);
}

if (annotation.children == NgAnnotation.IGNORE_CHILDREN) {
if (annotation.children == AbstractNgAnnotation.IGNORE_CHILDREN) {
childMode = annotation.children;
}

Expand All @@ -61,7 +61,7 @@ class ElementBinderBuilder {
static RegExp _MAPPING = new RegExp(r'^(\@|=\>\!|\=\>|\<\=\>|\&)\s*(.*)$');

createMappings(DirectiveRef ref) {
NgAnnotation annotation = ref.annotation;
AbstractNgAnnotation annotation = ref.annotation;
if (annotation.map != null) annotation.map.forEach((attrName, mapping) {
Match match = _MAPPING.firstMatch(mapping);
if (match == null) {
Expand Down
2 changes: 1 addition & 1 deletion lib/core_dom/module_internal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'dart:html' as dom;
import 'package:di/di.dart';
import 'package:perf_api/perf_api.dart';

import 'package:angular/core/annotation.dart';
import 'package:angular/core/annotation_src.dart';
import 'package:angular/core/module_internal.dart';
import 'package:angular/core/parser/parser.dart';
import 'package:angular/core_dom/dom_util.dart' as util;
Expand Down
6 changes: 3 additions & 3 deletions lib/core_dom/selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ part of angular.core.dom_internal;
*/
class _Directive {
final Type type;
final NgAnnotation annotation;
final AbstractNgAnnotation annotation;

_Directive(this.type, this.annotation);

Expand All @@ -38,7 +38,7 @@ class _Directive {


class _ContainsSelector {
final NgAnnotation annotation;
final AbstractNgAnnotation annotation;
final RegExp regexp;

_ContainsSelector(this.annotation, String regexp)
Expand Down Expand Up @@ -252,7 +252,7 @@ class DirectiveSelector {
elementSelector = new _ElementSelector('');
attrSelector = <_ContainsSelector>[];
textSelector = <_ContainsSelector>[];
_directives.forEach((NgAnnotation annotation, Type type) {
_directives.forEach((AbstractNgAnnotation annotation, Type type) {
var match;
var selector = annotation.selector;
List<_SelectorPart> selectorParts;
Expand Down
4 changes: 2 additions & 2 deletions lib/directive/ng_if.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ abstract class _NgUnlessIfAttrDirectiveBase {
* </div>
*/
@NgDirective(
children: NgAnnotation.TRANSCLUDE_CHILDREN,
children: AbstractNgAnnotation.TRANSCLUDE_CHILDREN,
selector:'[ng-if]',
map: const {'.': '=>condition'})
class NgIf extends _NgUnlessIfAttrDirectiveBase {
Expand Down Expand Up @@ -151,7 +151,7 @@ class NgIf extends _NgUnlessIfAttrDirectiveBase {
* </div>
*/
@NgDirective(
children: NgAnnotation.TRANSCLUDE_CHILDREN,
children: AbstractNgAnnotation.TRANSCLUDE_CHILDREN,
selector:'[ng-unless]',
map: const {'.': '=>condition'})
class NgUnless extends _NgUnlessIfAttrDirectiveBase {
Expand Down
2 changes: 1 addition & 1 deletion lib/directive/ng_non_bindable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ part of angular.directive;
*/
@NgDirective(
selector: '[ng-non-bindable]',
children: NgAnnotation.IGNORE_CHILDREN)
children: AbstractNgAnnotation.IGNORE_CHILDREN)
class NgNonBindable {}
2 changes: 1 addition & 1 deletion lib/directive/ng_repeat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ part of angular.directive;
*/

@NgDirective(
children: NgAnnotation.TRANSCLUDE_CHILDREN,
children: AbstractNgAnnotation.TRANSCLUDE_CHILDREN,
selector: '[ng-repeat]',
map: const {'.': '@expression'})
class NgRepeat {
Expand Down
4 changes: 2 additions & 2 deletions lib/directive/ng_switch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class _Case {

@NgDirective(
selector: '[ng-switch-when]',
children: NgAnnotation.TRANSCLUDE_CHILDREN,
children: AbstractNgAnnotation.TRANSCLUDE_CHILDREN,
map: const {'.': '@value'})
class NgSwitchWhen {
final NgSwitch ngSwitch;
Expand All @@ -125,7 +125,7 @@ class NgSwitchWhen {
}

@NgDirective(
children: NgAnnotation.TRANSCLUDE_CHILDREN,
children: AbstractNgAnnotation.TRANSCLUDE_CHILDREN,
selector: '[ng-switch-default]')
class NgSwitchDefault {

Expand Down
2 changes: 1 addition & 1 deletion lib/directive/ng_template.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ part of angular.directive;
map: const {'id': '@templateUrl'})
@NgDirective(
selector: 'script[type=text/ng-template]',
children: NgAnnotation.IGNORE_CHILDREN,
children: AbstractNgAnnotation.IGNORE_CHILDREN,
map: const {'id': '@templateUrl'})
class NgTemplate {
final dom.Element element;
Expand Down
8 changes: 4 additions & 4 deletions lib/tools/transformer/metadata_extractor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,9 @@ class AnnotationExtractor {
}
_annotationElements.add(type.unnamedConstructor);
}
ngAnnotationType = resolver.getType('angular.core.annotation.NgAnnotation');
ngAnnotationType = resolver.getType('angular.core.annotation.AbstractNgAnnotation');
if (ngAnnotationType == null) {
logger.warning('Unable to resolve NgAnnotation, '
logger.warning('Unable to resolve AbstractNgAnnotation, '
'skipping member annotations.');
}
}
Expand Down Expand Up @@ -296,11 +296,11 @@ class AnnotationExtractor {
return type;
}

/// Folds all AttrFieldAnnotations into the NgAnnotation annotation on the
/// Folds all AttrFieldAnnotations into the AbstractNgAnnotation annotation on the
/// class.
void _foldMemberAnnotations(Map<String, Annotation> memberAnnotations,
AnnotatedType type) {
// Filter down to NgAnnotation constructors.
// Filter down to AbstractNgAnnotation constructors.
var ngAnnotations = type.annotations.where((a) {
var element = a.element;
if (element is! ConstructorElement) return false;
Expand Down
12 changes: 6 additions & 6 deletions test/angular_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ main() {
var ALLOWED_NAMES = [
"angular.app.Application",
"angular.app.AngularModule",
"angular.core.annotation.NgAttachAware",
"angular.core.annotation.NgComponent",
"angular.core.annotation.NgController",
"angular.core.annotation.NgDetachAware",
"angular.core.annotation.NgDirective",
"angular.core.annotation.NgInjectableService",
"angular.core.annotation_src.NgAttachAware",
"angular.core.annotation_src.NgComponent",
"angular.core.annotation_src.NgController",
"angular.core.annotation_src.NgDetachAware",
"angular.core.annotation_src.NgDirective",
"angular.core.annotation_src.NgInjectableService",
"angular.core_internal.CacheStats",
"angular.core_internal.ExceptionHandler",
"angular.core_internal.Interpolate",
Expand Down
4 changes: 2 additions & 2 deletions test/core_dom/compiler_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ class LocalAttrDirective {

@NgDirective(
selector: '[simple-transclude-in-attach]',
visibility: NgDirective.CHILDREN_VISIBILITY, children: NgAnnotation.TRANSCLUDE_CHILDREN)
visibility: NgDirective.CHILDREN_VISIBILITY, children: AbstractNgAnnotation.TRANSCLUDE_CHILDREN)
class SimpleTranscludeInAttachAttrDirective {
SimpleTranscludeInAttachAttrDirective(ViewPort viewPort, BoundViewFactory boundViewFactory, Logger log, RootScope scope) {
scope.runAsync(() {
Expand Down Expand Up @@ -714,7 +714,7 @@ class TwoOfTwoDirectives {

@NgDirective(
selector: '[ignore-children]',
children: NgAnnotation.IGNORE_CHILDREN
children: AbstractNgAnnotation.IGNORE_CHILDREN
)
class IgnoreChildrenDirective {
IgnoreChildrenDirective(Logger log) {
Expand Down
10 changes: 5 additions & 5 deletions test/core_dom/element_binder_builder_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import 'dart:mirrors';

@NgComponent(selector:'component') class _Component{}
@NgDirective(selector:'[ignore-children]',
children: NgAnnotation.IGNORE_CHILDREN)
children: AbstractNgAnnotation.IGNORE_CHILDREN)
class _IgnoreChildren{}
@NgDirective(selector:'[structural]',
children: NgAnnotation.TRANSCLUDE_CHILDREN)
children: AbstractNgAnnotation.TRANSCLUDE_CHILDREN)
class _Structural{}
@NgDirective(selector:'[directive]') class _DirectiveAttr{}

Expand Down Expand Up @@ -36,7 +36,7 @@ main() => describe('ElementBinderBuilder', () {
});

addDirective(selector) {
directives.forEach((NgAnnotation annotation, Type type) {
directives.forEach((AbstractNgAnnotation annotation, Type type) {
if (annotation.selector == selector)
b.addDirective(new DirectiveRef(node, type, annotation, null));
});
Expand All @@ -50,7 +50,7 @@ main() => describe('ElementBinderBuilder', () {

expect(b.decorators.length).toEqual(1);
expect(b.component).toBeNull();
expect(b.childMode).toEqual(NgAnnotation.COMPILE_CHILDREN);
expect(b.childMode).toEqual(AbstractNgAnnotation.COMPILE_CHILDREN);

});

Expand All @@ -72,6 +72,6 @@ main() => describe('ElementBinderBuilder', () {

expect(b.decorators.length).toEqual(1);
expect(b.component).toBeNull();
expect(b.childMode).toEqual(NgAnnotation.IGNORE_CHILDREN);
expect(b.childMode).toEqual(AbstractNgAnnotation.IGNORE_CHILDREN);
});
});
4 changes: 2 additions & 2 deletions test/core_dom/selector_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import '../_specs.dart';
@NgComponent(selector:'component') class _Component{}
@NgDirective(selector:'[attribute]') class _Attribute{}
@NgDirective(selector:'[structural]',
children: NgAnnotation.TRANSCLUDE_CHILDREN)
children: AbstractNgAnnotation.TRANSCLUDE_CHILDREN)
class _Structural{}

@NgDirective(selector:'[ignore-children]',
children: NgAnnotation.IGNORE_CHILDREN)
children: AbstractNgAnnotation.IGNORE_CHILDREN)
class _IgnoreChildren{}

@NgDirective(selector: '[my-model][required]')
Expand Down
4 changes: 2 additions & 2 deletions test/core_dom/view_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Log {
add(String msg) => log.add(msg);
}

@NgDirective(children: NgAnnotation.TRANSCLUDE_CHILDREN, selector: 'foo')
@NgDirective(children: AbstractNgAnnotation.TRANSCLUDE_CHILDREN, selector: 'foo')
class LoggerViewDirective {
LoggerViewDirective(ViewPort port, ViewFactory viewFactory,
BoundViewFactory boundViewFactory, Logger logger) {
Expand Down Expand Up @@ -142,7 +142,7 @@ main() {
var directiveRef = new DirectiveRef(null,
LoggerViewDirective,
new NgDirective(children: NgAnnotation.TRANSCLUDE_CHILDREN, selector: 'foo'),
new NgDirective(children: AbstractNgAnnotation.TRANSCLUDE_CHILDREN, selector: 'foo'),
'');
directiveRef.viewFactory = viewFactoryFactory($('<b>text</b>'), [], perf, new Expando());
var binder = ebf.binder();
Expand Down
2 changes: 1 addition & 1 deletion test/directive/ng_if_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import '../_specs.dart';

@NgDirective(
selector: '[child-controller]',
children: NgAnnotation.TRANSCLUDE_CHILDREN)
children: AbstractNgAnnotation.TRANSCLUDE_CHILDREN)
class ChildController {
ChildController(BoundViewFactory boundViewFactory,
ViewPort viewPort,
Expand Down
2 changes: 1 addition & 1 deletion test/directive/ng_include_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ main() {
expect(element.text).toEqual('my name is Vojta');
}));

iit('should fetch template from url using interpolation', async((Scope scope, TemplateCache cache) {
it('should fetch template from url using interpolation', async((Scope scope, TemplateCache cache) {
cache.put('tpl1.html', new HttpResponse(200, 'My name is {{name}}'));
cache.put('tpl2.html', new HttpResponse(200, 'I am {{name}}'));

Expand Down
Loading

0 comments on commit b4c92ec

Please sign in to comment.