| 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.generated.testing.element_factory; | 5 library analyzer.src.generated.testing.element_factory; |
| 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/ast/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 * order to ensure that state is not shared between multiple tests. | 223 * order to ensure that state is not shared between multiple tests. |
| 224 */ | 224 */ |
| 225 static void flushStaticState() { | 225 static void flushStaticState() { |
| 226 _objectElement = null; | 226 _objectElement = null; |
| 227 } | 227 } |
| 228 | 228 |
| 229 static FunctionElementImpl functionElement(String functionName) => | 229 static FunctionElementImpl functionElement(String functionName) => |
| 230 functionElement4(functionName, null, null, null, null); | 230 functionElement4(functionName, null, null, null, null); |
| 231 | 231 |
| 232 static FunctionElementImpl functionElement2( | 232 static FunctionElementImpl functionElement2( |
| 233 String functionName, TypeDefiningElement returnElement) => | 233 String functionName, DartType returnType) => |
| 234 functionElement3(functionName, returnElement, null, null); | 234 functionElement3(functionName, returnType, null, null); |
| 235 | 235 |
| 236 static FunctionElementImpl functionElement3( | 236 static FunctionElementImpl functionElement3( |
| 237 String functionName, | 237 String functionName, |
| 238 TypeDefiningElement returnElement, | 238 DartType returnType, |
| 239 List<TypeDefiningElement> normalParameters, | 239 List<TypeDefiningElement> normalParameters, |
| 240 List<TypeDefiningElement> optionalParameters) { | 240 List<TypeDefiningElement> optionalParameters) { |
| 241 // We don't create parameter elements because we don't have parameter names | 241 // We don't create parameter elements because we don't have parameter names |
| 242 FunctionElementImpl functionElement = | 242 FunctionElementImpl functionElement = |
| 243 new FunctionElementImpl(functionName, 0); | 243 new FunctionElementImpl(functionName, 0); |
| 244 FunctionTypeImpl functionType = new FunctionTypeImpl(functionElement); | 244 FunctionTypeImpl functionType = new FunctionTypeImpl(functionElement); |
| 245 functionElement.type = functionType; | 245 functionElement.type = functionType; |
| 246 // return type | 246 functionElement.returnType = returnType ?? VoidTypeImpl.instance; |
| 247 if (returnElement == null) { | |
| 248 functionElement.returnType = VoidTypeImpl.instance; | |
| 249 } else { | |
| 250 functionElement.returnType = returnElement.type; | |
| 251 } | |
| 252 // parameters | 247 // parameters |
| 253 int normalCount = normalParameters == null ? 0 : normalParameters.length; | 248 int normalCount = normalParameters == null ? 0 : normalParameters.length; |
| 254 int optionalCount = | 249 int optionalCount = |
| 255 optionalParameters == null ? 0 : optionalParameters.length; | 250 optionalParameters == null ? 0 : optionalParameters.length; |
| 256 int totalCount = normalCount + optionalCount; | 251 int totalCount = normalCount + optionalCount; |
| 257 List<ParameterElement> parameters = new List<ParameterElement>(totalCount); | 252 List<ParameterElement> parameters = new List<ParameterElement>(totalCount); |
| 258 for (int i = 0; i < totalCount; i++) { | 253 for (int i = 0; i < totalCount; i++) { |
| 259 ParameterElementImpl parameter = new ParameterElementImpl("a$i", i); | 254 ParameterElementImpl parameter = new ParameterElementImpl("a$i", i); |
| 260 if (i < normalCount) { | 255 if (i < normalCount) { |
| 261 parameter.type = normalParameters[i].type; | 256 parameter.type = normalParameters[i].type; |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 } | 602 } |
| 608 | 603 |
| 609 static TypeParameterElementImpl typeParameterWithType(String name, | 604 static TypeParameterElementImpl typeParameterWithType(String name, |
| 610 [DartType bound]) { | 605 [DartType bound]) { |
| 611 TypeParameterElementImpl typeParameter = typeParameterElement(name); | 606 TypeParameterElementImpl typeParameter = typeParameterElement(name); |
| 612 typeParameter.type = new TypeParameterTypeImpl(typeParameter); | 607 typeParameter.type = new TypeParameterTypeImpl(typeParameter); |
| 613 typeParameter.bound = bound; | 608 typeParameter.bound = bound; |
| 614 return typeParameter; | 609 return typeParameter; |
| 615 } | 610 } |
| 616 } | 611 } |
| OLD | NEW |