OLD | NEW |
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 analyzer.src.dart.resolver.scope; | 5 library analyzer.src.dart.resolver.scope; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
10 import 'package:analyzer/dart/element/element.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
(...skipping 1089 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1100 /** | 1100 /** |
1101 * Add the given [element] to this scope. If there is already an element with | 1101 * Add the given [element] to this scope. If there is already an element with |
1102 * the given name defined in this scope, then an error will be generated and | 1102 * the given name defined in this scope, then an error will be generated and |
1103 * the original element will continue to be mapped to the name. If there is an | 1103 * the original element will continue to be mapped to the name. If there is an |
1104 * element with the given name in an enclosing scope, then a warning will be | 1104 * element with the given name in an enclosing scope, then a warning will be |
1105 * generated but the given element will hide the inherited element. | 1105 * generated but the given element will hide the inherited element. |
1106 */ | 1106 */ |
1107 void define(Element element) { | 1107 void define(Element element) { |
1108 String name = _getName(element); | 1108 String name = _getName(element); |
1109 if (name != null && !name.isEmpty) { | 1109 if (name != null && !name.isEmpty) { |
1110 if (_definedNames != null && _definedNames.containsKey(name)) { | 1110 _definedNames ??= new HashMap<String, Element>(); |
1111 errorListener | 1111 _definedNames.putIfAbsent(name, () => element); |
1112 .onError(getErrorForDuplicate(_definedNames[name], element)); | |
1113 } else { | |
1114 _definedNames ??= new HashMap<String, Element>(); | |
1115 _definedNames[name] = element; | |
1116 } | |
1117 } | 1112 } |
1118 } | 1113 } |
1119 | 1114 |
1120 /** | 1115 /** |
1121 * Add the given [element] to this scope without checking for duplication or | 1116 * Add the given [element] to this scope without checking for duplication or |
1122 * hiding. | 1117 * hiding. |
1123 */ | 1118 */ |
1124 void defineNameWithoutChecking(String name, Element element) { | 1119 void defineNameWithoutChecking(String name, Element element) { |
1125 _definedNames ??= new HashMap<String, Element>(); | 1120 _definedNames ??= new HashMap<String, Element>(); |
1126 _definedNames[name] = element; | 1121 _definedNames[name] = element; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1270 | 1265 |
1271 /** | 1266 /** |
1272 * Define the type parameters declared by the [classElement]. | 1267 * Define the type parameters declared by the [classElement]. |
1273 */ | 1268 */ |
1274 void _defineTypeParameters(ClassElement classElement) { | 1269 void _defineTypeParameters(ClassElement classElement) { |
1275 for (TypeParameterElement typeParameter in classElement.typeParameters) { | 1270 for (TypeParameterElement typeParameter in classElement.typeParameters) { |
1276 define(typeParameter); | 1271 define(typeParameter); |
1277 } | 1272 } |
1278 } | 1273 } |
1279 } | 1274 } |
OLD | NEW |