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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 unit.librarySource = librarySource; | 89 unit.librarySource = librarySource; |
90 return unit; | 90 return unit; |
91 } | 91 } |
92 | 92 |
93 static ConstLocalVariableElementImpl constLocalVariableElement(String name) => | 93 static ConstLocalVariableElementImpl constLocalVariableElement(String name) => |
94 new ConstLocalVariableElementImpl(name, 0); | 94 new ConstLocalVariableElementImpl(name, 0); |
95 | 95 |
96 static ConstructorElementImpl constructorElement( | 96 static ConstructorElementImpl constructorElement( |
97 ClassElement definingClass, String name, bool isConst, | 97 ClassElement definingClass, String name, bool isConst, |
98 [List<DartType> argumentTypes]) { | 98 [List<DartType> argumentTypes]) { |
99 DartType type = definingClass.type; | |
100 ConstructorElementImpl constructor = name == null | 99 ConstructorElementImpl constructor = name == null |
101 ? new ConstructorElementImpl("", -1) | 100 ? new ConstructorElementImpl("", -1) |
102 : new ConstructorElementImpl(name, 0); | 101 : new ConstructorElementImpl(name, 0); |
103 if (name != null) { | 102 if (name != null) { |
104 if (name.isEmpty) { | 103 if (name.isEmpty) { |
105 constructor.nameEnd = definingClass.name.length; | 104 constructor.nameEnd = definingClass.name.length; |
106 } else { | 105 } else { |
107 constructor.periodOffset = definingClass.name.length; | 106 constructor.periodOffset = definingClass.name.length; |
108 constructor.nameEnd = definingClass.name.length + name.length + 1; | 107 constructor.nameEnd = definingClass.name.length + name.length + 1; |
109 } | 108 } |
110 } | 109 } |
111 constructor.synthetic = name == null; | 110 constructor.synthetic = name == null; |
112 constructor.const2 = isConst; | 111 constructor.const2 = isConst; |
113 if (argumentTypes != null) { | 112 if (argumentTypes != null) { |
114 int count = argumentTypes.length; | 113 int count = argumentTypes.length; |
115 List<ParameterElement> parameters = new List<ParameterElement>(count); | 114 List<ParameterElement> parameters = new List<ParameterElement>(count); |
116 for (int i = 0; i < count; i++) { | 115 for (int i = 0; i < count; i++) { |
117 ParameterElementImpl parameter = new ParameterElementImpl("a$i", i); | 116 ParameterElementImpl parameter = new ParameterElementImpl("a$i", i); |
118 parameter.type = argumentTypes[i]; | 117 parameter.type = argumentTypes[i]; |
119 parameter.parameterKind = ParameterKind.REQUIRED; | 118 parameter.parameterKind = ParameterKind.REQUIRED; |
120 parameters[i] = parameter; | 119 parameters[i] = parameter; |
121 } | 120 } |
122 constructor.parameters = parameters; | 121 constructor.parameters = parameters; |
123 } else { | 122 } else { |
124 constructor.parameters = <ParameterElement>[]; | 123 constructor.parameters = <ParameterElement>[]; |
125 } | 124 } |
126 constructor.returnType = type; | |
127 constructor.enclosingElement = definingClass; | 125 constructor.enclosingElement = definingClass; |
128 constructor.type = new FunctionTypeImpl(constructor); | |
129 if (!constructor.isSynthetic) { | 126 if (!constructor.isSynthetic) { |
130 constructor.constantInitializers = <ConstructorInitializer>[]; | 127 constructor.constantInitializers = <ConstructorInitializer>[]; |
131 } | 128 } |
132 return constructor; | 129 return constructor; |
133 } | 130 } |
134 | 131 |
135 static ConstructorElementImpl constructorElement2( | 132 static ConstructorElementImpl constructorElement2( |
136 ClassElement definingClass, String name, | 133 ClassElement definingClass, String name, |
137 [List<DartType> argumentTypes]) => | 134 [List<DartType> argumentTypes]) => |
138 constructorElement(definingClass, name, false, argumentTypes); | 135 constructorElement(definingClass, name, false, argumentTypes); |
139 | 136 |
140 static EnumElementImpl enumElement( | 137 static EnumElementImpl enumElement(TypeProvider typeProvider, String enumName, |
141 TypeProvider typeProvider, String enumName, | |
142 [List<String> constantNames]) { | 138 [List<String> constantNames]) { |
143 // | 139 // |
144 // Build the enum. | 140 // Build the enum. |
145 // | 141 // |
146 EnumElementImpl enumElement = new EnumElementImpl(enumName, -1); | 142 EnumElementImpl enumElement = new EnumElementImpl(enumName, -1); |
147 InterfaceTypeImpl enumType = new InterfaceTypeImpl(enumElement); | 143 InterfaceTypeImpl enumType = new InterfaceTypeImpl(enumElement); |
148 enumElement.type = enumType; | 144 enumElement.type = enumType; |
149 // | 145 // |
150 // Populate the fields. | 146 // Populate the fields. |
151 // | 147 // |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 } | 617 } |
622 | 618 |
623 static TypeParameterElementImpl typeParameterWithType(String name, | 619 static TypeParameterElementImpl typeParameterWithType(String name, |
624 [DartType bound]) { | 620 [DartType bound]) { |
625 TypeParameterElementImpl typeParameter = typeParameterElement(name); | 621 TypeParameterElementImpl typeParameter = typeParameterElement(name); |
626 typeParameter.type = new TypeParameterTypeImpl(typeParameter); | 622 typeParameter.type = new TypeParameterTypeImpl(typeParameter); |
627 typeParameter.bound = bound; | 623 typeParameter.bound = bound; |
628 return typeParameter; | 624 return typeParameter; |
629 } | 625 } |
630 } | 626 } |
OLD | NEW |