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

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

Issue 2647833002: fix #28008, fix #28009 implement FutureOr<T> (Closed)
Patch Set: Merge remote-tracking branch 'origin/master' into 28008_futureort Created 3 years, 11 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 17 matching lines...) Expand all
239 ClassElementImpl streamElement = 244 ClassElementImpl streamElement =
240 ElementFactory.classElement2("Stream", ["T"]); 245 ElementFactory.classElement2("Stream", ["T"]);
241 streamElement.abstract = true; 246 streamElement.abstract = true;
242 streamElement.constructors = <ConstructorElement>[ 247 streamElement.constructors = <ConstructorElement>[
243 ElementFactory.constructorElement2(streamElement, null) 248 ElementFactory.constructorElement2(streamElement, null)
244 ]; 249 ];
245 DartType returnType = streamSubscriptionElement.type 250 DartType returnType = streamSubscriptionElement.type
246 .instantiate(streamElement.type.typeArguments); 251 .instantiate(streamElement.type.typeArguments);
247 FunctionElementImpl listenOnData = ElementFactory.functionElement3( 252 FunctionElementImpl listenOnData = ElementFactory.functionElement3(
248 'onData', 253 'onData',
249 VoidTypeImpl.instance.element, 254 VoidTypeImpl.instance,
250 <TypeDefiningElement>[streamElement.typeParameters[0]], 255 <TypeDefiningElement>[streamElement.typeParameters[0]],
251 null); 256 null);
252 listenOnData.isSynthetic = true; 257 listenOnData.isSynthetic = true;
253 List<DartType> parameterTypes = <DartType>[ 258 List<DartType> parameterTypes = <DartType>[
254 listenOnData.type, 259 listenOnData.type,
255 ]; 260 ];
256 // TODO(brianwilkerson) This is missing the optional parameters. 261 // TODO(brianwilkerson) This is missing the optional parameters.
257 MethodElementImpl listenMethod = 262 MethodElementImpl listenMethod =
258 ElementFactory.methodElement('listen', returnType, parameterTypes); 263 ElementFactory.methodElement('listen', returnType, parameterTypes);
259 streamElement.methods = <MethodElement>[listenMethod]; 264 streamElement.methods = <MethodElement>[listenMethod];
260 listenMethod.type = new FunctionTypeImpl(listenMethod); 265 listenMethod.type = new FunctionTypeImpl(listenMethod);
261 266
262 FunctionElementImpl listenParamFunction = parameterTypes[0].element; 267 FunctionElementImpl listenParamFunction = parameterTypes[0].element;
263 listenParamFunction.enclosingElement = listenMethod; 268 listenParamFunction.enclosingElement = listenMethod;
264 listenParamFunction.type = new FunctionTypeImpl(listenParamFunction); 269 listenParamFunction.type = new FunctionTypeImpl(listenParamFunction);
265 ParameterElementImpl listenParam = listenMethod.parameters[0]; 270 ParameterElementImpl listenParam = listenMethod.parameters[0];
266 listenParam.type = listenParamFunction.type; 271 listenParam.type = listenParamFunction.type;
267 272
268 asyncUnit.types = <ClassElement>[ 273 asyncUnit.types = <ClassElement>[
269 completerElement, 274 completerElement,
270 futureElement, 275 futureElement,
276 futureOrElement,
271 streamElement, 277 streamElement,
272 streamSubscriptionElement 278 streamSubscriptionElement
273 ]; 279 ];
274 // 280 //
275 // dart:html 281 // dart:html
276 // 282 //
277 CompilationUnitElementImpl htmlUnit = 283 CompilationUnitElementImpl htmlUnit =
278 new CompilationUnitElementImpl("html_dartium.dart"); 284 new CompilationUnitElementImpl("html_dartium.dart");
279 Source htmlSource = sourceFactory.forUri(DartSdk.DART_HTML); 285 Source htmlSource = sourceFactory.forUri(DartSdk.DART_HTML);
280 coreContext.setContents(htmlSource, ""); 286 coreContext.setContents(htmlSource, "");
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 contextElement, 320 contextElement,
315 context2dElement, 321 context2dElement,
316 ElementFactory.classElement("DivElement", elementType), 322 ElementFactory.classElement("DivElement", elementType),
317 documentElement, 323 documentElement,
318 elementElement, 324 elementElement,
319 htmlDocumentElement, 325 htmlDocumentElement,
320 ElementFactory.classElement("InputElement", elementType), 326 ElementFactory.classElement("InputElement", elementType),
321 ElementFactory.classElement("SelectElement", elementType) 327 ElementFactory.classElement("SelectElement", elementType)
322 ]; 328 ];
323 htmlUnit.functions = <FunctionElement>[ 329 htmlUnit.functions = <FunctionElement>[
324 ElementFactory.functionElement3("query", elementElement, 330 ElementFactory.functionElement3("query", elementElement.type,
325 <ClassElement>[provider.stringType.element], ClassElement.EMPTY_LIST) 331 <ClassElement>[provider.stringType.element], ClassElement.EMPTY_LIST)
326 ]; 332 ];
327 TopLevelVariableElementImpl document = 333 TopLevelVariableElementImpl document =
328 ElementFactory.topLevelVariableElement3( 334 ElementFactory.topLevelVariableElement3(
329 "document", false, true, htmlDocumentElement.type); 335 "document", false, true, htmlDocumentElement.type);
330 htmlUnit.topLevelVariables = <TopLevelVariableElement>[document]; 336 htmlUnit.topLevelVariables = <TopLevelVariableElement>[document];
331 htmlUnit.accessors = <PropertyAccessorElement>[document.getter]; 337 htmlUnit.accessors = <PropertyAccessorElement>[document.getter];
332 LibraryElementImpl htmlLibrary = new LibraryElementImpl.forNode(coreContext, 338 LibraryElementImpl htmlLibrary = new LibraryElementImpl.forNode(coreContext,
333 AstTestFactory.libraryIdentifier2(["dart", "dom", "html"])); 339 AstTestFactory.libraryIdentifier2(["dart", "dom", "html"]));
334 htmlLibrary.definingCompilationUnit = htmlUnit; 340 htmlLibrary.definingCompilationUnit = htmlUnit;
335 // 341 //
336 // dart:math 342 // dart:math
337 // 343 //
338 CompilationUnitElementImpl mathUnit = 344 CompilationUnitElementImpl mathUnit =
339 new CompilationUnitElementImpl("math.dart"); 345 new CompilationUnitElementImpl("math.dart");
340 Source mathSource = sourceFactory.forUri(_DART_MATH); 346 Source mathSource = sourceFactory.forUri(_DART_MATH);
341 coreContext.setContents(mathSource, ""); 347 coreContext.setContents(mathSource, "");
342 mathUnit.librarySource = mathUnit.source = mathSource; 348 mathUnit.librarySource = mathUnit.source = mathSource;
343 FunctionElement cosElement = ElementFactory.functionElement3( 349 FunctionElement cosElement = ElementFactory.functionElement3(
344 "cos", 350 "cos",
345 provider.doubleType.element, 351 provider.doubleType,
346 <ClassElement>[provider.numType.element], 352 <ClassElement>[provider.numType.element],
347 ClassElement.EMPTY_LIST); 353 ClassElement.EMPTY_LIST);
348 TopLevelVariableElement ln10Element = ElementFactory 354 TopLevelVariableElement ln10Element = ElementFactory
349 .topLevelVariableElement3("LN10", true, false, provider.doubleType); 355 .topLevelVariableElement3("LN10", true, false, provider.doubleType);
350 TypeParameterElement maxT = 356 TypeParameterElement maxT =
351 ElementFactory.typeParameterWithType('T', provider.numType); 357 ElementFactory.typeParameterWithType('T', provider.numType);
352 FunctionElementImpl maxElement = ElementFactory.functionElement3( 358 FunctionElementImpl maxElement = ElementFactory.functionElement3(
353 "max", maxT, [maxT, maxT], ClassElement.EMPTY_LIST); 359 "max", maxT.type, [maxT, maxT], ClassElement.EMPTY_LIST);
354 maxElement.typeParameters = [maxT]; 360 maxElement.typeParameters = [maxT];
355 maxElement.type = new FunctionTypeImpl(maxElement); 361 maxElement.type = new FunctionTypeImpl(maxElement);
356 TopLevelVariableElement piElement = ElementFactory.topLevelVariableElement3( 362 TopLevelVariableElement piElement = ElementFactory.topLevelVariableElement3(
357 "PI", true, false, provider.doubleType); 363 "PI", true, false, provider.doubleType);
358 ClassElementImpl randomElement = ElementFactory.classElement2("Random"); 364 ClassElementImpl randomElement = ElementFactory.classElement2("Random");
359 randomElement.abstract = true; 365 randomElement.abstract = true;
360 ConstructorElementImpl randomConstructor = 366 ConstructorElementImpl randomConstructor =
361 ElementFactory.constructorElement2(randomElement, null); 367 ElementFactory.constructorElement2(randomElement, null);
362 randomConstructor.factory = true; 368 randomConstructor.factory = true;
363 ParameterElementImpl seedParam = new ParameterElementImpl("seed", 0); 369 ParameterElementImpl seedParam = new ParameterElementImpl("seed", 0);
364 seedParam.parameterKind = ParameterKind.POSITIONAL; 370 seedParam.parameterKind = ParameterKind.POSITIONAL;
365 seedParam.type = provider.intType; 371 seedParam.type = provider.intType;
366 randomConstructor.parameters = <ParameterElement>[seedParam]; 372 randomConstructor.parameters = <ParameterElement>[seedParam];
367 randomElement.constructors = <ConstructorElement>[randomConstructor]; 373 randomElement.constructors = <ConstructorElement>[randomConstructor];
368 FunctionElement sinElement = ElementFactory.functionElement3( 374 FunctionElement sinElement = ElementFactory.functionElement3(
369 "sin", 375 "sin",
370 provider.doubleType.element, 376 provider.doubleType,
371 <ClassElement>[provider.numType.element], 377 <ClassElement>[provider.numType.element],
372 ClassElement.EMPTY_LIST); 378 ClassElement.EMPTY_LIST);
373 FunctionElement sqrtElement = ElementFactory.functionElement3( 379 FunctionElement sqrtElement = ElementFactory.functionElement3(
374 "sqrt", 380 "sqrt",
375 provider.doubleType.element, 381 provider.doubleType,
376 <ClassElement>[provider.numType.element], 382 <ClassElement>[provider.numType.element],
377 ClassElement.EMPTY_LIST); 383 ClassElement.EMPTY_LIST);
378 mathUnit.accessors = <PropertyAccessorElement>[ 384 mathUnit.accessors = <PropertyAccessorElement>[
379 ln10Element.getter, 385 ln10Element.getter,
380 piElement.getter 386 piElement.getter
381 ]; 387 ];
382 mathUnit.functions = <FunctionElement>[ 388 mathUnit.functions = <FunctionElement>[
383 cosElement, 389 cosElement,
384 maxElement, 390 maxElement,
385 sinElement, 391 sinElement,
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 578
573 void _addLibrary(LibraryMap map, String uri, bool isInternal, String path) { 579 void _addLibrary(LibraryMap map, String uri, bool isInternal, String path) {
574 SdkLibraryImpl library = new SdkLibraryImpl(uri); 580 SdkLibraryImpl library = new SdkLibraryImpl(uri);
575 if (isInternal) { 581 if (isInternal) {
576 library.category = "Internal"; 582 library.category = "Internal";
577 } 583 }
578 library.path = path; 584 library.path = path;
579 map.setLibrary(uri, library); 585 map.setLibrary(uri, library);
580 } 586 }
581 } 587 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/resynthesize.dart ('k') | pkg/analyzer/test/generated/resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698