| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 dart2js.resolution.scope; | 5 library dart2js.resolution.scope; |
| 6 | 6 |
| 7 import '../dart_types.dart'; | 7 import '../dart_types.dart'; |
| 8 import '../elements/elements.dart'; | 8 import '../elements/elements.dart'; |
| 9 | 9 |
| 10 abstract class Scope { | 10 abstract class Scope { |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 | 166 |
| 167 Element localLookup(String name) => library.find(name); | 167 Element localLookup(String name) => library.find(name); |
| 168 Element lookup(String name) => localLookup(name); | 168 Element lookup(String name) => localLookup(name); |
| 169 | 169 |
| 170 Element add(Element newElement) { | 170 Element add(Element newElement) { |
| 171 throw "Cannot add an element to a library scope"; | 171 throw "Cannot add an element to a library scope"; |
| 172 } | 172 } |
| 173 | 173 |
| 174 String toString() => 'LibraryScope($library)'; | 174 String toString() => 'LibraryScope($library)'; |
| 175 } | 175 } |
| 176 |
| 177 /// A mixin application scope. |
| 178 /// |
| 179 /// This scope is slightly different from a regular [ClassScope] as we copy |
| 180 /// methods from the mixin into the mixin application. Firstly, the parent |
| 181 /// scope is the mixin (and its library scope). Secondly, since a mixin |
| 182 /// application can have more type variables than the mixin, we need to ensure |
| 183 /// we only return the ones defined in the mixin (by overriding |
| 184 /// [lookupTypeVariable]). See [ClassResolverVisitor.applyMixin] for details. |
| 185 class MixinApplicationScope extends ClassScope { |
| 186 MixinApplicationElement get element => super.element; |
| 187 |
| 188 MixinApplicationScope(Scope parentScope, MixinApplicationElement element) |
| 189 : super(parentScope, element); |
| 190 |
| 191 @override |
| 192 Element lookupTypeVariable(String name) { |
| 193 List<DartType> typeVariables = element.mixin?.typeVariables; |
| 194 if (typeVariables == null) return null; |
| 195 int index = 0; |
| 196 for (TypeVariableType type in typeVariables) { |
| 197 if (type.name == name) return element.typeVariables[index].element; |
| 198 index++; |
| 199 } |
| 200 return null; |
| 201 } |
| 202 } |
| 203 |
| 204 /// An empty scope, used for error recovery. |
| 205 class NoScope extends Scope { |
| 206 @override |
| 207 Element add(Element element) { |
| 208 throw "Cannot add an element to a no-scope"; |
| 209 } |
| 210 |
| 211 @override |
| 212 Element lookup(String name) => null; |
| 213 } |
| OLD | NEW |