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

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

Issue 1711873002: Fix for summarizing typedef typed parameters. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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) 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.test.generated.resolver_test; 5 library analyzer.test.generated.resolver_test;
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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 ]; 213 ];
214 futureConstructor.factory = true; 214 futureConstructor.factory = true;
215 futureElement.constructors = <ConstructorElement>[futureConstructor]; 215 futureElement.constructors = <ConstructorElement>[futureConstructor];
216 // Future then(onValue(T value), { Function onError }); 216 // Future then(onValue(T value), { Function onError });
217 TypeDefiningElement futureThenR = DynamicElementImpl.instance; 217 TypeDefiningElement futureThenR = DynamicElementImpl.instance;
218 if (context.analysisOptions.strongMode) { 218 if (context.analysisOptions.strongMode) {
219 futureThenR = ElementFactory.typeParameterWithType('R'); 219 futureThenR = ElementFactory.typeParameterWithType('R');
220 } 220 }
221 FunctionElementImpl thenOnValue = ElementFactory.functionElement3( 221 FunctionElementImpl thenOnValue = ElementFactory.functionElement3(
222 'onValue', futureThenR, [futureElement.typeParameters[0]], null); 222 'onValue', futureThenR, [futureElement.typeParameters[0]], null);
223 thenOnValue.synthetic = true;
223 224
224 DartType futureRType = futureElement.type.substitute4([futureThenR.type]); 225 DartType futureRType = futureElement.type.substitute4([futureThenR.type]);
225 MethodElementImpl thenMethod = ElementFactory 226 MethodElementImpl thenMethod = ElementFactory
226 .methodElementWithParameters(futureElement, "then", futureRType, [ 227 .methodElementWithParameters(futureElement, "then", futureRType, [
227 ElementFactory.requiredParameter2("onValue", thenOnValue.type), 228 ElementFactory.requiredParameter2("onValue", thenOnValue.type),
228 ElementFactory.namedParameter2("onError", provider.functionType) 229 ElementFactory.namedParameter2("onError", provider.functionType)
229 ]); 230 ]);
230 if (!futureThenR.type.isDynamic) { 231 if (!futureThenR.type.isDynamic) {
231 thenMethod.typeParameters = [futureThenR]; 232 thenMethod.typeParameters = [futureThenR];
232 } 233 }
(...skipping 16 matching lines...) Expand all
249 ClassElementImpl streamSubscriptionElement = 250 ClassElementImpl streamSubscriptionElement =
250 ElementFactory.classElement2("StreamSubscription", ["T"]); 251 ElementFactory.classElement2("StreamSubscription", ["T"]);
251 // Stream 252 // Stream
252 ClassElementImpl streamElement = 253 ClassElementImpl streamElement =
253 ElementFactory.classElement2("Stream", ["T"]); 254 ElementFactory.classElement2("Stream", ["T"]);
254 streamElement.constructors = <ConstructorElement>[ 255 streamElement.constructors = <ConstructorElement>[
255 ElementFactory.constructorElement2(streamElement, null) 256 ElementFactory.constructorElement2(streamElement, null)
256 ]; 257 ];
257 DartType returnType = streamSubscriptionElement.type 258 DartType returnType = streamSubscriptionElement.type
258 .substitute4(streamElement.type.typeArguments); 259 .substitute4(streamElement.type.typeArguments);
259 List<DartType> parameterTypes = <DartType>[ 260 FunctionElementImpl listenOnData = ElementFactory.functionElement3(
260 ElementFactory 261 'onData',
261 .functionElement3('onData', VoidTypeImpl.instance.element, 262 VoidTypeImpl.instance.element,
262 <TypeDefiningElement>[streamElement.typeParameters[0]], null) 263 <TypeDefiningElement>[streamElement.typeParameters[0]],
263 .type, 264 null);
264 ]; 265 listenOnData.synthetic = true;
266 List<DartType> parameterTypes = <DartType>[listenOnData.type,];
265 // TODO(brianwilkerson) This is missing the optional parameters. 267 // TODO(brianwilkerson) This is missing the optional parameters.
266 MethodElementImpl listenMethod = 268 MethodElementImpl listenMethod =
267 ElementFactory.methodElement('listen', returnType, parameterTypes); 269 ElementFactory.methodElement('listen', returnType, parameterTypes);
268 streamElement.methods = <MethodElement>[listenMethod]; 270 streamElement.methods = <MethodElement>[listenMethod];
269 listenMethod.type = new FunctionTypeImpl(listenMethod); 271 listenMethod.type = new FunctionTypeImpl(listenMethod);
270 272
271 FunctionElementImpl listenParamFunction = parameterTypes[0].element; 273 FunctionElementImpl listenParamFunction = parameterTypes[0].element;
272 listenParamFunction.enclosingElement = listenMethod; 274 listenParamFunction.enclosingElement = listenMethod;
273 listenParamFunction.type = new FunctionTypeImpl(listenParamFunction); 275 listenParamFunction.type = new FunctionTypeImpl(listenParamFunction);
274 ParameterElementImpl listenParam = listenMethod.parameters[0]; 276 ParameterElementImpl listenParam = listenMethod.parameters[0];
(...skipping 16675 matching lines...) Expand 10 before | Expand all | Expand 10 after
16950 16952
16951 /** 16953 /**
16952 * Shared infrastructure for [StaticTypeAnalyzer2Test] and 16954 * Shared infrastructure for [StaticTypeAnalyzer2Test] and
16953 * [StrongModeStaticTypeAnalyzer2Test]. 16955 * [StrongModeStaticTypeAnalyzer2Test].
16954 */ 16956 */
16955 class _StaticTypeAnalyzer2TestShared extends ResolverTestCase { 16957 class _StaticTypeAnalyzer2TestShared extends ResolverTestCase {
16956 String testCode; 16958 String testCode;
16957 Source testSource; 16959 Source testSource;
16958 CompilationUnit testUnit; 16960 CompilationUnit testUnit;
16959 16961
16960 SimpleIdentifier _findIdentifier(String search) { 16962 /**
16961 SimpleIdentifier identifier = EngineTestCase.findNode( 16963 * Looks up the identifier with [name] and validates that its type type
16962 testUnit, testCode, search, (node) => node is SimpleIdentifier); 16964 * stringifies to [type] and that its generics match the given stringified
16963 return identifier; 16965 * output.
16966 */
16967 _expectFunctionType(String name, String type,
16968 {String elementTypeParams: '[]',
16969 String typeParams: '[]',
16970 String typeArgs: '[]',
16971 String typeFormals: '[]'}) {
16972 SimpleIdentifier identifier = _findIdentifier(name);
16973 // Element is either ExecutableElement or ParameterElement.
16974 var element = identifier.staticElement;
16975 FunctionTypeImpl functionType = identifier.staticType;
16976 expect(functionType.toString(), type);
16977 expect(element.typeParameters.toString(), elementTypeParams);
16978 expect(functionType.typeParameters.toString(), typeParams);
16979 expect(functionType.typeArguments.toString(), typeArgs);
16980 expect(functionType.typeFormals.toString(), typeFormals);
16964 } 16981 }
16965 16982
16966 /** 16983 /**
16967 * Looks up the identifier with [name] and validates its static [type]. 16984 * Looks up the identifier with [name] and validates its static [type].
16968 * 16985 *
16969 * If [type] is a string, validates that the identifier's static type 16986 * If [type] is a string, validates that the identifier's static type
16970 * stringifies to that text. Otherwise, [type] is used directly a [Matcher] 16987 * stringifies to that text. Otherwise, [type] is used directly a [Matcher]
16971 * to match the type. 16988 * to match the type.
16972 * 16989 *
16973 * If [propagatedType] is given, also validate's the identifier's propagated 16990 * If [propagatedType] is given, also validate's the identifier's propagated
(...skipping 23 matching lines...) Expand all
16997 VariableDeclaration declaration = 17014 VariableDeclaration declaration =
16998 identifier.getAncestor((node) => node is VariableDeclaration); 17015 identifier.getAncestor((node) => node is VariableDeclaration);
16999 Expression initializer = declaration.initializer; 17016 Expression initializer = declaration.initializer;
17000 _expectType(initializer.staticType, type); 17017 _expectType(initializer.staticType, type);
17001 if (propagatedType != null) { 17018 if (propagatedType != null) {
17002 _expectType(initializer.propagatedType, propagatedType); 17019 _expectType(initializer.propagatedType, propagatedType);
17003 } 17020 }
17004 } 17021 }
17005 17022
17006 /** 17023 /**
17007 * Looks up the identifier with [name] and validates that its type type
17008 * stringifies to [type] and that its generics match the given stringified
17009 * output.
17010 */
17011 _expectFunctionType(String name, String type,
17012 {String elementTypeParams: '[]',
17013 String typeParams: '[]',
17014 String typeArgs: '[]',
17015 String typeFormals: '[]'}) {
17016 SimpleIdentifier identifier = _findIdentifier(name);
17017 // Element is either ExecutableElement or ParameterElement.
17018 var element = identifier.staticElement;
17019 FunctionTypeImpl functionType = identifier.staticType;
17020 expect(functionType.toString(), type);
17021 expect(element.typeParameters.toString(), elementTypeParams);
17022 expect(functionType.typeParameters.toString(), typeParams);
17023 expect(functionType.typeArguments.toString(), typeArgs);
17024 expect(functionType.typeFormals.toString(), typeFormals);
17025 }
17026
17027 /**
17028 * Validates that [type] matches [expected]. 17024 * Validates that [type] matches [expected].
17029 * 17025 *
17030 * If [expected] is a string, validates that the type stringifies to that 17026 * If [expected] is a string, validates that the type stringifies to that
17031 * text. Otherwise, [expected] is used directly a [Matcher] to match the type. 17027 * text. Otherwise, [expected] is used directly a [Matcher] to match the type.
17032 */ 17028 */
17033 _expectType(DartType type, expected) { 17029 _expectType(DartType type, expected) {
17034 if (expected is String) { 17030 if (expected is String) {
17035 expect(type.toString(), expected); 17031 expect(type.toString(), expected);
17036 } else { 17032 } else {
17037 expect(type, expected); 17033 expect(type, expected);
17038 } 17034 }
17039 } 17035 }
17040 17036
17037 SimpleIdentifier _findIdentifier(String search) {
17038 SimpleIdentifier identifier = EngineTestCase.findNode(
17039 testUnit, testCode, search, (node) => node is SimpleIdentifier);
17040 return identifier;
17041 }
17042
17041 void _resolveTestUnit(String code) { 17043 void _resolveTestUnit(String code) {
17042 testCode = code; 17044 testCode = code;
17043 testSource = addSource(testCode); 17045 testSource = addSource(testCode);
17044 LibraryElement library = resolve2(testSource); 17046 LibraryElement library = resolve2(testSource);
17045 assertNoErrors(testSource); 17047 assertNoErrors(testSource);
17046 verify([testSource]); 17048 verify([testSource]);
17047 testUnit = resolveCompilationUnit(testSource, library); 17049 testUnit = resolveCompilationUnit(testSource, library);
17048 } 17050 }
17049 } 17051 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/summarize_elements.dart ('k') | pkg/analyzer/test/src/summary/resynthesize_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698