Skip to content

Commit 6e90cac

Browse files
Tim Blasimhevery
authored andcommitted
feat(dart/transformer:: Initial commit of ctor stubs & annotation register
Closes angular#646 Closes angular#496 Closes angular#498
1 parent cbc76fa commit 6e90cac

File tree

33 files changed

+1098
-0
lines changed

33 files changed

+1098
-0
lines changed

gulpfile.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,11 +516,17 @@ gulp.task('ci', function(done) {
516516
);
517517
});
518518

519+
gulp.task('tests/transform.dart', function() {
520+
return gulp.src('modules/angular2/test/transform/**')
521+
.pipe(gulp.dest('dist/dart/angular2/test/transform'));
522+
});
523+
519524
// -----------------
520525
// orchestrated targets
521526
gulp.task('build.dart', function(done) {
522527
runSequence(
523528
['build/deps.js.dart2js', 'build/transpile.dart', 'build/html.dart'],
529+
'tests/transform.dart',
524530
'build/pubspec.dart',
525531
'build/multicopy.dart',
526532
'build/pubbuild.dart',

modules/angular2/pubspec.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ homepage: <%= packageJson.homepage %>
99
environment:
1010
sdk: '>=1.4.0'
1111
dependencies:
12+
analyzer: '0.22.4'
13+
barback: '0.15.2+2'
14+
code_transformers: '0.2.5'
15+
dart_style: '0.1.3'
16+
html5lib: '0.12.0'
1217
stack_trace: '>=1.1.1 <1.2.0'
1318
dev_dependencies:
1419
guinness: ">=0.1.16 <0.2.0"
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import 'dart:collection' show Queue;
2+
import 'package:analyzer/src/generated/element.dart';
3+
4+
/// Provides a mechanism for checking an element for the provided
5+
/// [_annotationClass] and reporting the resulting (element, annotation) pairs.
6+
class AnnotationMatcher {
7+
/// Queue for annotations.
8+
final initQueue = new Queue<AnnotationMatch>();
9+
/// All the annotations we have seen for each element
10+
final _seenAnnotations = new Map<Element, Set<ElementAnnotation>>();
11+
12+
/// The class we are searching for to populate [initQueue].
13+
final ClassElement _annotationClass;
14+
15+
AnnotationMatcher(this._annotationClass);
16+
17+
/// Records all [_annotationClass] annotations and the [element]s they apply to.
18+
/// Returns [true] if 1) [element] is annotated with [_annotationClass] and
19+
/// 2) ([element], [_annotationClass]) has been seen previously.
20+
bool processAnnotations(ClassElement element) {
21+
var found = false;
22+
element.metadata.where((ElementAnnotation meta) {
23+
// Only process [_annotationClass]s.
24+
// TODO(tjblasi): Make this recognize non-ConstructorElement annotations.
25+
return meta.element is ConstructorElement &&
26+
_isAnnotationMatch(meta.element.returnType);
27+
}).where((ElementAnnotation meta) {
28+
// Only process ([element], [meta]) combinations we haven't seen previously.
29+
return !_seenAnnotations
30+
.putIfAbsent(element, () => new Set<ElementAnnotation>())
31+
.contains(meta);
32+
}).forEach((ElementAnnotation meta) {
33+
_seenAnnotations[element].add(meta);
34+
initQueue.addLast(new AnnotationMatch(element, meta));
35+
found = true;
36+
});
37+
return found;
38+
}
39+
40+
/// Whether [type], its superclass, or one of its interfaces matches [_annotationClass].
41+
bool _isAnnotationMatch(InterfaceType type) {
42+
if (type == null || type.element == null) return false;
43+
if (type.element.type == _annotationClass.type) return true;
44+
if (_isAnnotationMatch(type.superclass)) return true;
45+
for (var interface in type.interfaces) {
46+
if (_isAnnotationMatch(interface)) return true;
47+
}
48+
return false;
49+
}
50+
}
51+
52+
// Element/ElementAnnotation pair.
53+
class AnnotationMatch {
54+
final Element element;
55+
final ElementAnnotation annotation;
56+
57+
AnnotationMatch(this.element, this.annotation);
58+
}

0 commit comments

Comments
 (0)