| 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 | 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. | 6 // significant change. Please see the README file for more information. |
| 7 | 7 |
| 8 library engine.testing.element_factory; | 8 library engine.testing.element_factory; |
| 9 | 9 |
| 10 import 'dart:collection'; | 10 import 'dart:collection'; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 * The class `ElementFactory` defines utility methods used to create elements fo
r testing | 21 * The class `ElementFactory` defines utility methods used to create elements fo
r testing |
| 22 * purposes. The elements that are created are complete in the sense that as muc
h of the element | 22 * purposes. The elements that are created are complete in the sense that as muc
h of the element |
| 23 * model as can be created, given the provided information, has been created. | 23 * model as can be created, given the provided information, has been created. |
| 24 */ | 24 */ |
| 25 class ElementFactory { | 25 class ElementFactory { |
| 26 /** | 26 /** |
| 27 * The element representing the class 'Object'. | 27 * The element representing the class 'Object'. |
| 28 */ | 28 */ |
| 29 static ClassElementImpl _objectElement; | 29 static ClassElementImpl _objectElement; |
| 30 | 30 |
| 31 static ClassElementImpl classElement(String typeName, InterfaceType superclass
Type, List<String> parameterNames) { | 31 static ClassElementImpl classElement(String typeName, InterfaceType superclass
Type, [List<String> parameterNames]) { |
| 32 ClassElementImpl element = new ClassElementImpl(typeName, 0); | 32 ClassElementImpl element = new ClassElementImpl(typeName, 0); |
| 33 element.supertype = superclassType; | 33 element.supertype = superclassType; |
| 34 InterfaceTypeImpl type = new InterfaceTypeImpl.con1(element); | 34 InterfaceTypeImpl type = new InterfaceTypeImpl.con1(element); |
| 35 element.type = type; | 35 element.type = type; |
| 36 int count = parameterNames.length; | 36 if (parameterNames != null) { |
| 37 if (count > 0) { | 37 int count = parameterNames.length; |
| 38 List<TypeParameterElementImpl> typeParameters = new List<TypeParameterElem
entImpl>(count); | 38 if (count > 0) { |
| 39 List<TypeParameterTypeImpl> typeParameterTypes = new List<TypeParameterTyp
eImpl>(count); | 39 List<TypeParameterElementImpl> typeParameters |
| 40 for (int i = 0; i < count; i++) { | 40 = new List<TypeParameterElementImpl>(count); |
| 41 TypeParameterElementImpl typeParameter = new TypeParameterElementImpl(pa
rameterNames[i], 0); | 41 List<TypeParameterTypeImpl> typeParameterTypes |
| 42 typeParameters[i] = typeParameter; | 42 = new List<TypeParameterTypeImpl>(count); |
| 43 typeParameterTypes[i] = new TypeParameterTypeImpl(typeParameter); | 43 for (int i = 0; i < count; i++) { |
| 44 typeParameter.type = typeParameterTypes[i]; | 44 TypeParameterElementImpl typeParameter |
| 45 = new TypeParameterElementImpl(parameterNames[i], 0); |
| 46 typeParameters[i] = typeParameter; |
| 47 typeParameterTypes[i] = new TypeParameterTypeImpl(typeParameter); |
| 48 typeParameter.type = typeParameterTypes[i]; |
| 49 } |
| 50 element.typeParameters = typeParameters; |
| 51 type.typeArguments = typeParameterTypes; |
| 45 } | 52 } |
| 46 element.typeParameters = typeParameters; | |
| 47 type.typeArguments = typeParameterTypes; | |
| 48 } | 53 } |
| 49 return element; | 54 return element; |
| 50 } | 55 } |
| 51 | 56 |
| 52 static ClassElementImpl classElement2(String typeName, List<String> parameterN
ames) => classElement(typeName, objectType, parameterNames); | 57 static ClassElementImpl classElement2(String typeName, [List<String> parameter
Names]) |
| 58 => classElement(typeName, objectType, parameterNames); |
| 53 | 59 |
| 54 static CompilationUnitElementImpl compilationUnit(String fileName) { | 60 static CompilationUnitElementImpl compilationUnit(String fileName) { |
| 55 Source source = new NonExistingSource(fileName, UriKind.FILE_URI); | 61 Source source = new NonExistingSource(fileName, UriKind.FILE_URI); |
| 56 CompilationUnitElementImpl unit = new CompilationUnitElementImpl(fileName); | 62 CompilationUnitElementImpl unit = new CompilationUnitElementImpl(fileName); |
| 57 unit.source = source; | 63 unit.source = source; |
| 58 return unit; | 64 return unit; |
| 59 } | 65 } |
| 60 | 66 |
| 61 static ConstructorElementImpl constructorElement(ClassElement definingClass, S
tring name, bool isConst, List<DartType> argumentTypes) { | 67 static ConstructorElementImpl constructorElement(ClassElement definingClass, S
tring name, bool isConst, [List<DartType> argumentTypes]) { |
| 62 DartType type = definingClass.type; | 68 DartType type = definingClass.type; |
| 63 ConstructorElementImpl constructor = name == null ? new ConstructorElementIm
pl("", -1) : new ConstructorElementImpl(name, 0); | 69 ConstructorElementImpl constructor = name == null ? new ConstructorElementIm
pl("", -1) : new ConstructorElementImpl(name, 0); |
| 64 constructor.const2 = isConst; | 70 constructor.const2 = isConst; |
| 65 int count = argumentTypes.length; | 71 if (argumentTypes != null) { |
| 66 List<ParameterElement> parameters = new List<ParameterElement>(count); | 72 int count = argumentTypes.length; |
| 67 for (int i = 0; i < count; i++) { | 73 List<ParameterElement> parameters = new List<ParameterElement>(count); |
| 68 ParameterElementImpl parameter = new ParameterElementImpl("a$i", i); | 74 for (int i = 0; i < count; i++) { |
| 69 parameter.type = argumentTypes[i]; | 75 ParameterElementImpl parameter = new ParameterElementImpl("a$i", i); |
| 70 parameter.parameterKind = ParameterKind.REQUIRED; | 76 parameter.type = argumentTypes[i]; |
| 71 parameters[i] = parameter; | 77 parameter.parameterKind = ParameterKind.REQUIRED; |
| 78 parameters[i] = parameter; |
| 79 } |
| 80 constructor.parameters = parameters; |
| 81 } else { |
| 82 constructor.parameters = <ParameterElement>[]; |
| 72 } | 83 } |
| 73 constructor.parameters = parameters; | |
| 74 constructor.returnType = type; | 84 constructor.returnType = type; |
| 75 FunctionTypeImpl constructorType = new FunctionTypeImpl.con1(constructor); | 85 FunctionTypeImpl constructorType = new FunctionTypeImpl.con1(constructor); |
| 76 constructor.type = constructorType; | 86 constructor.type = constructorType; |
| 77 return constructor; | 87 return constructor; |
| 78 } | 88 } |
| 79 | 89 |
| 80 static ConstructorElementImpl constructorElement2(ClassElement definingClass,
String name, List<DartType> argumentTypes) => constructorElement(definingClass,
name, false, argumentTypes); | 90 static ConstructorElementImpl constructorElement2(ClassElement definingClass,
String name, [List<DartType> argumentTypes]) |
| 91 => constructorElement(definingClass, name, false, argumentTypes); |
| 81 | 92 |
| 82 static ClassElementImpl enumElement(TypeProvider typeProvider, String enumName
, List<String> constantNames) { | 93 static ClassElementImpl enumElement(TypeProvider typeProvider, String enumName
, [List<String> constantNames]) { |
| 83 // | 94 // |
| 84 // Build the enum. | 95 // Build the enum. |
| 85 // | 96 // |
| 86 ClassElementImpl enumElement = new ClassElementImpl(enumName, -1); | 97 ClassElementImpl enumElement = new ClassElementImpl(enumName, -1); |
| 87 InterfaceTypeImpl enumType = new InterfaceTypeImpl.con1(enumElement); | 98 InterfaceTypeImpl enumType = new InterfaceTypeImpl.con1(enumElement); |
| 88 enumElement.type = enumType; | 99 enumElement.type = enumType; |
| 89 enumElement.supertype = objectType; | 100 enumElement.supertype = objectType; |
| 90 // | 101 // |
| 91 // Populate the fields. | 102 // Populate the fields. |
| 92 // | 103 // |
| (...skipping 11 matching lines...) Expand all Loading... |
| 104 nameField.type = stringType; | 115 nameField.type = stringType; |
| 105 fields.add(nameField); | 116 fields.add(nameField); |
| 106 FieldElementImpl valuesField = new FieldElementImpl("values", -1); | 117 FieldElementImpl valuesField = new FieldElementImpl("values", -1); |
| 107 valuesField.static = true; | 118 valuesField.static = true; |
| 108 valuesField.const3 = true; | 119 valuesField.const3 = true; |
| 109 valuesField.type = typeProvider.listType.substitute4(<DartType> [enumType]); | 120 valuesField.type = typeProvider.listType.substitute4(<DartType> [enumType]); |
| 110 fields.add(valuesField); | 121 fields.add(valuesField); |
| 111 // | 122 // |
| 112 // Build the enum constants. | 123 // Build the enum constants. |
| 113 // | 124 // |
| 114 int constantCount = constantNames.length; | 125 if (constantNames != null) { |
| 115 for (int i = 0; i < constantCount; i++) { | 126 int constantCount = constantNames.length; |
| 116 String constantName = constantNames[i]; | 127 for (int i = 0; i < constantCount; i++) { |
| 117 FieldElementImpl constantElement = new ConstFieldElementImpl.con2(constant
Name, -1); | 128 String constantName = constantNames[i]; |
| 118 constantElement.static = true; | 129 FieldElementImpl constantElement = new ConstFieldElementImpl.con2(consta
ntName, -1); |
| 119 constantElement.const3 = true; | 130 constantElement.static = true; |
| 120 constantElement.type = enumType; | 131 constantElement.const3 = true; |
| 121 HashMap<String, DartObjectImpl> fieldMap = new HashMap<String, DartObjectI
mpl>(); | 132 constantElement.type = enumType; |
| 122 fieldMap[indexFieldName] = new DartObjectImpl(intType, new IntState(i)); | 133 HashMap<String, DartObjectImpl> fieldMap = new HashMap<String, DartObjec
tImpl>(); |
| 123 fieldMap[nameFieldName] = new DartObjectImpl(stringType, new StringState(c
onstantName)); | 134 fieldMap[indexFieldName] = new DartObjectImpl(intType, new IntState(i)); |
| 124 DartObjectImpl value = new DartObjectImpl(enumType, new GenericState(field
Map)); | 135 fieldMap[nameFieldName] = new DartObjectImpl(stringType, new StringState
(constantName)); |
| 125 constantElement.evaluationResult = new EvaluationResultImpl.con1(value); | 136 DartObjectImpl value = new DartObjectImpl(enumType, new GenericState(fie
ldMap)); |
| 126 fields.add(constantElement); | 137 constantElement.evaluationResult = new EvaluationResultImpl.con1(value); |
| 138 fields.add(constantElement); |
| 139 } |
| 127 } | 140 } |
| 128 // | 141 // |
| 129 // Finish building the enum. | 142 // Finish building the enum. |
| 130 // | 143 // |
| 131 enumElement.fields = fields; | 144 enumElement.fields = fields; |
| 132 // Client code isn't allowed to invoke the constructor, so we do not model i
t. | 145 // Client code isn't allowed to invoke the constructor, so we do not model i
t. |
| 133 return enumElement; | 146 return enumElement; |
| 134 } | 147 } |
| 135 | 148 |
| 136 static ExportElementImpl exportFor(LibraryElement exportedLibrary, List<Namesp
aceCombinator> combinators) { | 149 static ExportElementImpl exportFor(LibraryElement exportedLibrary, [List<Names
paceCombinator> combinators = NamespaceCombinator.EMPTY_ARRAY]) { |
| 137 ExportElementImpl spec = new ExportElementImpl(); | 150 ExportElementImpl spec = new ExportElementImpl(); |
| 138 spec.exportedLibrary = exportedLibrary; | 151 spec.exportedLibrary = exportedLibrary; |
| 139 spec.combinators = combinators; | 152 spec.combinators = combinators; |
| 140 return spec; | 153 return spec; |
| 141 } | 154 } |
| 142 | 155 |
| 143 static FieldElementImpl fieldElement(String name, bool isStatic, bool isFinal,
bool isConst, DartType type) { | 156 static FieldElementImpl fieldElement(String name, bool isStatic, bool isFinal,
bool isConst, DartType type) { |
| 144 FieldElementImpl field = new FieldElementImpl(name, 0); | 157 FieldElementImpl field = new FieldElementImpl(name, 0); |
| 145 field.const3 = isConst; | 158 field.const3 = isConst; |
| 146 field.final2 = isFinal; | 159 field.final2 = isFinal; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 FunctionElementImpl functionElement = new FunctionElementImpl(functionName,
0); | 264 FunctionElementImpl functionElement = new FunctionElementImpl(functionName,
0); |
| 252 functionElement.returnType = returnType == null ? VoidTypeImpl.instance : re
turnType; | 265 functionElement.returnType = returnType == null ? VoidTypeImpl.instance : re
turnType; |
| 253 functionElement.parameters = parameters; | 266 functionElement.parameters = parameters; |
| 254 FunctionTypeImpl functionType = new FunctionTypeImpl.con1(functionElement); | 267 FunctionTypeImpl functionType = new FunctionTypeImpl.con1(functionElement); |
| 255 functionElement.type = functionType; | 268 functionElement.type = functionType; |
| 256 return functionElement; | 269 return functionElement; |
| 257 } | 270 } |
| 258 | 271 |
| 259 static ClassElementImpl get object { | 272 static ClassElementImpl get object { |
| 260 if (_objectElement == null) { | 273 if (_objectElement == null) { |
| 261 _objectElement = classElement("Object", null, []); | 274 _objectElement = classElement("Object", null); |
| 262 } | 275 } |
| 263 return _objectElement; | 276 return _objectElement; |
| 264 } | 277 } |
| 265 | 278 |
| 266 static InterfaceType get objectType => object.type; | 279 static InterfaceType get objectType => object.type; |
| 267 | 280 |
| 268 static PropertyAccessorElementImpl getterElement(String name, bool isStatic, D
artType type) { | 281 static PropertyAccessorElementImpl getterElement(String name, bool isStatic, D
artType type) { |
| 269 FieldElementImpl field = new FieldElementImpl(name, -1); | 282 FieldElementImpl field = new FieldElementImpl(name, -1); |
| 270 field.static = isStatic; | 283 field.static = isStatic; |
| 271 field.synthetic = true; | 284 field.synthetic = true; |
| 272 field.type = type; | 285 field.type = type; |
| 273 PropertyAccessorElementImpl getter = new PropertyAccessorElementImpl.forVari
able(field); | 286 PropertyAccessorElementImpl getter = new PropertyAccessorElementImpl.forVari
able(field); |
| 274 getter.getter = true; | 287 getter.getter = true; |
| 275 getter.variable = field; | 288 getter.variable = field; |
| 276 getter.returnType = type; | 289 getter.returnType = type; |
| 277 field.getter = getter; | 290 field.getter = getter; |
| 278 FunctionTypeImpl getterType = new FunctionTypeImpl.con1(getter); | 291 FunctionTypeImpl getterType = new FunctionTypeImpl.con1(getter); |
| 279 getter.type = getterType; | 292 getter.type = getterType; |
| 280 return getter; | 293 return getter; |
| 281 } | 294 } |
| 282 | 295 |
| 283 static HtmlElementImpl htmlUnit(AnalysisContext context, String fileName) { | 296 static HtmlElementImpl htmlUnit(AnalysisContext context, String fileName) { |
| 284 Source source = new NonExistingSource(fileName, UriKind.FILE_URI); | 297 Source source = new NonExistingSource(fileName, UriKind.FILE_URI); |
| 285 HtmlElementImpl unit = new HtmlElementImpl(context, fileName); | 298 HtmlElementImpl unit = new HtmlElementImpl(context, fileName); |
| 286 unit.source = source; | 299 unit.source = source; |
| 287 return unit; | 300 return unit; |
| 288 } | 301 } |
| 289 | 302 |
| 290 static ImportElementImpl importFor(LibraryElement importedLibrary, PrefixEleme
nt prefix, List<NamespaceCombinator> combinators) { | 303 static ImportElementImpl importFor(LibraryElement importedLibrary, PrefixEleme
nt prefix, [List<NamespaceCombinator> combinators = NamespaceCombinator.EMPTY_AR
RAY]) { |
| 291 ImportElementImpl spec = new ImportElementImpl(0); | 304 ImportElementImpl spec = new ImportElementImpl(0); |
| 292 spec.importedLibrary = importedLibrary; | 305 spec.importedLibrary = importedLibrary; |
| 293 spec.prefix = prefix; | 306 spec.prefix = prefix; |
| 294 spec.combinators = combinators; | 307 spec.combinators = combinators; |
| 295 return spec; | 308 return spec; |
| 296 } | 309 } |
| 297 | 310 |
| 298 static LibraryElementImpl library(AnalysisContext context, String libraryName)
{ | 311 static LibraryElementImpl library(AnalysisContext context, String libraryName)
{ |
| 299 String fileName = "/$libraryName.dart"; | 312 String fileName = "/$libraryName.dart"; |
| 300 CompilationUnitElementImpl unit = compilationUnit(fileName); | 313 CompilationUnitElementImpl unit = compilationUnit(fileName); |
| 301 LibraryElementImpl library = new LibraryElementImpl(context, libraryName, 0)
; | 314 LibraryElementImpl library = new LibraryElementImpl(context, libraryName, 0)
; |
| 302 library.definingCompilationUnit = unit; | 315 library.definingCompilationUnit = unit; |
| 303 return library; | 316 return library; |
| 304 } | 317 } |
| 305 | 318 |
| 306 static LocalVariableElementImpl localVariableElement(Identifier name) => new L
ocalVariableElementImpl.forNode(name); | 319 static LocalVariableElementImpl localVariableElement(Identifier name) => new L
ocalVariableElementImpl.forNode(name); |
| 307 | 320 |
| 308 static LocalVariableElementImpl localVariableElement2(String name) => new Loca
lVariableElementImpl(name, 0); | 321 static LocalVariableElementImpl localVariableElement2(String name) => new Loca
lVariableElementImpl(name, 0); |
| 309 | 322 |
| 310 static MethodElementImpl methodElement(String methodName, DartType returnType,
List<DartType> argumentTypes) { | 323 static MethodElementImpl methodElement(String methodName, DartType returnType,
[List<DartType> argumentTypes]) { |
| 311 MethodElementImpl method = new MethodElementImpl(methodName, 0); | 324 MethodElementImpl method = new MethodElementImpl(methodName, 0); |
| 312 int count = argumentTypes.length; | 325 if (argumentTypes == null) { |
| 313 List<ParameterElement> parameters = new List<ParameterElement>(count); | 326 method.parameters = ParameterElementImpl.EMPTY_ARRAY; |
| 314 for (int i = 0; i < count; i++) { | 327 } else { |
| 315 ParameterElementImpl parameter = new ParameterElementImpl("a$i", i); | 328 int count = argumentTypes.length; |
| 316 parameter.type = argumentTypes[i]; | 329 List<ParameterElement> parameters = new List<ParameterElement>(count); |
| 317 parameter.parameterKind = ParameterKind.REQUIRED; | 330 for (int i = 0; i < count; i++) { |
| 318 parameters[i] = parameter; | 331 ParameterElementImpl parameter = new ParameterElementImpl("a$i", i); |
| 332 parameter.type = argumentTypes[i]; |
| 333 parameter.parameterKind = ParameterKind.REQUIRED; |
| 334 parameters[i] = parameter; |
| 335 } |
| 336 method.parameters = parameters; |
| 319 } | 337 } |
| 320 method.parameters = parameters; | |
| 321 method.returnType = returnType; | 338 method.returnType = returnType; |
| 322 FunctionTypeImpl methodType = new FunctionTypeImpl.con1(method); | 339 FunctionTypeImpl methodType = new FunctionTypeImpl.con1(method); |
| 323 method.type = methodType; | 340 method.type = methodType; |
| 324 return method; | 341 return method; |
| 325 } | 342 } |
| 326 | 343 |
| 327 static MethodElementImpl methodElementWithParameters(String methodName, List<D
artType> typeArguments, DartType returnType, List<ParameterElement> parameters)
{ | 344 static MethodElementImpl methodElementWithParameters(String methodName, List<D
artType> typeArguments, DartType returnType, List<ParameterElement> parameters)
{ |
| 328 MethodElementImpl method = new MethodElementImpl(methodName, 0); | 345 MethodElementImpl method = new MethodElementImpl(methodName, 0); |
| 329 method.parameters = parameters; | 346 method.parameters = parameters; |
| 330 method.returnType = returnType; | 347 method.returnType = returnType; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 setter.synthetic = true; | 440 setter.synthetic = true; |
| 424 setter.variable = variable; | 441 setter.variable = variable; |
| 425 setter.parameters = <ParameterElement> [requiredParameter2("_$name", type)
]; | 442 setter.parameters = <ParameterElement> [requiredParameter2("_$name", type)
]; |
| 426 setter.returnType = VoidTypeImpl.instance; | 443 setter.returnType = VoidTypeImpl.instance; |
| 427 setter.type = new FunctionTypeImpl.con1(setter); | 444 setter.type = new FunctionTypeImpl.con1(setter); |
| 428 variable.setter = setter; | 445 variable.setter = setter; |
| 429 } | 446 } |
| 430 return variable; | 447 return variable; |
| 431 } | 448 } |
| 432 } | 449 } |
| OLD | NEW |