| Index: sdk/lib/_internal/compiler/implementation/resolution/members.dart
|
| diff --git a/sdk/lib/_internal/compiler/implementation/resolution/members.dart b/sdk/lib/_internal/compiler/implementation/resolution/members.dart
|
| index bf1cf2267e9232baf26acf3007537b504545a1a5..c7e4611cf317e33eef8183fc9bc5d55879c4e439 100644
|
| --- a/sdk/lib/_internal/compiler/implementation/resolution/members.dart
|
| +++ b/sdk/lib/_internal/compiler/implementation/resolution/members.dart
|
| @@ -259,8 +259,11 @@ class ResolverTask extends CompilerTask {
|
| return measure(() {
|
| if (Elements.isErroneousElement(element)) return null;
|
|
|
| - for (MetadataAnnotation metadata in element.metadata) {
|
| - metadata.ensureResolved(compiler);
|
| + processMetadata([result]) {
|
| + for (MetadataAnnotation metadata in element.metadata) {
|
| + metadata.ensureResolved(compiler);
|
| + }
|
| + return result;
|
| }
|
|
|
| ElementKind kind = element.kind;
|
| @@ -268,18 +271,19 @@ class ResolverTask extends CompilerTask {
|
| identical(kind, ElementKind.FUNCTION) ||
|
| identical(kind, ElementKind.GETTER) ||
|
| identical(kind, ElementKind.SETTER)) {
|
| - return resolveMethodElement(element);
|
| + return processMetadata(resolveMethodElement(element));
|
| }
|
|
|
| - if (identical(kind, ElementKind.FIELD)) return resolveField(element);
|
| -
|
| + if (identical(kind, ElementKind.FIELD)) {
|
| + return processMetadata(resolveField(element));
|
| + }
|
| if (element.isClass) {
|
| ClassElement cls = element;
|
| cls.ensureResolved(compiler);
|
| - return null;
|
| + return processMetadata();
|
| } else if (element.isTypedef) {
|
| TypedefElement typdef = element;
|
| - return resolveTypedef(typdef);
|
| + return processMetadata(resolveTypedef(typdef));
|
| }
|
|
|
| compiler.unimplemented(element, "resolve($element)");
|
| @@ -543,10 +547,15 @@ class ResolverTask extends CompilerTask {
|
| });
|
| }
|
|
|
| + /// Creates a [ResolverVisitor] for resolving an AST in context of [element].
|
| + /// If [useEnclosingScope] is `true` then the initial scope of the visitor
|
| + /// does not include inner scope of [element].
|
| + ///
|
| /// This method should only be used by this library (or tests of
|
| /// this library).
|
| - ResolverVisitor visitorFor(Element element) {
|
| - return new ResolverVisitor(compiler, element, _ensureTreeElements(element));
|
| + ResolverVisitor visitorFor(Element element, {bool useEnclosingScope: false}) {
|
| + return new ResolverVisitor(compiler, element,
|
| + _ensureTreeElements(element), useEnclosingScope: useEnclosingScope);
|
| }
|
|
|
| TreeElements resolveField(VariableElementX element) {
|
| @@ -1185,20 +1194,18 @@ class ResolverTask extends CompilerTask {
|
| annotation.resolutionState = STATE_STARTED;
|
|
|
| Node node = annotation.parseNode(compiler);
|
| - // TODO(johnniwinther): Find the right analyzable element to hold the
|
| - // [TreeElements] for the annotation.
|
| Element annotatedElement = annotation.annotatedElement;
|
| - Element context = annotatedElement.enclosingElement;
|
| - if (context == null) {
|
| - context = annotatedElement;
|
| - }
|
| - ResolverVisitor visitor = visitorFor(context);
|
| + AnalyzableElement context = annotatedElement.analyzableElement;
|
| + assert(invariant(node, context != null,
|
| + message: "No context found for metadata annotation "
|
| + "on $annotatedElement."));
|
| + ResolverVisitor visitor = visitorFor(context, useEnclosingScope: true);
|
| node.accept(visitor);
|
| annotation.value =
|
| constantCompiler.compileMetadata(annotation, node, visitor.mapping);
|
| // TODO(johnniwinther): Register the relation between the annotation
|
| - // and the annotated element instead. This will allow the backed to
|
| - // retrieve the backend constant and only registered metadata on the
|
| + // and the annotated element instead. This will allow the backend to
|
| + // retrieve the backend constant and only register metadata on the
|
| // elements for which it is needed. (Issue 17732).
|
| compiler.backend.registerMetadataConstant(
|
| annotation.value, visitor.mapping);
|
| @@ -2003,7 +2010,8 @@ class ResolverVisitor extends MappingVisitor<Element> {
|
|
|
| ResolverVisitor(Compiler compiler,
|
| Element element,
|
| - TreeElementMapping mapping)
|
| + TreeElementMapping mapping,
|
| + {bool useEnclosingScope: false})
|
| : this.enclosingElement = element,
|
| // When the element is a field, we are actually resolving its
|
| // initial value, which should not have access to instance
|
| @@ -2013,7 +2021,8 @@ class ResolverVisitor extends MappingVisitor<Element> {
|
| this.currentClass = element.isMember ? element.enclosingClass
|
| : null,
|
| this.statementScope = new StatementScope(),
|
| - scope = element.buildScope(),
|
| + scope = useEnclosingScope
|
| + ? Scope.buildEnclosingScope(element) : element.buildScope(),
|
| // The type annotations on a typedef do not imply type checks.
|
| // TODO(karlklose): clean this up (dartbug.com/8870).
|
| inCheckContext = compiler.enableTypeAssertions &&
|
| @@ -4657,14 +4666,14 @@ Element lookupInScope(Compiler compiler, Node node,
|
| return Elements.unwrap(scope.lookup(name), compiler, node);
|
| }
|
|
|
| -TreeElements _ensureTreeElements(AnalyzableElement element) {
|
| +TreeElements _ensureTreeElements(AnalyzableElementX element) {
|
| if (element._treeElements == null) {
|
| element._treeElements = new TreeElementMapping(element);
|
| }
|
| return element._treeElements;
|
| }
|
|
|
| -abstract class AnalyzableElement implements Element {
|
| +abstract class AnalyzableElementX implements AnalyzableElement {
|
| TreeElements _treeElements;
|
|
|
| bool get hasTreeElements => _treeElements != null;
|
|
|