| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 /// Helpers for Analyzer's Element model and corelib model. | 5 /// Helpers for Analyzer's Element model and corelib model. |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart' | 7 import 'package:analyzer/dart/ast/ast.dart' |
| 8 show Expression, MethodInvocation, SimpleIdentifier; | 8 show |
| 9 ConstructorDeclaration, |
| 10 Expression, |
| 11 FunctionBody, |
| 12 FunctionExpression, |
| 13 MethodDeclaration, |
| 14 MethodInvocation, |
| 15 SimpleIdentifier; |
| 9 import 'package:analyzer/dart/element/element.dart' | 16 import 'package:analyzer/dart/element/element.dart' |
| 10 show Element, FunctionElement; | 17 show Element, ExecutableElement, FunctionElement; |
| 11 import 'package:analyzer/dart/element/type.dart' | 18 import 'package:analyzer/dart/element/type.dart' |
| 12 show DartType, InterfaceType, ParameterizedType; | 19 show DartType, InterfaceType, ParameterizedType; |
| 13 import 'package:analyzer/src/dart/element/type.dart' show DynamicTypeImpl; | 20 import 'package:analyzer/src/dart/element/type.dart' show DynamicTypeImpl; |
| 14 import 'package:analyzer/src/generated/constant.dart' show DartObject; | 21 import 'package:analyzer/src/generated/constant.dart' show DartObject; |
| 15 | 22 |
| 16 class Tuple2<T0, T1> { | 23 class Tuple2<T0, T1> { |
| 17 final T0 e0; | 24 final T0 e0; |
| 18 final T1 e1; | 25 final T1 e1; |
| 19 Tuple2(this.e0, this.e1); | 26 Tuple2(this.e0, this.e1); |
| 20 } | 27 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 var parent = node.parent; | 82 var parent = node.parent; |
| 76 return parent is MethodInvocation && parent.methodName == node; | 83 return parent is MethodInvocation && parent.methodName == node; |
| 77 } | 84 } |
| 78 | 85 |
| 79 bool isInlineJS(Element e) => | 86 bool isInlineJS(Element e) => |
| 80 e is FunctionElement && | 87 e is FunctionElement && |
| 81 e.name == 'JS' && | 88 e.name == 'JS' && |
| 82 e.library.isInSdk && | 89 e.library.isInSdk && |
| 83 e.library.source.uri.toString() == 'dart:_foreign_helper'; | 90 e.library.source.uri.toString() == 'dart:_foreign_helper'; |
| 84 | 91 |
| 92 ExecutableElement getFunctionBodyElement(FunctionBody body) { |
| 93 var f = body.parent; |
| 94 if (f is FunctionExpression) { |
| 95 return f.element; |
| 96 } else if (f is MethodDeclaration) { |
| 97 return f.element; |
| 98 } else { |
| 99 return (f as ConstructorDeclaration).element; |
| 100 } |
| 101 } |
| 102 |
| 85 /// Returns the value of the `name` field from the [match]ing annotation on | 103 /// Returns the value of the `name` field from the [match]ing annotation on |
| 86 /// [element], or `null` if we didn't find a valid match or it was not a string. | 104 /// [element], or `null` if we didn't find a valid match or it was not a string. |
| 87 /// | 105 /// |
| 88 /// For example, consider this code: | 106 /// For example, consider this code: |
| 89 /// | 107 /// |
| 90 /// class MyAnnotation { | 108 /// class MyAnnotation { |
| 91 /// final String name; | 109 /// final String name; |
| 92 /// // ... | 110 /// // ... |
| 93 /// const MyAnnotation(this.name/*, ... other params ... */); | 111 /// const MyAnnotation(this.name/*, ... other params ... */); |
| 94 /// } | 112 /// } |
| 95 /// | 113 /// |
| 96 /// @MyAnnotation('FooBar') | 114 /// @MyAnnotation('FooBar') |
| 97 /// main() { ... } | 115 /// main() { ... } |
| 98 /// | 116 /// |
| 99 /// If we match the annotation for the `@MyAnnotation('FooBar')` this will | 117 /// If we match the annotation for the `@MyAnnotation('FooBar')` this will |
| 100 /// return the string 'FooBar'. | 118 /// return the string 'FooBar'. |
| 101 String getAnnotationName(Element element, bool match(DartObject value)) => | 119 String getAnnotationName(Element element, bool match(DartObject value)) => |
| 102 findAnnotation(element, match)?.getField('name')?.toStringValue(); | 120 findAnnotation(element, match)?.getField('name')?.toStringValue(); |
| OLD | NEW |