| 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 engine.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/src/generated/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/ast/token.dart'; |
| 11 import 'package:analyzer/dart/element/element.dart'; |
| 12 import 'package:analyzer/dart/element/type.dart'; |
| 13 import 'package:analyzer/src/dart/element/element.dart'; |
| 14 import 'package:analyzer/src/dart/element/type.dart'; |
| 10 import 'package:analyzer/src/generated/constant.dart'; | 15 import 'package:analyzer/src/generated/constant.dart'; |
| 11 import 'package:analyzer/src/generated/element.dart'; | |
| 12 import 'package:analyzer/src/generated/engine.dart'; | 16 import 'package:analyzer/src/generated/engine.dart'; |
| 13 import 'package:analyzer/src/generated/java_core.dart'; | |
| 14 import 'package:analyzer/src/generated/resolver.dart'; | 17 import 'package:analyzer/src/generated/resolver.dart'; |
| 15 import 'package:analyzer/src/generated/scanner.dart'; | |
| 16 import 'package:analyzer/src/generated/source.dart'; | 18 import 'package:analyzer/src/generated/source.dart'; |
| 17 import 'package:analyzer/src/generated/testing/ast_factory.dart'; | 19 import 'package:analyzer/src/generated/testing/ast_factory.dart'; |
| 18 import 'package:analyzer/src/generated/utilities_dart.dart'; | 20 import 'package:analyzer/src/generated/utilities_dart.dart'; |
| 19 import 'package:path/path.dart'; | 21 import 'package:path/path.dart'; |
| 20 | 22 |
| 21 /** | 23 /** |
| 22 * The class `ElementFactory` defines utility methods used to create elements fo
r testing | 24 * The class `ElementFactory` defines utility methods used to create elements fo
r testing |
| 23 * purposes. The elements that are created are complete in the sense that as muc
h of the element | 25 * purposes. The elements that are created are complete in the sense that as muc
h of the element |
| 24 * model as can be created, given the provided information, has been created. | 26 * model as can be created, given the provided information, has been created. |
| 25 */ | 27 */ |
| 26 class ElementFactory { | 28 class ElementFactory { |
| 27 /** | 29 /** |
| 28 * The element representing the class 'Object'. | 30 * The element representing the class 'Object'. |
| 29 */ | 31 */ |
| 30 static ClassElementImpl _objectElement; | 32 static ClassElementImpl _objectElement; |
| 31 | 33 |
| 32 static ClassElementImpl get object { | 34 static ClassElementImpl get object { |
| 33 if (_objectElement == null) { | 35 if (_objectElement == null) { |
| 34 _objectElement = classElement("Object", null); | 36 _objectElement = classElement("Object", null); |
| 35 } | 37 } |
| 36 return _objectElement; | 38 return _objectElement; |
| 37 } | 39 } |
| 38 | 40 |
| 39 static InterfaceType get objectType => object.type; | 41 static InterfaceType get objectType => object.type; |
| 40 | 42 |
| 41 static ClassElementImpl classElement( | 43 static ClassElementImpl classElement( |
| 42 String typeName, InterfaceType superclassType, | 44 String typeName, InterfaceType superclassType, |
| 43 [List<String> parameterNames]) { | 45 [List<String> parameterNames]) { |
| 44 ClassElementImpl element = new ClassElementImpl(typeName, 0); | 46 ClassElementImpl element = new ClassElementImpl(typeName, 0); |
| 47 element.constructors = const <ConstructorElement>[]; |
| 45 element.supertype = superclassType; | 48 element.supertype = superclassType; |
| 46 InterfaceTypeImpl type = new InterfaceTypeImpl(element); | |
| 47 element.type = type; | |
| 48 if (parameterNames != null) { | 49 if (parameterNames != null) { |
| 49 int count = parameterNames.length; | 50 element.typeParameters = typeParameters(parameterNames); |
| 50 if (count > 0) { | |
| 51 List<TypeParameterElementImpl> typeParameters = | |
| 52 new List<TypeParameterElementImpl>(count); | |
| 53 List<TypeParameterTypeImpl> typeParameterTypes = | |
| 54 new List<TypeParameterTypeImpl>(count); | |
| 55 for (int i = 0; i < count; i++) { | |
| 56 TypeParameterElementImpl typeParameter = | |
| 57 typeParameterElement(parameterNames[i]); | |
| 58 typeParameters[i] = typeParameter; | |
| 59 typeParameterTypes[i] = new TypeParameterTypeImpl(typeParameter); | |
| 60 typeParameter.type = typeParameterTypes[i]; | |
| 61 } | |
| 62 element.typeParameters = typeParameters; | |
| 63 type.typeArguments = typeParameterTypes; | |
| 64 } | |
| 65 } | 51 } |
| 66 return element; | 52 return element; |
| 67 } | 53 } |
| 68 | 54 |
| 69 static ClassElementImpl classElement2(String typeName, | 55 static ClassElementImpl classElement2(String typeName, |
| 70 [List<String> parameterNames]) => | 56 [List<String> parameterNames]) => |
| 71 classElement(typeName, objectType, parameterNames); | 57 classElement(typeName, objectType, parameterNames); |
| 72 | 58 |
| 73 static classTypeAlias(String typeName, InterfaceType superclassType, | 59 static classTypeAlias(String typeName, InterfaceType superclassType, |
| 74 [List<String> parameterNames]) { | 60 [List<String> parameterNames]) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 94 unit.librarySource = librarySource; | 80 unit.librarySource = librarySource; |
| 95 return unit; | 81 return unit; |
| 96 } | 82 } |
| 97 | 83 |
| 98 static ConstLocalVariableElementImpl constLocalVariableElement(String name) => | 84 static ConstLocalVariableElementImpl constLocalVariableElement(String name) => |
| 99 new ConstLocalVariableElementImpl(name, 0); | 85 new ConstLocalVariableElementImpl(name, 0); |
| 100 | 86 |
| 101 static ConstructorElementImpl constructorElement( | 87 static ConstructorElementImpl constructorElement( |
| 102 ClassElement definingClass, String name, bool isConst, | 88 ClassElement definingClass, String name, bool isConst, |
| 103 [List<DartType> argumentTypes]) { | 89 [List<DartType> argumentTypes]) { |
| 104 DartType type = definingClass.type; | |
| 105 ConstructorElementImpl constructor = name == null | 90 ConstructorElementImpl constructor = name == null |
| 106 ? new ConstructorElementImpl("", -1) | 91 ? new ConstructorElementImpl("", -1) |
| 107 : new ConstructorElementImpl(name, 0); | 92 : new ConstructorElementImpl(name, 0); |
| 93 if (name != null) { |
| 94 if (name.isEmpty) { |
| 95 constructor.nameEnd = definingClass.name.length; |
| 96 } else { |
| 97 constructor.periodOffset = definingClass.name.length; |
| 98 constructor.nameEnd = definingClass.name.length + name.length + 1; |
| 99 } |
| 100 } |
| 101 constructor.synthetic = name == null; |
| 108 constructor.const2 = isConst; | 102 constructor.const2 = isConst; |
| 109 if (argumentTypes != null) { | 103 if (argumentTypes != null) { |
| 110 int count = argumentTypes.length; | 104 int count = argumentTypes.length; |
| 111 List<ParameterElement> parameters = new List<ParameterElement>(count); | 105 List<ParameterElement> parameters = new List<ParameterElement>(count); |
| 112 for (int i = 0; i < count; i++) { | 106 for (int i = 0; i < count; i++) { |
| 113 ParameterElementImpl parameter = new ParameterElementImpl("a$i", i); | 107 ParameterElementImpl parameter = new ParameterElementImpl("a$i", i); |
| 114 parameter.type = argumentTypes[i]; | 108 parameter.type = argumentTypes[i]; |
| 115 parameter.parameterKind = ParameterKind.REQUIRED; | 109 parameter.parameterKind = ParameterKind.REQUIRED; |
| 116 parameters[i] = parameter; | 110 parameters[i] = parameter; |
| 117 } | 111 } |
| 118 constructor.parameters = parameters; | 112 constructor.parameters = parameters; |
| 119 } else { | 113 } else { |
| 120 constructor.parameters = <ParameterElement>[]; | 114 constructor.parameters = <ParameterElement>[]; |
| 121 } | 115 } |
| 122 constructor.returnType = type; | 116 constructor.enclosingElement = definingClass; |
| 123 FunctionTypeImpl constructorType = new FunctionTypeImpl(constructor); | 117 if (!constructor.isSynthetic) { |
| 124 constructor.type = constructorType; | 118 constructor.constantInitializers = <ConstructorInitializer>[]; |
| 119 } |
| 125 return constructor; | 120 return constructor; |
| 126 } | 121 } |
| 127 | 122 |
| 128 static ConstructorElementImpl constructorElement2( | 123 static ConstructorElementImpl constructorElement2( |
| 129 ClassElement definingClass, String name, | 124 ClassElement definingClass, String name, |
| 130 [List<DartType> argumentTypes]) => | 125 [List<DartType> argumentTypes]) => |
| 131 constructorElement(definingClass, name, false, argumentTypes); | 126 constructorElement(definingClass, name, false, argumentTypes); |
| 132 | 127 |
| 133 static ClassElementImpl enumElement( | 128 static EnumElementImpl enumElement(TypeProvider typeProvider, String enumName, |
| 134 TypeProvider typeProvider, String enumName, | |
| 135 [List<String> constantNames]) { | 129 [List<String> constantNames]) { |
| 136 // | 130 // |
| 137 // Build the enum. | 131 // Build the enum. |
| 138 // | 132 // |
| 139 ClassElementImpl enumElement = new ClassElementImpl(enumName, -1); | 133 EnumElementImpl enumElement = new EnumElementImpl(enumName, -1); |
| 140 InterfaceTypeImpl enumType = new InterfaceTypeImpl(enumElement); | 134 InterfaceTypeImpl enumType = enumElement.type; |
| 141 enumElement.type = enumType; | |
| 142 enumElement.supertype = objectType; | |
| 143 enumElement.enum2 = true; | |
| 144 // | 135 // |
| 145 // Populate the fields. | 136 // Populate the fields. |
| 146 // | 137 // |
| 147 List<FieldElement> fields = new List<FieldElement>(); | 138 List<FieldElement> fields = new List<FieldElement>(); |
| 148 InterfaceType intType = typeProvider.intType; | 139 InterfaceType intType = typeProvider.intType; |
| 149 InterfaceType stringType = typeProvider.stringType; | 140 InterfaceType stringType = typeProvider.stringType; |
| 150 String indexFieldName = "index"; | 141 String indexFieldName = "index"; |
| 151 FieldElementImpl indexField = new FieldElementImpl(indexFieldName, -1); | 142 FieldElementImpl indexField = new FieldElementImpl(indexFieldName, -1); |
| 152 indexField.final2 = true; | 143 indexField.final2 = true; |
| 153 indexField.type = intType; | 144 indexField.type = intType; |
| 154 fields.add(indexField); | 145 fields.add(indexField); |
| 155 String nameFieldName = "_name"; | 146 String nameFieldName = "_name"; |
| 156 FieldElementImpl nameField = new FieldElementImpl(nameFieldName, -1); | 147 FieldElementImpl nameField = new FieldElementImpl(nameFieldName, -1); |
| 157 nameField.final2 = true; | 148 nameField.final2 = true; |
| 158 nameField.type = stringType; | 149 nameField.type = stringType; |
| 159 fields.add(nameField); | 150 fields.add(nameField); |
| 160 FieldElementImpl valuesField = new FieldElementImpl("values", -1); | 151 FieldElementImpl valuesField = new FieldElementImpl("values", -1); |
| 161 valuesField.static = true; | 152 valuesField.static = true; |
| 162 valuesField.const3 = true; | 153 valuesField.const3 = true; |
| 163 valuesField.type = typeProvider.listType.substitute4(<DartType>[enumType]); | 154 valuesField.type = typeProvider.listType.instantiate(<DartType>[enumType]); |
| 164 fields.add(valuesField); | 155 fields.add(valuesField); |
| 165 // | 156 // |
| 166 // Build the enum constants. | 157 // Build the enum constants. |
| 167 // | 158 // |
| 168 if (constantNames != null) { | 159 if (constantNames != null) { |
| 169 int constantCount = constantNames.length; | 160 int constantCount = constantNames.length; |
| 170 for (int i = 0; i < constantCount; i++) { | 161 for (int i = 0; i < constantCount; i++) { |
| 171 String constantName = constantNames[i]; | 162 String constantName = constantNames[i]; |
| 172 FieldElementImpl constantElement = | 163 FieldElementImpl constantElement = |
| 173 new ConstFieldElementImpl(constantName, -1); | 164 new ConstFieldElementImpl(constantName, -1); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 196 static ExportElementImpl exportFor(LibraryElement exportedLibrary, | 187 static ExportElementImpl exportFor(LibraryElement exportedLibrary, |
| 197 [List<NamespaceCombinator> combinators = | 188 [List<NamespaceCombinator> combinators = |
| 198 NamespaceCombinator.EMPTY_LIST]) { | 189 NamespaceCombinator.EMPTY_LIST]) { |
| 199 ExportElementImpl spec = new ExportElementImpl(-1); | 190 ExportElementImpl spec = new ExportElementImpl(-1); |
| 200 spec.exportedLibrary = exportedLibrary; | 191 spec.exportedLibrary = exportedLibrary; |
| 201 spec.combinators = combinators; | 192 spec.combinators = combinators; |
| 202 return spec; | 193 return spec; |
| 203 } | 194 } |
| 204 | 195 |
| 205 static FieldElementImpl fieldElement( | 196 static FieldElementImpl fieldElement( |
| 206 String name, bool isStatic, bool isFinal, bool isConst, DartType type) { | 197 String name, bool isStatic, bool isFinal, bool isConst, DartType type, |
| 207 FieldElementImpl field = new FieldElementImpl(name, 0); | 198 {Expression initializer}) { |
| 199 FieldElementImpl field = isConst |
| 200 ? new ConstFieldElementImpl(name, 0) |
| 201 : new FieldElementImpl(name, 0); |
| 208 field.const3 = isConst; | 202 field.const3 = isConst; |
| 209 field.final2 = isFinal; | 203 field.final2 = isFinal; |
| 210 field.static = isStatic; | 204 field.static = isStatic; |
| 211 field.type = type; | 205 field.type = type; |
| 212 PropertyAccessorElementImpl getter = | 206 if (isConst) { |
| 213 new PropertyAccessorElementImpl.forVariable(field); | 207 (field as ConstFieldElementImpl).constantInitializer = initializer; |
| 214 getter.getter = true; | 208 } |
| 215 getter.synthetic = true; | 209 new PropertyAccessorElementImpl_ImplicitGetter(field); |
| 216 getter.variable = field; | |
| 217 getter.returnType = type; | |
| 218 field.getter = getter; | |
| 219 FunctionTypeImpl getterType = new FunctionTypeImpl(getter); | |
| 220 getter.type = getterType; | |
| 221 if (!isConst && !isFinal) { | 210 if (!isConst && !isFinal) { |
| 222 PropertyAccessorElementImpl setter = | 211 new PropertyAccessorElementImpl_ImplicitSetter(field); |
| 223 new PropertyAccessorElementImpl.forVariable(field); | |
| 224 setter.setter = true; | |
| 225 setter.synthetic = true; | |
| 226 setter.variable = field; | |
| 227 setter.parameters = <ParameterElement>[ | |
| 228 requiredParameter2("_$name", type) | |
| 229 ]; | |
| 230 setter.returnType = VoidTypeImpl.instance; | |
| 231 setter.type = new FunctionTypeImpl(setter); | |
| 232 field.setter = setter; | |
| 233 } | 212 } |
| 234 return field; | 213 return field; |
| 235 } | 214 } |
| 236 | 215 |
| 237 static FieldFormalParameterElementImpl fieldFormalParameter( | 216 static FieldFormalParameterElementImpl fieldFormalParameter( |
| 238 Identifier name) => | 217 Identifier name) => |
| 239 new FieldFormalParameterElementImpl(name); | 218 new FieldFormalParameterElementImpl.forNode(name); |
| 219 |
| 220 /** |
| 221 * Destroy any static state retained by [ElementFactory]. This should be |
| 222 * called from the `setUp` method of any tests that use [ElementFactory], in |
| 223 * order to ensure that state is not shared between multiple tests. |
| 224 */ |
| 225 static void flushStaticState() { |
| 226 _objectElement = null; |
| 227 } |
| 240 | 228 |
| 241 static FunctionElementImpl functionElement(String functionName) => | 229 static FunctionElementImpl functionElement(String functionName) => |
| 242 functionElement4(functionName, null, null, null, null); | 230 functionElement4(functionName, null, null, null, null); |
| 243 | 231 |
| 244 static FunctionElementImpl functionElement2( | 232 static FunctionElementImpl functionElement2( |
| 245 String functionName, ClassElement returnElement) => | 233 String functionName, TypeDefiningElement returnElement) => |
| 246 functionElement3(functionName, returnElement, null, null); | 234 functionElement3(functionName, returnElement, null, null); |
| 247 | 235 |
| 248 static FunctionElementImpl functionElement3( | 236 static FunctionElementImpl functionElement3( |
| 249 String functionName, | 237 String functionName, |
| 250 ClassElement returnElement, | 238 TypeDefiningElement returnElement, |
| 251 List<TypeDefiningElement> normalParameters, | 239 List<TypeDefiningElement> normalParameters, |
| 252 List<TypeDefiningElement> optionalParameters) { | 240 List<TypeDefiningElement> optionalParameters) { |
| 253 // 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 |
| 254 FunctionElementImpl functionElement = | 242 FunctionElementImpl functionElement = |
| 255 new FunctionElementImpl(functionName, 0); | 243 new FunctionElementImpl(functionName, 0); |
| 256 FunctionTypeImpl functionType = new FunctionTypeImpl(functionElement); | 244 FunctionTypeImpl functionType = new FunctionTypeImpl(functionElement); |
| 257 functionElement.type = functionType; | 245 functionElement.type = functionType; |
| 258 // return type | 246 // return type |
| 259 if (returnElement == null) { | 247 if (returnElement == null) { |
| 260 functionElement.returnType = VoidTypeImpl.instance; | 248 functionElement.returnType = VoidTypeImpl.instance; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 291 List<ClassElement> namedParameters) { | 279 List<ClassElement> namedParameters) { |
| 292 FunctionElementImpl functionElement = | 280 FunctionElementImpl functionElement = |
| 293 new FunctionElementImpl(functionName, 0); | 281 new FunctionElementImpl(functionName, 0); |
| 294 FunctionTypeImpl functionType = new FunctionTypeImpl(functionElement); | 282 FunctionTypeImpl functionType = new FunctionTypeImpl(functionElement); |
| 295 functionElement.type = functionType; | 283 functionElement.type = functionType; |
| 296 // parameters | 284 // parameters |
| 297 int normalCount = normalParameters == null ? 0 : normalParameters.length; | 285 int normalCount = normalParameters == null ? 0 : normalParameters.length; |
| 298 int nameCount = names == null ? 0 : names.length; | 286 int nameCount = names == null ? 0 : names.length; |
| 299 int typeCount = namedParameters == null ? 0 : namedParameters.length; | 287 int typeCount = namedParameters == null ? 0 : namedParameters.length; |
| 300 if (names != null && nameCount != typeCount) { | 288 if (names != null && nameCount != typeCount) { |
| 301 throw new IllegalStateException( | 289 throw new StateError( |
| 302 "The passed String[] and ClassElement[] arrays had different lengths."
); | 290 "The passed String[] and ClassElement[] arrays had different lengths."
); |
| 303 } | 291 } |
| 304 int totalCount = normalCount + nameCount; | 292 int totalCount = normalCount + nameCount; |
| 305 List<ParameterElement> parameters = new List<ParameterElement>(totalCount); | 293 List<ParameterElement> parameters = new List<ParameterElement>(totalCount); |
| 306 for (int i = 0; i < totalCount; i++) { | 294 for (int i = 0; i < totalCount; i++) { |
| 307 if (i < normalCount) { | 295 if (i < normalCount) { |
| 308 ParameterElementImpl parameter = new ParameterElementImpl("a$i", i); | 296 ParameterElementImpl parameter = new ParameterElementImpl("a$i", i); |
| 309 parameter.type = normalParameters[i].type; | 297 parameter.type = normalParameters[i].type; |
| 310 parameter.parameterKind = ParameterKind.REQUIRED; | 298 parameter.parameterKind = ParameterKind.REQUIRED; |
| 311 parameters[i] = parameter; | 299 parameters[i] = parameter; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 new FunctionTypeImpl.forTypedef(functionTypeAliasElement); | 387 new FunctionTypeImpl.forTypedef(functionTypeAliasElement); |
| 400 return functionTypeAliasElement; | 388 return functionTypeAliasElement; |
| 401 } | 389 } |
| 402 | 390 |
| 403 static PropertyAccessorElementImpl getterElement( | 391 static PropertyAccessorElementImpl getterElement( |
| 404 String name, bool isStatic, DartType type) { | 392 String name, bool isStatic, DartType type) { |
| 405 FieldElementImpl field = new FieldElementImpl(name, -1); | 393 FieldElementImpl field = new FieldElementImpl(name, -1); |
| 406 field.static = isStatic; | 394 field.static = isStatic; |
| 407 field.synthetic = true; | 395 field.synthetic = true; |
| 408 field.type = type; | 396 field.type = type; |
| 397 field.final2 = true; |
| 409 PropertyAccessorElementImpl getter = | 398 PropertyAccessorElementImpl getter = |
| 410 new PropertyAccessorElementImpl.forVariable(field); | 399 new PropertyAccessorElementImpl(name, 0); |
| 400 getter.synthetic = false; |
| 411 getter.getter = true; | 401 getter.getter = true; |
| 412 getter.variable = field; | 402 getter.variable = field; |
| 413 getter.returnType = type; | 403 getter.returnType = type; |
| 404 getter.static = isStatic; |
| 414 field.getter = getter; | 405 field.getter = getter; |
| 415 FunctionTypeImpl getterType = new FunctionTypeImpl(getter); | 406 FunctionTypeImpl getterType = new FunctionTypeImpl(getter); |
| 416 getter.type = getterType; | 407 getter.type = getterType; |
| 417 return getter; | 408 return getter; |
| 418 } | 409 } |
| 419 | 410 |
| 420 @deprecated | |
| 421 static HtmlElementImpl htmlUnit(AnalysisContext context, String fileName) { | |
| 422 Source source = | |
| 423 new NonExistingSource(fileName, toUri(fileName), UriKind.FILE_URI); | |
| 424 HtmlElementImpl unit = new HtmlElementImpl(context, fileName); | |
| 425 unit.source = source; | |
| 426 return unit; | |
| 427 } | |
| 428 | |
| 429 static ImportElementImpl importFor( | 411 static ImportElementImpl importFor( |
| 430 LibraryElement importedLibrary, PrefixElement prefix, | 412 LibraryElement importedLibrary, PrefixElement prefix, |
| 431 [List<NamespaceCombinator> combinators = | 413 [List<NamespaceCombinator> combinators = |
| 432 NamespaceCombinator.EMPTY_LIST]) { | 414 NamespaceCombinator.EMPTY_LIST]) { |
| 433 ImportElementImpl spec = new ImportElementImpl(0); | 415 ImportElementImpl spec = new ImportElementImpl(0); |
| 434 spec.importedLibrary = importedLibrary; | 416 spec.importedLibrary = importedLibrary; |
| 435 spec.prefix = prefix; | 417 spec.prefix = prefix; |
| 436 spec.combinators = combinators; | 418 spec.combinators = combinators; |
| 437 return spec; | 419 return spec; |
| 438 } | 420 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 469 } | 451 } |
| 470 method.parameters = parameters; | 452 method.parameters = parameters; |
| 471 } | 453 } |
| 472 method.returnType = returnType; | 454 method.returnType = returnType; |
| 473 FunctionTypeImpl methodType = new FunctionTypeImpl(method); | 455 FunctionTypeImpl methodType = new FunctionTypeImpl(method); |
| 474 method.type = methodType; | 456 method.type = methodType; |
| 475 return method; | 457 return method; |
| 476 } | 458 } |
| 477 | 459 |
| 478 static MethodElementImpl methodElementWithParameters( | 460 static MethodElementImpl methodElementWithParameters( |
| 461 ClassElement enclosingElement, |
| 479 String methodName, | 462 String methodName, |
| 480 List<DartType> typeArguments, | |
| 481 DartType returnType, | 463 DartType returnType, |
| 482 List<ParameterElement> parameters) { | 464 List<ParameterElement> parameters) { |
| 483 MethodElementImpl method = new MethodElementImpl(methodName, 0); | 465 MethodElementImpl method = new MethodElementImpl(methodName, 0); |
| 466 method.enclosingElement = enclosingElement; |
| 484 method.parameters = parameters; | 467 method.parameters = parameters; |
| 485 method.returnType = returnType; | 468 method.returnType = returnType; |
| 486 FunctionTypeImpl methodType = new FunctionTypeImpl(method); | 469 method.type = new FunctionTypeImpl(method); |
| 487 methodType.typeArguments = typeArguments; | |
| 488 method.type = methodType; | |
| 489 return method; | 470 return method; |
| 490 } | 471 } |
| 491 | 472 |
| 492 static ParameterElementImpl namedParameter(String name) { | 473 static ParameterElementImpl namedParameter(String name) { |
| 493 ParameterElementImpl parameter = new ParameterElementImpl(name, 0); | 474 ParameterElementImpl parameter = new ParameterElementImpl(name, 0); |
| 494 parameter.parameterKind = ParameterKind.NAMED; | 475 parameter.parameterKind = ParameterKind.NAMED; |
| 495 return parameter; | 476 return parameter; |
| 496 } | 477 } |
| 497 | 478 |
| 498 static ParameterElementImpl namedParameter2(String name, DartType type) { | 479 static ParameterElementImpl namedParameter2(String name, DartType type) { |
| 499 ParameterElementImpl parameter = new ParameterElementImpl(name, 0); | 480 ParameterElementImpl parameter = new ParameterElementImpl(name, 0); |
| 500 parameter.parameterKind = ParameterKind.NAMED; | 481 parameter.parameterKind = ParameterKind.NAMED; |
| 501 parameter.type = type; | 482 parameter.type = type; |
| 502 return parameter; | 483 return parameter; |
| 503 } | 484 } |
| 504 | 485 |
| 486 static ParameterElementImpl namedParameter3(String name, |
| 487 {DartType type, Expression initializer, String initializerCode}) { |
| 488 DefaultParameterElementImpl parameter = |
| 489 new DefaultParameterElementImpl(name, 0); |
| 490 parameter.parameterKind = ParameterKind.NAMED; |
| 491 parameter.type = type; |
| 492 parameter.constantInitializer = initializer; |
| 493 parameter.defaultValueCode = initializerCode; |
| 494 return parameter; |
| 495 } |
| 496 |
| 505 static ParameterElementImpl positionalParameter(String name) { | 497 static ParameterElementImpl positionalParameter(String name) { |
| 506 ParameterElementImpl parameter = new ParameterElementImpl(name, 0); | 498 ParameterElementImpl parameter = new ParameterElementImpl(name, 0); |
| 507 parameter.parameterKind = ParameterKind.POSITIONAL; | 499 parameter.parameterKind = ParameterKind.POSITIONAL; |
| 508 return parameter; | 500 return parameter; |
| 509 } | 501 } |
| 510 | 502 |
| 511 static ParameterElementImpl positionalParameter2(String name, DartType type) { | 503 static ParameterElementImpl positionalParameter2(String name, DartType type) { |
| 512 ParameterElementImpl parameter = new ParameterElementImpl(name, 0); | 504 ParameterElementImpl parameter = new ParameterElementImpl(name, 0); |
| 513 parameter.parameterKind = ParameterKind.POSITIONAL; | 505 parameter.parameterKind = ParameterKind.POSITIONAL; |
| 514 parameter.type = type; | 506 parameter.type = type; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 531 return parameter; | 523 return parameter; |
| 532 } | 524 } |
| 533 | 525 |
| 534 static PropertyAccessorElementImpl setterElement( | 526 static PropertyAccessorElementImpl setterElement( |
| 535 String name, bool isStatic, DartType type) { | 527 String name, bool isStatic, DartType type) { |
| 536 FieldElementImpl field = new FieldElementImpl(name, -1); | 528 FieldElementImpl field = new FieldElementImpl(name, -1); |
| 537 field.static = isStatic; | 529 field.static = isStatic; |
| 538 field.synthetic = true; | 530 field.synthetic = true; |
| 539 field.type = type; | 531 field.type = type; |
| 540 PropertyAccessorElementImpl getter = | 532 PropertyAccessorElementImpl getter = |
| 541 new PropertyAccessorElementImpl.forVariable(field); | 533 new PropertyAccessorElementImpl(name, -1); |
| 542 getter.getter = true; | 534 getter.getter = true; |
| 543 getter.variable = field; | 535 getter.variable = field; |
| 544 getter.returnType = type; | 536 getter.returnType = type; |
| 545 field.getter = getter; | 537 field.getter = getter; |
| 546 FunctionTypeImpl getterType = new FunctionTypeImpl(getter); | 538 FunctionTypeImpl getterType = new FunctionTypeImpl(getter); |
| 547 getter.type = getterType; | 539 getter.type = getterType; |
| 548 ParameterElementImpl parameter = requiredParameter2("a", type); | 540 ParameterElementImpl parameter = requiredParameter2("a", type); |
| 549 PropertyAccessorElementImpl setter = | 541 PropertyAccessorElementImpl setter = |
| 550 new PropertyAccessorElementImpl.forVariable(field); | 542 new PropertyAccessorElementImpl(name, -1); |
| 551 setter.setter = true; | 543 setter.setter = true; |
| 552 setter.synthetic = true; | 544 setter.synthetic = true; |
| 553 setter.variable = field; | 545 setter.variable = field; |
| 554 setter.parameters = <ParameterElement>[parameter]; | 546 setter.parameters = <ParameterElement>[parameter]; |
| 555 setter.returnType = VoidTypeImpl.instance; | 547 setter.returnType = VoidTypeImpl.instance; |
| 556 setter.type = new FunctionTypeImpl(setter); | 548 setter.type = new FunctionTypeImpl(setter); |
| 557 field.setter = setter; | 549 field.setter = setter; |
| 558 return setter; | 550 return setter; |
| 559 } | 551 } |
| 560 | 552 |
| 561 static TopLevelVariableElementImpl topLevelVariableElement(Identifier name) => | 553 static TopLevelVariableElementImpl topLevelVariableElement(Identifier name) => |
| 562 new TopLevelVariableElementImpl.forNode(name); | 554 new TopLevelVariableElementImpl.forNode(name); |
| 563 | 555 |
| 564 static TopLevelVariableElementImpl topLevelVariableElement2(String name) => | 556 static TopLevelVariableElementImpl topLevelVariableElement2(String name) => |
| 565 topLevelVariableElement3(name, false, false, null); | 557 topLevelVariableElement3(name, false, false, null); |
| 566 | 558 |
| 567 static TopLevelVariableElementImpl topLevelVariableElement3( | 559 static TopLevelVariableElementImpl topLevelVariableElement3( |
| 568 String name, bool isConst, bool isFinal, DartType type) { | 560 String name, bool isConst, bool isFinal, DartType type) { |
| 569 TopLevelVariableElementImpl variable; | 561 TopLevelVariableElementImpl variable; |
| 570 if (isConst) { | 562 if (isConst) { |
| 571 ConstTopLevelVariableElementImpl constant = | 563 ConstTopLevelVariableElementImpl constant = |
| 572 new ConstTopLevelVariableElementImpl(AstFactory.identifier3(name)); | 564 new ConstTopLevelVariableElementImpl.forNode( |
| 573 constant.constantInitializer = AstFactory.instanceCreationExpression2( | 565 AstFactory.identifier3(name)); |
| 574 Keyword.CONST, AstFactory.typeName(type.element)); | 566 InstanceCreationExpression initializer = |
| 567 AstFactory.instanceCreationExpression2( |
| 568 Keyword.CONST, AstFactory.typeName(type.element)); |
| 569 if (type is InterfaceType) { |
| 570 ConstructorElement element = type.element.unnamedConstructor; |
| 571 initializer.staticElement = element; |
| 572 initializer.constructorName.staticElement = element; |
| 573 } |
| 574 constant.constantInitializer = initializer; |
| 575 variable = constant; | 575 variable = constant; |
| 576 } else { | 576 } else { |
| 577 variable = new TopLevelVariableElementImpl(name, -1); | 577 variable = new TopLevelVariableElementImpl(name, -1); |
| 578 } | 578 } |
| 579 variable.const3 = isConst; | 579 variable.const3 = isConst; |
| 580 variable.final2 = isFinal; | 580 variable.final2 = isFinal; |
| 581 variable.synthetic = true; | 581 variable.synthetic = false; |
| 582 PropertyAccessorElementImpl getter = | 582 variable.type = type; |
| 583 new PropertyAccessorElementImpl.forVariable(variable); | 583 new PropertyAccessorElementImpl_ImplicitGetter(variable); |
| 584 getter.getter = true; | |
| 585 getter.synthetic = true; | |
| 586 getter.variable = variable; | |
| 587 getter.returnType = type; | |
| 588 variable.getter = getter; | |
| 589 FunctionTypeImpl getterType = new FunctionTypeImpl(getter); | |
| 590 getter.type = getterType; | |
| 591 if (!isConst && !isFinal) { | 584 if (!isConst && !isFinal) { |
| 592 PropertyAccessorElementImpl setter = | 585 new PropertyAccessorElementImpl_ImplicitSetter(variable); |
| 593 new PropertyAccessorElementImpl.forVariable(variable); | |
| 594 setter.setter = true; | |
| 595 setter.static = true; | |
| 596 setter.synthetic = true; | |
| 597 setter.variable = variable; | |
| 598 setter.parameters = <ParameterElement>[ | |
| 599 requiredParameter2("_$name", type) | |
| 600 ]; | |
| 601 setter.returnType = VoidTypeImpl.instance; | |
| 602 setter.type = new FunctionTypeImpl(setter); | |
| 603 variable.setter = setter; | |
| 604 } | 586 } |
| 605 return variable; | 587 return variable; |
| 606 } | 588 } |
| 607 | 589 |
| 608 static TypeParameterElementImpl typeParameterElement(String name) { | 590 static TypeParameterElementImpl typeParameterElement(String name) { |
| 609 TypeParameterElementImpl element = new TypeParameterElementImpl(name, 0); | 591 TypeParameterElementImpl element = new TypeParameterElementImpl(name, 0); |
| 610 element.type = new TypeParameterTypeImpl(element); | 592 element.type = new TypeParameterTypeImpl(element); |
| 611 return element; | 593 return element; |
| 612 } | 594 } |
| 595 |
| 596 static List<TypeParameterElement> typeParameters(List<String> names) { |
| 597 int count = names.length; |
| 598 if (count == 0) { |
| 599 return TypeParameterElement.EMPTY_LIST; |
| 600 } |
| 601 List<TypeParameterElementImpl> typeParameters = |
| 602 new List<TypeParameterElementImpl>(count); |
| 603 for (int i = 0; i < count; i++) { |
| 604 typeParameters[i] = typeParameterWithType(names[i]); |
| 605 } |
| 606 return typeParameters; |
| 607 } |
| 608 |
| 609 static TypeParameterElementImpl typeParameterWithType(String name, |
| 610 [DartType bound]) { |
| 611 TypeParameterElementImpl typeParameter = typeParameterElement(name); |
| 612 typeParameter.type = new TypeParameterTypeImpl(typeParameter); |
| 613 typeParameter.bound = bound; |
| 614 return typeParameter; |
| 615 } |
| 613 } | 616 } |
| OLD | NEW |