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

Unified Diff: lib/src/compiler/element_helpers.dart

Issue 1979013003: fix #569, cache constants defined in methods (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: lib/src/compiler/element_helpers.dart
diff --git a/lib/src/compiler/element_helpers.dart b/lib/src/compiler/element_helpers.dart
index dc8ff6cb93a769ceaaecda88cc6751b1d650b371..a5d95d8328dab6388df1344b0c2b8f490ddd0f64 100644
--- a/lib/src/compiler/element_helpers.dart
+++ b/lib/src/compiler/element_helpers.dart
@@ -5,9 +5,16 @@
/// Helpers for Analyzer's Element model and corelib model.
import 'package:analyzer/dart/ast/ast.dart'
- show Expression, MethodInvocation, SimpleIdentifier;
+ show
+ ConstructorDeclaration,
+ Expression,
+ FunctionBody,
+ FunctionExpression,
+ MethodDeclaration,
+ MethodInvocation,
+ SimpleIdentifier;
import 'package:analyzer/dart/element/element.dart'
- show Element, FunctionElement;
+ show Element, ExecutableElement, FunctionElement;
import 'package:analyzer/dart/element/type.dart'
show DartType, InterfaceType, ParameterizedType;
import 'package:analyzer/src/dart/element/type.dart' show DynamicTypeImpl;
@@ -82,6 +89,17 @@ bool isInlineJS(Element e) =>
e.library.isInSdk &&
e.library.source.uri.toString() == 'dart:_foreign_helper';
+ExecutableElement getFunctionBodyElement(FunctionBody body) {
+ var f = body.parent;
+ if (f is FunctionExpression) {
+ return f.element;
+ } else if (f is MethodDeclaration) {
+ return f.element;
+ } else {
+ return (f as ConstructorDeclaration).element;
+ }
+}
+
/// Returns the value of the `name` field from the [match]ing annotation on
/// [element], or `null` if we didn't find a valid match or it was not a string.
///

Powered by Google App Engine
This is Rietveld 408576698