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

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

Issue 1022843002: Rewrite ImplicitConstructorBuilder to use only element model. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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 | Annotate | Revision Log
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 engine.resolver_test; 5 library engine.resolver_test;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/src/generated/ast.dart'; 9 import 'package:analyzer/src/generated/ast.dart';
10 import 'package:analyzer/src/generated/element.dart'; 10 import 'package:analyzer/src/generated/element.dart';
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 contextElement, 265 contextElement,
266 context2dElement, 266 context2dElement,
267 ElementFactory.classElement("DivElement", elementType), 267 ElementFactory.classElement("DivElement", elementType),
268 documentElement, 268 documentElement,
269 elementElement, 269 elementElement,
270 htmlDocumentElement, 270 htmlDocumentElement,
271 ElementFactory.classElement("InputElement", elementType), 271 ElementFactory.classElement("InputElement", elementType),
272 ElementFactory.classElement("SelectElement", elementType) 272 ElementFactory.classElement("SelectElement", elementType)
273 ]; 273 ];
274 htmlUnit.functions = <FunctionElement>[ 274 htmlUnit.functions = <FunctionElement>[
275 ElementFactory.functionElement3("query", elementElement, <ClassElement>[ 275 ElementFactory.functionElement3("query", elementElement,
276 provider.stringType.element 276 <ClassElement>[provider.stringType.element],
277 ], ClassElementImpl.EMPTY_ARRAY) 277 ClassElementImpl.EMPTY_ARRAY)
278 ]; 278 ];
279 TopLevelVariableElementImpl document = ElementFactory 279 TopLevelVariableElementImpl document = ElementFactory
280 .topLevelVariableElement3( 280 .topLevelVariableElement3(
281 "document", false, true, htmlDocumentElement.type); 281 "document", false, true, htmlDocumentElement.type);
282 htmlUnit.topLevelVariables = <TopLevelVariableElement>[document]; 282 htmlUnit.topLevelVariables = <TopLevelVariableElement>[document];
283 htmlUnit.accessors = <PropertyAccessorElement>[document.getter]; 283 htmlUnit.accessors = <PropertyAccessorElement>[document.getter];
284 LibraryElementImpl htmlLibrary = new LibraryElementImpl.forNode( 284 LibraryElementImpl htmlLibrary = new LibraryElementImpl.forNode(
285 coreContext, AstFactory.libraryIdentifier2(["dart", "dom", "html"])); 285 coreContext, AstFactory.libraryIdentifier2(["dart", "dom", "html"]));
286 htmlLibrary.definingCompilationUnit = htmlUnit; 286 htmlLibrary.definingCompilationUnit = htmlUnit;
287 // 287 //
288 // dart:math 288 // dart:math
289 // 289 //
290 CompilationUnitElementImpl mathUnit = 290 CompilationUnitElementImpl mathUnit =
291 new CompilationUnitElementImpl("math.dart"); 291 new CompilationUnitElementImpl("math.dart");
292 Source mathSource = sourceFactory.forUri(_DART_MATH); 292 Source mathSource = sourceFactory.forUri(_DART_MATH);
293 coreContext.setContents(mathSource, ""); 293 coreContext.setContents(mathSource, "");
294 mathUnit.source = mathSource; 294 mathUnit.source = mathSource;
295 FunctionElement cosElement = ElementFactory.functionElement3("cos", 295 FunctionElement cosElement = ElementFactory.functionElement3("cos",
296 provider.doubleType.element, <ClassElement>[ 296 provider.doubleType.element, <ClassElement>[provider.numType.element],
297 provider.numType.element 297 ClassElementImpl.EMPTY_ARRAY);
298 ], ClassElementImpl.EMPTY_ARRAY);
299 TopLevelVariableElement ln10Element = ElementFactory 298 TopLevelVariableElement ln10Element = ElementFactory
300 .topLevelVariableElement3("LN10", true, false, provider.doubleType); 299 .topLevelVariableElement3("LN10", true, false, provider.doubleType);
301 TopLevelVariableElement piElement = ElementFactory.topLevelVariableElement3( 300 TopLevelVariableElement piElement = ElementFactory.topLevelVariableElement3(
302 "PI", true, false, provider.doubleType); 301 "PI", true, false, provider.doubleType);
303 ClassElementImpl randomElement = ElementFactory.classElement2("Random"); 302 ClassElementImpl randomElement = ElementFactory.classElement2("Random");
304 randomElement.abstract = true; 303 randomElement.abstract = true;
305 ConstructorElementImpl randomConstructor = 304 ConstructorElementImpl randomConstructor =
306 ElementFactory.constructorElement2(randomElement, null); 305 ElementFactory.constructorElement2(randomElement, null);
307 randomConstructor.factory = true; 306 randomConstructor.factory = true;
308 ParameterElementImpl seedParam = new ParameterElementImpl("seed", 0); 307 ParameterElementImpl seedParam = new ParameterElementImpl("seed", 0);
309 seedParam.parameterKind = ParameterKind.POSITIONAL; 308 seedParam.parameterKind = ParameterKind.POSITIONAL;
310 seedParam.type = provider.intType; 309 seedParam.type = provider.intType;
311 randomConstructor.parameters = <ParameterElement>[seedParam]; 310 randomConstructor.parameters = <ParameterElement>[seedParam];
312 randomElement.constructors = <ConstructorElement>[randomConstructor]; 311 randomElement.constructors = <ConstructorElement>[randomConstructor];
313 FunctionElement sinElement = ElementFactory.functionElement3("sin", 312 FunctionElement sinElement = ElementFactory.functionElement3("sin",
314 provider.doubleType.element, <ClassElement>[ 313 provider.doubleType.element, <ClassElement>[provider.numType.element],
315 provider.numType.element 314 ClassElementImpl.EMPTY_ARRAY);
316 ], ClassElementImpl.EMPTY_ARRAY);
317 FunctionElement sqrtElement = ElementFactory.functionElement3("sqrt", 315 FunctionElement sqrtElement = ElementFactory.functionElement3("sqrt",
318 provider.doubleType.element, <ClassElement>[ 316 provider.doubleType.element, <ClassElement>[provider.numType.element],
319 provider.numType.element 317 ClassElementImpl.EMPTY_ARRAY);
320 ], ClassElementImpl.EMPTY_ARRAY);
321 mathUnit.accessors = <PropertyAccessorElement>[ 318 mathUnit.accessors = <PropertyAccessorElement>[
322 ln10Element.getter, 319 ln10Element.getter,
323 piElement.getter 320 piElement.getter
324 ]; 321 ];
325 mathUnit.functions = <FunctionElement>[cosElement, sinElement, sqrtElement]; 322 mathUnit.functions = <FunctionElement>[cosElement, sinElement, sqrtElement];
326 mathUnit.topLevelVariables = <TopLevelVariableElement>[ 323 mathUnit.topLevelVariables = <TopLevelVariableElement>[
327 ln10Element, 324 ln10Element,
328 piElement 325 piElement
329 ]; 326 ];
330 mathUnit.types = <ClassElement>[randomElement]; 327 mathUnit.types = <ClassElement>[randomElement];
(...skipping 1199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1530 ConstructorElementImpl constructor = 1527 ConstructorElementImpl constructor =
1531 ElementFactory.constructorElement2(classA, constructorName); 1528 ElementFactory.constructorElement2(classA, constructorName);
1532 String parameterName = "a"; 1529 String parameterName = "a";
1533 ParameterElement parameter = ElementFactory.namedParameter(parameterName); 1530 ParameterElement parameter = ElementFactory.namedParameter(parameterName);
1534 constructor.parameters = <ParameterElement>[parameter]; 1531 constructor.parameters = <ParameterElement>[parameter];
1535 classA.constructors = <ConstructorElement>[constructor]; 1532 classA.constructors = <ConstructorElement>[constructor];
1536 ConstructorName name = AstFactory.constructorName( 1533 ConstructorName name = AstFactory.constructorName(
1537 AstFactory.typeName(classA), constructorName); 1534 AstFactory.typeName(classA), constructorName);
1538 name.staticElement = constructor; 1535 name.staticElement = constructor;
1539 InstanceCreationExpression creation = AstFactory.instanceCreationExpression( 1536 InstanceCreationExpression creation = AstFactory.instanceCreationExpression(
1540 Keyword.NEW, name, [ 1537 Keyword.NEW, name,
1541 AstFactory.namedExpression2(parameterName, AstFactory.integer(0)) 1538 [AstFactory.namedExpression2(parameterName, AstFactory.integer(0))]);
1542 ]);
1543 _resolveNode(creation); 1539 _resolveNode(creation);
1544 expect(creation.staticElement, same(constructor)); 1540 expect(creation.staticElement, same(constructor));
1545 expect((creation.argumentList.arguments[ 1541 expect((creation.argumentList.arguments[
1546 0] as NamedExpression).name.label.staticElement, same(parameter)); 1542 0] as NamedExpression).name.label.staticElement, same(parameter));
1547 _listener.assertNoErrors(); 1543 _listener.assertNoErrors();
1548 } 1544 }
1549 1545
1550 void test_visitMethodInvocation() { 1546 void test_visitMethodInvocation() {
1551 InterfaceType numType = _typeProvider.numType; 1547 InterfaceType numType = _typeProvider.numType;
1552 SimpleIdentifier left = AstFactory.identifier3("i"); 1548 SimpleIdentifier left = AstFactory.identifier3("i");
(...skipping 3099 matching lines...) Expand 10 before | Expand all | Expand 10 after
4652 ClassElementImpl classI2 = ElementFactory.classElement2("I2"); 4648 ClassElementImpl classI2 = ElementFactory.classElement2("I2");
4653 PropertyAccessorElement getter = 4649 PropertyAccessorElement getter =
4654 ElementFactory.getterElement(methodName, false, _typeProvider.intType); 4650 ElementFactory.getterElement(methodName, false, _typeProvider.intType);
4655 classI2.accessors = <PropertyAccessorElement>[getter]; 4651 classI2.accessors = <PropertyAccessorElement>[getter];
4656 ClassElementImpl classA = ElementFactory.classElement2("A"); 4652 ClassElementImpl classA = ElementFactory.classElement2("A");
4657 classA.interfaces = <InterfaceType>[classI2.type, classI1.type]; 4653 classA.interfaces = <InterfaceType>[classI2.type, classI1.type];
4658 MemberMap mapA = 4654 MemberMap mapA =
4659 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA); 4655 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA);
4660 expect(mapA.size, _numOfMembersInObject); 4656 expect(mapA.size, _numOfMembersInObject);
4661 expect(mapA.get(methodName), isNull); 4657 expect(mapA.get(methodName), isNull);
4662 _assertErrors(classA, [ 4658 _assertErrors(classA,
4663 StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GETTER_AND_METHOD 4659 [StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GETTER_AND_METHOD]);
4664 ]);
4665 } 4660 }
4666 4661
4667 void test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance _int_str() { 4662 void test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance _int_str() {
4668 // class I1 { int m(); } 4663 // class I1 { int m(); }
4669 // class I2 { String m(); } 4664 // class I2 { String m(); }
4670 // class A implements I1, I2 {} 4665 // class A implements I1, I2 {}
4671 ClassElementImpl classI1 = ElementFactory.classElement2("I1"); 4666 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
4672 String methodName = "m"; 4667 String methodName = "m";
4673 MethodElement methodM1 = 4668 MethodElement methodM1 =
4674 ElementFactory.methodElement(methodName, null, [_typeProvider.intType]); 4669 ElementFactory.methodElement(methodName, null, [_typeProvider.intType]);
(...skipping 24 matching lines...) Expand all
4699 ClassElementImpl classI2 = ElementFactory.classElement2("I2"); 4694 ClassElementImpl classI2 = ElementFactory.classElement2("I2");
4700 PropertyAccessorElement getter = 4695 PropertyAccessorElement getter =
4701 ElementFactory.getterElement(methodName, false, _typeProvider.intType); 4696 ElementFactory.getterElement(methodName, false, _typeProvider.intType);
4702 classI2.accessors = <PropertyAccessorElement>[getter]; 4697 classI2.accessors = <PropertyAccessorElement>[getter];
4703 ClassElementImpl classA = ElementFactory.classElement2("A"); 4698 ClassElementImpl classA = ElementFactory.classElement2("A");
4704 classA.interfaces = <InterfaceType>[classI1.type, classI2.type]; 4699 classA.interfaces = <InterfaceType>[classI1.type, classI2.type];
4705 MemberMap mapA = 4700 MemberMap mapA =
4706 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA); 4701 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA);
4707 expect(mapA.size, _numOfMembersInObject); 4702 expect(mapA.size, _numOfMembersInObject);
4708 expect(mapA.get(methodName), isNull); 4703 expect(mapA.get(methodName), isNull);
4709 _assertErrors(classA, [ 4704 _assertErrors(classA,
4710 StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GETTER_AND_METHOD 4705 [StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GETTER_AND_METHOD]);
4711 ]);
4712 } 4706 }
4713 4707
4714 void test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance _numOfRequiredParams() { 4708 void test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance _numOfRequiredParams() {
4715 // class I1 { dynamic m(int, [int]); } 4709 // class I1 { dynamic m(int, [int]); }
4716 // class I2 { dynamic m(int, int, int); } 4710 // class I2 { dynamic m(int, int, int); }
4717 // class A implements I1, I2 {} 4711 // class A implements I1, I2 {}
4718 ClassElementImpl classI1 = ElementFactory.classElement2("I1"); 4712 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
4719 String methodName = "m"; 4713 String methodName = "m";
4720 MethodElementImpl methodM1 = 4714 MethodElementImpl methodM1 =
4721 ElementFactory.methodElement(methodName, _typeProvider.dynamicType); 4715 ElementFactory.methodElement(methodName, _typeProvider.dynamicType);
(...skipping 5266 matching lines...) Expand 10 before | Expand all | Expand 10 after
9988 FormalParameter p1 = AstFactory.simpleFormalParameter3("p1"); 9982 FormalParameter p1 = AstFactory.simpleFormalParameter3("p1");
9989 _setType(p1, dynamicType); 9983 _setType(p1, dynamicType);
9990 FormalParameter p2 = AstFactory.simpleFormalParameter3("p2"); 9984 FormalParameter p2 = AstFactory.simpleFormalParameter3("p2");
9991 _setType(p2, dynamicType); 9985 _setType(p2, dynamicType);
9992 FunctionExpression node = _resolvedFunctionExpression( 9986 FunctionExpression node = _resolvedFunctionExpression(
9993 AstFactory.formalParameterList([p1, p2]), 9987 AstFactory.formalParameterList([p1, p2]),
9994 AstFactory.blockFunctionBody2()); 9988 AstFactory.blockFunctionBody2());
9995 _analyze5(p1); 9989 _analyze5(p1);
9996 _analyze5(p2); 9990 _analyze5(p2);
9997 DartType resultType = _analyze(node); 9991 DartType resultType = _analyze(node);
9998 _assertFunctionType(dynamicType, 9992 _assertFunctionType(dynamicType, <DartType>[
9999 <DartType>[dynamicType, dynamicType], null, null, resultType); 9993 dynamicType,
9994 dynamicType
9995 ], null, null, resultType);
10000 _listener.assertNoErrors(); 9996 _listener.assertNoErrors();
10001 } 9997 }
10002 9998
10003 void test_visitFunctionExpression_normal_expression() { 9999 void test_visitFunctionExpression_normal_expression() {
10004 // (p1, p2) -> 0 10000 // (p1, p2) -> 0
10005 DartType dynamicType = _typeProvider.dynamicType; 10001 DartType dynamicType = _typeProvider.dynamicType;
10006 FormalParameter p = AstFactory.simpleFormalParameter3("p"); 10002 FormalParameter p = AstFactory.simpleFormalParameter3("p");
10007 _setType(p, dynamicType); 10003 _setType(p, dynamicType);
10008 FunctionExpression node = _resolvedFunctionExpression( 10004 FunctionExpression node = _resolvedFunctionExpression(
10009 AstFactory.formalParameterList([p]), 10005 AstFactory.formalParameterList([p]),
(...skipping 13 matching lines...) Expand all
10023 FormalParameter p2 = AstFactory.namedFormalParameter( 10019 FormalParameter p2 = AstFactory.namedFormalParameter(
10024 AstFactory.simpleFormalParameter3("p2"), _resolvedInteger(0)); 10020 AstFactory.simpleFormalParameter3("p2"), _resolvedInteger(0));
10025 _setType(p2, dynamicType); 10021 _setType(p2, dynamicType);
10026 FunctionExpression node = _resolvedFunctionExpression( 10022 FunctionExpression node = _resolvedFunctionExpression(
10027 AstFactory.formalParameterList([p1, p2]), 10023 AstFactory.formalParameterList([p1, p2]),
10028 AstFactory.blockFunctionBody2()); 10024 AstFactory.blockFunctionBody2());
10029 _analyze5(p2); 10025 _analyze5(p2);
10030 DartType resultType = _analyze(node); 10026 DartType resultType = _analyze(node);
10031 Map<String, DartType> expectedNamedTypes = new HashMap<String, DartType>(); 10027 Map<String, DartType> expectedNamedTypes = new HashMap<String, DartType>();
10032 expectedNamedTypes["p2"] = dynamicType; 10028 expectedNamedTypes["p2"] = dynamicType;
10033 _assertFunctionType(dynamicType, 10029 _assertFunctionType(dynamicType, <DartType>[dynamicType], null,
10034 <DartType>[dynamicType], null, expectedNamedTypes, resultType); 10030 expectedNamedTypes, resultType);
10035 _listener.assertNoErrors(); 10031 _listener.assertNoErrors();
10036 } 10032 }
10037 10033
10038 void test_visitFunctionExpression_normalAndNamed_expression() { 10034 void test_visitFunctionExpression_normalAndNamed_expression() {
10039 // (p1, {p2 : 0}) -> 0 10035 // (p1, {p2 : 0}) -> 0
10040 DartType dynamicType = _typeProvider.dynamicType; 10036 DartType dynamicType = _typeProvider.dynamicType;
10041 FormalParameter p1 = AstFactory.simpleFormalParameter3("p1"); 10037 FormalParameter p1 = AstFactory.simpleFormalParameter3("p1");
10042 _setType(p1, dynamicType); 10038 _setType(p1, dynamicType);
10043 FormalParameter p2 = AstFactory.namedFormalParameter( 10039 FormalParameter p2 = AstFactory.namedFormalParameter(
10044 AstFactory.simpleFormalParameter3("p2"), _resolvedInteger(0)); 10040 AstFactory.simpleFormalParameter3("p2"), _resolvedInteger(0));
10045 _setType(p2, dynamicType); 10041 _setType(p2, dynamicType);
10046 FunctionExpression node = _resolvedFunctionExpression( 10042 FunctionExpression node = _resolvedFunctionExpression(
10047 AstFactory.formalParameterList([p1, p2]), 10043 AstFactory.formalParameterList([p1, p2]),
10048 AstFactory.expressionFunctionBody(_resolvedInteger(0))); 10044 AstFactory.expressionFunctionBody(_resolvedInteger(0)));
10049 _analyze5(p2); 10045 _analyze5(p2);
10050 DartType resultType = _analyze(node); 10046 DartType resultType = _analyze(node);
10051 Map<String, DartType> expectedNamedTypes = new HashMap<String, DartType>(); 10047 Map<String, DartType> expectedNamedTypes = new HashMap<String, DartType>();
10052 expectedNamedTypes["p2"] = dynamicType; 10048 expectedNamedTypes["p2"] = dynamicType;
10053 _assertFunctionType(_typeProvider.intType, 10049 _assertFunctionType(_typeProvider.intType, <DartType>[dynamicType], null,
10054 <DartType>[dynamicType], null, expectedNamedTypes, resultType); 10050 expectedNamedTypes, resultType);
10055 _listener.assertNoErrors(); 10051 _listener.assertNoErrors();
10056 } 10052 }
10057 10053
10058 void test_visitFunctionExpression_normalAndPositional_block() { 10054 void test_visitFunctionExpression_normalAndPositional_block() {
10059 // (p1, [p2 = 0]) {} 10055 // (p1, [p2 = 0]) {}
10060 DartType dynamicType = _typeProvider.dynamicType; 10056 DartType dynamicType = _typeProvider.dynamicType;
10061 FormalParameter p1 = AstFactory.simpleFormalParameter3("p1"); 10057 FormalParameter p1 = AstFactory.simpleFormalParameter3("p1");
10062 _setType(p1, dynamicType); 10058 _setType(p1, dynamicType);
10063 FormalParameter p2 = AstFactory.positionalFormalParameter( 10059 FormalParameter p2 = AstFactory.positionalFormalParameter(
10064 AstFactory.simpleFormalParameter3("p2"), _resolvedInteger(0)); 10060 AstFactory.simpleFormalParameter3("p2"), _resolvedInteger(0));
10065 _setType(p2, dynamicType); 10061 _setType(p2, dynamicType);
10066 FunctionExpression node = _resolvedFunctionExpression( 10062 FunctionExpression node = _resolvedFunctionExpression(
10067 AstFactory.formalParameterList([p1, p2]), 10063 AstFactory.formalParameterList([p1, p2]),
10068 AstFactory.blockFunctionBody2()); 10064 AstFactory.blockFunctionBody2());
10069 _analyze5(p1); 10065 _analyze5(p1);
10070 _analyze5(p2); 10066 _analyze5(p2);
10071 DartType resultType = _analyze(node); 10067 DartType resultType = _analyze(node);
10072 _assertFunctionType(dynamicType, 10068 _assertFunctionType(dynamicType, <DartType>[dynamicType],
10073 <DartType>[dynamicType], <DartType>[dynamicType], null, resultType); 10069 <DartType>[dynamicType], null, resultType);
10074 _listener.assertNoErrors(); 10070 _listener.assertNoErrors();
10075 } 10071 }
10076 10072
10077 void test_visitFunctionExpression_normalAndPositional_expression() { 10073 void test_visitFunctionExpression_normalAndPositional_expression() {
10078 // (p1, [p2 = 0]) -> 0 10074 // (p1, [p2 = 0]) -> 0
10079 DartType dynamicType = _typeProvider.dynamicType; 10075 DartType dynamicType = _typeProvider.dynamicType;
10080 FormalParameter p1 = AstFactory.simpleFormalParameter3("p1"); 10076 FormalParameter p1 = AstFactory.simpleFormalParameter3("p1");
10081 _setType(p1, dynamicType); 10077 _setType(p1, dynamicType);
10082 FormalParameter p2 = AstFactory.positionalFormalParameter( 10078 FormalParameter p2 = AstFactory.positionalFormalParameter(
10083 AstFactory.simpleFormalParameter3("p2"), _resolvedInteger(0)); 10079 AstFactory.simpleFormalParameter3("p2"), _resolvedInteger(0));
10084 _setType(p2, dynamicType); 10080 _setType(p2, dynamicType);
10085 FunctionExpression node = _resolvedFunctionExpression( 10081 FunctionExpression node = _resolvedFunctionExpression(
10086 AstFactory.formalParameterList([p1, p2]), 10082 AstFactory.formalParameterList([p1, p2]),
10087 AstFactory.expressionFunctionBody(_resolvedInteger(0))); 10083 AstFactory.expressionFunctionBody(_resolvedInteger(0)));
10088 _analyze5(p1); 10084 _analyze5(p1);
10089 _analyze5(p2); 10085 _analyze5(p2);
10090 DartType resultType = _analyze(node); 10086 DartType resultType = _analyze(node);
10091 _assertFunctionType(_typeProvider.intType, 10087 _assertFunctionType(_typeProvider.intType, <DartType>[dynamicType],
10092 <DartType>[dynamicType], <DartType>[dynamicType], null, resultType); 10088 <DartType>[dynamicType], null, resultType);
10093 _listener.assertNoErrors(); 10089 _listener.assertNoErrors();
10094 } 10090 }
10095 10091
10096 void test_visitFunctionExpression_positional_block() { 10092 void test_visitFunctionExpression_positional_block() {
10097 // ([p1 = 0, p2 = 0]) {} 10093 // ([p1 = 0, p2 = 0]) {}
10098 DartType dynamicType = _typeProvider.dynamicType; 10094 DartType dynamicType = _typeProvider.dynamicType;
10099 FormalParameter p1 = AstFactory.positionalFormalParameter( 10095 FormalParameter p1 = AstFactory.positionalFormalParameter(
10100 AstFactory.simpleFormalParameter3("p1"), _resolvedInteger(0)); 10096 AstFactory.simpleFormalParameter3("p1"), _resolvedInteger(0));
10101 _setType(p1, dynamicType); 10097 _setType(p1, dynamicType);
10102 FormalParameter p2 = AstFactory.positionalFormalParameter( 10098 FormalParameter p2 = AstFactory.positionalFormalParameter(
10103 AstFactory.simpleFormalParameter3("p2"), _resolvedInteger(0)); 10099 AstFactory.simpleFormalParameter3("p2"), _resolvedInteger(0));
10104 _setType(p2, dynamicType); 10100 _setType(p2, dynamicType);
10105 FunctionExpression node = _resolvedFunctionExpression( 10101 FunctionExpression node = _resolvedFunctionExpression(
10106 AstFactory.formalParameterList([p1, p2]), 10102 AstFactory.formalParameterList([p1, p2]),
10107 AstFactory.blockFunctionBody2()); 10103 AstFactory.blockFunctionBody2());
10108 _analyze5(p1); 10104 _analyze5(p1);
10109 _analyze5(p2); 10105 _analyze5(p2);
10110 DartType resultType = _analyze(node); 10106 DartType resultType = _analyze(node);
10111 _assertFunctionType(dynamicType, 10107 _assertFunctionType(dynamicType, null, <DartType>[
10112 null, <DartType>[dynamicType, dynamicType], null, resultType); 10108 dynamicType,
10109 dynamicType
10110 ], null, resultType);
10113 _listener.assertNoErrors(); 10111 _listener.assertNoErrors();
10114 } 10112 }
10115 10113
10116 void test_visitFunctionExpression_positional_expression() { 10114 void test_visitFunctionExpression_positional_expression() {
10117 // ([p1 = 0, p2 = 0]) -> 0 10115 // ([p1 = 0, p2 = 0]) -> 0
10118 DartType dynamicType = _typeProvider.dynamicType; 10116 DartType dynamicType = _typeProvider.dynamicType;
10119 FormalParameter p = AstFactory.positionalFormalParameter( 10117 FormalParameter p = AstFactory.positionalFormalParameter(
10120 AstFactory.simpleFormalParameter3("p"), _resolvedInteger(0)); 10118 AstFactory.simpleFormalParameter3("p"), _resolvedInteger(0));
10121 _setType(p, dynamicType); 10119 _setType(p, dynamicType);
10122 FunctionExpression node = _resolvedFunctionExpression( 10120 FunctionExpression node = _resolvedFunctionExpression(
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
10205 // new C.m() 10203 // new C.m()
10206 ClassElementImpl classElement = ElementFactory.classElement2("C"); 10204 ClassElementImpl classElement = ElementFactory.classElement2("C");
10207 String constructorName = "m"; 10205 String constructorName = "m";
10208 ConstructorElementImpl constructor = 10206 ConstructorElementImpl constructor =
10209 ElementFactory.constructorElement2(classElement, constructorName); 10207 ElementFactory.constructorElement2(classElement, constructorName);
10210 constructor.returnType = classElement.type; 10208 constructor.returnType = classElement.type;
10211 FunctionTypeImpl constructorType = new FunctionTypeImpl.con1(constructor); 10209 FunctionTypeImpl constructorType = new FunctionTypeImpl.con1(constructor);
10212 constructor.type = constructorType; 10210 constructor.type = constructorType;
10213 classElement.constructors = <ConstructorElement>[constructor]; 10211 classElement.constructors = <ConstructorElement>[constructor];
10214 InstanceCreationExpression node = AstFactory.instanceCreationExpression2( 10212 InstanceCreationExpression node = AstFactory.instanceCreationExpression2(
10215 null, AstFactory.typeName(classElement), [ 10213 null, AstFactory.typeName(classElement),
10216 AstFactory.identifier3(constructorName) 10214 [AstFactory.identifier3(constructorName)]);
10217 ]);
10218 node.staticElement = constructor; 10215 node.staticElement = constructor;
10219 expect(_analyze(node), same(classElement.type)); 10216 expect(_analyze(node), same(classElement.type));
10220 _listener.assertNoErrors(); 10217 _listener.assertNoErrors();
10221 } 10218 }
10222 10219
10223 void test_visitInstanceCreationExpression_typeParameters() { 10220 void test_visitInstanceCreationExpression_typeParameters() {
10224 // new C<I>() 10221 // new C<I>()
10225 ClassElementImpl elementC = ElementFactory.classElement2("C", ["E"]); 10222 ClassElementImpl elementC = ElementFactory.classElement2("C", ["E"]);
10226 ClassElementImpl elementI = ElementFactory.classElement2("I"); 10223 ClassElementImpl elementI = ElementFactory.classElement2("I");
10227 ConstructorElementImpl constructor = 10224 ConstructorElementImpl constructor =
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
10297 DartType resultType = _analyze(node); 10294 DartType resultType = _analyze(node);
10298 _assertType2(_typeProvider.listType 10295 _assertType2(_typeProvider.listType
10299 .substitute4(<DartType>[_typeProvider.dynamicType]), resultType); 10296 .substitute4(<DartType>[_typeProvider.dynamicType]), resultType);
10300 _listener.assertNoErrors(); 10297 _listener.assertNoErrors();
10301 } 10298 }
10302 10299
10303 void test_visitMapLiteral_empty() { 10300 void test_visitMapLiteral_empty() {
10304 // {} 10301 // {}
10305 Expression node = AstFactory.mapLiteral2(); 10302 Expression node = AstFactory.mapLiteral2();
10306 DartType resultType = _analyze(node); 10303 DartType resultType = _analyze(node);
10307 _assertType2(_typeProvider.mapType.substitute4(<DartType>[ 10304 _assertType2(_typeProvider.mapType.substitute4(
10308 _typeProvider.dynamicType, 10305 <DartType>[_typeProvider.dynamicType, _typeProvider.dynamicType]),
10309 _typeProvider.dynamicType 10306 resultType);
10310 ]), resultType);
10311 _listener.assertNoErrors(); 10307 _listener.assertNoErrors();
10312 } 10308 }
10313 10309
10314 void test_visitMapLiteral_nonEmpty() { 10310 void test_visitMapLiteral_nonEmpty() {
10315 // {"k" : 0} 10311 // {"k" : 0}
10316 Expression node = AstFactory 10312 Expression node = AstFactory
10317 .mapLiteral2([AstFactory.mapLiteralEntry("k", _resolvedInteger(0))]); 10313 .mapLiteral2([AstFactory.mapLiteralEntry("k", _resolvedInteger(0))]);
10318 DartType resultType = _analyze(node); 10314 DartType resultType = _analyze(node);
10319 _assertType2(_typeProvider.mapType.substitute4(<DartType>[ 10315 _assertType2(_typeProvider.mapType.substitute4(
10320 _typeProvider.dynamicType, 10316 <DartType>[_typeProvider.dynamicType, _typeProvider.dynamicType]),
10321 _typeProvider.dynamicType 10317 resultType);
10322 ]), resultType);
10323 _listener.assertNoErrors(); 10318 _listener.assertNoErrors();
10324 } 10319 }
10325 10320
10326 void test_visitMethodInvocation_then() { 10321 void test_visitMethodInvocation_then() {
10327 // then() 10322 // then()
10328 Expression node = AstFactory.methodInvocation(null, "then"); 10323 Expression node = AstFactory.methodInvocation(null, "then");
10329 _analyze(node); 10324 _analyze(node);
10330 _listener.assertNoErrors(); 10325 _listener.assertNoErrors();
10331 } 10326 }
10332 10327
(...skipping 2693 matching lines...) Expand 10 before | Expand all | Expand 10 after
13026 new FileBasedSource.con1(FileUtilities2.createFile("/lib.dart")); 13021 new FileBasedSource.con1(FileUtilities2.createFile("/lib.dart"));
13027 _library = new Library(context, _listener, librarySource); 13022 _library = new Library(context, _listener, librarySource);
13028 LibraryElementImpl element = new LibraryElementImpl.forNode( 13023 LibraryElementImpl element = new LibraryElementImpl.forNode(
13029 context, AstFactory.libraryIdentifier2(["lib"])); 13024 context, AstFactory.libraryIdentifier2(["lib"]));
13030 element.definingCompilationUnit = 13025 element.definingCompilationUnit =
13031 new CompilationUnitElementImpl("lib.dart"); 13026 new CompilationUnitElementImpl("lib.dart");
13032 _library.libraryElement = element; 13027 _library.libraryElement = element;
13033 _typeProvider = new TestTypeProvider(); 13028 _typeProvider = new TestTypeProvider();
13034 _visitor = 13029 _visitor =
13035 new TypeResolverVisitor.con1(_library, librarySource, _typeProvider); 13030 new TypeResolverVisitor.con1(_library, librarySource, _typeProvider);
13036 _implicitConstructorBuilder = new ImplicitConstructorBuilder(librarySource, 13031 _implicitConstructorBuilder = new ImplicitConstructorBuilder(_listener,
13037 _library.libraryElement, _library.libraryScope, _typeProvider,
13038 (ClassElement classElement, ClassElement superclassElement, 13032 (ClassElement classElement, ClassElement superclassElement,
13039 void computation()) { 13033 void computation()) {
13040 // For these tests, we assume the classes for which implicit 13034 // For these tests, we assume the classes for which implicit
13041 // constructors need to be built are visited in proper dependency order, 13035 // constructors need to be built are visited in proper dependency order,
13042 // so we just invoke the computation immediately. 13036 // so we just invoke the computation immediately.
13043 computation(); 13037 computation();
13044 }); 13038 });
13045 } 13039 }
13046 13040
13047 void test_visitCatchClause_exception() { 13041 void test_visitCatchClause_exception() {
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
13189 (constructorBc2.parameters[0] as ParameterElementImpl).parameterKind = 13183 (constructorBc2.parameters[0] as ParameterElementImpl).parameterKind =
13190 ParameterKind.POSITIONAL; 13184 ParameterKind.POSITIONAL;
13191 ConstructorElementImpl constructorBc3 = 13185 ConstructorElementImpl constructorBc3 =
13192 ElementFactory.constructorElement2(classB, 'c3', [classT.type]); 13186 ElementFactory.constructorElement2(classB, 'c3', [classT.type]);
13193 (constructorBc3.parameters[0] as ParameterElementImpl).parameterKind = 13187 (constructorBc3.parameters[0] as ParameterElementImpl).parameterKind =
13194 ParameterKind.NAMED; 13188 ParameterKind.NAMED;
13195 classB.constructors = [constructorBc1, constructorBc2, constructorBc3]; 13189 classB.constructors = [constructorBc1, constructorBc2, constructorBc3];
13196 ClassElement classM = ElementFactory.classElement2('M', []); 13190 ClassElement classM = ElementFactory.classElement2('M', []);
13197 WithClause withClause = 13191 WithClause withClause =
13198 AstFactory.withClause([AstFactory.typeName(classM, [])]); 13192 AstFactory.withClause([AstFactory.typeName(classM, [])]);
13199 ClassElement classC = ElementFactory.classElement2('C', []); 13193 ClassElement classC = ElementFactory.classTypeAlias2('C', []);
13200 ClassTypeAlias alias = AstFactory.classTypeAlias( 13194 ClassTypeAlias alias = AstFactory.classTypeAlias(
13201 'C', null, null, AstFactory.typeName(classB, []), withClause, null); 13195 'C', null, null, AstFactory.typeName(classB, []), withClause, null);
13202 alias.name.staticElement = classC; 13196 alias.name.staticElement = classC;
13203 _resolveNode(alias, [classT, classB, classM, classC]); 13197 _resolveNode(alias, [classT, classB, classM, classC]);
13204 expect(classC.constructors, hasLength(1)); 13198 expect(classC.constructors, hasLength(1));
13205 ConstructorElement constructor = classC.constructors[0]; 13199 ConstructorElement constructor = classC.constructors[0];
13206 expect(constructor.isFactory, isFalse); 13200 expect(constructor.isFactory, isFalse);
13207 expect(constructor.isSynthetic, isTrue); 13201 expect(constructor.isSynthetic, isTrue);
13208 expect(constructor.name, 'c1'); 13202 expect(constructor.name, 'c1');
13209 expect(constructor.functions, hasLength(0)); 13203 expect(constructor.functions, hasLength(0));
(...skipping 10 matching lines...) Expand all
13220 // class M {} 13214 // class M {}
13221 // class C = B with M 13215 // class C = B with M
13222 ClassElement classT = ElementFactory.classElement2('T', []); 13216 ClassElement classT = ElementFactory.classElement2('T', []);
13223 ClassElementImpl classB = ElementFactory.classElement2('B', []); 13217 ClassElementImpl classB = ElementFactory.classElement2('B', []);
13224 ConstructorElementImpl constructorB = 13218 ConstructorElementImpl constructorB =
13225 ElementFactory.constructorElement2(classB, '', [classT.type]); 13219 ElementFactory.constructorElement2(classB, '', [classT.type]);
13226 classB.constructors = [constructorB]; 13220 classB.constructors = [constructorB];
13227 ClassElement classM = ElementFactory.classElement2('M', []); 13221 ClassElement classM = ElementFactory.classElement2('M', []);
13228 WithClause withClause = 13222 WithClause withClause =
13229 AstFactory.withClause([AstFactory.typeName(classM, [])]); 13223 AstFactory.withClause([AstFactory.typeName(classM, [])]);
13230 ClassElement classC = ElementFactory.classElement2('C', []); 13224 ClassElement classC = ElementFactory.classTypeAlias2('C', []);
13231 ClassTypeAlias alias = AstFactory.classTypeAlias( 13225 ClassTypeAlias alias = AstFactory.classTypeAlias(
13232 'C', null, null, AstFactory.typeName(classB, []), withClause, null); 13226 'C', null, null, AstFactory.typeName(classB, []), withClause, null);
13233 alias.name.staticElement = classC; 13227 alias.name.staticElement = classC;
13234 _resolveNode(alias, [classT, classB, classM, classC]); 13228 _resolveNode(alias, [classT, classB, classM, classC]);
13235 expect(classC.constructors, hasLength(1)); 13229 expect(classC.constructors, hasLength(1));
13236 ConstructorElement constructor = classC.constructors[0]; 13230 ConstructorElement constructor = classC.constructors[0];
13237 expect(constructor.isFactory, isFalse); 13231 expect(constructor.isFactory, isFalse);
13238 expect(constructor.isSynthetic, isTrue); 13232 expect(constructor.isSynthetic, isTrue);
13239 expect(constructor.name, ''); 13233 expect(constructor.name, '');
13240 expect(constructor.functions, hasLength(0)); 13234 expect(constructor.functions, hasLength(0));
(...skipping 10 matching lines...) Expand all
13251 // class M {} 13245 // class M {}
13252 // class C = B with M 13246 // class C = B with M
13253 ClassElementImpl classB = ElementFactory.classElement2('B', []); 13247 ClassElementImpl classB = ElementFactory.classElement2('B', []);
13254 ConstructorElementImpl constructorB = 13248 ConstructorElementImpl constructorB =
13255 ElementFactory.constructorElement2(classB, '', []); 13249 ElementFactory.constructorElement2(classB, '', []);
13256 constructorB.setModifier(Modifier.SYNTHETIC, true); 13250 constructorB.setModifier(Modifier.SYNTHETIC, true);
13257 classB.constructors = [constructorB]; 13251 classB.constructors = [constructorB];
13258 ClassElement classM = ElementFactory.classElement2('M', []); 13252 ClassElement classM = ElementFactory.classElement2('M', []);
13259 WithClause withClause = 13253 WithClause withClause =
13260 AstFactory.withClause([AstFactory.typeName(classM, [])]); 13254 AstFactory.withClause([AstFactory.typeName(classM, [])]);
13261 ClassElement classC = ElementFactory.classElement2('C', []); 13255 ClassElement classC = ElementFactory.classTypeAlias2('C', []);
13262 ClassTypeAlias alias = AstFactory.classTypeAlias( 13256 ClassTypeAlias alias = AstFactory.classTypeAlias(
13263 'C', null, null, AstFactory.typeName(classB, []), withClause, null); 13257 'C', null, null, AstFactory.typeName(classB, []), withClause, null);
13264 alias.name.staticElement = classC; 13258 alias.name.staticElement = classC;
13265 _resolveNode(alias, [classB, classM, classC]); 13259 _resolveNode(alias, [classB, classM, classC]);
13266 expect(classC.constructors, hasLength(1)); 13260 expect(classC.constructors, hasLength(1));
13267 ConstructorElement constructor = classC.constructors[0]; 13261 ConstructorElement constructor = classC.constructors[0];
13268 expect(constructor.isFactory, isFalse); 13262 expect(constructor.isFactory, isFalse);
13269 expect(constructor.isSynthetic, isTrue); 13263 expect(constructor.isSynthetic, isTrue);
13270 expect(constructor.name, ''); 13264 expect(constructor.name, '');
13271 expect(constructor.functions, hasLength(0)); 13265 expect(constructor.functions, hasLength(0));
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
13434 * being resolved 13428 * being resolved
13435 * @return the element to which the expression was resolved 13429 * @return the element to which the expression was resolved
13436 */ 13430 */
13437 void _resolveNode(AstNode node, [List<Element> definedElements]) { 13431 void _resolveNode(AstNode node, [List<Element> definedElements]) {
13438 if (definedElements != null) { 13432 if (definedElements != null) {
13439 for (Element element in definedElements) { 13433 for (Element element in definedElements) {
13440 _library.libraryScope.define(element); 13434 _library.libraryScope.define(element);
13441 } 13435 }
13442 } 13436 }
13443 node.accept(_visitor); 13437 node.accept(_visitor);
13444 node.accept(_implicitConstructorBuilder); 13438 if (node is Declaration) {
13439 node.element.accept(_implicitConstructorBuilder);
13440 }
13445 } 13441 }
13446 } 13442 }
13447 13443
13448 class _AnalysisContextFactory_initContextWithCore 13444 class _AnalysisContextFactory_initContextWithCore
13449 extends DirectoryBasedDartSdk { 13445 extends DirectoryBasedDartSdk {
13450 _AnalysisContextFactory_initContextWithCore(JavaFile arg0) : super(arg0); 13446 _AnalysisContextFactory_initContextWithCore(JavaFile arg0) : super(arg0);
13451 13447
13452 @override 13448 @override
13453 LibraryMap initialLibraryMap(bool useDart2jsPaths) { 13449 LibraryMap initialLibraryMap(bool useDart2jsPaths) {
13454 LibraryMap map = new LibraryMap(); 13450 LibraryMap map = new LibraryMap();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
13496 // check propagated type 13492 // check propagated type
13497 FunctionType propagatedType = node.propagatedType as FunctionType; 13493 FunctionType propagatedType = node.propagatedType as FunctionType;
13498 expect(propagatedType.returnType, test.typeProvider.stringType); 13494 expect(propagatedType.returnType, test.typeProvider.stringType);
13499 } on AnalysisException catch (e, stackTrace) { 13495 } on AnalysisException catch (e, stackTrace) {
13500 thrownException[0] = new CaughtException(e, stackTrace); 13496 thrownException[0] = new CaughtException(e, stackTrace);
13501 } 13497 }
13502 } 13498 }
13503 return null; 13499 return null;
13504 } 13500 }
13505 } 13501 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698