Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Side by Side Diff: lib/src/transformer/utils.dart

Issue 615913004: Add @jsify annotation. Support automatically proxying Lists and Maps to Dart in Proxies. Support co… (Closed) Base URL: https://github.com/dart-lang/js-interop.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library js.transformer.utils; 5 library js.transformer.utils;
6 6
7 import 'package:analyzer/analyzer.dart' hide ParameterKind; 7 import 'package:analyzer/analyzer.dart' hide ParameterKind;
8 import 'package:analyzer/src/generated/element.dart'; 8 import 'package:analyzer/src/generated/element.dart';
9 import 'package:barback/barback.dart'; 9 import 'package:barback/barback.dart';
10 import 'package:js/src/metadata.dart'; 10 import 'package:js/src/metadata.dart';
(...skipping 15 matching lines...) Expand all
26 LibraryElement getMetadataLib(LibraryElement jsLib) => 26 LibraryElement getMetadataLib(LibraryElement jsLib) =>
27 getEnvironementImplLib(jsLib) 27 getEnvironementImplLib(jsLib)
28 .exportedLibraries 28 .exportedLibraries
29 .singleWhere((l) => l.name == 'js.metadata'); 29 .singleWhere((l) => l.name == 'js.metadata');
30 30
31 LibraryElement getImplLib(LibraryElement jsLib) => 31 LibraryElement getImplLib(LibraryElement jsLib) =>
32 getEnvironementImplLib(jsLib) 32 getEnvironementImplLib(jsLib)
33 .exportedLibraries 33 .exportedLibraries
34 .singleWhere((l) => l.name == 'js.impl'); 34 .singleWhere((l) => l.name == 'js.impl');
35 35
36 bool hasAnnotation(Element element, ClassElement annotation) {
37
38 for (var metadata in element.metadata) {
39 var metaElement = metadata.element;
40 var exp;
41 var type;
42 if (metaElement is PropertyAccessorElement) {
43 exp = metaElement.variable;
44 type = exp.evaluationResult.value.type;
45 } else if (metaElement is ConstructorElement) {
46 exp = metaElement;
47 type = metaElement.enclosingElement.type;
48 } else {
49 throw new UnimplementedError('Unsupported annotation: ${metadata}');
50 }
51 if (exp == annotation) return true;
52 if (type.isSubtypeOf(annotation.type)) {
53 return true;
54 }
55 }
56 return false;
57 }
58
36 JsProxy getProxyAnnotation(ClassElement interface, ClassElement jsProxyClass) { 59 JsProxy getProxyAnnotation(ClassElement interface, ClassElement jsProxyClass) {
37 var node = interface.node; 60 var node = interface.node;
38 for (Annotation a in node.metadata) { 61 for (Annotation a in node.metadata) {
39 var e = a.element; 62 var e = a.element;
40 if (e is ConstructorElement && e.type.returnType == jsProxyClass.type) { 63 if (e is ConstructorElement && e.type.returnType == jsProxyClass.type) {
41 bool global; 64 bool global;
42 String constructor; 65 String constructor;
43 for (Expression e in a.arguments.arguments) { 66 for (Expression e in a.arguments.arguments) {
44 if (e is NamedExpression) { 67 if (e is NamedExpression) {
45 if (e.name.label.name == 'global' && e.expression is BooleanLiteral) { 68 if (e.name.label.name == 'global' && e.expression is BooleanLiteral) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 .map((p) => p.name); 134 .map((p) => p.name);
112 var optionalParameters = parameters 135 var optionalParameters = parameters
113 .where((p) => p.kind == ParameterKind.POSITIONAL) 136 .where((p) => p.kind == ParameterKind.POSITIONAL)
114 .map((p) => p.name); 137 .map((p) => p.name);
115 var namedParameters = parameters 138 var namedParameters = parameters
116 .where((p) => p.kind == ParameterKind.NAMED) 139 .where((p) => p.kind == ParameterKind.NAMED)
117 .map((p) => p.name); 140 .map((p) => p.name);
118 var r = formatter(requiredParameters, optionalParameters, namedParameters); 141 var r = formatter(requiredParameters, optionalParameters, namedParameters);
119 return r; 142 return r;
120 } 143 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698