Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: pkg/analyzer/test/generated/analysis_context_factory.dart

Issue 2647833002: fix #28008, fix #28009 implement FutureOr<T> (Closed)
Patch Set: add test Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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.test.generated.analysis_context_factory; 5 library analyzer.test.generated.analysis_context_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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 provider.numType.element, 134 provider.numType.element,
135 objectClassElement, 135 objectClassElement,
136 overrideClassElement, 136 overrideClassElement,
137 proxyClassElement, 137 proxyClassElement,
138 provider.stackTraceType.element, 138 provider.stackTraceType.element,
139 provider.stringType.element, 139 provider.stringType.element,
140 provider.symbolType.element, 140 provider.symbolType.element,
141 provider.typeType.element 141 provider.typeType.element
142 ]; 142 ];
143 coreUnit.functions = <FunctionElement>[ 143 coreUnit.functions = <FunctionElement>[
144 ElementFactory.functionElement3("identical", provider.boolType.element, 144 ElementFactory.functionElement3("identical", provider.boolType,
145 <ClassElement>[objectClassElement, objectClassElement], null), 145 <ClassElement>[objectClassElement, objectClassElement], null),
146 ElementFactory.functionElement3("print", VoidTypeImpl.instance.element, 146 ElementFactory.functionElement3("print", VoidTypeImpl.instance,
147 <ClassElement>[objectClassElement], null) 147 <ClassElement>[objectClassElement], null)
148 ]; 148 ];
149 TopLevelVariableElement proxyTopLevelVariableElt = ElementFactory 149 TopLevelVariableElement proxyTopLevelVariableElt = ElementFactory
150 .topLevelVariableElement3("proxy", true, false, proxyClassElement.type); 150 .topLevelVariableElement3("proxy", true, false, proxyClassElement.type);
151 ConstTopLevelVariableElementImpl deprecatedTopLevelVariableElt = 151 ConstTopLevelVariableElementImpl deprecatedTopLevelVariableElt =
152 ElementFactory.topLevelVariableElement3( 152 ElementFactory.topLevelVariableElement3(
153 "deprecated", true, false, provider.deprecatedType); 153 "deprecated", true, false, provider.deprecatedType);
154 TopLevelVariableElement overrideTopLevelVariableElt = 154 TopLevelVariableElement overrideTopLevelVariableElt =
155 ElementFactory.topLevelVariableElement3( 155 ElementFactory.topLevelVariableElement3(
156 "override", true, false, overrideClassElement.type); 156 "override", true, false, overrideClassElement.type);
(...skipping 26 matching lines...) Expand all
183 // dart:async 183 // dart:async
184 // 184 //
185 LibraryElementImpl asyncLibrary = new LibraryElementImpl.forNode( 185 LibraryElementImpl asyncLibrary = new LibraryElementImpl.forNode(
186 coreContext, AstTestFactory.libraryIdentifier2(["dart", "async"])); 186 coreContext, AstTestFactory.libraryIdentifier2(["dart", "async"]));
187 CompilationUnitElementImpl asyncUnit = 187 CompilationUnitElementImpl asyncUnit =
188 new CompilationUnitElementImpl("async.dart"); 188 new CompilationUnitElementImpl("async.dart");
189 Source asyncSource = sourceFactory.forUri(DartSdk.DART_ASYNC); 189 Source asyncSource = sourceFactory.forUri(DartSdk.DART_ASYNC);
190 coreContext.setContents(asyncSource, ""); 190 coreContext.setContents(asyncSource, "");
191 asyncUnit.librarySource = asyncUnit.source = asyncSource; 191 asyncUnit.librarySource = asyncUnit.source = asyncSource;
192 asyncLibrary.definingCompilationUnit = asyncUnit; 192 asyncLibrary.definingCompilationUnit = asyncUnit;
193 // Future 193 // Future<T>
194 ClassElementImpl futureElement = 194 ClassElementImpl futureElement =
195 ElementFactory.classElement2("Future", ["T"]); 195 ElementFactory.classElement2("Future", ["T"]);
196 // FutureOr<T>
197 ClassElementImpl futureOrElement =
198 ElementFactory.classElement2("FutureOr", ["T"]);
196 futureElement.enclosingElement = asyncUnit; 199 futureElement.enclosingElement = asyncUnit;
197 // factory Future.value([value]) 200 // factory Future.value([value])
198 ConstructorElementImpl futureConstructor = 201 ConstructorElementImpl futureConstructor =
199 ElementFactory.constructorElement2(futureElement, "value"); 202 ElementFactory.constructorElement2(futureElement, "value");
200 futureConstructor.parameters = <ParameterElement>[ 203 futureConstructor.parameters = <ParameterElement>[
201 ElementFactory.positionalParameter2("value", provider.dynamicType) 204 ElementFactory.positionalParameter2("value", provider.dynamicType)
202 ]; 205 ];
203 futureConstructor.factory = true; 206 futureConstructor.factory = true;
204 futureElement.constructors = <ConstructorElement>[futureConstructor]; 207 futureElement.constructors = <ConstructorElement>[futureConstructor];
205 // Future then(onValue(T value), { Function onError }); 208 // Future<R> then<R>(FutureOr<R> onValue(T value), { Function onError });
206 TypeDefiningElement futureThenR = DynamicElementImpl.instance; 209 TypeDefiningElement futureThenR = DynamicElementImpl.instance;
210 DartType onValueReturnType = DynamicTypeImpl.instance;
207 if (context.analysisOptions.strongMode) { 211 if (context.analysisOptions.strongMode) {
208 futureThenR = ElementFactory.typeParameterWithType('R'); 212 futureThenR = ElementFactory.typeParameterWithType('R');
213 onValueReturnType = futureOrElement.type.instantiate([futureThenR.type]);
209 } 214 }
210 FunctionElementImpl thenOnValue = ElementFactory.functionElement3('onValue', 215 FunctionElementImpl thenOnValue = ElementFactory.functionElement3('onValue',
211 DynamicElementImpl.instance, [futureElement.typeParameters[0]], null); 216 onValueReturnType, [futureElement.typeParameters[0]], null);
212 thenOnValue.isSynthetic = true; 217 thenOnValue.isSynthetic = true;
213 218
214 DartType futureRType = futureElement.type.instantiate([futureThenR.type]); 219 DartType futureRType = futureElement.type.instantiate([futureThenR.type]);
215 MethodElementImpl thenMethod = ElementFactory 220 MethodElementImpl thenMethod = ElementFactory
216 .methodElementWithParameters(futureElement, "then", futureRType, [ 221 .methodElementWithParameters(futureElement, "then", futureRType, [
217 ElementFactory.requiredParameter2("onValue", thenOnValue.type), 222 ElementFactory.requiredParameter2("onValue", thenOnValue.type),
218 ElementFactory.namedParameter2("onError", provider.functionType) 223 ElementFactory.namedParameter2("onError", provider.functionType)
219 ]); 224 ]);
220 if (!futureThenR.type.isDynamic) { 225 if (!futureThenR.type.isDynamic) {
221 thenMethod.typeParameters = <TypeParameterElement>[futureThenR]; 226 thenMethod.typeParameters = <TypeParameterElement>[futureThenR];
(...skipping 16 matching lines...) Expand all
238 // Stream 243 // Stream
239 ClassElementImpl streamElement = 244 ClassElementImpl streamElement =
240 ElementFactory.classElement2("Stream", ["T"]); 245 ElementFactory.classElement2("Stream", ["T"]);
241 streamElement.constructors = <ConstructorElement>[ 246 streamElement.constructors = <ConstructorElement>[
242 ElementFactory.constructorElement2(streamElement, null) 247 ElementFactory.constructorElement2(streamElement, null)
243 ]; 248 ];
244 DartType returnType = streamSubscriptionElement.type 249 DartType returnType = streamSubscriptionElement.type
245 .instantiate(streamElement.type.typeArguments); 250 .instantiate(streamElement.type.typeArguments);
246 FunctionElementImpl listenOnData = ElementFactory.functionElement3( 251 FunctionElementImpl listenOnData = ElementFactory.functionElement3(
247 'onData', 252 'onData',
248 VoidTypeImpl.instance.element, 253 VoidTypeImpl.instance,
249 <TypeDefiningElement>[streamElement.typeParameters[0]], 254 <TypeDefiningElement>[streamElement.typeParameters[0]],
250 null); 255 null);
251 listenOnData.isSynthetic = true; 256 listenOnData.isSynthetic = true;
252 List<DartType> parameterTypes = <DartType>[ 257 List<DartType> parameterTypes = <DartType>[
253 listenOnData.type, 258 listenOnData.type,
254 ]; 259 ];
255 // TODO(brianwilkerson) This is missing the optional parameters. 260 // TODO(brianwilkerson) This is missing the optional parameters.
256 MethodElementImpl listenMethod = 261 MethodElementImpl listenMethod =
257 ElementFactory.methodElement('listen', returnType, parameterTypes); 262 ElementFactory.methodElement('listen', returnType, parameterTypes);
258 streamElement.methods = <MethodElement>[listenMethod]; 263 streamElement.methods = <MethodElement>[listenMethod];
259 listenMethod.type = new FunctionTypeImpl(listenMethod); 264 listenMethod.type = new FunctionTypeImpl(listenMethod);
260 265
261 FunctionElementImpl listenParamFunction = parameterTypes[0].element; 266 FunctionElementImpl listenParamFunction = parameterTypes[0].element;
262 listenParamFunction.enclosingElement = listenMethod; 267 listenParamFunction.enclosingElement = listenMethod;
263 listenParamFunction.type = new FunctionTypeImpl(listenParamFunction); 268 listenParamFunction.type = new FunctionTypeImpl(listenParamFunction);
264 ParameterElementImpl listenParam = listenMethod.parameters[0]; 269 ParameterElementImpl listenParam = listenMethod.parameters[0];
265 listenParam.type = listenParamFunction.type; 270 listenParam.type = listenParamFunction.type;
266 271
267 asyncUnit.types = <ClassElement>[ 272 asyncUnit.types = <ClassElement>[
268 completerElement, 273 completerElement,
269 futureElement, 274 futureElement,
275 futureOrElement,
270 streamElement, 276 streamElement,
271 streamSubscriptionElement 277 streamSubscriptionElement
272 ]; 278 ];
273 // 279 //
274 // dart:html 280 // dart:html
275 // 281 //
276 CompilationUnitElementImpl htmlUnit = 282 CompilationUnitElementImpl htmlUnit =
277 new CompilationUnitElementImpl("html_dartium.dart"); 283 new CompilationUnitElementImpl("html_dartium.dart");
278 Source htmlSource = sourceFactory.forUri(DartSdk.DART_HTML); 284 Source htmlSource = sourceFactory.forUri(DartSdk.DART_HTML);
279 coreContext.setContents(htmlSource, ""); 285 coreContext.setContents(htmlSource, "");
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 contextElement, 319 contextElement,
314 context2dElement, 320 context2dElement,
315 ElementFactory.classElement("DivElement", elementType), 321 ElementFactory.classElement("DivElement", elementType),
316 documentElement, 322 documentElement,
317 elementElement, 323 elementElement,
318 htmlDocumentElement, 324 htmlDocumentElement,
319 ElementFactory.classElement("InputElement", elementType), 325 ElementFactory.classElement("InputElement", elementType),
320 ElementFactory.classElement("SelectElement", elementType) 326 ElementFactory.classElement("SelectElement", elementType)
321 ]; 327 ];
322 htmlUnit.functions = <FunctionElement>[ 328 htmlUnit.functions = <FunctionElement>[
323 ElementFactory.functionElement3("query", elementElement, 329 ElementFactory.functionElement3("query", elementElement.type,
324 <ClassElement>[provider.stringType.element], ClassElement.EMPTY_LIST) 330 <ClassElement>[provider.stringType.element], ClassElement.EMPTY_LIST)
325 ]; 331 ];
326 TopLevelVariableElementImpl document = 332 TopLevelVariableElementImpl document =
327 ElementFactory.topLevelVariableElement3( 333 ElementFactory.topLevelVariableElement3(
328 "document", false, true, htmlDocumentElement.type); 334 "document", false, true, htmlDocumentElement.type);
329 htmlUnit.topLevelVariables = <TopLevelVariableElement>[document]; 335 htmlUnit.topLevelVariables = <TopLevelVariableElement>[document];
330 htmlUnit.accessors = <PropertyAccessorElement>[document.getter]; 336 htmlUnit.accessors = <PropertyAccessorElement>[document.getter];
331 LibraryElementImpl htmlLibrary = new LibraryElementImpl.forNode(coreContext, 337 LibraryElementImpl htmlLibrary = new LibraryElementImpl.forNode(coreContext,
332 AstTestFactory.libraryIdentifier2(["dart", "dom", "html"])); 338 AstTestFactory.libraryIdentifier2(["dart", "dom", "html"]));
333 htmlLibrary.definingCompilationUnit = htmlUnit; 339 htmlLibrary.definingCompilationUnit = htmlUnit;
334 // 340 //
335 // dart:math 341 // dart:math
336 // 342 //
337 CompilationUnitElementImpl mathUnit = 343 CompilationUnitElementImpl mathUnit =
338 new CompilationUnitElementImpl("math.dart"); 344 new CompilationUnitElementImpl("math.dart");
339 Source mathSource = sourceFactory.forUri(_DART_MATH); 345 Source mathSource = sourceFactory.forUri(_DART_MATH);
340 coreContext.setContents(mathSource, ""); 346 coreContext.setContents(mathSource, "");
341 mathUnit.librarySource = mathUnit.source = mathSource; 347 mathUnit.librarySource = mathUnit.source = mathSource;
342 FunctionElement cosElement = ElementFactory.functionElement3( 348 FunctionElement cosElement = ElementFactory.functionElement3(
343 "cos", 349 "cos",
344 provider.doubleType.element, 350 provider.doubleType,
345 <ClassElement>[provider.numType.element], 351 <ClassElement>[provider.numType.element],
346 ClassElement.EMPTY_LIST); 352 ClassElement.EMPTY_LIST);
347 TopLevelVariableElement ln10Element = ElementFactory 353 TopLevelVariableElement ln10Element = ElementFactory
348 .topLevelVariableElement3("LN10", true, false, provider.doubleType); 354 .topLevelVariableElement3("LN10", true, false, provider.doubleType);
349 TypeParameterElement maxT = 355 TypeParameterElement maxT =
350 ElementFactory.typeParameterWithType('T', provider.numType); 356 ElementFactory.typeParameterWithType('T', provider.numType);
351 FunctionElementImpl maxElement = ElementFactory.functionElement3( 357 FunctionElementImpl maxElement = ElementFactory.functionElement3(
352 "max", maxT, [maxT, maxT], ClassElement.EMPTY_LIST); 358 "max", maxT.type, [maxT, maxT], ClassElement.EMPTY_LIST);
353 maxElement.typeParameters = [maxT]; 359 maxElement.typeParameters = [maxT];
354 maxElement.type = new FunctionTypeImpl(maxElement); 360 maxElement.type = new FunctionTypeImpl(maxElement);
355 TopLevelVariableElement piElement = ElementFactory.topLevelVariableElement3( 361 TopLevelVariableElement piElement = ElementFactory.topLevelVariableElement3(
356 "PI", true, false, provider.doubleType); 362 "PI", true, false, provider.doubleType);
357 ClassElementImpl randomElement = ElementFactory.classElement2("Random"); 363 ClassElementImpl randomElement = ElementFactory.classElement2("Random");
358 randomElement.abstract = true; 364 randomElement.abstract = true;
359 ConstructorElementImpl randomConstructor = 365 ConstructorElementImpl randomConstructor =
360 ElementFactory.constructorElement2(randomElement, null); 366 ElementFactory.constructorElement2(randomElement, null);
361 randomConstructor.factory = true; 367 randomConstructor.factory = true;
362 ParameterElementImpl seedParam = new ParameterElementImpl("seed", 0); 368 ParameterElementImpl seedParam = new ParameterElementImpl("seed", 0);
363 seedParam.parameterKind = ParameterKind.POSITIONAL; 369 seedParam.parameterKind = ParameterKind.POSITIONAL;
364 seedParam.type = provider.intType; 370 seedParam.type = provider.intType;
365 randomConstructor.parameters = <ParameterElement>[seedParam]; 371 randomConstructor.parameters = <ParameterElement>[seedParam];
366 randomElement.constructors = <ConstructorElement>[randomConstructor]; 372 randomElement.constructors = <ConstructorElement>[randomConstructor];
367 FunctionElement sinElement = ElementFactory.functionElement3( 373 FunctionElement sinElement = ElementFactory.functionElement3(
368 "sin", 374 "sin",
369 provider.doubleType.element, 375 provider.doubleType,
370 <ClassElement>[provider.numType.element], 376 <ClassElement>[provider.numType.element],
371 ClassElement.EMPTY_LIST); 377 ClassElement.EMPTY_LIST);
372 FunctionElement sqrtElement = ElementFactory.functionElement3( 378 FunctionElement sqrtElement = ElementFactory.functionElement3(
373 "sqrt", 379 "sqrt",
374 provider.doubleType.element, 380 provider.doubleType,
375 <ClassElement>[provider.numType.element], 381 <ClassElement>[provider.numType.element],
376 ClassElement.EMPTY_LIST); 382 ClassElement.EMPTY_LIST);
377 mathUnit.accessors = <PropertyAccessorElement>[ 383 mathUnit.accessors = <PropertyAccessorElement>[
378 ln10Element.getter, 384 ln10Element.getter,
379 piElement.getter 385 piElement.getter
380 ]; 386 ];
381 mathUnit.functions = <FunctionElement>[ 387 mathUnit.functions = <FunctionElement>[
382 cosElement, 388 cosElement,
383 maxElement, 389 maxElement,
384 sinElement, 390 sinElement,
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 577
572 void _addLibrary(LibraryMap map, String uri, bool isInternal, String path) { 578 void _addLibrary(LibraryMap map, String uri, bool isInternal, String path) {
573 SdkLibraryImpl library = new SdkLibraryImpl(uri); 579 SdkLibraryImpl library = new SdkLibraryImpl(uri);
574 if (isInternal) { 580 if (isInternal) {
575 library.category = "Internal"; 581 library.category = "Internal";
576 } 582 }
577 library.path = path; 583 library.path = path;
578 map.setLibrary(uri, library); 584 map.setLibrary(uri, library);
579 } 585 }
580 } 586 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698