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'; |
11 import 'package:analyzer/src/dart/element/element.dart'; | 11 import 'package:analyzer/src/dart/element/element.dart'; |
12 import 'package:analyzer/src/generated/engine.dart'; | 12 import 'package:analyzer/src/generated/engine.dart'; |
13 import 'package:analyzer/src/generated/error.dart'; | 13 import 'package:analyzer/src/generated/error.dart'; |
14 import 'package:analyzer/src/generated/java_core.dart'; | 14 import 'package:analyzer/src/generated/java_core.dart'; |
15 import 'package:analyzer/src/generated/java_engine.dart'; | 15 import 'package:analyzer/src/generated/java_engine.dart'; |
16 import 'package:analyzer/src/generated/source.dart'; | 16 import 'package:analyzer/src/generated/source.dart'; |
17 | 17 |
18 /** | 18 /** |
19 * The scope defined by a block. | 19 * The scope defined by a block. |
20 */ | 20 */ |
21 class BlockScope extends EnclosedScope { | 21 class BlockScope extends EnclosedScope { |
22 /** | 22 /** |
23 * Initialize a newly created scope, enclosed within the [enclosingScope], | 23 * Initialize a newly created scope, enclosed within the [enclosingScope], |
24 * based on the given [classElement]. | 24 * based on the given [classElement]. |
25 */ | 25 */ |
26 BlockScope(Scope enclosingScope, Block block) : super(enclosingScope) { | 26 BlockScope(Scope enclosingScope, Block block) : super(enclosingScope) { |
27 if (block == null) { | 27 if (block == null) { |
28 throw new IllegalArgumentException("block cannot be null"); | 28 throw new ArgumentError("block cannot be null"); |
29 } | 29 } |
30 _defineElements(block); | 30 _defineElements(block); |
31 } | 31 } |
32 | 32 |
33 void _defineElements(Block block) { | 33 void _defineElements(Block block) { |
34 for (Element element in elementsInBlock(block)) { | 34 for (Element element in elementsInBlock(block)) { |
35 define(element); | 35 define(element); |
36 } | 36 } |
37 } | 37 } |
38 | 38 |
(...skipping 23 matching lines...) Expand all Loading... |
62 * The scope defined by a class. | 62 * The scope defined by a class. |
63 */ | 63 */ |
64 class ClassScope extends EnclosedScope { | 64 class ClassScope extends EnclosedScope { |
65 /** | 65 /** |
66 * Initialize a newly created scope, enclosed within the [enclosingScope], | 66 * Initialize a newly created scope, enclosed within the [enclosingScope], |
67 * based on the given [classElement]. | 67 * based on the given [classElement]. |
68 */ | 68 */ |
69 ClassScope(Scope enclosingScope, ClassElement classElement) | 69 ClassScope(Scope enclosingScope, ClassElement classElement) |
70 : super(enclosingScope) { | 70 : super(enclosingScope) { |
71 if (classElement == null) { | 71 if (classElement == null) { |
72 throw new IllegalArgumentException("class element cannot be null"); | 72 throw new ArgumentError("class element cannot be null"); |
73 } | 73 } |
74 _defineMembers(classElement); | 74 _defineMembers(classElement); |
75 } | 75 } |
76 | 76 |
77 @override | 77 @override |
78 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) { | 78 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) { |
79 if (existing is PropertyAccessorElement && duplicate is MethodElement) { | 79 if (existing is PropertyAccessorElement && duplicate is MethodElement) { |
80 if (existing.nameOffset < duplicate.nameOffset) { | 80 if (existing.nameOffset < duplicate.nameOffset) { |
81 return new AnalysisError( | 81 return new AnalysisError( |
82 duplicate.source, | 82 duplicate.source, |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 */ | 166 */ |
167 bool _parametersDefined = false; | 167 bool _parametersDefined = false; |
168 | 168 |
169 /** | 169 /** |
170 * Initialize a newly created scope, enclosed within the [enclosingScope], | 170 * Initialize a newly created scope, enclosed within the [enclosingScope], |
171 * that represents the given [_functionElement]. | 171 * that represents the given [_functionElement]. |
172 */ | 172 */ |
173 FunctionScope(Scope enclosingScope, this._functionElement) | 173 FunctionScope(Scope enclosingScope, this._functionElement) |
174 : super(new EnclosedScope(new EnclosedScope(enclosingScope))) { | 174 : super(new EnclosedScope(new EnclosedScope(enclosingScope))) { |
175 if (_functionElement == null) { | 175 if (_functionElement == null) { |
176 throw new IllegalArgumentException("function element cannot be null"); | 176 throw new ArgumentError("function element cannot be null"); |
177 } | 177 } |
178 _defineTypeParameters(); | 178 _defineTypeParameters(); |
179 } | 179 } |
180 | 180 |
181 /** | 181 /** |
182 * Define the parameters for the given function in the scope that encloses | 182 * Define the parameters for the given function in the scope that encloses |
183 * this function. | 183 * this function. |
184 */ | 184 */ |
185 void defineParameters() { | 185 void defineParameters() { |
186 if (_parametersDefined) { | 186 if (_parametersDefined) { |
(...skipping 960 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1147 * The scope defined by the type parameters in a class. | 1147 * The scope defined by the type parameters in a class. |
1148 */ | 1148 */ |
1149 class TypeParameterScope extends EnclosedScope { | 1149 class TypeParameterScope extends EnclosedScope { |
1150 /** | 1150 /** |
1151 * Initialize a newly created scope, enclosed within the [enclosingScope], | 1151 * Initialize a newly created scope, enclosed within the [enclosingScope], |
1152 * that defined the type parameters from the given [classElement]. | 1152 * that defined the type parameters from the given [classElement]. |
1153 */ | 1153 */ |
1154 TypeParameterScope(Scope enclosingScope, ClassElement classElement) | 1154 TypeParameterScope(Scope enclosingScope, ClassElement classElement) |
1155 : super(enclosingScope) { | 1155 : super(enclosingScope) { |
1156 if (classElement == null) { | 1156 if (classElement == null) { |
1157 throw new IllegalArgumentException("class element cannot be null"); | 1157 throw new ArgumentError("class element cannot be null"); |
1158 } | 1158 } |
1159 _defineTypeParameters(classElement); | 1159 _defineTypeParameters(classElement); |
1160 } | 1160 } |
1161 | 1161 |
1162 /** | 1162 /** |
1163 * Define the type parameters declared by the [classElement]. | 1163 * Define the type parameters declared by the [classElement]. |
1164 */ | 1164 */ |
1165 void _defineTypeParameters(ClassElement classElement) { | 1165 void _defineTypeParameters(ClassElement classElement) { |
1166 for (TypeParameterElement typeParameter in classElement.typeParameters) { | 1166 for (TypeParameterElement typeParameter in classElement.typeParameters) { |
1167 define(typeParameter); | 1167 define(typeParameter); |
1168 } | 1168 } |
1169 } | 1169 } |
1170 } | 1170 } |
OLD | NEW |