| 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 // This code was auto-generated, is not intended to be edited, and is subject to | |
| 6 // significant change. Please see the README file for more information. | |
| 7 | |
| 8 library engine.testing.element_factory; | 5 library engine.testing.element_factory; |
| 9 | 6 |
| 10 import 'dart:collection'; | 7 import 'dart:collection'; |
| 11 | 8 |
| 12 import 'package:analyzer/src/generated/ast.dart'; | 9 import 'package:analyzer/src/generated/ast.dart'; |
| 13 import 'package:analyzer/src/generated/constant.dart'; | 10 import 'package:analyzer/src/generated/constant.dart'; |
| 14 import 'package:analyzer/src/generated/element.dart'; | 11 import 'package:analyzer/src/generated/element.dart'; |
| 15 import 'package:analyzer/src/generated/engine.dart'; | 12 import 'package:analyzer/src/generated/engine.dart'; |
| 16 import 'package:analyzer/src/generated/java_core.dart'; | 13 import 'package:analyzer/src/generated/java_core.dart'; |
| 17 import 'package:analyzer/src/generated/resolver.dart'; | 14 import 'package:analyzer/src/generated/resolver.dart'; |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 } | 187 } |
| 191 // | 188 // |
| 192 // Finish building the enum. | 189 // Finish building the enum. |
| 193 // | 190 // |
| 194 enumElement.fields = fields; | 191 enumElement.fields = fields; |
| 195 // Client code isn't allowed to invoke the constructor, so we do not model i
t. | 192 // Client code isn't allowed to invoke the constructor, so we do not model i
t. |
| 196 return enumElement; | 193 return enumElement; |
| 197 } | 194 } |
| 198 | 195 |
| 199 static ExportElementImpl exportFor(LibraryElement exportedLibrary, | 196 static ExportElementImpl exportFor(LibraryElement exportedLibrary, |
| 200 [List<NamespaceCombinator> combinators = NamespaceCombinator.EMPTY_LIST])
{ | 197 [List<NamespaceCombinator> combinators = |
| 198 NamespaceCombinator.EMPTY_LIST]) { |
| 201 ExportElementImpl spec = new ExportElementImpl(-1); | 199 ExportElementImpl spec = new ExportElementImpl(-1); |
| 202 spec.exportedLibrary = exportedLibrary; | 200 spec.exportedLibrary = exportedLibrary; |
| 203 spec.combinators = combinators; | 201 spec.combinators = combinators; |
| 204 return spec; | 202 return spec; |
| 205 } | 203 } |
| 206 | 204 |
| 207 static FieldElementImpl fieldElement( | 205 static FieldElementImpl fieldElement( |
| 208 String name, bool isStatic, bool isFinal, bool isConst, DartType type) { | 206 String name, bool isStatic, bool isFinal, bool isConst, DartType type) { |
| 209 FieldElementImpl field = new FieldElementImpl(name, 0); | 207 FieldElementImpl field = new FieldElementImpl(name, 0); |
| 210 field.const3 = isConst; | 208 field.const3 = isConst; |
| 211 field.final2 = isFinal; | 209 field.final2 = isFinal; |
| 212 field.static = isStatic; | 210 field.static = isStatic; |
| 213 field.type = type; | 211 field.type = type; |
| 214 PropertyAccessorElementImpl getter = | 212 PropertyAccessorElementImpl getter = |
| 215 new PropertyAccessorElementImpl.forVariable(field); | 213 new PropertyAccessorElementImpl.forVariable(field); |
| 216 getter.getter = true; | 214 getter.getter = true; |
| 217 getter.synthetic = true; | 215 getter.synthetic = true; |
| 218 getter.variable = field; | 216 getter.variable = field; |
| 219 getter.returnType = type; | 217 getter.returnType = type; |
| 220 field.getter = getter; | 218 field.getter = getter; |
| 221 FunctionTypeImpl getterType = new FunctionTypeImpl(getter); | 219 FunctionTypeImpl getterType = new FunctionTypeImpl(getter); |
| 222 getter.type = getterType; | 220 getter.type = getterType; |
| 223 if (!isConst && !isFinal) { | 221 if (!isConst && !isFinal) { |
| 224 PropertyAccessorElementImpl setter = | 222 PropertyAccessorElementImpl setter = |
| 225 new PropertyAccessorElementImpl.forVariable(field); | 223 new PropertyAccessorElementImpl.forVariable(field); |
| 226 setter.setter = true; | 224 setter.setter = true; |
| 227 setter.synthetic = true; | 225 setter.synthetic = true; |
| 228 setter.variable = field; | 226 setter.variable = field; |
| 229 setter.parameters = | 227 setter.parameters = <ParameterElement>[ |
| 230 <ParameterElement>[requiredParameter2("_$name", type)]; | 228 requiredParameter2("_$name", type) |
| 229 ]; |
| 231 setter.returnType = VoidTypeImpl.instance; | 230 setter.returnType = VoidTypeImpl.instance; |
| 232 setter.type = new FunctionTypeImpl(setter); | 231 setter.type = new FunctionTypeImpl(setter); |
| 233 field.setter = setter; | 232 field.setter = setter; |
| 234 } | 233 } |
| 235 return field; | 234 return field; |
| 236 } | 235 } |
| 237 | 236 |
| 238 static FieldFormalParameterElementImpl fieldFormalParameter( | 237 static FieldFormalParameterElementImpl fieldFormalParameter( |
| 239 Identifier name) => new FieldFormalParameterElementImpl(name); | 238 Identifier name) => |
| 239 new FieldFormalParameterElementImpl(name); |
| 240 | 240 |
| 241 static FunctionElementImpl functionElement(String functionName) => | 241 static FunctionElementImpl functionElement(String functionName) => |
| 242 functionElement4(functionName, null, null, null, null); | 242 functionElement4(functionName, null, null, null, null); |
| 243 | 243 |
| 244 static FunctionElementImpl functionElement2( | 244 static FunctionElementImpl functionElement2( |
| 245 String functionName, ClassElement returnElement) => | 245 String functionName, ClassElement returnElement) => |
| 246 functionElement3(functionName, returnElement, null, null); | 246 functionElement3(functionName, returnElement, null, null); |
| 247 | 247 |
| 248 static FunctionElementImpl functionElement3(String functionName, | 248 static FunctionElementImpl functionElement3( |
| 249 ClassElement returnElement, List<ClassElement> normalParameters, | 249 String functionName, |
| 250 List<ClassElement> optionalParameters) { | 250 ClassElement returnElement, |
| 251 List<TypeDefiningElement> normalParameters, |
| 252 List<TypeDefiningElement> optionalParameters) { |
| 251 // We don't create parameter elements because we don't have parameter names | 253 // We don't create parameter elements because we don't have parameter names |
| 252 FunctionElementImpl functionElement = | 254 FunctionElementImpl functionElement = |
| 253 new FunctionElementImpl(functionName, 0); | 255 new FunctionElementImpl(functionName, 0); |
| 254 FunctionTypeImpl functionType = new FunctionTypeImpl(functionElement); | 256 FunctionTypeImpl functionType = new FunctionTypeImpl(functionElement); |
| 255 functionElement.type = functionType; | 257 functionElement.type = functionType; |
| 256 // return type | 258 // return type |
| 257 if (returnElement == null) { | 259 if (returnElement == null) { |
| 258 functionElement.returnType = VoidTypeImpl.instance; | 260 functionElement.returnType = VoidTypeImpl.instance; |
| 259 } else { | 261 } else { |
| 260 functionElement.returnType = returnElement.type; | 262 functionElement.returnType = returnElement.type; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 274 parameter.type = optionalParameters[i - normalCount].type; | 276 parameter.type = optionalParameters[i - normalCount].type; |
| 275 parameter.parameterKind = ParameterKind.POSITIONAL; | 277 parameter.parameterKind = ParameterKind.POSITIONAL; |
| 276 } | 278 } |
| 277 parameters[i] = parameter; | 279 parameters[i] = parameter; |
| 278 } | 280 } |
| 279 functionElement.parameters = parameters; | 281 functionElement.parameters = parameters; |
| 280 // done | 282 // done |
| 281 return functionElement; | 283 return functionElement; |
| 282 } | 284 } |
| 283 | 285 |
| 284 static FunctionElementImpl functionElement4(String functionName, | 286 static FunctionElementImpl functionElement4( |
| 285 ClassElement returnElement, List<ClassElement> normalParameters, | 287 String functionName, |
| 286 List<String> names, List<ClassElement> namedParameters) { | 288 ClassElement returnElement, |
| 289 List<ClassElement> normalParameters, |
| 290 List<String> names, |
| 291 List<ClassElement> namedParameters) { |
| 287 FunctionElementImpl functionElement = | 292 FunctionElementImpl functionElement = |
| 288 new FunctionElementImpl(functionName, 0); | 293 new FunctionElementImpl(functionName, 0); |
| 289 FunctionTypeImpl functionType = new FunctionTypeImpl(functionElement); | 294 FunctionTypeImpl functionType = new FunctionTypeImpl(functionElement); |
| 290 functionElement.type = functionType; | 295 functionElement.type = functionType; |
| 291 // parameters | 296 // parameters |
| 292 int normalCount = normalParameters == null ? 0 : normalParameters.length; | 297 int normalCount = normalParameters == null ? 0 : normalParameters.length; |
| 293 int nameCount = names == null ? 0 : names.length; | 298 int nameCount = names == null ? 0 : names.length; |
| 294 int typeCount = namedParameters == null ? 0 : namedParameters.length; | 299 int typeCount = namedParameters == null ? 0 : namedParameters.length; |
| 295 if (names != null && nameCount != typeCount) { | 300 if (names != null && nameCount != typeCount) { |
| 296 throw new IllegalStateException( | 301 throw new IllegalStateException( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 319 } else { | 324 } else { |
| 320 functionElement.returnType = returnElement.type; | 325 functionElement.returnType = returnElement.type; |
| 321 } | 326 } |
| 322 return functionElement; | 327 return functionElement; |
| 323 } | 328 } |
| 324 | 329 |
| 325 static FunctionElementImpl functionElement5( | 330 static FunctionElementImpl functionElement5( |
| 326 String functionName, List<ClassElement> normalParameters) => | 331 String functionName, List<ClassElement> normalParameters) => |
| 327 functionElement3(functionName, null, normalParameters, null); | 332 functionElement3(functionName, null, normalParameters, null); |
| 328 | 333 |
| 329 static FunctionElementImpl functionElement6(String functionName, | 334 static FunctionElementImpl functionElement6( |
| 330 List<ClassElement> normalParameters, | 335 String functionName, |
| 331 List<ClassElement> optionalParameters) => functionElement3( | 336 List<ClassElement> normalParameters, |
| 337 List<ClassElement> optionalParameters) => |
| 338 functionElement3( |
| 332 functionName, null, normalParameters, optionalParameters); | 339 functionName, null, normalParameters, optionalParameters); |
| 333 | 340 |
| 334 static FunctionElementImpl functionElement7(String functionName, | 341 static FunctionElementImpl functionElement7( |
| 335 List<ClassElement> normalParameters, List<String> names, | 342 String functionName, |
| 336 List<ClassElement> namedParameters) => functionElement4( | 343 List<ClassElement> normalParameters, |
| 344 List<String> names, |
| 345 List<ClassElement> namedParameters) => |
| 346 functionElement4( |
| 337 functionName, null, normalParameters, names, namedParameters); | 347 functionName, null, normalParameters, names, namedParameters); |
| 338 | 348 |
| 349 static FunctionElementImpl functionElement8( |
| 350 List<DartType> parameters, DartType returnType, |
| 351 {List<DartType> optional, Map<String, DartType> named}) { |
| 352 List<ParameterElement> parameterElements = new List<ParameterElement>(); |
| 353 for (int i = 0; i < parameters.length; i++) { |
| 354 ParameterElementImpl parameterElement = |
| 355 new ParameterElementImpl("a$i", i); |
| 356 parameterElement.type = parameters[i]; |
| 357 parameterElement.parameterKind = ParameterKind.REQUIRED; |
| 358 parameterElements.add(parameterElement); |
| 359 } |
| 360 if (optional != null) { |
| 361 int j = parameters.length; |
| 362 for (int i = 0; i < optional.length; i++) { |
| 363 ParameterElementImpl parameterElement = |
| 364 new ParameterElementImpl("o$i", j); |
| 365 parameterElement.type = optional[i]; |
| 366 parameterElement.parameterKind = ParameterKind.POSITIONAL; |
| 367 parameterElements.add(parameterElement); |
| 368 j++; |
| 369 } |
| 370 } else if (named != null) { |
| 371 int j = parameters.length; |
| 372 for (String s in named.keys) { |
| 373 ParameterElementImpl parameterElement = new ParameterElementImpl(s, j); |
| 374 parameterElement.type = named[s]; |
| 375 parameterElement.parameterKind = ParameterKind.NAMED; |
| 376 parameterElements.add(parameterElement); |
| 377 } |
| 378 } |
| 379 |
| 380 return functionElementWithParameters("f", returnType, parameterElements); |
| 381 } |
| 382 |
| 339 static FunctionElementImpl functionElementWithParameters(String functionName, | 383 static FunctionElementImpl functionElementWithParameters(String functionName, |
| 340 DartType returnType, List<ParameterElement> parameters) { | 384 DartType returnType, List<ParameterElement> parameters) { |
| 341 FunctionElementImpl functionElement = | 385 FunctionElementImpl functionElement = |
| 342 new FunctionElementImpl(functionName, 0); | 386 new FunctionElementImpl(functionName, 0); |
| 343 functionElement.returnType = | 387 functionElement.returnType = |
| 344 returnType == null ? VoidTypeImpl.instance : returnType; | 388 returnType == null ? VoidTypeImpl.instance : returnType; |
| 345 functionElement.parameters = parameters; | 389 functionElement.parameters = parameters; |
| 346 FunctionTypeImpl functionType = new FunctionTypeImpl(functionElement); | 390 FunctionTypeImpl functionType = new FunctionTypeImpl(functionElement); |
| 347 functionElement.type = functionType; | 391 functionElement.type = functionType; |
| 348 return functionElement; | 392 return functionElement; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 377 static HtmlElementImpl htmlUnit(AnalysisContext context, String fileName) { | 421 static HtmlElementImpl htmlUnit(AnalysisContext context, String fileName) { |
| 378 Source source = | 422 Source source = |
| 379 new NonExistingSource(fileName, toUri(fileName), UriKind.FILE_URI); | 423 new NonExistingSource(fileName, toUri(fileName), UriKind.FILE_URI); |
| 380 HtmlElementImpl unit = new HtmlElementImpl(context, fileName); | 424 HtmlElementImpl unit = new HtmlElementImpl(context, fileName); |
| 381 unit.source = source; | 425 unit.source = source; |
| 382 return unit; | 426 return unit; |
| 383 } | 427 } |
| 384 | 428 |
| 385 static ImportElementImpl importFor( | 429 static ImportElementImpl importFor( |
| 386 LibraryElement importedLibrary, PrefixElement prefix, | 430 LibraryElement importedLibrary, PrefixElement prefix, |
| 387 [List<NamespaceCombinator> combinators = NamespaceCombinator.EMPTY_LIST])
{ | 431 [List<NamespaceCombinator> combinators = |
| 432 NamespaceCombinator.EMPTY_LIST]) { |
| 388 ImportElementImpl spec = new ImportElementImpl(0); | 433 ImportElementImpl spec = new ImportElementImpl(0); |
| 389 spec.importedLibrary = importedLibrary; | 434 spec.importedLibrary = importedLibrary; |
| 390 spec.prefix = prefix; | 435 spec.prefix = prefix; |
| 391 spec.combinators = combinators; | 436 spec.combinators = combinators; |
| 392 return spec; | 437 return spec; |
| 393 } | 438 } |
| 394 | 439 |
| 395 static LibraryElementImpl library( | 440 static LibraryElementImpl library( |
| 396 AnalysisContext context, String libraryName) { | 441 AnalysisContext context, String libraryName) { |
| 397 String fileName = "/$libraryName.dart"; | 442 String fileName = "/$libraryName.dart"; |
| 398 CompilationUnitElementImpl unit = compilationUnit(fileName); | 443 CompilationUnitElementImpl unit = compilationUnit(fileName); |
| 399 LibraryElementImpl library = | 444 LibraryElementImpl library = |
| 400 new LibraryElementImpl(context, libraryName, 0); | 445 new LibraryElementImpl(context, libraryName, 0, libraryName.length); |
| 401 library.definingCompilationUnit = unit; | 446 library.definingCompilationUnit = unit; |
| 402 return library; | 447 return library; |
| 403 } | 448 } |
| 404 | 449 |
| 405 static LocalVariableElementImpl localVariableElement(Identifier name) => | 450 static LocalVariableElementImpl localVariableElement(Identifier name) => |
| 406 new LocalVariableElementImpl.forNode(name); | 451 new LocalVariableElementImpl.forNode(name); |
| 407 | 452 |
| 408 static LocalVariableElementImpl localVariableElement2(String name) => | 453 static LocalVariableElementImpl localVariableElement2(String name) => |
| 409 new LocalVariableElementImpl(name, 0); | 454 new LocalVariableElementImpl(name, 0); |
| 410 | 455 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 423 parameters[i] = parameter; | 468 parameters[i] = parameter; |
| 424 } | 469 } |
| 425 method.parameters = parameters; | 470 method.parameters = parameters; |
| 426 } | 471 } |
| 427 method.returnType = returnType; | 472 method.returnType = returnType; |
| 428 FunctionTypeImpl methodType = new FunctionTypeImpl(method); | 473 FunctionTypeImpl methodType = new FunctionTypeImpl(method); |
| 429 method.type = methodType; | 474 method.type = methodType; |
| 430 return method; | 475 return method; |
| 431 } | 476 } |
| 432 | 477 |
| 433 static MethodElementImpl methodElementWithParameters(String methodName, | 478 static MethodElementImpl methodElementWithParameters( |
| 434 List<DartType> typeArguments, DartType returnType, | 479 String methodName, |
| 480 List<DartType> typeArguments, |
| 481 DartType returnType, |
| 435 List<ParameterElement> parameters) { | 482 List<ParameterElement> parameters) { |
| 436 MethodElementImpl method = new MethodElementImpl(methodName, 0); | 483 MethodElementImpl method = new MethodElementImpl(methodName, 0); |
| 437 method.parameters = parameters; | 484 method.parameters = parameters; |
| 438 method.returnType = returnType; | 485 method.returnType = returnType; |
| 439 FunctionTypeImpl methodType = new FunctionTypeImpl(method); | 486 FunctionTypeImpl methodType = new FunctionTypeImpl(method); |
| 440 methodType.typeArguments = typeArguments; | 487 methodType.typeArguments = typeArguments; |
| 441 method.type = methodType; | 488 method.type = methodType; |
| 442 return method; | 489 return method; |
| 443 } | 490 } |
| 444 | 491 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 variable.getter = getter; | 588 variable.getter = getter; |
| 542 FunctionTypeImpl getterType = new FunctionTypeImpl(getter); | 589 FunctionTypeImpl getterType = new FunctionTypeImpl(getter); |
| 543 getter.type = getterType; | 590 getter.type = getterType; |
| 544 if (!isConst && !isFinal) { | 591 if (!isConst && !isFinal) { |
| 545 PropertyAccessorElementImpl setter = | 592 PropertyAccessorElementImpl setter = |
| 546 new PropertyAccessorElementImpl.forVariable(variable); | 593 new PropertyAccessorElementImpl.forVariable(variable); |
| 547 setter.setter = true; | 594 setter.setter = true; |
| 548 setter.static = true; | 595 setter.static = true; |
| 549 setter.synthetic = true; | 596 setter.synthetic = true; |
| 550 setter.variable = variable; | 597 setter.variable = variable; |
| 551 setter.parameters = | 598 setter.parameters = <ParameterElement>[ |
| 552 <ParameterElement>[requiredParameter2("_$name", type)]; | 599 requiredParameter2("_$name", type) |
| 600 ]; |
| 553 setter.returnType = VoidTypeImpl.instance; | 601 setter.returnType = VoidTypeImpl.instance; |
| 554 setter.type = new FunctionTypeImpl(setter); | 602 setter.type = new FunctionTypeImpl(setter); |
| 555 variable.setter = setter; | 603 variable.setter = setter; |
| 556 } | 604 } |
| 557 return variable; | 605 return variable; |
| 558 } | 606 } |
| 559 | 607 |
| 560 static TypeParameterElementImpl typeParameterElement(String name) { | 608 static TypeParameterElementImpl typeParameterElement(String name) { |
| 561 TypeParameterElementImpl element = new TypeParameterElementImpl(name, 0); | 609 TypeParameterElementImpl element = new TypeParameterElementImpl(name, 0); |
| 562 element.type = new TypeParameterTypeImpl(element); | 610 element.type = new TypeParameterTypeImpl(element); |
| 563 return element; | 611 return element; |
| 564 } | 612 } |
| 565 } | 613 } |
| OLD | NEW |