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

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

Issue 712083003: Create fewer unnecessary lists (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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 import 'package:analyzer/src/generated/java_core.dart'; 8 import 'package:analyzer/src/generated/java_core.dart';
9 import 'package:analyzer/src/generated/java_engine.dart'; 9 import 'package:analyzer/src/generated/java_engine.dart';
10 import 'package:analyzer/src/generated/java_engine_io.dart'; 10 import 'package:analyzer/src/generated/java_engine_io.dart';
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 context.sourceFactory = sourceFactory; 81 context.sourceFactory = sourceFactory;
82 AnalysisContext coreContext = sdk.context; 82 AnalysisContext coreContext = sdk.context;
83 // 83 //
84 // dart:core 84 // dart:core
85 // 85 //
86 TestTypeProvider provider = new TestTypeProvider(); 86 TestTypeProvider provider = new TestTypeProvider();
87 CompilationUnitElementImpl coreUnit = new CompilationUnitElementImpl("core.d art"); 87 CompilationUnitElementImpl coreUnit = new CompilationUnitElementImpl("core.d art");
88 Source coreSource = sourceFactory.forUri(DartSdk.DART_CORE); 88 Source coreSource = sourceFactory.forUri(DartSdk.DART_CORE);
89 coreContext.setContents(coreSource, ""); 89 coreContext.setContents(coreSource, "");
90 coreUnit.source = coreSource; 90 coreUnit.source = coreSource;
91 ClassElementImpl proxyClassElement = ElementFactory.classElement2("_Proxy", []); 91 ClassElementImpl proxyClassElement = ElementFactory.classElement2("_Proxy");
92 coreUnit.types = <ClassElement> [ 92 coreUnit.types = <ClassElement> [
93 provider.boolType.element, 93 provider.boolType.element,
94 provider.deprecatedType.element, 94 provider.deprecatedType.element,
95 provider.doubleType.element, 95 provider.doubleType.element,
96 provider.functionType.element, 96 provider.functionType.element,
97 provider.intType.element, 97 provider.intType.element,
98 provider.listType.element, 98 provider.listType.element,
99 provider.mapType.element, 99 provider.mapType.element,
100 provider.nullType.element, 100 provider.nullType.element,
101 provider.numType.element, 101 provider.numType.element,
(...skipping 18 matching lines...) Expand all
120 // dart:async 120 // dart:async
121 // 121 //
122 CompilationUnitElementImpl asyncUnit = new CompilationUnitElementImpl("async .dart"); 122 CompilationUnitElementImpl asyncUnit = new CompilationUnitElementImpl("async .dart");
123 Source asyncSource = sourceFactory.forUri(DartSdk.DART_ASYNC); 123 Source asyncSource = sourceFactory.forUri(DartSdk.DART_ASYNC);
124 coreContext.setContents(asyncSource, ""); 124 coreContext.setContents(asyncSource, "");
125 asyncUnit.source = asyncSource; 125 asyncUnit.source = asyncSource;
126 // Future 126 // Future
127 ClassElementImpl futureElement = ElementFactory.classElement2("Future", ["T" ]); 127 ClassElementImpl futureElement = ElementFactory.classElement2("Future", ["T" ]);
128 InterfaceType futureType = futureElement.type; 128 InterfaceType futureType = futureElement.type;
129 // factory Future.value([value]) 129 // factory Future.value([value])
130 ConstructorElementImpl futureConstructor = ElementFactory.constructorElement 2(futureElement, "value", []); 130 ConstructorElementImpl futureConstructor = ElementFactory.constructorElement 2(futureElement, "value");
131 futureConstructor.parameters = <ParameterElement> [ElementFactory.positional Parameter2("value", provider.dynamicType)]; 131 futureConstructor.parameters = <ParameterElement> [ElementFactory.positional Parameter2("value", provider.dynamicType)];
132 futureConstructor.factory = true; 132 futureConstructor.factory = true;
133 (futureConstructor.type as FunctionTypeImpl).typeArguments = futureElement.t ype.typeArguments; 133 (futureConstructor.type as FunctionTypeImpl).typeArguments = futureElement.t ype.typeArguments;
134 futureElement.constructors = <ConstructorElement> [futureConstructor]; 134 futureElement.constructors = <ConstructorElement> [futureConstructor];
135 // Future then(onValue(T value), { Function onError }); 135 // Future then(onValue(T value), { Function onError });
136 List<ParameterElement> parameters = <ParameterElement> [ElementFactory.requi redParameter2("value", futureElement.typeParameters[0].type)]; 136 List<ParameterElement> parameters = <ParameterElement> [ElementFactory.requi redParameter2("value", futureElement.typeParameters[0].type)];
137 FunctionTypeAliasElementImpl aliasElement = new FunctionTypeAliasElementImpl .forNode(null); 137 FunctionTypeAliasElementImpl aliasElement = new FunctionTypeAliasElementImpl .forNode(null);
138 aliasElement.synthetic = true; 138 aliasElement.synthetic = true;
139 aliasElement.shareParameters(parameters); 139 aliasElement.shareParameters(parameters);
140 aliasElement.returnType = provider.dynamicType; 140 aliasElement.returnType = provider.dynamicType;
141 FunctionTypeImpl aliasType = new FunctionTypeImpl.con2(aliasElement); 141 FunctionTypeImpl aliasType = new FunctionTypeImpl.con2(aliasElement);
142 aliasElement.shareTypeParameters(futureElement.typeParameters); 142 aliasElement.shareTypeParameters(futureElement.typeParameters);
143 aliasType.typeArguments = futureElement.type.typeArguments; 143 aliasType.typeArguments = futureElement.type.typeArguments;
144 MethodElement thenMethod = ElementFactory.methodElementWithParameters("then" , futureElement.type.typeArguments, futureType, [ 144 MethodElement thenMethod = ElementFactory.methodElementWithParameters("then" , futureElement.type.typeArguments, futureType, [
145 ElementFactory.requiredParameter2("onValue", aliasType), 145 ElementFactory.requiredParameter2("onValue", aliasType),
146 ElementFactory.namedParameter2("onError", provider.functionType)]); 146 ElementFactory.namedParameter2("onError", provider.functionType)]);
147 futureElement.methods = <MethodElement> [thenMethod]; 147 futureElement.methods = <MethodElement> [thenMethod];
148 // Completer 148 // Completer
149 ClassElementImpl completerElement = ElementFactory.classElement2("Completer" , ["T"]); 149 ClassElementImpl completerElement = ElementFactory.classElement2("Completer" , ["T"]);
150 ConstructorElementImpl completerConstructor = ElementFactory.constructorElem ent2(completerElement, null, []); 150 ConstructorElementImpl completerConstructor = ElementFactory.constructorElem ent2(completerElement, null);
151 (completerConstructor.type as FunctionTypeImpl).typeArguments = completerEle ment.type.typeArguments; 151 (completerConstructor.type as FunctionTypeImpl).typeArguments = completerEle ment.type.typeArguments;
152 completerElement.constructors = <ConstructorElement> [completerConstructor]; 152 completerElement.constructors = <ConstructorElement> [completerConstructor];
153 asyncUnit.types = <ClassElement> [ 153 asyncUnit.types = <ClassElement> [
154 completerElement, 154 completerElement,
155 futureElement, 155 futureElement,
156 ElementFactory.classElement2("Stream", ["T"])]; 156 ElementFactory.classElement2("Stream", ["T"])];
157 LibraryElementImpl asyncLibrary = new LibraryElementImpl.forNode(coreContext , AstFactory.libraryIdentifier2(["dart", "async"])); 157 LibraryElementImpl asyncLibrary = new LibraryElementImpl.forNode(coreContext , AstFactory.libraryIdentifier2(["dart", "async"]));
158 asyncLibrary.definingCompilationUnit = asyncUnit; 158 asyncLibrary.definingCompilationUnit = asyncUnit;
159 // 159 //
160 // dart:html 160 // dart:html
161 // 161 //
162 CompilationUnitElementImpl htmlUnit = new CompilationUnitElementImpl("html_d artium.dart"); 162 CompilationUnitElementImpl htmlUnit = new CompilationUnitElementImpl("html_d artium.dart");
163 Source htmlSource = sourceFactory.forUri(DartSdk.DART_HTML); 163 Source htmlSource = sourceFactory.forUri(DartSdk.DART_HTML);
164 coreContext.setContents(htmlSource, ""); 164 coreContext.setContents(htmlSource, "");
165 htmlUnit.source = htmlSource; 165 htmlUnit.source = htmlSource;
166 ClassElementImpl elementElement = ElementFactory.classElement2("Element", [] ); 166 ClassElementImpl elementElement = ElementFactory.classElement2("Element");
167 InterfaceType elementType = elementElement.type; 167 InterfaceType elementType = elementElement.type;
168 ClassElementImpl canvasElement = ElementFactory.classElement("CanvasElement" , elementType, []); 168 ClassElementImpl canvasElement = ElementFactory.classElement("CanvasElement" , elementType);
169 ClassElementImpl contextElement = ElementFactory.classElement2("CanvasRender ingContext", []); 169 ClassElementImpl contextElement = ElementFactory.classElement2("CanvasRender ingContext");
170 InterfaceType contextElementType = contextElement.type; 170 InterfaceType contextElementType = contextElement.type;
171 ClassElementImpl context2dElement = ElementFactory.classElement("CanvasRende ringContext2D", contextElementType, []); 171 ClassElementImpl context2dElement = ElementFactory.classElement("CanvasRende ringContext2D", contextElementType);
172 canvasElement.methods = <MethodElement> [ElementFactory.methodElement("getCo ntext", contextElementType, [provider.stringType])]; 172 canvasElement.methods = <MethodElement> [ElementFactory.methodElement("getCo ntext", contextElementType, [provider.stringType])];
173 canvasElement.accessors = <PropertyAccessorElement> [ElementFactory.getterEl ement("context2D", false, context2dElement.type)]; 173 canvasElement.accessors = <PropertyAccessorElement> [ElementFactory.getterEl ement("context2D", false, context2dElement.type)];
174 ClassElementImpl documentElement = ElementFactory.classElement("Document", e lementType, []); 174 ClassElementImpl documentElement = ElementFactory.classElement("Document", e lementType);
175 ClassElementImpl htmlDocumentElement = ElementFactory.classElement("HtmlDocu ment", documentElement.type, []); 175 ClassElementImpl htmlDocumentElement = ElementFactory.classElement("HtmlDocu ment", documentElement.type);
176 htmlDocumentElement.methods = <MethodElement> [ElementFactory.methodElement( "query", elementType, <DartType> [provider.stringType])]; 176 htmlDocumentElement.methods = <MethodElement> [ElementFactory.methodElement( "query", elementType, <DartType> [provider.stringType])];
177 htmlUnit.types = <ClassElement> [ 177 htmlUnit.types = <ClassElement> [
178 ElementFactory.classElement("AnchorElement", elementType, []), 178 ElementFactory.classElement("AnchorElement", elementType),
179 ElementFactory.classElement("BodyElement", elementType, []), 179 ElementFactory.classElement("BodyElement", elementType),
180 ElementFactory.classElement("ButtonElement", elementType, []), 180 ElementFactory.classElement("ButtonElement", elementType),
181 canvasElement, 181 canvasElement,
182 contextElement, 182 contextElement,
183 context2dElement, 183 context2dElement,
184 ElementFactory.classElement("DivElement", elementType, []), 184 ElementFactory.classElement("DivElement", elementType),
185 documentElement, 185 documentElement,
186 elementElement, 186 elementElement,
187 htmlDocumentElement, 187 htmlDocumentElement,
188 ElementFactory.classElement("InputElement", elementType, []), 188 ElementFactory.classElement("InputElement", elementType),
189 ElementFactory.classElement("SelectElement", elementType, [])]; 189 ElementFactory.classElement("SelectElement", elementType)];
190 htmlUnit.functions = <FunctionElement> [ElementFactory.functionElement3("que ry", elementElement, <ClassElement> [provider.stringType.element], ClassElementI mpl.EMPTY_ARRAY)]; 190 htmlUnit.functions = <FunctionElement> [ElementFactory.functionElement3("que ry", elementElement, <ClassElement> [provider.stringType.element], ClassElementI mpl.EMPTY_ARRAY)];
191 TopLevelVariableElementImpl document = ElementFactory.topLevelVariableElemen t3("document", false, true, htmlDocumentElement.type); 191 TopLevelVariableElementImpl document = ElementFactory.topLevelVariableElemen t3("document", false, true, htmlDocumentElement.type);
192 htmlUnit.topLevelVariables = <TopLevelVariableElement> [document]; 192 htmlUnit.topLevelVariables = <TopLevelVariableElement> [document];
193 htmlUnit.accessors = <PropertyAccessorElement> [document.getter]; 193 htmlUnit.accessors = <PropertyAccessorElement> [document.getter];
194 LibraryElementImpl htmlLibrary = new LibraryElementImpl.forNode(coreContext, AstFactory.libraryIdentifier2(["dart", "dom", "html"])); 194 LibraryElementImpl htmlLibrary = new LibraryElementImpl.forNode(coreContext, AstFactory.libraryIdentifier2(["dart", "dom", "html"]));
195 htmlLibrary.definingCompilationUnit = htmlUnit; 195 htmlLibrary.definingCompilationUnit = htmlUnit;
196 // 196 //
197 // dart:math 197 // dart:math
198 // 198 //
199 CompilationUnitElementImpl mathUnit = new CompilationUnitElementImpl("math.d art"); 199 CompilationUnitElementImpl mathUnit = new CompilationUnitElementImpl("math.d art");
200 Source mathSource = sourceFactory.forUri(_DART_MATH); 200 Source mathSource = sourceFactory.forUri(_DART_MATH);
201 coreContext.setContents(mathSource, ""); 201 coreContext.setContents(mathSource, "");
202 mathUnit.source = mathSource; 202 mathUnit.source = mathSource;
203 FunctionElement cosElement = ElementFactory.functionElement3("cos", provider .doubleType.element, <ClassElement> [provider.numType.element], <ClassElement> [ ]); 203 FunctionElement cosElement = ElementFactory.functionElement3("cos", provider .doubleType.element, <ClassElement>[provider.numType.element], ClassElementImpl. EMPTY_ARRAY);
204 TopLevelVariableElement ln10Element = ElementFactory.topLevelVariableElement 3("LN10", true, false, provider.doubleType); 204 TopLevelVariableElement ln10Element = ElementFactory.topLevelVariableElement 3("LN10", true, false, provider.doubleType);
205 TopLevelVariableElement piElement = ElementFactory.topLevelVariableElement3( "PI", true, false, provider.doubleType); 205 TopLevelVariableElement piElement = ElementFactory.topLevelVariableElement3( "PI", true, false, provider.doubleType);
206 ClassElementImpl randomElement = ElementFactory.classElement2("Random", []); 206 ClassElementImpl randomElement = ElementFactory.classElement2("Random");
207 randomElement.abstract = true; 207 randomElement.abstract = true;
208 ConstructorElementImpl randomConstructor = ElementFactory.constructorElement 2(randomElement, null, []); 208 ConstructorElementImpl randomConstructor = ElementFactory.constructorElement 2(randomElement, null);
209 randomConstructor.factory = true; 209 randomConstructor.factory = true;
210 ParameterElementImpl seedParam = new ParameterElementImpl("seed", 0); 210 ParameterElementImpl seedParam = new ParameterElementImpl("seed", 0);
211 seedParam.parameterKind = ParameterKind.POSITIONAL; 211 seedParam.parameterKind = ParameterKind.POSITIONAL;
212 seedParam.type = provider.intType; 212 seedParam.type = provider.intType;
213 randomConstructor.parameters = <ParameterElement> [seedParam]; 213 randomConstructor.parameters = <ParameterElement> [seedParam];
214 randomElement.constructors = <ConstructorElement> [randomConstructor]; 214 randomElement.constructors = <ConstructorElement> [randomConstructor];
215 FunctionElement sinElement = ElementFactory.functionElement3("sin", provider .doubleType.element, <ClassElement> [provider.numType.element], <ClassElement> [ ]); 215 FunctionElement sinElement = ElementFactory.functionElement3("sin", provider .doubleType.element, <ClassElement> [provider.numType.element], ClassElementImpl .EMPTY_ARRAY);
216 FunctionElement sqrtElement = ElementFactory.functionElement3("sqrt", provid er.doubleType.element, <ClassElement> [provider.numType.element], <ClassElement> []); 216 FunctionElement sqrtElement = ElementFactory.functionElement3("sqrt", provid er.doubleType.element, <ClassElement> [provider.numType.element], ClassElementIm pl.EMPTY_ARRAY);
217 mathUnit.accessors = <PropertyAccessorElement> [ln10Element.getter, piElemen t.getter]; 217 mathUnit.accessors = <PropertyAccessorElement> [ln10Element.getter, piElemen t.getter];
218 mathUnit.functions = <FunctionElement> [cosElement, sinElement, sqrtElement] ; 218 mathUnit.functions = <FunctionElement> [cosElement, sinElement, sqrtElement] ;
219 mathUnit.topLevelVariables = <TopLevelVariableElement> [ln10Element, piEleme nt]; 219 mathUnit.topLevelVariables = <TopLevelVariableElement> [ln10Element, piEleme nt];
220 mathUnit.types = <ClassElement> [randomElement]; 220 mathUnit.types = <ClassElement> [randomElement];
221 LibraryElementImpl mathLibrary = new LibraryElementImpl.forNode(coreContext, AstFactory.libraryIdentifier2(["dart", "math"])); 221 LibraryElementImpl mathLibrary = new LibraryElementImpl.forNode(coreContext, AstFactory.libraryIdentifier2(["dart", "math"]));
222 mathLibrary.definingCompilationUnit = mathUnit; 222 mathLibrary.definingCompilationUnit = mathUnit;
223 // 223 //
224 // Set empty sources for the rest of the libraries. 224 // Set empty sources for the rest of the libraries.
225 // 225 //
226 Source source = sourceFactory.forUri(_DART_INTERCEPTORS); 226 Source source = sourceFactory.forUri(_DART_INTERCEPTORS);
(...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after
1059 return p + p; 1059 return p + p;
1060 } 1060 }
1061 }'''; 1061 }''';
1062 _assertMethodMatches(true, content, content); 1062 _assertMethodMatches(true, content, content);
1063 } 1063 }
1064 1064
1065 void _assertCompilationUnitMatches(bool expectMatch, String oldContent, String newContent) { 1065 void _assertCompilationUnitMatches(bool expectMatch, String oldContent, String newContent) {
1066 Source source = addSource(oldContent); 1066 Source source = addSource(oldContent);
1067 LibraryElement library = resolve(source); 1067 LibraryElement library = resolve(source);
1068 CompilationUnit oldUnit = resolveCompilationUnit(source, library); 1068 CompilationUnit oldUnit = resolveCompilationUnit(source, library);
1069 CompilationUnit newUnit = ParserTestCase.parseCompilationUnit(newContent, [] ); 1069 CompilationUnit newUnit = ParserTestCase.parseCompilationUnit(newContent);
1070 DeclarationMatcher matcher = new DeclarationMatcher(); 1070 DeclarationMatcher matcher = new DeclarationMatcher();
1071 expect(matcher.matches(newUnit, oldUnit.element), expectMatch); 1071 expect(matcher.matches(newUnit, oldUnit.element), expectMatch);
1072 } 1072 }
1073 1073
1074 void _assertMethodMatches(bool expectMatch, String oldContent, String newConte nt) { 1074 void _assertMethodMatches(bool expectMatch, String oldContent, String newConte nt) {
1075 Source source = addSource(oldContent); 1075 Source source = addSource(oldContent);
1076 LibraryElement library = resolve(source); 1076 LibraryElement library = resolve(source);
1077 CompilationUnit oldUnit = resolveCompilationUnit(source, library); 1077 CompilationUnit oldUnit = resolveCompilationUnit(source, library);
1078 MethodElement element = _getFirstMethod(oldUnit).element as MethodElement; 1078 MethodElement element = _getFirstMethod(oldUnit).element as MethodElement;
1079 AnalysisContext context = analysisContext; 1079 AnalysisContext context = analysisContext;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1138 1138
1139 /** 1139 /**
1140 * The resolver being used to resolve the test cases. 1140 * The resolver being used to resolve the test cases.
1141 */ 1141 */
1142 ElementResolver _resolver; 1142 ElementResolver _resolver;
1143 1143
1144 void fail_visitExportDirective_combinators() { 1144 void fail_visitExportDirective_combinators() {
1145 fail("Not yet tested"); 1145 fail("Not yet tested");
1146 // Need to set up the exported library so that the identifier can be resolve d 1146 // Need to set up the exported library so that the identifier can be resolve d
1147 ExportDirective directive = AstFactory.exportDirective2(null, [AstFactory.hi deCombinator2(["A"])]); 1147 ExportDirective directive = AstFactory.exportDirective2(null, [AstFactory.hi deCombinator2(["A"])]);
1148 _resolveNode(directive, []); 1148 _resolveNode(directive);
1149 _listener.assertNoErrors(); 1149 _listener.assertNoErrors();
1150 } 1150 }
1151 1151
1152 void fail_visitFunctionExpressionInvocation() { 1152 void fail_visitFunctionExpressionInvocation() {
1153 fail("Not yet tested"); 1153 fail("Not yet tested");
1154 _listener.assertNoErrors(); 1154 _listener.assertNoErrors();
1155 } 1155 }
1156 1156
1157 void fail_visitImportDirective_combinators_noPrefix() { 1157 void fail_visitImportDirective_combinators_noPrefix() {
1158 fail("Not yet tested"); 1158 fail("Not yet tested");
1159 // Need to set up the imported library so that the identifier can be resolve d 1159 // Need to set up the imported library so that the identifier can be resolve d
1160 ImportDirective directive = AstFactory.importDirective3(null, null, [AstFact ory.showCombinator2(["A"])]); 1160 ImportDirective directive = AstFactory.importDirective3(null, null, [AstFact ory.showCombinator2(["A"])]);
1161 _resolveNode(directive, []); 1161 _resolveNode(directive);
1162 _listener.assertNoErrors(); 1162 _listener.assertNoErrors();
1163 } 1163 }
1164 1164
1165 void fail_visitImportDirective_combinators_prefix() { 1165 void fail_visitImportDirective_combinators_prefix() {
1166 fail("Not yet tested"); 1166 fail("Not yet tested");
1167 // Need to set up the imported library so that the identifiers can be resolv ed 1167 // Need to set up the imported library so that the identifiers can be resolv ed
1168 String prefixName = "p"; 1168 String prefixName = "p";
1169 _definingLibrary.imports = <ImportElement> [ElementFactory.importFor(null, E lementFactory.prefix(prefixName), [])]; 1169 _definingLibrary.imports = <ImportElement> [ElementFactory.importFor(null, E lementFactory.prefix(prefixName))];
1170 ImportDirective directive = AstFactory.importDirective3(null, prefixName, [ 1170 ImportDirective directive = AstFactory.importDirective3(null, prefixName, [
1171 AstFactory.showCombinator2(["A"]), 1171 AstFactory.showCombinator2(["A"]),
1172 AstFactory.hideCombinator2(["B"])]); 1172 AstFactory.hideCombinator2(["B"])]);
1173 _resolveNode(directive, []); 1173 _resolveNode(directive);
1174 _listener.assertNoErrors(); 1174 _listener.assertNoErrors();
1175 } 1175 }
1176 1176
1177 void fail_visitRedirectingConstructorInvocation() { 1177 void fail_visitRedirectingConstructorInvocation() {
1178 fail("Not yet tested"); 1178 fail("Not yet tested");
1179 _listener.assertNoErrors(); 1179 _listener.assertNoErrors();
1180 } 1180 }
1181 1181
1182 @override 1182 @override
1183 void setUp() { 1183 void setUp() {
1184 _listener = new GatheringErrorListener(); 1184 _listener = new GatheringErrorListener();
1185 _typeProvider = new TestTypeProvider(); 1185 _typeProvider = new TestTypeProvider();
1186 _resolver = _createResolver(); 1186 _resolver = _createResolver();
1187 } 1187 }
1188 1188
1189 void test_lookUpMethodInInterfaces() { 1189 void test_lookUpMethodInInterfaces() {
1190 InterfaceType intType = _typeProvider.intType; 1190 InterfaceType intType = _typeProvider.intType;
1191 // 1191 //
1192 // abstract class A { int operator[](int index); } 1192 // abstract class A { int operator[](int index); }
1193 // 1193 //
1194 ClassElementImpl classA = ElementFactory.classElement2("A", []); 1194 ClassElementImpl classA = ElementFactory.classElement2("A");
1195 MethodElement operator = ElementFactory.methodElement("[]", intType, [intTyp e]); 1195 MethodElement operator = ElementFactory.methodElement("[]", intType, [intTyp e]);
1196 classA.methods = <MethodElement> [operator]; 1196 classA.methods = <MethodElement> [operator];
1197 // 1197 //
1198 // class B implements A {} 1198 // class B implements A {}
1199 // 1199 //
1200 ClassElementImpl classB = ElementFactory.classElement2("B", []); 1200 ClassElementImpl classB = ElementFactory.classElement2("B");
1201 classB.interfaces = <InterfaceType> [classA.type]; 1201 classB.interfaces = <InterfaceType> [classA.type];
1202 // 1202 //
1203 // class C extends Object with B {} 1203 // class C extends Object with B {}
1204 // 1204 //
1205 ClassElementImpl classC = ElementFactory.classElement2("C", []); 1205 ClassElementImpl classC = ElementFactory.classElement2("C");
1206 classC.mixins = <InterfaceType> [classB.type]; 1206 classC.mixins = <InterfaceType> [classB.type];
1207 // 1207 //
1208 // class D extends C {} 1208 // class D extends C {}
1209 // 1209 //
1210 ClassElementImpl classD = ElementFactory.classElement("D", classC.type, []); 1210 ClassElementImpl classD = ElementFactory.classElement("D", classC.type);
1211 // 1211 //
1212 // D a; 1212 // D a;
1213 // a[i]; 1213 // a[i];
1214 // 1214 //
1215 SimpleIdentifier array = AstFactory.identifier3("a"); 1215 SimpleIdentifier array = AstFactory.identifier3("a");
1216 array.staticType = classD.type; 1216 array.staticType = classD.type;
1217 IndexExpression expression = AstFactory.indexExpression(array, AstFactory.id entifier3("i")); 1217 IndexExpression expression = AstFactory.indexExpression(array, AstFactory.id entifier3("i"));
1218 expect(_resolveIndexExpression(expression, []), same(operator)); 1218 expect(_resolveIndexExpression(expression), same(operator));
1219 _listener.assertNoErrors(); 1219 _listener.assertNoErrors();
1220 } 1220 }
1221 1221
1222 void test_visitAssignmentExpression_compound() { 1222 void test_visitAssignmentExpression_compound() {
1223 InterfaceType intType = _typeProvider.intType; 1223 InterfaceType intType = _typeProvider.intType;
1224 SimpleIdentifier leftHandSide = AstFactory.identifier3("a"); 1224 SimpleIdentifier leftHandSide = AstFactory.identifier3("a");
1225 leftHandSide.staticType = intType; 1225 leftHandSide.staticType = intType;
1226 AssignmentExpression assignment = AstFactory.assignmentExpression(leftHandSi de, TokenType.PLUS_EQ, AstFactory.integer(1)); 1226 AssignmentExpression assignment = AstFactory.assignmentExpression(leftHandSi de, TokenType.PLUS_EQ, AstFactory.integer(1));
1227 _resolveNode(assignment, []); 1227 _resolveNode(assignment);
1228 expect(assignment.staticElement, same(getMethod(_typeProvider.numType, "+")) ); 1228 expect(assignment.staticElement, same(getMethod(_typeProvider.numType, "+")) );
1229 _listener.assertNoErrors(); 1229 _listener.assertNoErrors();
1230 } 1230 }
1231 1231
1232 void test_visitAssignmentExpression_simple() { 1232 void test_visitAssignmentExpression_simple() {
1233 AssignmentExpression expression = AstFactory.assignmentExpression(AstFactory .identifier3("x"), TokenType.EQ, AstFactory.integer(0)); 1233 AssignmentExpression expression = AstFactory.assignmentExpression(AstFactory .identifier3("x"), TokenType.EQ, AstFactory.integer(0));
1234 _resolveNode(expression, []); 1234 _resolveNode(expression);
1235 expect(expression.staticElement, isNull); 1235 expect(expression.staticElement, isNull);
1236 _listener.assertNoErrors(); 1236 _listener.assertNoErrors();
1237 } 1237 }
1238 1238
1239 void test_visitBinaryExpression() { 1239 void test_visitBinaryExpression() {
1240 // num i; 1240 // num i;
1241 // var j; 1241 // var j;
1242 // i + j 1242 // i + j
1243 InterfaceType numType = _typeProvider.numType; 1243 InterfaceType numType = _typeProvider.numType;
1244 SimpleIdentifier left = AstFactory.identifier3("i"); 1244 SimpleIdentifier left = AstFactory.identifier3("i");
1245 left.staticType = numType; 1245 left.staticType = numType;
1246 BinaryExpression expression = AstFactory.binaryExpression(left, TokenType.PL US, AstFactory.identifier3("j")); 1246 BinaryExpression expression = AstFactory.binaryExpression(left, TokenType.PL US, AstFactory.identifier3("j"));
1247 _resolveNode(expression, []); 1247 _resolveNode(expression);
1248 expect(expression.staticElement, getMethod(numType, "+")); 1248 expect(expression.staticElement, getMethod(numType, "+"));
1249 expect(expression.propagatedElement, isNull); 1249 expect(expression.propagatedElement, isNull);
1250 _listener.assertNoErrors(); 1250 _listener.assertNoErrors();
1251 } 1251 }
1252 1252
1253 void test_visitBinaryExpression_propagatedElement() { 1253 void test_visitBinaryExpression_propagatedElement() {
1254 // var i = 1; 1254 // var i = 1;
1255 // var j; 1255 // var j;
1256 // i + j 1256 // i + j
1257 InterfaceType numType = _typeProvider.numType; 1257 InterfaceType numType = _typeProvider.numType;
1258 SimpleIdentifier left = AstFactory.identifier3("i"); 1258 SimpleIdentifier left = AstFactory.identifier3("i");
1259 left.propagatedType = numType; 1259 left.propagatedType = numType;
1260 BinaryExpression expression = AstFactory.binaryExpression(left, TokenType.PL US, AstFactory.identifier3("j")); 1260 BinaryExpression expression = AstFactory.binaryExpression(left, TokenType.PL US, AstFactory.identifier3("j"));
1261 _resolveNode(expression, []); 1261 _resolveNode(expression);
1262 expect(expression.staticElement, isNull); 1262 expect(expression.staticElement, isNull);
1263 expect(expression.propagatedElement, getMethod(numType, "+")); 1263 expect(expression.propagatedElement, getMethod(numType, "+"));
1264 _listener.assertNoErrors(); 1264 _listener.assertNoErrors();
1265 } 1265 }
1266 1266
1267 void test_visitBreakStatement_withLabel() { 1267 void test_visitBreakStatement_withLabel() {
1268 String label = "loop"; 1268 String label = "loop";
1269 LabelElementImpl labelElement = new LabelElementImpl(AstFactory.identifier3( label), false, false); 1269 LabelElementImpl labelElement = new LabelElementImpl(AstFactory.identifier3( label), false, false);
1270 BreakStatement statement = AstFactory.breakStatement2(label); 1270 BreakStatement statement = AstFactory.breakStatement2(label);
1271 expect(_resolveBreak(statement, labelElement), same(labelElement)); 1271 expect(_resolveBreak(statement, labelElement), same(labelElement));
1272 _listener.assertNoErrors(); 1272 _listener.assertNoErrors();
1273 } 1273 }
1274 1274
1275 void test_visitBreakStatement_withoutLabel() { 1275 void test_visitBreakStatement_withoutLabel() {
1276 BreakStatement statement = AstFactory.breakStatement(); 1276 BreakStatement statement = AstFactory.breakStatement();
1277 _resolveStatement(statement, null); 1277 _resolveStatement(statement, null);
1278 _listener.assertNoErrors(); 1278 _listener.assertNoErrors();
1279 } 1279 }
1280 1280
1281 void test_visitConstructorName_named() { 1281 void test_visitConstructorName_named() {
1282 ClassElementImpl classA = ElementFactory.classElement2("A", []); 1282 ClassElementImpl classA = ElementFactory.classElement2("A");
1283 String constructorName = "a"; 1283 String constructorName = "a";
1284 ConstructorElement constructor = ElementFactory.constructorElement2(classA, constructorName, []); 1284 ConstructorElement constructor = ElementFactory.constructorElement2(classA, constructorName);
1285 classA.constructors = <ConstructorElement> [constructor]; 1285 classA.constructors = <ConstructorElement> [constructor];
1286 ConstructorName name = AstFactory.constructorName(AstFactory.typeName(classA , []), constructorName); 1286 ConstructorName name = AstFactory.constructorName(AstFactory.typeName(classA ), constructorName);
1287 _resolveNode(name, []); 1287 _resolveNode(name);
1288 expect(name.staticElement, same(constructor)); 1288 expect(name.staticElement, same(constructor));
1289 _listener.assertNoErrors(); 1289 _listener.assertNoErrors();
1290 } 1290 }
1291 1291
1292 void test_visitConstructorName_unnamed() { 1292 void test_visitConstructorName_unnamed() {
1293 ClassElementImpl classA = ElementFactory.classElement2("A", []); 1293 ClassElementImpl classA = ElementFactory.classElement2("A");
1294 String constructorName = null; 1294 String constructorName = null;
1295 ConstructorElement constructor = ElementFactory.constructorElement2(classA, constructorName, []); 1295 ConstructorElement constructor = ElementFactory.constructorElement2(classA, constructorName);
1296 classA.constructors = <ConstructorElement> [constructor]; 1296 classA.constructors = <ConstructorElement> [constructor];
1297 ConstructorName name = AstFactory.constructorName(AstFactory.typeName(classA , []), constructorName); 1297 ConstructorName name = AstFactory.constructorName(AstFactory.typeName(classA ), constructorName);
1298 _resolveNode(name, []); 1298 _resolveNode(name);
1299 expect(name.staticElement, same(constructor)); 1299 expect(name.staticElement, same(constructor));
1300 _listener.assertNoErrors(); 1300 _listener.assertNoErrors();
1301 } 1301 }
1302 1302
1303 void test_visitContinueStatement_withLabel() { 1303 void test_visitContinueStatement_withLabel() {
1304 String label = "loop"; 1304 String label = "loop";
1305 LabelElementImpl labelElement = new LabelElementImpl(AstFactory.identifier3( label), false, false); 1305 LabelElementImpl labelElement = new LabelElementImpl(AstFactory.identifier3( label), false, false);
1306 ContinueStatement statement = AstFactory.continueStatement(label); 1306 ContinueStatement statement = AstFactory.continueStatement(label);
1307 expect(_resolveContinue(statement, labelElement), same(labelElement)); 1307 expect(_resolveContinue(statement, labelElement), same(labelElement));
1308 _listener.assertNoErrors(); 1308 _listener.assertNoErrors();
1309 } 1309 }
1310 1310
1311 void test_visitContinueStatement_withoutLabel() { 1311 void test_visitContinueStatement_withoutLabel() {
1312 ContinueStatement statement = AstFactory.continueStatement(); 1312 ContinueStatement statement = AstFactory.continueStatement();
1313 _resolveStatement(statement, null); 1313 _resolveStatement(statement, null);
1314 _listener.assertNoErrors(); 1314 _listener.assertNoErrors();
1315 } 1315 }
1316 1316
1317 void test_visitExportDirective_noCombinators() { 1317 void test_visitExportDirective_noCombinators() {
1318 ExportDirective directive = AstFactory.exportDirective2(null, []); 1318 ExportDirective directive = AstFactory.exportDirective2(null);
1319 directive.element = ElementFactory.exportFor(ElementFactory.library(_definin gLibrary.context, "lib"), []); 1319 directive.element = ElementFactory.exportFor(ElementFactory.library(_definin gLibrary.context, "lib"));
1320 _resolveNode(directive, []); 1320 _resolveNode(directive);
1321 _listener.assertNoErrors(); 1321 _listener.assertNoErrors();
1322 } 1322 }
1323 1323
1324 void test_visitFieldFormalParameter() { 1324 void test_visitFieldFormalParameter() {
1325 String fieldName = "f"; 1325 String fieldName = "f";
1326 InterfaceType intType = _typeProvider.intType; 1326 InterfaceType intType = _typeProvider.intType;
1327 FieldElementImpl fieldElement = ElementFactory.fieldElement(fieldName, false , false, false, intType); 1327 FieldElementImpl fieldElement = ElementFactory.fieldElement(fieldName, false , false, false, intType);
1328 ClassElementImpl classA = ElementFactory.classElement2("A", []); 1328 ClassElementImpl classA = ElementFactory.classElement2("A");
1329 classA.fields = <FieldElement> [fieldElement]; 1329 classA.fields = <FieldElement> [fieldElement];
1330 FieldFormalParameter parameter = AstFactory.fieldFormalParameter2(fieldName) ; 1330 FieldFormalParameter parameter = AstFactory.fieldFormalParameter2(fieldName) ;
1331 FieldFormalParameterElementImpl parameterElement = ElementFactory.fieldForma lParameter(parameter.identifier); 1331 FieldFormalParameterElementImpl parameterElement = ElementFactory.fieldForma lParameter(parameter.identifier);
1332 parameterElement.field = fieldElement; 1332 parameterElement.field = fieldElement;
1333 parameterElement.type = intType; 1333 parameterElement.type = intType;
1334 parameter.identifier.staticElement = parameterElement; 1334 parameter.identifier.staticElement = parameterElement;
1335 _resolveInClass(parameter, classA); 1335 _resolveInClass(parameter, classA);
1336 expect(parameter.element.type, same(intType)); 1336 expect(parameter.element.type, same(intType));
1337 } 1337 }
1338 1338
1339 void test_visitImportDirective_noCombinators_noPrefix() { 1339 void test_visitImportDirective_noCombinators_noPrefix() {
1340 ImportDirective directive = AstFactory.importDirective3(null, null, []); 1340 ImportDirective directive = AstFactory.importDirective3(null, null);
1341 directive.element = ElementFactory.importFor(ElementFactory.library(_definin gLibrary.context, "lib"), null, []); 1341 directive.element = ElementFactory.importFor(ElementFactory.library(_definin gLibrary.context, "lib"), null);
1342 _resolveNode(directive, []); 1342 _resolveNode(directive);
1343 _listener.assertNoErrors(); 1343 _listener.assertNoErrors();
1344 } 1344 }
1345 1345
1346 void test_visitImportDirective_noCombinators_prefix() { 1346 void test_visitImportDirective_noCombinators_prefix() {
1347 String prefixName = "p"; 1347 String prefixName = "p";
1348 ImportElement importElement = ElementFactory.importFor(ElementFactory.librar y(_definingLibrary.context, "lib"), ElementFactory.prefix(prefixName), []); 1348 ImportElement importElement = ElementFactory.importFor(ElementFactory.librar y(_definingLibrary.context, "lib"), ElementFactory.prefix(prefixName));
1349 _definingLibrary.imports = <ImportElement> [importElement]; 1349 _definingLibrary.imports = <ImportElement> [importElement];
1350 ImportDirective directive = AstFactory.importDirective3(null, prefixName, [] ); 1350 ImportDirective directive = AstFactory.importDirective3(null, prefixName);
1351 directive.element = importElement; 1351 directive.element = importElement;
1352 _resolveNode(directive, []); 1352 _resolveNode(directive);
1353 _listener.assertNoErrors(); 1353 _listener.assertNoErrors();
1354 } 1354 }
1355 1355
1356 void test_visitImportDirective_withCombinators() { 1356 void test_visitImportDirective_withCombinators() {
1357 ShowCombinator combinator = AstFactory.showCombinator2(["A", "B", "C"]); 1357 ShowCombinator combinator = AstFactory.showCombinator2(["A", "B", "C"]);
1358 ImportDirective directive = AstFactory.importDirective3(null, null, [combina tor]); 1358 ImportDirective directive = AstFactory.importDirective3(null, null, [combina tor]);
1359 LibraryElementImpl library = ElementFactory.library(_definingLibrary.context , "lib"); 1359 LibraryElementImpl library = ElementFactory.library(_definingLibrary.context , "lib");
1360 TopLevelVariableElementImpl varA = ElementFactory.topLevelVariableElement2(" A"); 1360 TopLevelVariableElementImpl varA = ElementFactory.topLevelVariableElement2(" A");
1361 TopLevelVariableElementImpl varB = ElementFactory.topLevelVariableElement2(" B"); 1361 TopLevelVariableElementImpl varB = ElementFactory.topLevelVariableElement2(" B");
1362 TopLevelVariableElementImpl varC = ElementFactory.topLevelVariableElement2(" C"); 1362 TopLevelVariableElementImpl varC = ElementFactory.topLevelVariableElement2(" C");
1363 CompilationUnitElementImpl unit = library.definingCompilationUnit as Compila tionUnitElementImpl; 1363 CompilationUnitElementImpl unit = library.definingCompilationUnit as Compila tionUnitElementImpl;
1364 unit.accessors = <PropertyAccessorElement> [varA.getter, varA.setter, varB.g etter, varC.setter]; 1364 unit.accessors = <PropertyAccessorElement> [varA.getter, varA.setter, varB.g etter, varC.setter];
1365 unit.topLevelVariables = <TopLevelVariableElement> [varA, varB, varC]; 1365 unit.topLevelVariables = <TopLevelVariableElement> [varA, varB, varC];
1366 directive.element = ElementFactory.importFor(library, null, []); 1366 directive.element = ElementFactory.importFor(library, null);
1367 _resolveNode(directive, []); 1367 _resolveNode(directive);
1368 expect(combinator.shownNames[0].staticElement, same(varA)); 1368 expect(combinator.shownNames[0].staticElement, same(varA));
1369 expect(combinator.shownNames[1].staticElement, same(varB)); 1369 expect(combinator.shownNames[1].staticElement, same(varB));
1370 expect(combinator.shownNames[2].staticElement, same(varC)); 1370 expect(combinator.shownNames[2].staticElement, same(varC));
1371 _listener.assertNoErrors(); 1371 _listener.assertNoErrors();
1372 } 1372 }
1373 1373
1374 void test_visitIndexExpression_get() { 1374 void test_visitIndexExpression_get() {
1375 ClassElementImpl classA = ElementFactory.classElement2("A", []); 1375 ClassElementImpl classA = ElementFactory.classElement2("A");
1376 InterfaceType intType = _typeProvider.intType; 1376 InterfaceType intType = _typeProvider.intType;
1377 MethodElement getter = ElementFactory.methodElement("[]", intType, [intType] ); 1377 MethodElement getter = ElementFactory.methodElement("[]", intType, [intType] );
1378 classA.methods = <MethodElement> [getter]; 1378 classA.methods = <MethodElement> [getter];
1379 SimpleIdentifier array = AstFactory.identifier3("a"); 1379 SimpleIdentifier array = AstFactory.identifier3("a");
1380 array.staticType = classA.type; 1380 array.staticType = classA.type;
1381 IndexExpression expression = AstFactory.indexExpression(array, AstFactory.id entifier3("i")); 1381 IndexExpression expression = AstFactory.indexExpression(array, AstFactory.id entifier3("i"));
1382 expect(_resolveIndexExpression(expression, []), same(getter)); 1382 expect(_resolveIndexExpression(expression), same(getter));
1383 _listener.assertNoErrors(); 1383 _listener.assertNoErrors();
1384 } 1384 }
1385 1385
1386 void test_visitIndexExpression_set() { 1386 void test_visitIndexExpression_set() {
1387 ClassElementImpl classA = ElementFactory.classElement2("A", []); 1387 ClassElementImpl classA = ElementFactory.classElement2("A");
1388 InterfaceType intType = _typeProvider.intType; 1388 InterfaceType intType = _typeProvider.intType;
1389 MethodElement setter = ElementFactory.methodElement("[]=", intType, [intType ]); 1389 MethodElement setter = ElementFactory.methodElement("[]=", intType, [intType ]);
1390 classA.methods = <MethodElement> [setter]; 1390 classA.methods = <MethodElement> [setter];
1391 SimpleIdentifier array = AstFactory.identifier3("a"); 1391 SimpleIdentifier array = AstFactory.identifier3("a");
1392 array.staticType = classA.type; 1392 array.staticType = classA.type;
1393 IndexExpression expression = AstFactory.indexExpression(array, AstFactory.id entifier3("i")); 1393 IndexExpression expression = AstFactory.indexExpression(array, AstFactory.id entifier3("i"));
1394 AstFactory.assignmentExpression(expression, TokenType.EQ, AstFactory.integer (0)); 1394 AstFactory.assignmentExpression(expression, TokenType.EQ, AstFactory.integer (0));
1395 expect(_resolveIndexExpression(expression, []), same(setter)); 1395 expect(_resolveIndexExpression(expression), same(setter));
1396 _listener.assertNoErrors(); 1396 _listener.assertNoErrors();
1397 } 1397 }
1398 1398
1399 void test_visitInstanceCreationExpression_named() { 1399 void test_visitInstanceCreationExpression_named() {
1400 ClassElementImpl classA = ElementFactory.classElement2("A", []); 1400 ClassElementImpl classA = ElementFactory.classElement2("A");
1401 String constructorName = "a"; 1401 String constructorName = "a";
1402 ConstructorElement constructor = ElementFactory.constructorElement2(classA, constructorName, []); 1402 ConstructorElement constructor = ElementFactory.constructorElement2(classA, constructorName);
1403 classA.constructors = <ConstructorElement> [constructor]; 1403 classA.constructors = <ConstructorElement> [constructor];
1404 ConstructorName name = AstFactory.constructorName(AstFactory.typeName(classA , []), constructorName); 1404 ConstructorName name = AstFactory.constructorName(AstFactory.typeName(classA ), constructorName);
1405 name.staticElement = constructor; 1405 name.staticElement = constructor;
1406 InstanceCreationExpression creation = AstFactory.instanceCreationExpression( Keyword.NEW, name, []); 1406 InstanceCreationExpression creation = AstFactory.instanceCreationExpression( Keyword.NEW, name);
1407 _resolveNode(creation, []); 1407 _resolveNode(creation);
1408 expect(creation.staticElement, same(constructor)); 1408 expect(creation.staticElement, same(constructor));
1409 _listener.assertNoErrors(); 1409 _listener.assertNoErrors();
1410 } 1410 }
1411 1411
1412 void test_visitInstanceCreationExpression_unnamed() { 1412 void test_visitInstanceCreationExpression_unnamed() {
1413 ClassElementImpl classA = ElementFactory.classElement2("A", []); 1413 ClassElementImpl classA = ElementFactory.classElement2("A");
1414 String constructorName = null; 1414 String constructorName = null;
1415 ConstructorElement constructor = ElementFactory.constructorElement2(classA, constructorName, []); 1415 ConstructorElement constructor = ElementFactory.constructorElement2(classA, constructorName);
1416 classA.constructors = <ConstructorElement> [constructor]; 1416 classA.constructors = <ConstructorElement> [constructor];
1417 ConstructorName name = AstFactory.constructorName(AstFactory.typeName(classA , []), constructorName); 1417 ConstructorName name = AstFactory.constructorName(AstFactory.typeName(classA ), constructorName);
1418 name.staticElement = constructor; 1418 name.staticElement = constructor;
1419 InstanceCreationExpression creation = AstFactory.instanceCreationExpression( Keyword.NEW, name, []); 1419 InstanceCreationExpression creation = AstFactory.instanceCreationExpression( Keyword.NEW, name);
1420 _resolveNode(creation, []); 1420 _resolveNode(creation);
1421 expect(creation.staticElement, same(constructor)); 1421 expect(creation.staticElement, same(constructor));
1422 _listener.assertNoErrors(); 1422 _listener.assertNoErrors();
1423 } 1423 }
1424 1424
1425 void test_visitInstanceCreationExpression_unnamed_namedParameter() { 1425 void test_visitInstanceCreationExpression_unnamed_namedParameter() {
1426 ClassElementImpl classA = ElementFactory.classElement2("A", []); 1426 ClassElementImpl classA = ElementFactory.classElement2("A");
1427 String constructorName = null; 1427 String constructorName = null;
1428 ConstructorElementImpl constructor = ElementFactory.constructorElement2(clas sA, constructorName, []); 1428 ConstructorElementImpl constructor = ElementFactory.constructorElement2(clas sA, constructorName);
1429 String parameterName = "a"; 1429 String parameterName = "a";
1430 ParameterElement parameter = ElementFactory.namedParameter(parameterName); 1430 ParameterElement parameter = ElementFactory.namedParameter(parameterName);
1431 constructor.parameters = <ParameterElement> [parameter]; 1431 constructor.parameters = <ParameterElement> [parameter];
1432 classA.constructors = <ConstructorElement> [constructor]; 1432 classA.constructors = <ConstructorElement> [constructor];
1433 ConstructorName name = AstFactory.constructorName(AstFactory.typeName(classA , []), constructorName); 1433 ConstructorName name = AstFactory.constructorName(AstFactory.typeName(classA ), constructorName);
1434 name.staticElement = constructor; 1434 name.staticElement = constructor;
1435 InstanceCreationExpression creation = AstFactory.instanceCreationExpression( Keyword.NEW, name, [AstFactory.namedExpression2(parameterName, AstFactory.intege r(0))]); 1435 InstanceCreationExpression creation = AstFactory.instanceCreationExpression( Keyword.NEW, name, [AstFactory.namedExpression2(parameterName, AstFactory.intege r(0))]);
1436 _resolveNode(creation, []); 1436 _resolveNode(creation);
1437 expect(creation.staticElement, same(constructor)); 1437 expect(creation.staticElement, same(constructor));
1438 expect((creation.argumentList.arguments[0] as NamedExpression).name.label.st aticElement, same(parameter)); 1438 expect((creation.argumentList.arguments[0] as NamedExpression).name.label.st aticElement, same(parameter));
1439 _listener.assertNoErrors(); 1439 _listener.assertNoErrors();
1440 } 1440 }
1441 1441
1442 void test_visitMethodInvocation() { 1442 void test_visitMethodInvocation() {
1443 InterfaceType numType = _typeProvider.numType; 1443 InterfaceType numType = _typeProvider.numType;
1444 SimpleIdentifier left = AstFactory.identifier3("i"); 1444 SimpleIdentifier left = AstFactory.identifier3("i");
1445 left.staticType = numType; 1445 left.staticType = numType;
1446 String methodName = "abs"; 1446 String methodName = "abs";
1447 MethodInvocation invocation = AstFactory.methodInvocation(left, methodName, []); 1447 MethodInvocation invocation = AstFactory.methodInvocation(left, methodName);
1448 _resolveNode(invocation, []); 1448 _resolveNode(invocation);
1449 expect(invocation.methodName.staticElement, same(getMethod(numType, methodNa me))); 1449 expect(invocation.methodName.staticElement, same(getMethod(numType, methodNa me)));
1450 _listener.assertNoErrors(); 1450 _listener.assertNoErrors();
1451 } 1451 }
1452 1452
1453 void test_visitMethodInvocation_namedParameter() { 1453 void test_visitMethodInvocation_namedParameter() {
1454 ClassElementImpl classA = ElementFactory.classElement2("A", []); 1454 ClassElementImpl classA = ElementFactory.classElement2("A");
1455 String methodName = "m"; 1455 String methodName = "m";
1456 String parameterName = "p"; 1456 String parameterName = "p";
1457 MethodElementImpl method = ElementFactory.methodElement(methodName, null, [] ); 1457 MethodElementImpl method = ElementFactory.methodElement(methodName, null);
1458 ParameterElement parameter = ElementFactory.namedParameter(parameterName); 1458 ParameterElement parameter = ElementFactory.namedParameter(parameterName);
1459 method.parameters = <ParameterElement> [parameter]; 1459 method.parameters = <ParameterElement> [parameter];
1460 classA.methods = <MethodElement> [method]; 1460 classA.methods = <MethodElement> [method];
1461 SimpleIdentifier left = AstFactory.identifier3("i"); 1461 SimpleIdentifier left = AstFactory.identifier3("i");
1462 left.staticType = classA.type; 1462 left.staticType = classA.type;
1463 MethodInvocation invocation = AstFactory.methodInvocation(left, methodName, [AstFactory.namedExpression2(parameterName, AstFactory.integer(0))]); 1463 MethodInvocation invocation = AstFactory.methodInvocation(left, methodName, [AstFactory.namedExpression2(parameterName, AstFactory.integer(0))]);
1464 _resolveNode(invocation, []); 1464 _resolveNode(invocation);
1465 expect(invocation.methodName.staticElement, same(method)); 1465 expect(invocation.methodName.staticElement, same(method));
1466 expect((invocation.argumentList.arguments[0] as NamedExpression).name.label. staticElement, same(parameter)); 1466 expect((invocation.argumentList.arguments[0] as NamedExpression).name.label. staticElement, same(parameter));
1467 _listener.assertNoErrors(); 1467 _listener.assertNoErrors();
1468 } 1468 }
1469 1469
1470 void test_visitPostfixExpression() { 1470 void test_visitPostfixExpression() {
1471 InterfaceType numType = _typeProvider.numType; 1471 InterfaceType numType = _typeProvider.numType;
1472 SimpleIdentifier operand = AstFactory.identifier3("i"); 1472 SimpleIdentifier operand = AstFactory.identifier3("i");
1473 operand.staticType = numType; 1473 operand.staticType = numType;
1474 PostfixExpression expression = AstFactory.postfixExpression(operand, TokenTy pe.PLUS_PLUS); 1474 PostfixExpression expression = AstFactory.postfixExpression(operand, TokenTy pe.PLUS_PLUS);
1475 _resolveNode(expression, []); 1475 _resolveNode(expression);
1476 expect(expression.staticElement, getMethod(numType, "+")); 1476 expect(expression.staticElement, getMethod(numType, "+"));
1477 _listener.assertNoErrors(); 1477 _listener.assertNoErrors();
1478 } 1478 }
1479 1479
1480 void test_visitPrefixedIdentifier_dynamic() { 1480 void test_visitPrefixedIdentifier_dynamic() {
1481 DartType dynamicType = _typeProvider.dynamicType; 1481 DartType dynamicType = _typeProvider.dynamicType;
1482 SimpleIdentifier target = AstFactory.identifier3("a"); 1482 SimpleIdentifier target = AstFactory.identifier3("a");
1483 VariableElementImpl variable = ElementFactory.localVariableElement(target); 1483 VariableElementImpl variable = ElementFactory.localVariableElement(target);
1484 variable.type = dynamicType; 1484 variable.type = dynamicType;
1485 target.staticElement = variable; 1485 target.staticElement = variable;
1486 target.staticType = dynamicType; 1486 target.staticType = dynamicType;
1487 PrefixedIdentifier identifier = AstFactory.identifier(target, AstFactory.ide ntifier3("b")); 1487 PrefixedIdentifier identifier = AstFactory.identifier(target, AstFactory.ide ntifier3("b"));
1488 _resolveNode(identifier, []); 1488 _resolveNode(identifier);
1489 expect(identifier.staticElement, isNull); 1489 expect(identifier.staticElement, isNull);
1490 expect(identifier.identifier.staticElement, isNull); 1490 expect(identifier.identifier.staticElement, isNull);
1491 _listener.assertNoErrors(); 1491 _listener.assertNoErrors();
1492 } 1492 }
1493 1493
1494 void test_visitPrefixedIdentifier_nonDynamic() { 1494 void test_visitPrefixedIdentifier_nonDynamic() {
1495 ClassElementImpl classA = ElementFactory.classElement2("A", []); 1495 ClassElementImpl classA = ElementFactory.classElement2("A");
1496 String getterName = "b"; 1496 String getterName = "b";
1497 PropertyAccessorElement getter = ElementFactory.getterElement(getterName, fa lse, _typeProvider.intType); 1497 PropertyAccessorElement getter = ElementFactory.getterElement(getterName, fa lse, _typeProvider.intType);
1498 classA.accessors = <PropertyAccessorElement> [getter]; 1498 classA.accessors = <PropertyAccessorElement> [getter];
1499 SimpleIdentifier target = AstFactory.identifier3("a"); 1499 SimpleIdentifier target = AstFactory.identifier3("a");
1500 VariableElementImpl variable = ElementFactory.localVariableElement(target); 1500 VariableElementImpl variable = ElementFactory.localVariableElement(target);
1501 variable.type = classA.type; 1501 variable.type = classA.type;
1502 target.staticElement = variable; 1502 target.staticElement = variable;
1503 target.staticType = classA.type; 1503 target.staticType = classA.type;
1504 PrefixedIdentifier identifier = AstFactory.identifier(target, AstFactory.ide ntifier3(getterName)); 1504 PrefixedIdentifier identifier = AstFactory.identifier(target, AstFactory.ide ntifier3(getterName));
1505 _resolveNode(identifier, []); 1505 _resolveNode(identifier);
1506 expect(identifier.staticElement, same(getter)); 1506 expect(identifier.staticElement, same(getter));
1507 expect(identifier.identifier.staticElement, same(getter)); 1507 expect(identifier.identifier.staticElement, same(getter));
1508 _listener.assertNoErrors(); 1508 _listener.assertNoErrors();
1509 } 1509 }
1510 1510
1511 void test_visitPrefixedIdentifier_staticClassMember_getter() { 1511 void test_visitPrefixedIdentifier_staticClassMember_getter() {
1512 ClassElementImpl classA = ElementFactory.classElement2("A", []); 1512 ClassElementImpl classA = ElementFactory.classElement2("A");
1513 // set accessors 1513 // set accessors
1514 String propName = "b"; 1514 String propName = "b";
1515 PropertyAccessorElement getter = ElementFactory.getterElement(propName, fals e, _typeProvider.intType); 1515 PropertyAccessorElement getter = ElementFactory.getterElement(propName, fals e, _typeProvider.intType);
1516 PropertyAccessorElement setter = ElementFactory.setterElement(propName, fals e, _typeProvider.intType); 1516 PropertyAccessorElement setter = ElementFactory.setterElement(propName, fals e, _typeProvider.intType);
1517 classA.accessors = <PropertyAccessorElement> [getter, setter]; 1517 classA.accessors = <PropertyAccessorElement> [getter, setter];
1518 // prepare "A.m" 1518 // prepare "A.m"
1519 SimpleIdentifier target = AstFactory.identifier3("A"); 1519 SimpleIdentifier target = AstFactory.identifier3("A");
1520 target.staticElement = classA; 1520 target.staticElement = classA;
1521 target.staticType = classA.type; 1521 target.staticType = classA.type;
1522 PrefixedIdentifier identifier = AstFactory.identifier(target, AstFactory.ide ntifier3(propName)); 1522 PrefixedIdentifier identifier = AstFactory.identifier(target, AstFactory.ide ntifier3(propName));
1523 // resolve 1523 // resolve
1524 _resolveNode(identifier, []); 1524 _resolveNode(identifier);
1525 expect(identifier.staticElement, same(getter)); 1525 expect(identifier.staticElement, same(getter));
1526 expect(identifier.identifier.staticElement, same(getter)); 1526 expect(identifier.identifier.staticElement, same(getter));
1527 _listener.assertNoErrors(); 1527 _listener.assertNoErrors();
1528 } 1528 }
1529 1529
1530 void test_visitPrefixedIdentifier_staticClassMember_method() { 1530 void test_visitPrefixedIdentifier_staticClassMember_method() {
1531 ClassElementImpl classA = ElementFactory.classElement2("A", []); 1531 ClassElementImpl classA = ElementFactory.classElement2("A");
1532 // set accessors 1532 // set accessors
1533 String propName = "m"; 1533 String propName = "m";
1534 PropertyAccessorElement setter = ElementFactory.setterElement(propName, fals e, _typeProvider.intType); 1534 PropertyAccessorElement setter = ElementFactory.setterElement(propName, fals e, _typeProvider.intType);
1535 classA.accessors = <PropertyAccessorElement> [setter]; 1535 classA.accessors = <PropertyAccessorElement> [setter];
1536 // set methods 1536 // set methods
1537 MethodElement method = ElementFactory.methodElement("m", _typeProvider.intTy pe, []); 1537 MethodElement method = ElementFactory.methodElement("m", _typeProvider.intTy pe);
1538 classA.methods = <MethodElement> [method]; 1538 classA.methods = <MethodElement> [method];
1539 // prepare "A.m" 1539 // prepare "A.m"
1540 SimpleIdentifier target = AstFactory.identifier3("A"); 1540 SimpleIdentifier target = AstFactory.identifier3("A");
1541 target.staticElement = classA; 1541 target.staticElement = classA;
1542 target.staticType = classA.type; 1542 target.staticType = classA.type;
1543 PrefixedIdentifier identifier = AstFactory.identifier(target, AstFactory.ide ntifier3(propName)); 1543 PrefixedIdentifier identifier = AstFactory.identifier(target, AstFactory.ide ntifier3(propName));
1544 AstFactory.assignmentExpression(identifier, TokenType.EQ, AstFactory.nullLit eral()); 1544 AstFactory.assignmentExpression(identifier, TokenType.EQ, AstFactory.nullLit eral());
1545 // resolve 1545 // resolve
1546 _resolveNode(identifier, []); 1546 _resolveNode(identifier);
1547 expect(identifier.staticElement, same(method)); 1547 expect(identifier.staticElement, same(method));
1548 expect(identifier.identifier.staticElement, same(method)); 1548 expect(identifier.identifier.staticElement, same(method));
1549 _listener.assertNoErrors(); 1549 _listener.assertNoErrors();
1550 } 1550 }
1551 1551
1552 void test_visitPrefixedIdentifier_staticClassMember_setter() { 1552 void test_visitPrefixedIdentifier_staticClassMember_setter() {
1553 ClassElementImpl classA = ElementFactory.classElement2("A", []); 1553 ClassElementImpl classA = ElementFactory.classElement2("A");
1554 // set accessors 1554 // set accessors
1555 String propName = "b"; 1555 String propName = "b";
1556 PropertyAccessorElement getter = ElementFactory.getterElement(propName, fals e, _typeProvider.intType); 1556 PropertyAccessorElement getter = ElementFactory.getterElement(propName, fals e, _typeProvider.intType);
1557 PropertyAccessorElement setter = ElementFactory.setterElement(propName, fals e, _typeProvider.intType); 1557 PropertyAccessorElement setter = ElementFactory.setterElement(propName, fals e, _typeProvider.intType);
1558 classA.accessors = <PropertyAccessorElement> [getter, setter]; 1558 classA.accessors = <PropertyAccessorElement> [getter, setter];
1559 // prepare "A.b = null" 1559 // prepare "A.b = null"
1560 SimpleIdentifier target = AstFactory.identifier3("A"); 1560 SimpleIdentifier target = AstFactory.identifier3("A");
1561 target.staticElement = classA; 1561 target.staticElement = classA;
1562 target.staticType = classA.type; 1562 target.staticType = classA.type;
1563 PrefixedIdentifier identifier = AstFactory.identifier(target, AstFactory.ide ntifier3(propName)); 1563 PrefixedIdentifier identifier = AstFactory.identifier(target, AstFactory.ide ntifier3(propName));
1564 AstFactory.assignmentExpression(identifier, TokenType.EQ, AstFactory.nullLit eral()); 1564 AstFactory.assignmentExpression(identifier, TokenType.EQ, AstFactory.nullLit eral());
1565 // resolve 1565 // resolve
1566 _resolveNode(identifier, []); 1566 _resolveNode(identifier);
1567 expect(identifier.staticElement, same(setter)); 1567 expect(identifier.staticElement, same(setter));
1568 expect(identifier.identifier.staticElement, same(setter)); 1568 expect(identifier.identifier.staticElement, same(setter));
1569 _listener.assertNoErrors(); 1569 _listener.assertNoErrors();
1570 } 1570 }
1571 1571
1572 void test_visitPrefixExpression() { 1572 void test_visitPrefixExpression() {
1573 InterfaceType numType = _typeProvider.numType; 1573 InterfaceType numType = _typeProvider.numType;
1574 SimpleIdentifier operand = AstFactory.identifier3("i"); 1574 SimpleIdentifier operand = AstFactory.identifier3("i");
1575 operand.staticType = numType; 1575 operand.staticType = numType;
1576 PrefixExpression expression = AstFactory.prefixExpression(TokenType.PLUS_PLU S, operand); 1576 PrefixExpression expression = AstFactory.prefixExpression(TokenType.PLUS_PLU S, operand);
1577 _resolveNode(expression, []); 1577 _resolveNode(expression);
1578 expect(expression.staticElement, getMethod(numType, "+")); 1578 expect(expression.staticElement, getMethod(numType, "+"));
1579 _listener.assertNoErrors(); 1579 _listener.assertNoErrors();
1580 } 1580 }
1581 1581
1582 void test_visitPropertyAccess_getter_identifier() { 1582 void test_visitPropertyAccess_getter_identifier() {
1583 ClassElementImpl classA = ElementFactory.classElement2("A", []); 1583 ClassElementImpl classA = ElementFactory.classElement2("A");
1584 String getterName = "b"; 1584 String getterName = "b";
1585 PropertyAccessorElement getter = ElementFactory.getterElement(getterName, fa lse, _typeProvider.intType); 1585 PropertyAccessorElement getter = ElementFactory.getterElement(getterName, fa lse, _typeProvider.intType);
1586 classA.accessors = <PropertyAccessorElement> [getter]; 1586 classA.accessors = <PropertyAccessorElement> [getter];
1587 SimpleIdentifier target = AstFactory.identifier3("a"); 1587 SimpleIdentifier target = AstFactory.identifier3("a");
1588 target.staticType = classA.type; 1588 target.staticType = classA.type;
1589 PropertyAccess access = AstFactory.propertyAccess2(target, getterName); 1589 PropertyAccess access = AstFactory.propertyAccess2(target, getterName);
1590 _resolveNode(access, []); 1590 _resolveNode(access);
1591 expect(access.propertyName.staticElement, same(getter)); 1591 expect(access.propertyName.staticElement, same(getter));
1592 _listener.assertNoErrors(); 1592 _listener.assertNoErrors();
1593 } 1593 }
1594 1594
1595 void test_visitPropertyAccess_getter_super() { 1595 void test_visitPropertyAccess_getter_super() {
1596 // 1596 //
1597 // class A { 1597 // class A {
1598 // int get b; 1598 // int get b;
1599 // } 1599 // }
1600 // class B { 1600 // class B {
1601 // ... super.m ... 1601 // ... super.m ...
1602 // } 1602 // }
1603 // 1603 //
1604 ClassElementImpl classA = ElementFactory.classElement2("A", []); 1604 ClassElementImpl classA = ElementFactory.classElement2("A");
1605 String getterName = "b"; 1605 String getterName = "b";
1606 PropertyAccessorElement getter = ElementFactory.getterElement(getterName, fa lse, _typeProvider.intType); 1606 PropertyAccessorElement getter = ElementFactory.getterElement(getterName, fa lse, _typeProvider.intType);
1607 classA.accessors = <PropertyAccessorElement> [getter]; 1607 classA.accessors = <PropertyAccessorElement> [getter];
1608 SuperExpression target = AstFactory.superExpression(); 1608 SuperExpression target = AstFactory.superExpression();
1609 target.staticType = ElementFactory.classElement("B", classA.type, []).type; 1609 target.staticType = ElementFactory.classElement("B", classA.type).type;
1610 PropertyAccess access = AstFactory.propertyAccess2(target, getterName); 1610 PropertyAccess access = AstFactory.propertyAccess2(target, getterName);
1611 AstFactory.methodDeclaration2(null, null, null, null, AstFactory.identifier3 ("m"), AstFactory.formalParameterList([]), AstFactory.expressionFunctionBody(acc ess)); 1611 AstFactory.methodDeclaration2(null, null, null, null, AstFactory.identifier3 ("m"), AstFactory.formalParameterList(), AstFactory.expressionFunctionBody(acces s));
1612 _resolveNode(access, []); 1612 _resolveNode(access);
1613 expect(access.propertyName.staticElement, same(getter)); 1613 expect(access.propertyName.staticElement, same(getter));
1614 _listener.assertNoErrors(); 1614 _listener.assertNoErrors();
1615 } 1615 }
1616 1616
1617 void test_visitPropertyAccess_setter_this() { 1617 void test_visitPropertyAccess_setter_this() {
1618 ClassElementImpl classA = ElementFactory.classElement2("A", []); 1618 ClassElementImpl classA = ElementFactory.classElement2("A");
1619 String setterName = "b"; 1619 String setterName = "b";
1620 PropertyAccessorElement setter = ElementFactory.setterElement(setterName, fa lse, _typeProvider.intType); 1620 PropertyAccessorElement setter = ElementFactory.setterElement(setterName, fa lse, _typeProvider.intType);
1621 classA.accessors = <PropertyAccessorElement> [setter]; 1621 classA.accessors = <PropertyAccessorElement> [setter];
1622 ThisExpression target = AstFactory.thisExpression(); 1622 ThisExpression target = AstFactory.thisExpression();
1623 target.staticType = classA.type; 1623 target.staticType = classA.type;
1624 PropertyAccess access = AstFactory.propertyAccess2(target, setterName); 1624 PropertyAccess access = AstFactory.propertyAccess2(target, setterName);
1625 AstFactory.assignmentExpression(access, TokenType.EQ, AstFactory.integer(0)) ; 1625 AstFactory.assignmentExpression(access, TokenType.EQ, AstFactory.integer(0)) ;
1626 _resolveNode(access, []); 1626 _resolveNode(access);
1627 expect(access.propertyName.staticElement, same(setter)); 1627 expect(access.propertyName.staticElement, same(setter));
1628 _listener.assertNoErrors(); 1628 _listener.assertNoErrors();
1629 } 1629 }
1630 1630
1631 void test_visitSimpleIdentifier_classScope() { 1631 void test_visitSimpleIdentifier_classScope() {
1632 InterfaceType doubleType = _typeProvider.doubleType; 1632 InterfaceType doubleType = _typeProvider.doubleType;
1633 String fieldName = "NAN"; 1633 String fieldName = "NAN";
1634 SimpleIdentifier node = AstFactory.identifier3(fieldName); 1634 SimpleIdentifier node = AstFactory.identifier3(fieldName);
1635 _resolveInClass(node, doubleType.element); 1635 _resolveInClass(node, doubleType.element);
1636 expect(node.staticElement, getGetter(doubleType, fieldName)); 1636 expect(node.staticElement, getGetter(doubleType, fieldName));
1637 _listener.assertNoErrors(); 1637 _listener.assertNoErrors();
1638 } 1638 }
1639 1639
1640 void test_visitSimpleIdentifier_dynamic() { 1640 void test_visitSimpleIdentifier_dynamic() {
1641 SimpleIdentifier node = AstFactory.identifier3("dynamic"); 1641 SimpleIdentifier node = AstFactory.identifier3("dynamic");
1642 _resolveIdentifier(node, []); 1642 _resolveIdentifier(node);
1643 expect(node.staticElement, same(_typeProvider.dynamicType.element)); 1643 expect(node.staticElement, same(_typeProvider.dynamicType.element));
1644 expect(node.staticType, same(_typeProvider.typeType)); 1644 expect(node.staticType, same(_typeProvider.typeType));
1645 _listener.assertNoErrors(); 1645 _listener.assertNoErrors();
1646 } 1646 }
1647 1647
1648 void test_visitSimpleIdentifier_lexicalScope() { 1648 void test_visitSimpleIdentifier_lexicalScope() {
1649 SimpleIdentifier node = AstFactory.identifier3("i"); 1649 SimpleIdentifier node = AstFactory.identifier3("i");
1650 VariableElementImpl element = ElementFactory.localVariableElement(node); 1650 VariableElementImpl element = ElementFactory.localVariableElement(node);
1651 expect(_resolveIdentifier(node, [element]), same(element)); 1651 expect(_resolveIdentifier(node, [element]), same(element));
1652 _listener.assertNoErrors(); 1652 _listener.assertNoErrors();
1653 } 1653 }
1654 1654
1655 void test_visitSimpleIdentifier_lexicalScope_field_setter() { 1655 void test_visitSimpleIdentifier_lexicalScope_field_setter() {
1656 InterfaceType intType = _typeProvider.intType; 1656 InterfaceType intType = _typeProvider.intType;
1657 ClassElementImpl classA = ElementFactory.classElement2("A", []); 1657 ClassElementImpl classA = ElementFactory.classElement2("A");
1658 String fieldName = "a"; 1658 String fieldName = "a";
1659 FieldElement field = ElementFactory.fieldElement(fieldName, false, false, fa lse, intType); 1659 FieldElement field = ElementFactory.fieldElement(fieldName, false, false, fa lse, intType);
1660 classA.fields = <FieldElement> [field]; 1660 classA.fields = <FieldElement> [field];
1661 classA.accessors = <PropertyAccessorElement> [field.getter, field.setter]; 1661 classA.accessors = <PropertyAccessorElement> [field.getter, field.setter];
1662 SimpleIdentifier node = AstFactory.identifier3(fieldName); 1662 SimpleIdentifier node = AstFactory.identifier3(fieldName);
1663 AstFactory.assignmentExpression(node, TokenType.EQ, AstFactory.integer(0)); 1663 AstFactory.assignmentExpression(node, TokenType.EQ, AstFactory.integer(0));
1664 _resolveInClass(node, classA); 1664 _resolveInClass(node, classA);
1665 Element element = node.staticElement; 1665 Element element = node.staticElement;
1666 EngineTestCase.assertInstanceOf((obj) => obj is PropertyAccessorElement, Pro pertyAccessorElement, element); 1666 EngineTestCase.assertInstanceOf((obj) => obj is PropertyAccessorElement, Pro pertyAccessorElement, element);
1667 expect((element as PropertyAccessorElement).isSetter, isTrue); 1667 expect((element as PropertyAccessorElement).isSetter, isTrue);
1668 _listener.assertNoErrors(); 1668 _listener.assertNoErrors();
1669 } 1669 }
1670 1670
1671 void test_visitSuperConstructorInvocation() { 1671 void test_visitSuperConstructorInvocation() {
1672 ClassElementImpl superclass = ElementFactory.classElement2("A", []); 1672 ClassElementImpl superclass = ElementFactory.classElement2("A");
1673 ConstructorElementImpl superConstructor = ElementFactory.constructorElement2 (superclass, null, []); 1673 ConstructorElementImpl superConstructor = ElementFactory.constructorElement2 (superclass, null);
1674 superclass.constructors = <ConstructorElement> [superConstructor]; 1674 superclass.constructors = <ConstructorElement> [superConstructor];
1675 ClassElementImpl subclass = ElementFactory.classElement("B", superclass.type , []); 1675 ClassElementImpl subclass = ElementFactory.classElement("B", superclass.type );
1676 ConstructorElementImpl subConstructor = ElementFactory.constructorElement2(s ubclass, null, []); 1676 ConstructorElementImpl subConstructor = ElementFactory.constructorElement2(s ubclass, null);
1677 subclass.constructors = <ConstructorElement> [subConstructor]; 1677 subclass.constructors = <ConstructorElement> [subConstructor];
1678 SuperConstructorInvocation invocation = AstFactory.superConstructorInvocatio n([]); 1678 SuperConstructorInvocation invocation = AstFactory.superConstructorInvocatio n();
1679 _resolveInClass(invocation, subclass); 1679 _resolveInClass(invocation, subclass);
1680 expect(invocation.staticElement, superConstructor); 1680 expect(invocation.staticElement, superConstructor);
1681 _listener.assertNoErrors(); 1681 _listener.assertNoErrors();
1682 } 1682 }
1683 1683
1684 void test_visitSuperConstructorInvocation_namedParameter() { 1684 void test_visitSuperConstructorInvocation_namedParameter() {
1685 ClassElementImpl superclass = ElementFactory.classElement2("A", []); 1685 ClassElementImpl superclass = ElementFactory.classElement2("A");
1686 ConstructorElementImpl superConstructor = ElementFactory.constructorElement2 (superclass, null, []); 1686 ConstructorElementImpl superConstructor = ElementFactory.constructorElement2 (superclass, null);
1687 String parameterName = "p"; 1687 String parameterName = "p";
1688 ParameterElement parameter = ElementFactory.namedParameter(parameterName); 1688 ParameterElement parameter = ElementFactory.namedParameter(parameterName);
1689 superConstructor.parameters = <ParameterElement> [parameter]; 1689 superConstructor.parameters = <ParameterElement> [parameter];
1690 superclass.constructors = <ConstructorElement> [superConstructor]; 1690 superclass.constructors = <ConstructorElement> [superConstructor];
1691 ClassElementImpl subclass = ElementFactory.classElement("B", superclass.type , []); 1691 ClassElementImpl subclass = ElementFactory.classElement("B", superclass.type );
1692 ConstructorElementImpl subConstructor = ElementFactory.constructorElement2(s ubclass, null, []); 1692 ConstructorElementImpl subConstructor = ElementFactory.constructorElement2(s ubclass, null);
1693 subclass.constructors = <ConstructorElement> [subConstructor]; 1693 subclass.constructors = <ConstructorElement> [subConstructor];
1694 SuperConstructorInvocation invocation = AstFactory.superConstructorInvocatio n([AstFactory.namedExpression2(parameterName, AstFactory.integer(0))]); 1694 SuperConstructorInvocation invocation = AstFactory.superConstructorInvocatio n([AstFactory.namedExpression2(parameterName, AstFactory.integer(0))]);
1695 _resolveInClass(invocation, subclass); 1695 _resolveInClass(invocation, subclass);
1696 expect(invocation.staticElement, superConstructor); 1696 expect(invocation.staticElement, superConstructor);
1697 expect((invocation.argumentList.arguments[0] as NamedExpression).name.label. staticElement, same(parameter)); 1697 expect((invocation.argumentList.arguments[0] as NamedExpression).name.label. staticElement, same(parameter));
1698 _listener.assertNoErrors(); 1698 _listener.assertNoErrors();
1699 } 1699 }
1700 1700
1701 /** 1701 /**
1702 * Create the resolver used by the tests. 1702 * Create the resolver used by the tests.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1750 1750
1751 /** 1751 /**
1752 * Return the element associated with the given identifier after the resolver has resolved the 1752 * Return the element associated with the given identifier after the resolver has resolved the
1753 * identifier. 1753 * identifier.
1754 * 1754 *
1755 * @param node the expression to be resolved 1755 * @param node the expression to be resolved
1756 * @param definedElements the elements that are to be defined in the scope in which the element is 1756 * @param definedElements the elements that are to be defined in the scope in which the element is
1757 * being resolved 1757 * being resolved
1758 * @return the element to which the expression was resolved 1758 * @return the element to which the expression was resolved
1759 */ 1759 */
1760 Element _resolveIdentifier(Identifier node, List<Element> definedElements) { 1760 Element _resolveIdentifier(Identifier node, [List<Element> definedElements]) {
1761 _resolveNode(node, definedElements); 1761 _resolveNode(node, definedElements);
1762 return node.staticElement; 1762 return node.staticElement;
1763 } 1763 }
1764 1764
1765 /** 1765 /**
1766 * Return the element associated with the given identifier after the resolver has resolved the 1766 * Return the element associated with the given identifier after the resolver has resolved the
1767 * identifier. 1767 * identifier.
1768 * 1768 *
1769 * @param node the expression to be resolved 1769 * @param node the expression to be resolved
1770 * @param enclosingClass the element representing the class enclosing the iden tifier 1770 * @param enclosingClass the element representing the class enclosing the iden tifier
(...skipping 18 matching lines...) Expand all
1789 1789
1790 /** 1790 /**
1791 * Return the element associated with the given expression after the resolver has resolved the 1791 * Return the element associated with the given expression after the resolver has resolved the
1792 * expression. 1792 * expression.
1793 * 1793 *
1794 * @param node the expression to be resolved 1794 * @param node the expression to be resolved
1795 * @param definedElements the elements that are to be defined in the scope in which the element is 1795 * @param definedElements the elements that are to be defined in the scope in which the element is
1796 * being resolved 1796 * being resolved
1797 * @return the element to which the expression was resolved 1797 * @return the element to which the expression was resolved
1798 */ 1798 */
1799 Element _resolveIndexExpression(IndexExpression node, List<Element> definedEle ments) { 1799 Element _resolveIndexExpression(IndexExpression node, [List<Element> definedEl ements]) {
1800 _resolveNode(node, definedElements); 1800 _resolveNode(node, definedElements);
1801 return node.staticElement; 1801 return node.staticElement;
1802 } 1802 }
1803 1803
1804 /** 1804 /**
1805 * Return the element associated with the given identifier after the resolver has resolved the 1805 * Return the element associated with the given identifier after the resolver has resolved the
1806 * identifier. 1806 * identifier.
1807 * 1807 *
1808 * @param node the expression to be resolved 1808 * @param node the expression to be resolved
1809 * @param definedElements the elements that are to be defined in the scope in which the element is 1809 * @param definedElements the elements that are to be defined in the scope in which the element is
1810 * being resolved 1810 * being resolved
1811 * @return the element to which the expression was resolved 1811 * @return the element to which the expression was resolved
1812 */ 1812 */
1813 void _resolveNode(AstNode node, List<Element> definedElements) { 1813 void _resolveNode(AstNode node, [List<Element> definedElements]) {
1814 try { 1814 try {
1815 Scope outerScope = _visitor.nameScope_J2DAccessor as Scope; 1815 Scope outerScope = _visitor.nameScope_J2DAccessor as Scope;
1816 try { 1816 try {
1817 EnclosedScope innerScope = new EnclosedScope(outerScope); 1817 EnclosedScope innerScope = new EnclosedScope(outerScope);
1818 for (Element element in definedElements) { 1818 if (definedElements != null) {
1819 innerScope.define(element); 1819 for (Element element in definedElements) {
1820 innerScope.define(element);
1821 }
1820 } 1822 }
1821 _visitor.nameScope_J2DAccessor = innerScope; 1823 _visitor.nameScope_J2DAccessor = innerScope;
1822 node.accept(_resolver); 1824 node.accept(_resolver);
1823 } finally { 1825 } finally {
1824 _visitor.nameScope_J2DAccessor = outerScope; 1826 _visitor.nameScope_J2DAccessor = outerScope;
1825 } 1827 }
1826 } catch (exception) { 1828 } catch (exception) {
1827 throw new IllegalArgumentException("Could not resolve node", exception); 1829 throw new IllegalArgumentException("Could not resolve node", exception);
1828 } 1830 }
1829 } 1831 }
(...skipping 1426 matching lines...) Expand 10 before | Expand all | Expand 10 after
3256 3258
3257 void test_unusedLocalVariable_isRead_usedArgument() { 3259 void test_unusedLocalVariable_isRead_usedArgument() {
3258 enableUnusedLocalVariable = true; 3260 enableUnusedLocalVariable = true;
3259 Source source = addSource(r''' 3261 Source source = addSource(r'''
3260 main() { 3262 main() {
3261 var v = 1; 3263 var v = 1;
3262 print(++v); 3264 print(++v);
3263 } 3265 }
3264 print(x) {}'''); 3266 print(x) {}''');
3265 resolve(source); 3267 resolve(source);
3266 assertErrors(source, []); 3268 assertErrors(source);
3267 verify([source]); 3269 verify([source]);
3268 } 3270 }
3269 3271
3270 void test_unusedLocalVariable_isRead_usedInvocationTarget() { 3272 void test_unusedLocalVariable_isRead_usedInvocationTarget() {
3271 enableUnusedLocalVariable = true; 3273 enableUnusedLocalVariable = true;
3272 Source source = addSource(r''' 3274 Source source = addSource(r'''
3273 class A { 3275 class A {
3274 foo() {} 3276 foo() {}
3275 } 3277 }
3276 main() { 3278 main() {
3277 var a = new A(); 3279 var a = new A();
3278 a.foo(); 3280 a.foo();
3279 } 3281 }
3280 '''); 3282 ''');
3281 resolve(source); 3283 resolve(source);
3282 assertErrors(source, []); 3284 assertErrors(source);
3283 verify([source]); 3285 verify([source]);
3284 } 3286 }
3285 3287
3286 void test_unusedLocalVariable_isInvoked() { 3288 void test_unusedLocalVariable_isInvoked() {
3287 enableUnusedLocalVariable = true; 3289 enableUnusedLocalVariable = true;
3288 Source source = addSource(r''' 3290 Source source = addSource(r'''
3289 typedef Foo(); 3291 typedef Foo();
3290 main() { 3292 main() {
3291 Foo foo; 3293 Foo foo;
3292 foo(); 3294 foo();
3293 }'''); 3295 }''');
3294 resolve(source); 3296 resolve(source);
3295 assertErrors(source, []); 3297 assertErrors(source);
3296 verify([source]); 3298 verify([source]);
3297 } 3299 }
3298 3300
3299 void test_unusedLocalVariable_inCatch_exception() { 3301 void test_unusedLocalVariable_inCatch_exception() {
3300 enableUnusedLocalVariable = true; 3302 enableUnusedLocalVariable = true;
3301 Source source = addSource(r''' 3303 Source source = addSource(r'''
3302 main() { 3304 main() {
3303 try { 3305 try {
3304 } catch (exception) { 3306 } catch (exception) {
3305 } 3307 }
3306 }'''); 3308 }''');
3307 resolve(source); 3309 resolve(source);
3308 assertErrors(source, []); 3310 assertErrors(source);
3309 verify([source]); 3311 verify([source]);
3310 } 3312 }
3311 3313
3312 void test_unusedLocalVariable_inCatch_stackTrace() { 3314 void test_unusedLocalVariable_inCatch_stackTrace() {
3313 enableUnusedLocalVariable = true; 3315 enableUnusedLocalVariable = true;
3314 Source source = addSource(r''' 3316 Source source = addSource(r'''
3315 main() { 3317 main() {
3316 try { 3318 try {
3317 } catch (exception, stackTrace) { 3319 } catch (exception, stackTrace) {
3318 } 3320 }
3319 }'''); 3321 }''');
3320 resolve(source); 3322 resolve(source);
3321 assertErrors(source, [HintCode.UNUSED_LOCAL_VARIABLE]); 3323 assertErrors(source, [HintCode.UNUSED_LOCAL_VARIABLE]);
3322 verify([source]); 3324 verify([source]);
3323 } 3325 }
3324 3326
3325 void test_unusedLocalVariable_inCatch_stackTrace_used() { 3327 void test_unusedLocalVariable_inCatch_stackTrace_used() {
3326 enableUnusedLocalVariable = true; 3328 enableUnusedLocalVariable = true;
3327 Source source = addSource(r''' 3329 Source source = addSource(r'''
3328 main() { 3330 main() {
3329 try { 3331 try {
3330 } catch (exception, stackTrace) { 3332 } catch (exception, stackTrace) {
3331 print('exception at $stackTrace'); 3333 print('exception at $stackTrace');
3332 } 3334 }
3333 } 3335 }
3334 print(x) {}'''); 3336 print(x) {}''');
3335 resolve(source); 3337 resolve(source);
3336 assertErrors(source, []); 3338 assertErrors(source);
3337 verify([source]); 3339 verify([source]);
3338 } 3340 }
3339 3341
3340 void test_useOfVoidResult_assignmentExpression_function() { 3342 void test_useOfVoidResult_assignmentExpression_function() {
3341 Source source = addSource(r''' 3343 Source source = addSource(r'''
3342 void f() {} 3344 void f() {}
3343 class A { 3345 class A {
3344 n() { 3346 n() {
3345 var a; 3347 var a;
3346 a = f(); 3348 a = f();
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
3476 void setUp() { 3478 void setUp() {
3477 _typeProvider = new TestTypeProvider(); 3479 _typeProvider = new TestTypeProvider();
3478 _inheritanceManager = _createInheritanceManager(); 3480 _inheritanceManager = _createInheritanceManager();
3479 InterfaceType objectType = _typeProvider.objectType; 3481 InterfaceType objectType = _typeProvider.objectType;
3480 _numOfMembersInObject = objectType.methods.length + objectType.accessors.len gth; 3482 _numOfMembersInObject = objectType.methods.length + objectType.accessors.len gth;
3481 } 3483 }
3482 3484
3483 void test_getMapOfMembersInheritedFromClasses_accessor_extends() { 3485 void test_getMapOfMembersInheritedFromClasses_accessor_extends() {
3484 // class A { int get g; } 3486 // class A { int get g; }
3485 // class B extends A {} 3487 // class B extends A {}
3486 ClassElementImpl classA = ElementFactory.classElement2("A", []); 3488 ClassElementImpl classA = ElementFactory.classElement2("A");
3487 String getterName = "g"; 3489 String getterName = "g";
3488 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, f alse, _typeProvider.intType); 3490 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, f alse, _typeProvider.intType);
3489 classA.accessors = <PropertyAccessorElement> [getterG]; 3491 classA.accessors = <PropertyAccessorElement> [getterG];
3490 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); 3492 ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
3491 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla ssB); 3493 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla ssB);
3492 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla ssA); 3494 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla ssA);
3493 expect(mapA.size, _numOfMembersInObject); 3495 expect(mapA.size, _numOfMembersInObject);
3494 expect(mapB.size, _numOfMembersInObject + 1); 3496 expect(mapB.size, _numOfMembersInObject + 1);
3495 expect(mapB.get(getterName), same(getterG)); 3497 expect(mapB.get(getterName), same(getterG));
3496 _assertNoErrors(classA); 3498 _assertNoErrors(classA);
3497 _assertNoErrors(classB); 3499 _assertNoErrors(classB);
3498 } 3500 }
3499 3501
3500 void test_getMapOfMembersInheritedFromClasses_accessor_implements() { 3502 void test_getMapOfMembersInheritedFromClasses_accessor_implements() {
3501 // class A { int get g; } 3503 // class A { int get g; }
3502 // class B implements A {} 3504 // class B implements A {}
3503 ClassElementImpl classA = ElementFactory.classElement2("A", []); 3505 ClassElementImpl classA = ElementFactory.classElement2("A");
3504 String getterName = "g"; 3506 String getterName = "g";
3505 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, f alse, _typeProvider.intType); 3507 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, f alse, _typeProvider.intType);
3506 classA.accessors = <PropertyAccessorElement> [getterG]; 3508 classA.accessors = <PropertyAccessorElement> [getterG];
3507 ClassElementImpl classB = ElementFactory.classElement2("B", []); 3509 ClassElementImpl classB = ElementFactory.classElement2("B");
3508 classB.interfaces = <InterfaceType> [classA.type]; 3510 classB.interfaces = <InterfaceType> [classA.type];
3509 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla ssB); 3511 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla ssB);
3510 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla ssA); 3512 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla ssA);
3511 expect(mapA.size, _numOfMembersInObject); 3513 expect(mapA.size, _numOfMembersInObject);
3512 expect(mapB.size, _numOfMembersInObject); 3514 expect(mapB.size, _numOfMembersInObject);
3513 expect(mapB.get(getterName), isNull); 3515 expect(mapB.get(getterName), isNull);
3514 _assertNoErrors(classA); 3516 _assertNoErrors(classA);
3515 _assertNoErrors(classB); 3517 _assertNoErrors(classB);
3516 } 3518 }
3517 3519
3518 void test_getMapOfMembersInheritedFromClasses_accessor_with() { 3520 void test_getMapOfMembersInheritedFromClasses_accessor_with() {
3519 // class A { int get g; } 3521 // class A { int get g; }
3520 // class B extends Object with A {} 3522 // class B extends Object with A {}
3521 ClassElementImpl classA = ElementFactory.classElement2("A", []); 3523 ClassElementImpl classA = ElementFactory.classElement2("A");
3522 String getterName = "g"; 3524 String getterName = "g";
3523 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, f alse, _typeProvider.intType); 3525 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, f alse, _typeProvider.intType);
3524 classA.accessors = <PropertyAccessorElement> [getterG]; 3526 classA.accessors = <PropertyAccessorElement> [getterG];
3525 ClassElementImpl classB = ElementFactory.classElement2("B", []); 3527 ClassElementImpl classB = ElementFactory.classElement2("B");
3526 classB.mixins = <InterfaceType> [classA.type]; 3528 classB.mixins = <InterfaceType> [classA.type];
3527 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla ssB); 3529 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla ssB);
3528 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla ssA); 3530 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla ssA);
3529 expect(mapA.size, _numOfMembersInObject); 3531 expect(mapA.size, _numOfMembersInObject);
3530 expect(mapB.size, _numOfMembersInObject + 1); 3532 expect(mapB.size, _numOfMembersInObject + 1);
3531 expect(mapB.get(getterName), same(getterG)); 3533 expect(mapB.get(getterName), same(getterG));
3532 _assertNoErrors(classA); 3534 _assertNoErrors(classA);
3533 _assertNoErrors(classB); 3535 _assertNoErrors(classB);
3534 } 3536 }
3535 3537
3536 void test_getMapOfMembersInheritedFromClasses_implicitExtends() { 3538 void test_getMapOfMembersInheritedFromClasses_implicitExtends() {
3537 // class A {} 3539 // class A {}
3538 ClassElementImpl classA = ElementFactory.classElement2("A", []); 3540 ClassElementImpl classA = ElementFactory.classElement2("A");
3539 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla ssA); 3541 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla ssA);
3540 expect(mapA.size, _numOfMembersInObject); 3542 expect(mapA.size, _numOfMembersInObject);
3541 _assertNoErrors(classA); 3543 _assertNoErrors(classA);
3542 } 3544 }
3543 3545
3544 void test_getMapOfMembersInheritedFromClasses_method_extends() { 3546 void test_getMapOfMembersInheritedFromClasses_method_extends() {
3545 // class A { int g(); } 3547 // class A { int g(); }
3546 // class B extends A {} 3548 // class B extends A {}
3547 ClassElementImpl classA = ElementFactory.classElement2("A", []); 3549 ClassElementImpl classA = ElementFactory.classElement2("A");
3548 String methodName = "m"; 3550 String methodName = "m";
3549 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid er.intType, []); 3551 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid er.intType);
3550 classA.methods = <MethodElement> [methodM]; 3552 classA.methods = <MethodElement> [methodM];
3551 ClassElementImpl classB = ElementFactory.classElement2("B", []); 3553 ClassElementImpl classB = ElementFactory.classElement2("B");
3552 classB.supertype = classA.type; 3554 classB.supertype = classA.type;
3553 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla ssB); 3555 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla ssB);
3554 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla ssA); 3556 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla ssA);
3555 expect(mapA.size, _numOfMembersInObject); 3557 expect(mapA.size, _numOfMembersInObject);
3556 expect(mapB.size, _numOfMembersInObject + 1); 3558 expect(mapB.size, _numOfMembersInObject + 1);
3557 expect(mapB.get(methodName), same(methodM)); 3559 expect(mapB.get(methodName), same(methodM));
3558 _assertNoErrors(classA); 3560 _assertNoErrors(classA);
3559 _assertNoErrors(classB); 3561 _assertNoErrors(classB);
3560 } 3562 }
3561 3563
3562 void test_getMapOfMembersInheritedFromClasses_method_implements() { 3564 void test_getMapOfMembersInheritedFromClasses_method_implements() {
3563 // class A { int g(); } 3565 // class A { int g(); }
3564 // class B implements A {} 3566 // class B implements A {}
3565 ClassElementImpl classA = ElementFactory.classElement2("A", []); 3567 ClassElementImpl classA = ElementFactory.classElement2("A");
3566 String methodName = "m"; 3568 String methodName = "m";
3567 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid er.intType, []); 3569 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid er.intType);
3568 classA.methods = <MethodElement> [methodM]; 3570 classA.methods = <MethodElement> [methodM];
3569 ClassElementImpl classB = ElementFactory.classElement2("B", []); 3571 ClassElementImpl classB = ElementFactory.classElement2("B");
3570 classB.interfaces = <InterfaceType> [classA.type]; 3572 classB.interfaces = <InterfaceType> [classA.type];
3571 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla ssB); 3573 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla ssB);
3572 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla ssA); 3574 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla ssA);
3573 expect(mapA.size, _numOfMembersInObject); 3575 expect(mapA.size, _numOfMembersInObject);
3574 expect(mapB.size, _numOfMembersInObject); 3576 expect(mapB.size, _numOfMembersInObject);
3575 expect(mapB.get(methodName), isNull); 3577 expect(mapB.get(methodName), isNull);
3576 _assertNoErrors(classA); 3578 _assertNoErrors(classA);
3577 _assertNoErrors(classB); 3579 _assertNoErrors(classB);
3578 } 3580 }
3579 3581
3580 void test_getMapOfMembersInheritedFromClasses_method_with() { 3582 void test_getMapOfMembersInheritedFromClasses_method_with() {
3581 // class A { int g(); } 3583 // class A { int g(); }
3582 // class B extends Object with A {} 3584 // class B extends Object with A {}
3583 ClassElementImpl classA = ElementFactory.classElement2("A", []); 3585 ClassElementImpl classA = ElementFactory.classElement2("A");
3584 String methodName = "m"; 3586 String methodName = "m";
3585 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid er.intType, []); 3587 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid er.intType);
3586 classA.methods = <MethodElement> [methodM]; 3588 classA.methods = <MethodElement> [methodM];
3587 ClassElementImpl classB = ElementFactory.classElement2("B", []); 3589 ClassElementImpl classB = ElementFactory.classElement2("B");
3588 classB.mixins = <InterfaceType> [classA.type]; 3590 classB.mixins = <InterfaceType> [classA.type];
3589 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla ssB); 3591 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla ssB);
3590 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla ssA); 3592 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla ssA);
3591 expect(mapA.size, _numOfMembersInObject); 3593 expect(mapA.size, _numOfMembersInObject);
3592 expect(mapB.size, _numOfMembersInObject + 1); 3594 expect(mapB.size, _numOfMembersInObject + 1);
3593 expect(mapB.get(methodName), same(methodM)); 3595 expect(mapB.get(methodName), same(methodM));
3594 _assertNoErrors(classA); 3596 _assertNoErrors(classA);
3595 _assertNoErrors(classB); 3597 _assertNoErrors(classB);
3596 } 3598 }
3597 3599
3598 void test_getMapOfMembersInheritedFromInterfaces_accessor_extends() { 3600 void test_getMapOfMembersInheritedFromInterfaces_accessor_extends() {
3599 // class A { int get g; } 3601 // class A { int get g; }
3600 // class B extends A {} 3602 // class B extends A {}
3601 ClassElementImpl classA = ElementFactory.classElement2("A", []); 3603 ClassElementImpl classA = ElementFactory.classElement2("A");
3602 String getterName = "g"; 3604 String getterName = "g";
3603 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, f alse, _typeProvider.intType); 3605 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, f alse, _typeProvider.intType);
3604 classA.accessors = <PropertyAccessorElement> [getterG]; 3606 classA.accessors = <PropertyAccessorElement> [getterG];
3605 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); 3607 ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
3606 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classB); 3608 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classB);
3607 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classA); 3609 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classA);
3608 expect(mapA.size, _numOfMembersInObject); 3610 expect(mapA.size, _numOfMembersInObject);
3609 expect(mapB.size, _numOfMembersInObject + 1); 3611 expect(mapB.size, _numOfMembersInObject + 1);
3610 expect(mapB.get(getterName), same(getterG)); 3612 expect(mapB.get(getterName), same(getterG));
3611 _assertNoErrors(classA); 3613 _assertNoErrors(classA);
3612 _assertNoErrors(classB); 3614 _assertNoErrors(classB);
3613 } 3615 }
3614 3616
3615 void test_getMapOfMembersInheritedFromInterfaces_accessor_implements() { 3617 void test_getMapOfMembersInheritedFromInterfaces_accessor_implements() {
3616 // class A { int get g; } 3618 // class A { int get g; }
3617 // class B implements A {} 3619 // class B implements A {}
3618 ClassElementImpl classA = ElementFactory.classElement2("A", []); 3620 ClassElementImpl classA = ElementFactory.classElement2("A");
3619 String getterName = "g"; 3621 String getterName = "g";
3620 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, f alse, _typeProvider.intType); 3622 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, f alse, _typeProvider.intType);
3621 classA.accessors = <PropertyAccessorElement> [getterG]; 3623 classA.accessors = <PropertyAccessorElement> [getterG];
3622 ClassElementImpl classB = ElementFactory.classElement2("B", []); 3624 ClassElementImpl classB = ElementFactory.classElement2("B");
3623 classB.interfaces = <InterfaceType> [classA.type]; 3625 classB.interfaces = <InterfaceType> [classA.type];
3624 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classB); 3626 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classB);
3625 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classA); 3627 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classA);
3626 expect(mapA.size, _numOfMembersInObject); 3628 expect(mapA.size, _numOfMembersInObject);
3627 expect(mapB.size, _numOfMembersInObject + 1); 3629 expect(mapB.size, _numOfMembersInObject + 1);
3628 expect(mapB.get(getterName), same(getterG)); 3630 expect(mapB.get(getterName), same(getterG));
3629 _assertNoErrors(classA); 3631 _assertNoErrors(classA);
3630 _assertNoErrors(classB); 3632 _assertNoErrors(classB);
3631 } 3633 }
3632 3634
3633 void test_getMapOfMembersInheritedFromInterfaces_accessor_with() { 3635 void test_getMapOfMembersInheritedFromInterfaces_accessor_with() {
3634 // class A { int get g; } 3636 // class A { int get g; }
3635 // class B extends Object with A {} 3637 // class B extends Object with A {}
3636 ClassElementImpl classA = ElementFactory.classElement2("A", []); 3638 ClassElementImpl classA = ElementFactory.classElement2("A");
3637 String getterName = "g"; 3639 String getterName = "g";
3638 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, f alse, _typeProvider.intType); 3640 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, f alse, _typeProvider.intType);
3639 classA.accessors = <PropertyAccessorElement> [getterG]; 3641 classA.accessors = <PropertyAccessorElement> [getterG];
3640 ClassElementImpl classB = ElementFactory.classElement2("B", []); 3642 ClassElementImpl classB = ElementFactory.classElement2("B");
3641 classB.mixins = <InterfaceType> [classA.type]; 3643 classB.mixins = <InterfaceType> [classA.type];
3642 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classB); 3644 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classB);
3643 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classA); 3645 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classA);
3644 expect(mapA.size, _numOfMembersInObject); 3646 expect(mapA.size, _numOfMembersInObject);
3645 expect(mapB.size, _numOfMembersInObject + 1); 3647 expect(mapB.size, _numOfMembersInObject + 1);
3646 expect(mapB.get(getterName), same(getterG)); 3648 expect(mapB.get(getterName), same(getterG));
3647 _assertNoErrors(classA); 3649 _assertNoErrors(classA);
3648 _assertNoErrors(classB); 3650 _assertNoErrors(classB);
3649 } 3651 }
3650 3652
3651 void test_getMapOfMembersInheritedFromInterfaces_implicitExtends() { 3653 void test_getMapOfMembersInheritedFromInterfaces_implicitExtends() {
3652 // class A {} 3654 // class A {}
3653 ClassElementImpl classA = ElementFactory.classElement2("A", []); 3655 ClassElementImpl classA = ElementFactory.classElement2("A");
3654 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classA); 3656 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classA);
3655 expect(mapA.size, _numOfMembersInObject); 3657 expect(mapA.size, _numOfMembersInObject);
3656 _assertNoErrors(classA); 3658 _assertNoErrors(classA);
3657 } 3659 }
3658 3660
3659 void test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance _getter_method() { 3661 void test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance _getter_method() {
3660 // class I1 { int m(); } 3662 // class I1 { int m(); }
3661 // class I2 { int get m; } 3663 // class I2 { int get m; }
3662 // class A implements I2, I1 {} 3664 // class A implements I2, I1 {}
3663 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); 3665 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
3664 String methodName = "m"; 3666 String methodName = "m";
3665 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid er.intType, []); 3667 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid er.intType);
3666 classI1.methods = <MethodElement> [methodM]; 3668 classI1.methods = <MethodElement> [methodM];
3667 ClassElementImpl classI2 = ElementFactory.classElement2("I2", []); 3669 ClassElementImpl classI2 = ElementFactory.classElement2("I2");
3668 PropertyAccessorElement getter = ElementFactory.getterElement(methodName, fa lse, _typeProvider.intType); 3670 PropertyAccessorElement getter = ElementFactory.getterElement(methodName, fa lse, _typeProvider.intType);
3669 classI2.accessors = <PropertyAccessorElement> [getter]; 3671 classI2.accessors = <PropertyAccessorElement> [getter];
3670 ClassElementImpl classA = ElementFactory.classElement2("A", []); 3672 ClassElementImpl classA = ElementFactory.classElement2("A");
3671 classA.interfaces = <InterfaceType> [classI2.type, classI1.type]; 3673 classA.interfaces = <InterfaceType> [classI2.type, classI1.type];
3672 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classA); 3674 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classA);
3673 expect(mapA.size, _numOfMembersInObject); 3675 expect(mapA.size, _numOfMembersInObject);
3674 expect(mapA.get(methodName), isNull); 3676 expect(mapA.get(methodName), isNull);
3675 _assertErrors(classA, [StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GET TER_AND_METHOD]); 3677 _assertErrors(classA, [StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GET TER_AND_METHOD]);
3676 } 3678 }
3677 3679
3678 void test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance _int_str() { 3680 void test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance _int_str() {
3679 // class I1 { int m(); } 3681 // class I1 { int m(); }
3680 // class I2 { String m(); } 3682 // class I2 { String m(); }
3681 // class A implements I1, I2 {} 3683 // class A implements I1, I2 {}
3682 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); 3684 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
3683 String methodName = "m"; 3685 String methodName = "m";
3684 MethodElement methodM1 = ElementFactory.methodElement(methodName, null, [_ty peProvider.intType]); 3686 MethodElement methodM1 = ElementFactory.methodElement(methodName, null, [_ty peProvider.intType]);
3685 classI1.methods = <MethodElement> [methodM1]; 3687 classI1.methods = <MethodElement> [methodM1];
3686 ClassElementImpl classI2 = ElementFactory.classElement2("I2", []); 3688 ClassElementImpl classI2 = ElementFactory.classElement2("I2");
3687 MethodElement methodM2 = ElementFactory.methodElement(methodName, null, [_ty peProvider.stringType]); 3689 MethodElement methodM2 = ElementFactory.methodElement(methodName, null, [_ty peProvider.stringType]);
3688 classI2.methods = <MethodElement> [methodM2]; 3690 classI2.methods = <MethodElement> [methodM2];
3689 ClassElementImpl classA = ElementFactory.classElement2("A", []); 3691 ClassElementImpl classA = ElementFactory.classElement2("A");
3690 classA.interfaces = <InterfaceType> [classI1.type, classI2.type]; 3692 classA.interfaces = <InterfaceType> [classI1.type, classI2.type];
3691 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classA); 3693 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classA);
3692 expect(mapA.size, _numOfMembersInObject); 3694 expect(mapA.size, _numOfMembersInObject);
3693 expect(mapA.get(methodName), isNull); 3695 expect(mapA.get(methodName), isNull);
3694 _assertErrors(classA, [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE ]); 3696 _assertErrors(classA, [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE ]);
3695 } 3697 }
3696 3698
3697 void test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance _method_getter() { 3699 void test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance _method_getter() {
3698 // class I1 { int m(); } 3700 // class I1 { int m(); }
3699 // class I2 { int get m; } 3701 // class I2 { int get m; }
3700 // class A implements I1, I2 {} 3702 // class A implements I1, I2 {}
3701 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); 3703 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
3702 String methodName = "m"; 3704 String methodName = "m";
3703 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid er.intType, []); 3705 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid er.intType);
3704 classI1.methods = <MethodElement> [methodM]; 3706 classI1.methods = <MethodElement> [methodM];
3705 ClassElementImpl classI2 = ElementFactory.classElement2("I2", []); 3707 ClassElementImpl classI2 = ElementFactory.classElement2("I2");
3706 PropertyAccessorElement getter = ElementFactory.getterElement(methodName, fa lse, _typeProvider.intType); 3708 PropertyAccessorElement getter = ElementFactory.getterElement(methodName, fa lse, _typeProvider.intType);
3707 classI2.accessors = <PropertyAccessorElement> [getter]; 3709 classI2.accessors = <PropertyAccessorElement> [getter];
3708 ClassElementImpl classA = ElementFactory.classElement2("A", []); 3710 ClassElementImpl classA = ElementFactory.classElement2("A");
3709 classA.interfaces = <InterfaceType> [classI1.type, classI2.type]; 3711 classA.interfaces = <InterfaceType> [classI1.type, classI2.type];
3710 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classA); 3712 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classA);
3711 expect(mapA.size, _numOfMembersInObject); 3713 expect(mapA.size, _numOfMembersInObject);
3712 expect(mapA.get(methodName), isNull); 3714 expect(mapA.get(methodName), isNull);
3713 _assertErrors(classA, [StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GET TER_AND_METHOD]); 3715 _assertErrors(classA, [StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GET TER_AND_METHOD]);
3714 } 3716 }
3715 3717
3716 void test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance _numOfRequiredParams() { 3718 void test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance _numOfRequiredParams() {
3717 // class I1 { dynamic m(int, [int]); } 3719 // class I1 { dynamic m(int, [int]); }
3718 // class I2 { dynamic m(int, int, int); } 3720 // class I2 { dynamic m(int, int, int); }
3719 // class A implements I1, I2 {} 3721 // class A implements I1, I2 {}
3720 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); 3722 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
3721 String methodName = "m"; 3723 String methodName = "m";
3722 MethodElementImpl methodM1 = ElementFactory.methodElement(methodName, _typeP rovider.dynamicType, []); 3724 MethodElementImpl methodM1 = ElementFactory.methodElement(methodName, _typeP rovider.dynamicType);
3723 ParameterElementImpl parameter1 = new ParameterElementImpl.forNode(AstFactor y.identifier3("a1")); 3725 ParameterElementImpl parameter1 = new ParameterElementImpl.forNode(AstFactor y.identifier3("a1"));
3724 parameter1.type = _typeProvider.intType; 3726 parameter1.type = _typeProvider.intType;
3725 parameter1.parameterKind = ParameterKind.REQUIRED; 3727 parameter1.parameterKind = ParameterKind.REQUIRED;
3726 ParameterElementImpl parameter2 = new ParameterElementImpl.forNode(AstFactor y.identifier3("a2")); 3728 ParameterElementImpl parameter2 = new ParameterElementImpl.forNode(AstFactor y.identifier3("a2"));
3727 parameter2.type = _typeProvider.intType; 3729 parameter2.type = _typeProvider.intType;
3728 parameter2.parameterKind = ParameterKind.POSITIONAL; 3730 parameter2.parameterKind = ParameterKind.POSITIONAL;
3729 methodM1.parameters = <ParameterElement> [parameter1, parameter2]; 3731 methodM1.parameters = <ParameterElement> [parameter1, parameter2];
3730 classI1.methods = <MethodElement> [methodM1]; 3732 classI1.methods = <MethodElement> [methodM1];
3731 ClassElementImpl classI2 = ElementFactory.classElement2("I2", []); 3733 ClassElementImpl classI2 = ElementFactory.classElement2("I2");
3732 MethodElementImpl methodM2 = ElementFactory.methodElement(methodName, _typeP rovider.dynamicType, []); 3734 MethodElementImpl methodM2 = ElementFactory.methodElement(methodName, _typeP rovider.dynamicType);
3733 ParameterElementImpl parameter3 = new ParameterElementImpl.forNode(AstFactor y.identifier3("a3")); 3735 ParameterElementImpl parameter3 = new ParameterElementImpl.forNode(AstFactor y.identifier3("a3"));
3734 parameter3.type = _typeProvider.intType; 3736 parameter3.type = _typeProvider.intType;
3735 parameter3.parameterKind = ParameterKind.REQUIRED; 3737 parameter3.parameterKind = ParameterKind.REQUIRED;
3736 ParameterElementImpl parameter4 = new ParameterElementImpl.forNode(AstFactor y.identifier3("a4")); 3738 ParameterElementImpl parameter4 = new ParameterElementImpl.forNode(AstFactor y.identifier3("a4"));
3737 parameter4.type = _typeProvider.intType; 3739 parameter4.type = _typeProvider.intType;
3738 parameter4.parameterKind = ParameterKind.REQUIRED; 3740 parameter4.parameterKind = ParameterKind.REQUIRED;
3739 ParameterElementImpl parameter5 = new ParameterElementImpl.forNode(AstFactor y.identifier3("a5")); 3741 ParameterElementImpl parameter5 = new ParameterElementImpl.forNode(AstFactor y.identifier3("a5"));
3740 parameter5.type = _typeProvider.intType; 3742 parameter5.type = _typeProvider.intType;
3741 parameter5.parameterKind = ParameterKind.REQUIRED; 3743 parameter5.parameterKind = ParameterKind.REQUIRED;
3742 methodM2.parameters = <ParameterElement> [parameter3, parameter4, parameter5 ]; 3744 methodM2.parameters = <ParameterElement> [parameter3, parameter4, parameter5 ];
3743 classI2.methods = <MethodElement> [methodM2]; 3745 classI2.methods = <MethodElement> [methodM2];
3744 ClassElementImpl classA = ElementFactory.classElement2("A", []); 3746 ClassElementImpl classA = ElementFactory.classElement2("A");
3745 classA.interfaces = <InterfaceType> [classI1.type, classI2.type]; 3747 classA.interfaces = <InterfaceType> [classI1.type, classI2.type];
3746 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classA); 3748 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classA);
3747 expect(mapA.size, _numOfMembersInObject); 3749 expect(mapA.size, _numOfMembersInObject);
3748 expect(mapA.get(methodName), isNull); 3750 expect(mapA.get(methodName), isNull);
3749 _assertErrors(classA, [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE ]); 3751 _assertErrors(classA, [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE ]);
3750 } 3752 }
3751 3753
3752 void test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance _str_int() { 3754 void test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance _str_int() {
3753 // class I1 { int m(); } 3755 // class I1 { int m(); }
3754 // class I2 { String m(); } 3756 // class I2 { String m(); }
3755 // class A implements I2, I1 {} 3757 // class A implements I2, I1 {}
3756 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); 3758 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
3757 String methodName = "m"; 3759 String methodName = "m";
3758 MethodElement methodM1 = ElementFactory.methodElement(methodName, null, [_ty peProvider.stringType]); 3760 MethodElement methodM1 = ElementFactory.methodElement(methodName, null, [_ty peProvider.stringType]);
3759 classI1.methods = <MethodElement> [methodM1]; 3761 classI1.methods = <MethodElement> [methodM1];
3760 ClassElementImpl classI2 = ElementFactory.classElement2("I2", []); 3762 ClassElementImpl classI2 = ElementFactory.classElement2("I2");
3761 MethodElement methodM2 = ElementFactory.methodElement(methodName, null, [_ty peProvider.intType]); 3763 MethodElement methodM2 = ElementFactory.methodElement(methodName, null, [_ty peProvider.intType]);
3762 classI2.methods = <MethodElement> [methodM2]; 3764 classI2.methods = <MethodElement> [methodM2];
3763 ClassElementImpl classA = ElementFactory.classElement2("A", []); 3765 ClassElementImpl classA = ElementFactory.classElement2("A");
3764 classA.interfaces = <InterfaceType> [classI2.type, classI1.type]; 3766 classA.interfaces = <InterfaceType> [classI2.type, classI1.type];
3765 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classA); 3767 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classA);
3766 expect(mapA.size, _numOfMembersInObject); 3768 expect(mapA.size, _numOfMembersInObject);
3767 expect(mapA.get(methodName), isNull); 3769 expect(mapA.get(methodName), isNull);
3768 _assertErrors(classA, [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE ]); 3770 _assertErrors(classA, [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE ]);
3769 } 3771 }
3770 3772
3771 void test_getMapOfMembersInheritedFromInterfaces_method_extends() { 3773 void test_getMapOfMembersInheritedFromInterfaces_method_extends() {
3772 // class A { int g(); } 3774 // class A { int g(); }
3773 // class B extends A {} 3775 // class B extends A {}
3774 ClassElementImpl classA = ElementFactory.classElement2("A", []); 3776 ClassElementImpl classA = ElementFactory.classElement2("A");
3775 String methodName = "m"; 3777 String methodName = "m";
3776 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid er.intType, []); 3778 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid er.intType);
3777 classA.methods = <MethodElement> [methodM]; 3779 classA.methods = <MethodElement> [methodM];
3778 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); 3780 ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
3779 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classB); 3781 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classB);
3780 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classA); 3782 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classA);
3781 expect(mapA.size, _numOfMembersInObject); 3783 expect(mapA.size, _numOfMembersInObject);
3782 expect(mapB.size, _numOfMembersInObject + 1); 3784 expect(mapB.size, _numOfMembersInObject + 1);
3783 expect(mapB.get(methodName), same(methodM)); 3785 expect(mapB.get(methodName), same(methodM));
3784 _assertNoErrors(classA); 3786 _assertNoErrors(classA);
3785 _assertNoErrors(classB); 3787 _assertNoErrors(classB);
3786 } 3788 }
3787 3789
3788 void test_getMapOfMembersInheritedFromInterfaces_method_implements() { 3790 void test_getMapOfMembersInheritedFromInterfaces_method_implements() {
3789 // class A { int g(); } 3791 // class A { int g(); }
3790 // class B implements A {} 3792 // class B implements A {}
3791 ClassElementImpl classA = ElementFactory.classElement2("A", []); 3793 ClassElementImpl classA = ElementFactory.classElement2("A");
3792 String methodName = "m"; 3794 String methodName = "m";
3793 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid er.intType, []); 3795 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid er.intType);
3794 classA.methods = <MethodElement> [methodM]; 3796 classA.methods = <MethodElement> [methodM];
3795 ClassElementImpl classB = ElementFactory.classElement2("B", []); 3797 ClassElementImpl classB = ElementFactory.classElement2("B");
3796 classB.interfaces = <InterfaceType> [classA.type]; 3798 classB.interfaces = <InterfaceType> [classA.type];
3797 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classB); 3799 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classB);
3798 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classA); 3800 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classA);
3799 expect(mapA.size, _numOfMembersInObject); 3801 expect(mapA.size, _numOfMembersInObject);
3800 expect(mapB.size, _numOfMembersInObject + 1); 3802 expect(mapB.size, _numOfMembersInObject + 1);
3801 expect(mapB.get(methodName), same(methodM)); 3803 expect(mapB.get(methodName), same(methodM));
3802 _assertNoErrors(classA); 3804 _assertNoErrors(classA);
3803 _assertNoErrors(classB); 3805 _assertNoErrors(classB);
3804 } 3806 }
3805 3807
3806 void test_getMapOfMembersInheritedFromInterfaces_method_with() { 3808 void test_getMapOfMembersInheritedFromInterfaces_method_with() {
3807 // class A { int g(); } 3809 // class A { int g(); }
3808 // class B extends Object with A {} 3810 // class B extends Object with A {}
3809 ClassElementImpl classA = ElementFactory.classElement2("A", []); 3811 ClassElementImpl classA = ElementFactory.classElement2("A");
3810 String methodName = "m"; 3812 String methodName = "m";
3811 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid er.intType, []); 3813 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid er.intType);
3812 classA.methods = <MethodElement> [methodM]; 3814 classA.methods = <MethodElement> [methodM];
3813 ClassElementImpl classB = ElementFactory.classElement2("B", []); 3815 ClassElementImpl classB = ElementFactory.classElement2("B");
3814 classB.mixins = <InterfaceType> [classA.type]; 3816 classB.mixins = <InterfaceType> [classA.type];
3815 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classB); 3817 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classB);
3816 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classA); 3818 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classA);
3817 expect(mapA.size, _numOfMembersInObject); 3819 expect(mapA.size, _numOfMembersInObject);
3818 expect(mapB.size, _numOfMembersInObject + 1); 3820 expect(mapB.size, _numOfMembersInObject + 1);
3819 expect(mapB.get(methodName), same(methodM)); 3821 expect(mapB.get(methodName), same(methodM));
3820 _assertNoErrors(classA); 3822 _assertNoErrors(classA);
3821 _assertNoErrors(classB); 3823 _assertNoErrors(classB);
3822 } 3824 }
3823 3825
3824 void test_getMapOfMembersInheritedFromInterfaces_union_differentNames() { 3826 void test_getMapOfMembersInheritedFromInterfaces_union_differentNames() {
3825 // class I1 { int m1(); } 3827 // class I1 { int m1(); }
3826 // class I2 { int m2(); } 3828 // class I2 { int m2(); }
3827 // class A implements I1, I2 {} 3829 // class A implements I1, I2 {}
3828 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); 3830 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
3829 String methodName1 = "m1"; 3831 String methodName1 = "m1";
3830 MethodElement methodM1 = ElementFactory.methodElement(methodName1, _typeProv ider.intType, []); 3832 MethodElement methodM1 = ElementFactory.methodElement(methodName1, _typeProv ider.intType);
3831 classI1.methods = <MethodElement> [methodM1]; 3833 classI1.methods = <MethodElement> [methodM1];
3832 ClassElementImpl classI2 = ElementFactory.classElement2("I2", []); 3834 ClassElementImpl classI2 = ElementFactory.classElement2("I2");
3833 String methodName2 = "m2"; 3835 String methodName2 = "m2";
3834 MethodElement methodM2 = ElementFactory.methodElement(methodName2, _typeProv ider.intType, []); 3836 MethodElement methodM2 = ElementFactory.methodElement(methodName2, _typeProv ider.intType);
3835 classI2.methods = <MethodElement> [methodM2]; 3837 classI2.methods = <MethodElement> [methodM2];
3836 ClassElementImpl classA = ElementFactory.classElement2("A", []); 3838 ClassElementImpl classA = ElementFactory.classElement2("A");
3837 classA.interfaces = <InterfaceType> [classI1.type, classI2.type]; 3839 classA.interfaces = <InterfaceType> [classI1.type, classI2.type];
3838 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classA); 3840 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classA);
3839 expect(mapA.size, _numOfMembersInObject + 2); 3841 expect(mapA.size, _numOfMembersInObject + 2);
3840 expect(mapA.get(methodName1), same(methodM1)); 3842 expect(mapA.get(methodName1), same(methodM1));
3841 expect(mapA.get(methodName2), same(methodM2)); 3843 expect(mapA.get(methodName2), same(methodM2));
3842 _assertNoErrors(classA); 3844 _assertNoErrors(classA);
3843 } 3845 }
3844 3846
3845 void test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_2_gett ers() { 3847 void test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_2_gett ers() {
3846 // class I1 { int get g; } 3848 // class I1 { int get g; }
3847 // class I2 { num get g; } 3849 // class I2 { num get g; }
3848 // class A implements I1, I2 {} 3850 // class A implements I1, I2 {}
3849 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); 3851 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
3850 String accessorName = "g"; 3852 String accessorName = "g";
3851 PropertyAccessorElement getter1 = ElementFactory.getterElement(accessorName, false, _typeProvider.intType); 3853 PropertyAccessorElement getter1 = ElementFactory.getterElement(accessorName, false, _typeProvider.intType);
3852 classI1.accessors = <PropertyAccessorElement> [getter1]; 3854 classI1.accessors = <PropertyAccessorElement> [getter1];
3853 ClassElementImpl classI2 = ElementFactory.classElement2("I2", []); 3855 ClassElementImpl classI2 = ElementFactory.classElement2("I2");
3854 PropertyAccessorElement getter2 = ElementFactory.getterElement(accessorName, false, _typeProvider.numType); 3856 PropertyAccessorElement getter2 = ElementFactory.getterElement(accessorName, false, _typeProvider.numType);
3855 classI2.accessors = <PropertyAccessorElement> [getter2]; 3857 classI2.accessors = <PropertyAccessorElement> [getter2];
3856 ClassElementImpl classA = ElementFactory.classElement2("A", []); 3858 ClassElementImpl classA = ElementFactory.classElement2("A");
3857 classA.interfaces = <InterfaceType> [classI1.type, classI2.type]; 3859 classA.interfaces = <InterfaceType> [classI1.type, classI2.type];
3858 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classA); 3860 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classA);
3859 expect(mapA.size, _numOfMembersInObject + 1); 3861 expect(mapA.size, _numOfMembersInObject + 1);
3860 PropertyAccessorElement syntheticAccessor = ElementFactory.getterElement(acc essorName, false, _typeProvider.dynamicType); 3862 PropertyAccessorElement syntheticAccessor = ElementFactory.getterElement(acc essorName, false, _typeProvider.dynamicType);
3861 expect(mapA.get(accessorName).type, syntheticAccessor.type); 3863 expect(mapA.get(accessorName).type, syntheticAccessor.type);
3862 _assertNoErrors(classA); 3864 _assertNoErrors(classA);
3863 } 3865 }
3864 3866
3865 void test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_2_meth ods() { 3867 void test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_2_meth ods() {
3866 // class I1 { dynamic m(int); } 3868 // class I1 { dynamic m(int); }
3867 // class I2 { dynamic m(num); } 3869 // class I2 { dynamic m(num); }
3868 // class A implements I1, I2 {} 3870 // class A implements I1, I2 {}
3869 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); 3871 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
3870 String methodName = "m"; 3872 String methodName = "m";
3871 MethodElementImpl methodM1 = ElementFactory.methodElement(methodName, _typeP rovider.dynamicType, []); 3873 MethodElementImpl methodM1 = ElementFactory.methodElement(methodName, _typeP rovider.dynamicType);
3872 ParameterElementImpl parameter1 = new ParameterElementImpl.forNode(AstFactor y.identifier3("a0")); 3874 ParameterElementImpl parameter1 = new ParameterElementImpl.forNode(AstFactor y.identifier3("a0"));
3873 parameter1.type = _typeProvider.intType; 3875 parameter1.type = _typeProvider.intType;
3874 parameter1.parameterKind = ParameterKind.REQUIRED; 3876 parameter1.parameterKind = ParameterKind.REQUIRED;
3875 methodM1.parameters = <ParameterElement> [parameter1]; 3877 methodM1.parameters = <ParameterElement> [parameter1];
3876 classI1.methods = <MethodElement> [methodM1]; 3878 classI1.methods = <MethodElement> [methodM1];
3877 ClassElementImpl classI2 = ElementFactory.classElement2("I2", []); 3879 ClassElementImpl classI2 = ElementFactory.classElement2("I2");
3878 MethodElementImpl methodM2 = ElementFactory.methodElement(methodName, _typeP rovider.dynamicType, []); 3880 MethodElementImpl methodM2 = ElementFactory.methodElement(methodName, _typeP rovider.dynamicType);
3879 ParameterElementImpl parameter2 = new ParameterElementImpl.forNode(AstFactor y.identifier3("a0")); 3881 ParameterElementImpl parameter2 = new ParameterElementImpl.forNode(AstFactor y.identifier3("a0"));
3880 parameter2.type = _typeProvider.numType; 3882 parameter2.type = _typeProvider.numType;
3881 parameter2.parameterKind = ParameterKind.REQUIRED; 3883 parameter2.parameterKind = ParameterKind.REQUIRED;
3882 methodM2.parameters = <ParameterElement> [parameter2]; 3884 methodM2.parameters = <ParameterElement> [parameter2];
3883 classI2.methods = <MethodElement> [methodM2]; 3885 classI2.methods = <MethodElement> [methodM2];
3884 ClassElementImpl classA = ElementFactory.classElement2("A", []); 3886 ClassElementImpl classA = ElementFactory.classElement2("A");
3885 classA.interfaces = <InterfaceType> [classI1.type, classI2.type]; 3887 classA.interfaces = <InterfaceType> [classI1.type, classI2.type];
3886 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classA); 3888 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classA);
3887 expect(mapA.size, _numOfMembersInObject + 1); 3889 expect(mapA.size, _numOfMembersInObject + 1);
3888 MethodElement syntheticMethod = ElementFactory.methodElement(methodName, _ty peProvider.dynamicType, [_typeProvider.dynamicType]); 3890 MethodElement syntheticMethod = ElementFactory.methodElement(methodName, _ty peProvider.dynamicType, [_typeProvider.dynamicType]);
3889 expect(mapA.get(methodName).type, syntheticMethod.type); 3891 expect(mapA.get(methodName).type, syntheticMethod.type);
3890 _assertNoErrors(classA); 3892 _assertNoErrors(classA);
3891 } 3893 }
3892 3894
3893 void test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_2_sett ers() { 3895 void test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_2_sett ers() {
3894 // class I1 { set s(int); } 3896 // class I1 { set s(int); }
3895 // class I2 { set s(num); } 3897 // class I2 { set s(num); }
3896 // class A implements I1, I2 {} 3898 // class A implements I1, I2 {}
3897 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); 3899 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
3898 String accessorName = "s"; 3900 String accessorName = "s";
3899 PropertyAccessorElement setter1 = ElementFactory.setterElement(accessorName, false, _typeProvider.intType); 3901 PropertyAccessorElement setter1 = ElementFactory.setterElement(accessorName, false, _typeProvider.intType);
3900 classI1.accessors = <PropertyAccessorElement> [setter1]; 3902 classI1.accessors = <PropertyAccessorElement> [setter1];
3901 ClassElementImpl classI2 = ElementFactory.classElement2("I2", []); 3903 ClassElementImpl classI2 = ElementFactory.classElement2("I2");
3902 PropertyAccessorElement setter2 = ElementFactory.setterElement(accessorName, false, _typeProvider.numType); 3904 PropertyAccessorElement setter2 = ElementFactory.setterElement(accessorName, false, _typeProvider.numType);
3903 classI2.accessors = <PropertyAccessorElement> [setter2]; 3905 classI2.accessors = <PropertyAccessorElement> [setter2];
3904 ClassElementImpl classA = ElementFactory.classElement2("A", []); 3906 ClassElementImpl classA = ElementFactory.classElement2("A");
3905 classA.interfaces = <InterfaceType> [classI1.type, classI2.type]; 3907 classA.interfaces = <InterfaceType> [classI1.type, classI2.type];
3906 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classA); 3908 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classA);
3907 expect(mapA.size, _numOfMembersInObject + 1); 3909 expect(mapA.size, _numOfMembersInObject + 1);
3908 PropertyAccessorElementImpl syntheticAccessor = ElementFactory.setterElement (accessorName, false, _typeProvider.dynamicType); 3910 PropertyAccessorElementImpl syntheticAccessor = ElementFactory.setterElement (accessorName, false, _typeProvider.dynamicType);
3909 syntheticAccessor.returnType = _typeProvider.dynamicType; 3911 syntheticAccessor.returnType = _typeProvider.dynamicType;
3910 expect(mapA.get("$accessorName=").type, syntheticAccessor.type); 3912 expect(mapA.get("$accessorName=").type, syntheticAccessor.type);
3911 _assertNoErrors(classA); 3913 _assertNoErrors(classA);
3912 } 3914 }
3913 3915
3914 void test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_3_gett ers() { 3916 void test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_3_gett ers() {
3915 // class A {} 3917 // class A {}
3916 // class B extends A {} 3918 // class B extends A {}
3917 // class C extends B {} 3919 // class C extends B {}
3918 // class I1 { A get g; } 3920 // class I1 { A get g; }
3919 // class I2 { B get g; } 3921 // class I2 { B get g; }
3920 // class I3 { C get g; } 3922 // class I3 { C get g; }
3921 // class D implements I1, I2, I3 {} 3923 // class D implements I1, I2, I3 {}
3922 ClassElementImpl classA = ElementFactory.classElement2("A", []); 3924 ClassElementImpl classA = ElementFactory.classElement2("A");
3923 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); 3925 ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
3924 ClassElementImpl classC = ElementFactory.classElement("C", classB.type, []); 3926 ClassElementImpl classC = ElementFactory.classElement("C", classB.type);
3925 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); 3927 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
3926 String accessorName = "g"; 3928 String accessorName = "g";
3927 PropertyAccessorElement getter1 = ElementFactory.getterElement(accessorName, false, classA.type); 3929 PropertyAccessorElement getter1 = ElementFactory.getterElement(accessorName, false, classA.type);
3928 classI1.accessors = <PropertyAccessorElement> [getter1]; 3930 classI1.accessors = <PropertyAccessorElement> [getter1];
3929 ClassElementImpl classI2 = ElementFactory.classElement2("I2", []); 3931 ClassElementImpl classI2 = ElementFactory.classElement2("I2");
3930 PropertyAccessorElement getter2 = ElementFactory.getterElement(accessorName, false, classB.type); 3932 PropertyAccessorElement getter2 = ElementFactory.getterElement(accessorName, false, classB.type);
3931 classI2.accessors = <PropertyAccessorElement> [getter2]; 3933 classI2.accessors = <PropertyAccessorElement> [getter2];
3932 ClassElementImpl classI3 = ElementFactory.classElement2("I3", []); 3934 ClassElementImpl classI3 = ElementFactory.classElement2("I3");
3933 PropertyAccessorElement getter3 = ElementFactory.getterElement(accessorName, false, classC.type); 3935 PropertyAccessorElement getter3 = ElementFactory.getterElement(accessorName, false, classC.type);
3934 classI3.accessors = <PropertyAccessorElement> [getter3]; 3936 classI3.accessors = <PropertyAccessorElement> [getter3];
3935 ClassElementImpl classD = ElementFactory.classElement2("D", []); 3937 ClassElementImpl classD = ElementFactory.classElement2("D");
3936 classD.interfaces = <InterfaceType> [classI1.type, classI2.type, classI3.typ e]; 3938 classD.interfaces = <InterfaceType> [classI1.type, classI2.type, classI3.typ e];
3937 MemberMap mapD = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classD); 3939 MemberMap mapD = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classD);
3938 expect(mapD.size, _numOfMembersInObject + 1); 3940 expect(mapD.size, _numOfMembersInObject + 1);
3939 PropertyAccessorElement syntheticAccessor = ElementFactory.getterElement(acc essorName, false, _typeProvider.dynamicType); 3941 PropertyAccessorElement syntheticAccessor = ElementFactory.getterElement(acc essorName, false, _typeProvider.dynamicType);
3940 expect(mapD.get(accessorName).type, syntheticAccessor.type); 3942 expect(mapD.get(accessorName).type, syntheticAccessor.type);
3941 _assertNoErrors(classD); 3943 _assertNoErrors(classD);
3942 } 3944 }
3943 3945
3944 void test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_3_meth ods() { 3946 void test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_3_meth ods() {
3945 // class A {} 3947 // class A {}
3946 // class B extends A {} 3948 // class B extends A {}
3947 // class C extends B {} 3949 // class C extends B {}
3948 // class I1 { dynamic m(A a); } 3950 // class I1 { dynamic m(A a); }
3949 // class I2 { dynamic m(B b); } 3951 // class I2 { dynamic m(B b); }
3950 // class I3 { dynamic m(C c); } 3952 // class I3 { dynamic m(C c); }
3951 // class D implements I1, I2, I3 {} 3953 // class D implements I1, I2, I3 {}
3952 ClassElementImpl classA = ElementFactory.classElement2("A", []); 3954 ClassElementImpl classA = ElementFactory.classElement2("A");
3953 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); 3955 ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
3954 ClassElementImpl classC = ElementFactory.classElement("C", classB.type, []); 3956 ClassElementImpl classC = ElementFactory.classElement("C", classB.type);
3955 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); 3957 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
3956 String methodName = "m"; 3958 String methodName = "m";
3957 MethodElementImpl methodM1 = ElementFactory.methodElement(methodName, _typeP rovider.dynamicType, []); 3959 MethodElementImpl methodM1 = ElementFactory.methodElement(methodName, _typeP rovider.dynamicType);
3958 ParameterElementImpl parameter1 = new ParameterElementImpl.forNode(AstFactor y.identifier3("a0")); 3960 ParameterElementImpl parameter1 = new ParameterElementImpl.forNode(AstFactor y.identifier3("a0"));
3959 parameter1.type = classA.type; 3961 parameter1.type = classA.type;
3960 parameter1.parameterKind = ParameterKind.REQUIRED; 3962 parameter1.parameterKind = ParameterKind.REQUIRED;
3961 methodM1.parameters = <ParameterElement> [parameter1]; 3963 methodM1.parameters = <ParameterElement> [parameter1];
3962 classI1.methods = <MethodElement> [methodM1]; 3964 classI1.methods = <MethodElement> [methodM1];
3963 ClassElementImpl classI2 = ElementFactory.classElement2("I2", []); 3965 ClassElementImpl classI2 = ElementFactory.classElement2("I2");
3964 MethodElementImpl methodM2 = ElementFactory.methodElement(methodName, _typeP rovider.dynamicType, []); 3966 MethodElementImpl methodM2 = ElementFactory.methodElement(methodName, _typeP rovider.dynamicType);
3965 ParameterElementImpl parameter2 = new ParameterElementImpl.forNode(AstFactor y.identifier3("a0")); 3967 ParameterElementImpl parameter2 = new ParameterElementImpl.forNode(AstFactor y.identifier3("a0"));
3966 parameter2.type = classB.type; 3968 parameter2.type = classB.type;
3967 parameter2.parameterKind = ParameterKind.REQUIRED; 3969 parameter2.parameterKind = ParameterKind.REQUIRED;
3968 methodM2.parameters = <ParameterElement> [parameter2]; 3970 methodM2.parameters = <ParameterElement> [parameter2];
3969 classI2.methods = <MethodElement> [methodM2]; 3971 classI2.methods = <MethodElement> [methodM2];
3970 ClassElementImpl classI3 = ElementFactory.classElement2("I3", []); 3972 ClassElementImpl classI3 = ElementFactory.classElement2("I3");
3971 MethodElementImpl methodM3 = ElementFactory.methodElement(methodName, _typeP rovider.dynamicType, []); 3973 MethodElementImpl methodM3 = ElementFactory.methodElement(methodName, _typeP rovider.dynamicType);
3972 ParameterElementImpl parameter3 = new ParameterElementImpl.forNode(AstFactor y.identifier3("a0")); 3974 ParameterElementImpl parameter3 = new ParameterElementImpl.forNode(AstFactor y.identifier3("a0"));
3973 parameter3.type = classC.type; 3975 parameter3.type = classC.type;
3974 parameter3.parameterKind = ParameterKind.REQUIRED; 3976 parameter3.parameterKind = ParameterKind.REQUIRED;
3975 methodM3.parameters = <ParameterElement> [parameter3]; 3977 methodM3.parameters = <ParameterElement> [parameter3];
3976 classI3.methods = <MethodElement> [methodM3]; 3978 classI3.methods = <MethodElement> [methodM3];
3977 ClassElementImpl classD = ElementFactory.classElement2("D", []); 3979 ClassElementImpl classD = ElementFactory.classElement2("D");
3978 classD.interfaces = <InterfaceType> [classI1.type, classI2.type, classI3.typ e]; 3980 classD.interfaces = <InterfaceType> [classI1.type, classI2.type, classI3.typ e];
3979 MemberMap mapD = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classD); 3981 MemberMap mapD = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classD);
3980 expect(mapD.size, _numOfMembersInObject + 1); 3982 expect(mapD.size, _numOfMembersInObject + 1);
3981 MethodElement syntheticMethod = ElementFactory.methodElement(methodName, _ty peProvider.dynamicType, [_typeProvider.dynamicType]); 3983 MethodElement syntheticMethod = ElementFactory.methodElement(methodName, _ty peProvider.dynamicType, [_typeProvider.dynamicType]);
3982 expect(mapD.get(methodName).type, syntheticMethod.type); 3984 expect(mapD.get(methodName).type, syntheticMethod.type);
3983 _assertNoErrors(classD); 3985 _assertNoErrors(classD);
3984 } 3986 }
3985 3987
3986 void test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_3_sett ers() { 3988 void test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_3_sett ers() {
3987 // class A {} 3989 // class A {}
3988 // class B extends A {} 3990 // class B extends A {}
3989 // class C extends B {} 3991 // class C extends B {}
3990 // class I1 { set s(A); } 3992 // class I1 { set s(A); }
3991 // class I2 { set s(B); } 3993 // class I2 { set s(B); }
3992 // class I3 { set s(C); } 3994 // class I3 { set s(C); }
3993 // class D implements I1, I2, I3 {} 3995 // class D implements I1, I2, I3 {}
3994 ClassElementImpl classA = ElementFactory.classElement2("A", []); 3996 ClassElementImpl classA = ElementFactory.classElement2("A");
3995 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); 3997 ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
3996 ClassElementImpl classC = ElementFactory.classElement("C", classB.type, []); 3998 ClassElementImpl classC = ElementFactory.classElement("C", classB.type);
3997 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); 3999 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
3998 String accessorName = "s"; 4000 String accessorName = "s";
3999 PropertyAccessorElement setter1 = ElementFactory.setterElement(accessorName, false, classA.type); 4001 PropertyAccessorElement setter1 = ElementFactory.setterElement(accessorName, false, classA.type);
4000 classI1.accessors = <PropertyAccessorElement> [setter1]; 4002 classI1.accessors = <PropertyAccessorElement> [setter1];
4001 ClassElementImpl classI2 = ElementFactory.classElement2("I2", []); 4003 ClassElementImpl classI2 = ElementFactory.classElement2("I2");
4002 PropertyAccessorElement setter2 = ElementFactory.setterElement(accessorName, false, classB.type); 4004 PropertyAccessorElement setter2 = ElementFactory.setterElement(accessorName, false, classB.type);
4003 classI2.accessors = <PropertyAccessorElement> [setter2]; 4005 classI2.accessors = <PropertyAccessorElement> [setter2];
4004 ClassElementImpl classI3 = ElementFactory.classElement2("I3", []); 4006 ClassElementImpl classI3 = ElementFactory.classElement2("I3");
4005 PropertyAccessorElement setter3 = ElementFactory.setterElement(accessorName, false, classC.type); 4007 PropertyAccessorElement setter3 = ElementFactory.setterElement(accessorName, false, classC.type);
4006 classI3.accessors = <PropertyAccessorElement> [setter3]; 4008 classI3.accessors = <PropertyAccessorElement> [setter3];
4007 ClassElementImpl classD = ElementFactory.classElement2("D", []); 4009 ClassElementImpl classD = ElementFactory.classElement2("D");
4008 classD.interfaces = <InterfaceType> [classI1.type, classI2.type, classI3.typ e]; 4010 classD.interfaces = <InterfaceType> [classI1.type, classI2.type, classI3.typ e];
4009 MemberMap mapD = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classD); 4011 MemberMap mapD = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classD);
4010 expect(mapD.size, _numOfMembersInObject + 1); 4012 expect(mapD.size, _numOfMembersInObject + 1);
4011 PropertyAccessorElementImpl syntheticAccessor = ElementFactory.setterElement (accessorName, false, _typeProvider.dynamicType); 4013 PropertyAccessorElementImpl syntheticAccessor = ElementFactory.setterElement (accessorName, false, _typeProvider.dynamicType);
4012 syntheticAccessor.returnType = _typeProvider.dynamicType; 4014 syntheticAccessor.returnType = _typeProvider.dynamicType;
4013 expect(mapD.get("$accessorName=").type, syntheticAccessor.type); 4015 expect(mapD.get("$accessorName=").type, syntheticAccessor.type);
4014 _assertNoErrors(classD); 4016 _assertNoErrors(classD);
4015 } 4017 }
4016 4018
4017 void test_getMapOfMembersInheritedFromInterfaces_union_oneSubtype_2_methods() { 4019 void test_getMapOfMembersInheritedFromInterfaces_union_oneSubtype_2_methods() {
4018 // class I1 { int m(); } 4020 // class I1 { int m(); }
4019 // class I2 { int m([int]); } 4021 // class I2 { int m([int]); }
4020 // class A implements I1, I2 {} 4022 // class A implements I1, I2 {}
4021 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); 4023 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
4022 String methodName = "m"; 4024 String methodName = "m";
4023 MethodElement methodM1 = ElementFactory.methodElement(methodName, _typeProvi der.intType, []); 4025 MethodElement methodM1 = ElementFactory.methodElement(methodName, _typeProvi der.intType);
4024 classI1.methods = <MethodElement> [methodM1]; 4026 classI1.methods = <MethodElement> [methodM1];
4025 ClassElementImpl classI2 = ElementFactory.classElement2("I2", []); 4027 ClassElementImpl classI2 = ElementFactory.classElement2("I2");
4026 MethodElementImpl methodM2 = ElementFactory.methodElement(methodName, _typeP rovider.intType, []); 4028 MethodElementImpl methodM2 = ElementFactory.methodElement(methodName, _typeP rovider.intType);
4027 ParameterElementImpl parameter1 = new ParameterElementImpl.forNode(AstFactor y.identifier3("a1")); 4029 ParameterElementImpl parameter1 = new ParameterElementImpl.forNode(AstFactor y.identifier3("a1"));
4028 parameter1.type = _typeProvider.intType; 4030 parameter1.type = _typeProvider.intType;
4029 parameter1.parameterKind = ParameterKind.POSITIONAL; 4031 parameter1.parameterKind = ParameterKind.POSITIONAL;
4030 methodM2.parameters = <ParameterElement> [parameter1]; 4032 methodM2.parameters = <ParameterElement> [parameter1];
4031 classI2.methods = <MethodElement> [methodM2]; 4033 classI2.methods = <MethodElement> [methodM2];
4032 ClassElementImpl classA = ElementFactory.classElement2("A", []); 4034 ClassElementImpl classA = ElementFactory.classElement2("A");
4033 classA.interfaces = <InterfaceType> [classI1.type, classI2.type]; 4035 classA.interfaces = <InterfaceType> [classI1.type, classI2.type];
4034 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classA); 4036 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classA);
4035 expect(mapA.size, _numOfMembersInObject + 1); 4037 expect(mapA.size, _numOfMembersInObject + 1);
4036 expect(mapA.get(methodName), same(methodM2)); 4038 expect(mapA.get(methodName), same(methodM2));
4037 _assertNoErrors(classA); 4039 _assertNoErrors(classA);
4038 } 4040 }
4039 4041
4040 void test_getMapOfMembersInheritedFromInterfaces_union_oneSubtype_3_methods() { 4042 void test_getMapOfMembersInheritedFromInterfaces_union_oneSubtype_3_methods() {
4041 // class I1 { int m(); } 4043 // class I1 { int m(); }
4042 // class I2 { int m([int]); } 4044 // class I2 { int m([int]); }
4043 // class I3 { int m([int, int]); } 4045 // class I3 { int m([int, int]); }
4044 // class A implements I1, I2, I3 {} 4046 // class A implements I1, I2, I3 {}
4045 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); 4047 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
4046 String methodName = "m"; 4048 String methodName = "m";
4047 MethodElementImpl methodM1 = ElementFactory.methodElement(methodName, _typeP rovider.intType, []); 4049 MethodElementImpl methodM1 = ElementFactory.methodElement(methodName, _typeP rovider.intType);
4048 classI1.methods = <MethodElement> [methodM1]; 4050 classI1.methods = <MethodElement> [methodM1];
4049 ClassElementImpl classI2 = ElementFactory.classElement2("I2", []); 4051 ClassElementImpl classI2 = ElementFactory.classElement2("I2");
4050 MethodElementImpl methodM2 = ElementFactory.methodElement(methodName, _typeP rovider.intType, []); 4052 MethodElementImpl methodM2 = ElementFactory.methodElement(methodName, _typeP rovider.intType);
4051 ParameterElementImpl parameter1 = new ParameterElementImpl.forNode(AstFactor y.identifier3("a1")); 4053 ParameterElementImpl parameter1 = new ParameterElementImpl.forNode(AstFactor y.identifier3("a1"));
4052 parameter1.type = _typeProvider.intType; 4054 parameter1.type = _typeProvider.intType;
4053 parameter1.parameterKind = ParameterKind.POSITIONAL; 4055 parameter1.parameterKind = ParameterKind.POSITIONAL;
4054 methodM1.parameters = <ParameterElement> [parameter1]; 4056 methodM1.parameters = <ParameterElement> [parameter1];
4055 classI2.methods = <MethodElement> [methodM2]; 4057 classI2.methods = <MethodElement> [methodM2];
4056 ClassElementImpl classI3 = ElementFactory.classElement2("I3", []); 4058 ClassElementImpl classI3 = ElementFactory.classElement2("I3");
4057 MethodElementImpl methodM3 = ElementFactory.methodElement(methodName, _typeP rovider.intType, []); 4059 MethodElementImpl methodM3 = ElementFactory.methodElement(methodName, _typeP rovider.intType);
4058 ParameterElementImpl parameter2 = new ParameterElementImpl.forNode(AstFactor y.identifier3("a2")); 4060 ParameterElementImpl parameter2 = new ParameterElementImpl.forNode(AstFactor y.identifier3("a2"));
4059 parameter2.type = _typeProvider.intType; 4061 parameter2.type = _typeProvider.intType;
4060 parameter2.parameterKind = ParameterKind.POSITIONAL; 4062 parameter2.parameterKind = ParameterKind.POSITIONAL;
4061 ParameterElementImpl parameter3 = new ParameterElementImpl.forNode(AstFactor y.identifier3("a3")); 4063 ParameterElementImpl parameter3 = new ParameterElementImpl.forNode(AstFactor y.identifier3("a3"));
4062 parameter3.type = _typeProvider.intType; 4064 parameter3.type = _typeProvider.intType;
4063 parameter3.parameterKind = ParameterKind.POSITIONAL; 4065 parameter3.parameterKind = ParameterKind.POSITIONAL;
4064 methodM3.parameters = <ParameterElement> [parameter2, parameter3]; 4066 methodM3.parameters = <ParameterElement> [parameter2, parameter3];
4065 classI3.methods = <MethodElement> [methodM3]; 4067 classI3.methods = <MethodElement> [methodM3];
4066 ClassElementImpl classA = ElementFactory.classElement2("A", []); 4068 ClassElementImpl classA = ElementFactory.classElement2("A");
4067 classA.interfaces = <InterfaceType> [classI1.type, classI2.type, classI3.typ e]; 4069 classA.interfaces = <InterfaceType> [classI1.type, classI2.type, classI3.typ e];
4068 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classA); 4070 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classA);
4069 expect(mapA.size, _numOfMembersInObject + 1); 4071 expect(mapA.size, _numOfMembersInObject + 1);
4070 expect(mapA.get(methodName), same(methodM3)); 4072 expect(mapA.get(methodName), same(methodM3));
4071 _assertNoErrors(classA); 4073 _assertNoErrors(classA);
4072 } 4074 }
4073 4075
4074 void test_getMapOfMembersInheritedFromInterfaces_union_oneSubtype_4_methods() { 4076 void test_getMapOfMembersInheritedFromInterfaces_union_oneSubtype_4_methods() {
4075 // class I1 { int m(); } 4077 // class I1 { int m(); }
4076 // class I2 { int m(); } 4078 // class I2 { int m(); }
4077 // class I3 { int m([int]); } 4079 // class I3 { int m([int]); }
4078 // class I4 { int m([int, int]); } 4080 // class I4 { int m([int, int]); }
4079 // class A implements I1, I2, I3, I4 {} 4081 // class A implements I1, I2, I3, I4 {}
4080 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); 4082 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
4081 String methodName = "m"; 4083 String methodName = "m";
4082 MethodElement methodM1 = ElementFactory.methodElement(methodName, _typeProvi der.intType, []); 4084 MethodElement methodM1 = ElementFactory.methodElement(methodName, _typeProvi der.intType);
4083 classI1.methods = <MethodElement> [methodM1]; 4085 classI1.methods = <MethodElement> [methodM1];
4084 ClassElementImpl classI2 = ElementFactory.classElement2("I2", []); 4086 ClassElementImpl classI2 = ElementFactory.classElement2("I2");
4085 MethodElement methodM2 = ElementFactory.methodElement(methodName, _typeProvi der.intType, []); 4087 MethodElement methodM2 = ElementFactory.methodElement(methodName, _typeProvi der.intType);
4086 classI2.methods = <MethodElement> [methodM2]; 4088 classI2.methods = <MethodElement> [methodM2];
4087 ClassElementImpl classI3 = ElementFactory.classElement2("I3", []); 4089 ClassElementImpl classI3 = ElementFactory.classElement2("I3");
4088 MethodElementImpl methodM3 = ElementFactory.methodElement(methodName, _typeP rovider.intType, []); 4090 MethodElementImpl methodM3 = ElementFactory.methodElement(methodName, _typeP rovider.intType);
4089 ParameterElementImpl parameter1 = new ParameterElementImpl.forNode(AstFactor y.identifier3("a1")); 4091 ParameterElementImpl parameter1 = new ParameterElementImpl.forNode(AstFactor y.identifier3("a1"));
4090 parameter1.type = _typeProvider.intType; 4092 parameter1.type = _typeProvider.intType;
4091 parameter1.parameterKind = ParameterKind.POSITIONAL; 4093 parameter1.parameterKind = ParameterKind.POSITIONAL;
4092 methodM3.parameters = <ParameterElement> [parameter1]; 4094 methodM3.parameters = <ParameterElement> [parameter1];
4093 classI3.methods = <MethodElement> [methodM3]; 4095 classI3.methods = <MethodElement> [methodM3];
4094 ClassElementImpl classI4 = ElementFactory.classElement2("I4", []); 4096 ClassElementImpl classI4 = ElementFactory.classElement2("I4");
4095 MethodElementImpl methodM4 = ElementFactory.methodElement(methodName, _typeP rovider.intType, []); 4097 MethodElementImpl methodM4 = ElementFactory.methodElement(methodName, _typeP rovider.intType);
4096 ParameterElementImpl parameter2 = new ParameterElementImpl.forNode(AstFactor y.identifier3("a2")); 4098 ParameterElementImpl parameter2 = new ParameterElementImpl.forNode(AstFactor y.identifier3("a2"));
4097 parameter2.type = _typeProvider.intType; 4099 parameter2.type = _typeProvider.intType;
4098 parameter2.parameterKind = ParameterKind.POSITIONAL; 4100 parameter2.parameterKind = ParameterKind.POSITIONAL;
4099 ParameterElementImpl parameter3 = new ParameterElementImpl.forNode(AstFactor y.identifier3("a3")); 4101 ParameterElementImpl parameter3 = new ParameterElementImpl.forNode(AstFactor y.identifier3("a3"));
4100 parameter3.type = _typeProvider.intType; 4102 parameter3.type = _typeProvider.intType;
4101 parameter3.parameterKind = ParameterKind.POSITIONAL; 4103 parameter3.parameterKind = ParameterKind.POSITIONAL;
4102 methodM4.parameters = <ParameterElement> [parameter2, parameter3]; 4104 methodM4.parameters = <ParameterElement> [parameter2, parameter3];
4103 classI4.methods = <MethodElement> [methodM4]; 4105 classI4.methods = <MethodElement> [methodM4];
4104 ClassElementImpl classA = ElementFactory.classElement2("A", []); 4106 ClassElementImpl classA = ElementFactory.classElement2("A");
4105 classA.interfaces = <InterfaceType> [classI1.type, classI2.type, classI3.typ e, classI4.type]; 4107 classA.interfaces = <InterfaceType> [classI1.type, classI2.type, classI3.typ e, classI4.type];
4106 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classA); 4108 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces( classA);
4107 expect(mapA.size, _numOfMembersInObject + 1); 4109 expect(mapA.size, _numOfMembersInObject + 1);
4108 expect(mapA.get(methodName), same(methodM4)); 4110 expect(mapA.get(methodName), same(methodM4));
4109 _assertNoErrors(classA); 4111 _assertNoErrors(classA);
4110 } 4112 }
4111 4113
4112 void test_lookupInheritance_interface_getter() { 4114 void test_lookupInheritance_interface_getter() {
4113 ClassElementImpl classA = ElementFactory.classElement2("A", []); 4115 ClassElementImpl classA = ElementFactory.classElement2("A");
4114 String getterName = "g"; 4116 String getterName = "g";
4115 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, f alse, _typeProvider.intType); 4117 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, f alse, _typeProvider.intType);
4116 classA.accessors = <PropertyAccessorElement> [getterG]; 4118 classA.accessors = <PropertyAccessorElement> [getterG];
4117 ClassElementImpl classB = ElementFactory.classElement2("B", []); 4119 ClassElementImpl classB = ElementFactory.classElement2("B");
4118 classB.interfaces = <InterfaceType> [classA.type]; 4120 classB.interfaces = <InterfaceType> [classA.type];
4119 expect(_inheritanceManager.lookupInheritance(classB, getterName), same(gette rG)); 4121 expect(_inheritanceManager.lookupInheritance(classB, getterName), same(gette rG));
4120 _assertNoErrors(classA); 4122 _assertNoErrors(classA);
4121 _assertNoErrors(classB); 4123 _assertNoErrors(classB);
4122 } 4124 }
4123 4125
4124 void test_lookupInheritance_interface_method() { 4126 void test_lookupInheritance_interface_method() {
4125 ClassElementImpl classA = ElementFactory.classElement2("A", []); 4127 ClassElementImpl classA = ElementFactory.classElement2("A");
4126 String methodName = "m"; 4128 String methodName = "m";
4127 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid er.intType, []); 4129 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid er.intType);
4128 classA.methods = <MethodElement> [methodM]; 4130 classA.methods = <MethodElement> [methodM];
4129 ClassElementImpl classB = ElementFactory.classElement2("B", []); 4131 ClassElementImpl classB = ElementFactory.classElement2("B");
4130 classB.interfaces = <InterfaceType> [classA.type]; 4132 classB.interfaces = <InterfaceType> [classA.type];
4131 expect(_inheritanceManager.lookupInheritance(classB, methodName), same(metho dM)); 4133 expect(_inheritanceManager.lookupInheritance(classB, methodName), same(metho dM));
4132 _assertNoErrors(classA); 4134 _assertNoErrors(classA);
4133 _assertNoErrors(classB); 4135 _assertNoErrors(classB);
4134 } 4136 }
4135 4137
4136 void test_lookupInheritance_interface_setter() { 4138 void test_lookupInheritance_interface_setter() {
4137 ClassElementImpl classA = ElementFactory.classElement2("A", []); 4139 ClassElementImpl classA = ElementFactory.classElement2("A");
4138 String setterName = "s"; 4140 String setterName = "s";
4139 PropertyAccessorElement setterS = ElementFactory.setterElement(setterName, f alse, _typeProvider.intType); 4141 PropertyAccessorElement setterS = ElementFactory.setterElement(setterName, f alse, _typeProvider.intType);
4140 classA.accessors = <PropertyAccessorElement> [setterS]; 4142 classA.accessors = <PropertyAccessorElement> [setterS];
4141 ClassElementImpl classB = ElementFactory.classElement2("B", []); 4143 ClassElementImpl classB = ElementFactory.classElement2("B");
4142 classB.interfaces = <InterfaceType> [classA.type]; 4144 classB.interfaces = <InterfaceType> [classA.type];
4143 expect(_inheritanceManager.lookupInheritance(classB, "$setterName="), same(s etterS)); 4145 expect(_inheritanceManager.lookupInheritance(classB, "$setterName="), same(s etterS));
4144 _assertNoErrors(classA); 4146 _assertNoErrors(classA);
4145 _assertNoErrors(classB); 4147 _assertNoErrors(classB);
4146 } 4148 }
4147 4149
4148 void test_lookupInheritance_interface_staticMember() { 4150 void test_lookupInheritance_interface_staticMember() {
4149 ClassElementImpl classA = ElementFactory.classElement2("A", []); 4151 ClassElementImpl classA = ElementFactory.classElement2("A");
4150 String methodName = "m"; 4152 String methodName = "m";
4151 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid er.intType, []); 4153 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid er.intType);
4152 (methodM as MethodElementImpl).static = true; 4154 (methodM as MethodElementImpl).static = true;
4153 classA.methods = <MethodElement> [methodM]; 4155 classA.methods = <MethodElement> [methodM];
4154 ClassElementImpl classB = ElementFactory.classElement2("B", []); 4156 ClassElementImpl classB = ElementFactory.classElement2("B");
4155 classB.interfaces = <InterfaceType> [classA.type]; 4157 classB.interfaces = <InterfaceType> [classA.type];
4156 expect(_inheritanceManager.lookupInheritance(classB, methodName), isNull); 4158 expect(_inheritanceManager.lookupInheritance(classB, methodName), isNull);
4157 _assertNoErrors(classA); 4159 _assertNoErrors(classA);
4158 _assertNoErrors(classB); 4160 _assertNoErrors(classB);
4159 } 4161 }
4160 4162
4161 void test_lookupInheritance_interfaces_infiniteLoop() { 4163 void test_lookupInheritance_interfaces_infiniteLoop() {
4162 ClassElementImpl classA = ElementFactory.classElement2("A", []); 4164 ClassElementImpl classA = ElementFactory.classElement2("A");
4163 classA.interfaces = <InterfaceType> [classA.type]; 4165 classA.interfaces = <InterfaceType> [classA.type];
4164 expect(_inheritanceManager.lookupInheritance(classA, "name"), isNull); 4166 expect(_inheritanceManager.lookupInheritance(classA, "name"), isNull);
4165 _assertNoErrors(classA); 4167 _assertNoErrors(classA);
4166 } 4168 }
4167 4169
4168 void test_lookupInheritance_interfaces_infiniteLoop2() { 4170 void test_lookupInheritance_interfaces_infiniteLoop2() {
4169 ClassElementImpl classA = ElementFactory.classElement2("A", []); 4171 ClassElementImpl classA = ElementFactory.classElement2("A");
4170 ClassElementImpl classB = ElementFactory.classElement2("B", []); 4172 ClassElementImpl classB = ElementFactory.classElement2("B");
4171 classA.interfaces = <InterfaceType> [classB.type]; 4173 classA.interfaces = <InterfaceType> [classB.type];
4172 classB.interfaces = <InterfaceType> [classA.type]; 4174 classB.interfaces = <InterfaceType> [classA.type];
4173 expect(_inheritanceManager.lookupInheritance(classA, "name"), isNull); 4175 expect(_inheritanceManager.lookupInheritance(classA, "name"), isNull);
4174 _assertNoErrors(classA); 4176 _assertNoErrors(classA);
4175 _assertNoErrors(classB); 4177 _assertNoErrors(classB);
4176 } 4178 }
4177 4179
4178 void test_lookupInheritance_interfaces_union2() { 4180 void test_lookupInheritance_interfaces_union2() {
4179 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); 4181 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
4180 String methodName1 = "m1"; 4182 String methodName1 = "m1";
4181 MethodElement methodM1 = ElementFactory.methodElement(methodName1, _typeProv ider.intType, []); 4183 MethodElement methodM1 = ElementFactory.methodElement(methodName1, _typeProv ider.intType);
4182 classI1.methods = <MethodElement> [methodM1]; 4184 classI1.methods = <MethodElement> [methodM1];
4183 ClassElementImpl classI2 = ElementFactory.classElement2("I2", []); 4185 ClassElementImpl classI2 = ElementFactory.classElement2("I2");
4184 String methodName2 = "m2"; 4186 String methodName2 = "m2";
4185 MethodElement methodM2 = ElementFactory.methodElement(methodName2, _typeProv ider.intType, []); 4187 MethodElement methodM2 = ElementFactory.methodElement(methodName2, _typeProv ider.intType);
4186 classI2.methods = <MethodElement> [methodM2]; 4188 classI2.methods = <MethodElement> [methodM2];
4187 classI2.interfaces = <InterfaceType> [classI1.type]; 4189 classI2.interfaces = <InterfaceType> [classI1.type];
4188 ClassElementImpl classA = ElementFactory.classElement2("A", []); 4190 ClassElementImpl classA = ElementFactory.classElement2("A");
4189 classA.interfaces = <InterfaceType> [classI2.type]; 4191 classA.interfaces = <InterfaceType> [classI2.type];
4190 expect(_inheritanceManager.lookupInheritance(classA, methodName1), same(meth odM1)); 4192 expect(_inheritanceManager.lookupInheritance(classA, methodName1), same(meth odM1));
4191 expect(_inheritanceManager.lookupInheritance(classA, methodName2), same(meth odM2)); 4193 expect(_inheritanceManager.lookupInheritance(classA, methodName2), same(meth odM2));
4192 _assertNoErrors(classI1); 4194 _assertNoErrors(classI1);
4193 _assertNoErrors(classI2); 4195 _assertNoErrors(classI2);
4194 _assertNoErrors(classA); 4196 _assertNoErrors(classA);
4195 } 4197 }
4196 4198
4197 void test_lookupInheritance_mixin_getter() { 4199 void test_lookupInheritance_mixin_getter() {
4198 ClassElementImpl classA = ElementFactory.classElement2("A", []); 4200 ClassElementImpl classA = ElementFactory.classElement2("A");
4199 String getterName = "g"; 4201 String getterName = "g";
4200 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, f alse, _typeProvider.intType); 4202 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, f alse, _typeProvider.intType);
4201 classA.accessors = <PropertyAccessorElement> [getterG]; 4203 classA.accessors = <PropertyAccessorElement> [getterG];
4202 ClassElementImpl classB = ElementFactory.classElement2("B", []); 4204 ClassElementImpl classB = ElementFactory.classElement2("B");
4203 classB.mixins = <InterfaceType> [classA.type]; 4205 classB.mixins = <InterfaceType> [classA.type];
4204 expect(_inheritanceManager.lookupInheritance(classB, getterName), same(gette rG)); 4206 expect(_inheritanceManager.lookupInheritance(classB, getterName), same(gette rG));
4205 _assertNoErrors(classA); 4207 _assertNoErrors(classA);
4206 _assertNoErrors(classB); 4208 _assertNoErrors(classB);
4207 } 4209 }
4208 4210
4209 void test_lookupInheritance_mixin_method() { 4211 void test_lookupInheritance_mixin_method() {
4210 ClassElementImpl classA = ElementFactory.classElement2("A", []); 4212 ClassElementImpl classA = ElementFactory.classElement2("A");
4211 String methodName = "m"; 4213 String methodName = "m";
4212 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid er.intType, []); 4214 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid er.intType);
4213 classA.methods = <MethodElement> [methodM]; 4215 classA.methods = <MethodElement> [methodM];
4214 ClassElementImpl classB = ElementFactory.classElement2("B", []); 4216 ClassElementImpl classB = ElementFactory.classElement2("B");
4215 classB.mixins = <InterfaceType> [classA.type]; 4217 classB.mixins = <InterfaceType> [classA.type];
4216 expect(_inheritanceManager.lookupInheritance(classB, methodName), same(metho dM)); 4218 expect(_inheritanceManager.lookupInheritance(classB, methodName), same(metho dM));
4217 _assertNoErrors(classA); 4219 _assertNoErrors(classA);
4218 _assertNoErrors(classB); 4220 _assertNoErrors(classB);
4219 } 4221 }
4220 4222
4221 void test_lookupInheritance_mixin_setter() { 4223 void test_lookupInheritance_mixin_setter() {
4222 ClassElementImpl classA = ElementFactory.classElement2("A", []); 4224 ClassElementImpl classA = ElementFactory.classElement2("A");
4223 String setterName = "s"; 4225 String setterName = "s";
4224 PropertyAccessorElement setterS = ElementFactory.setterElement(setterName, f alse, _typeProvider.intType); 4226 PropertyAccessorElement setterS = ElementFactory.setterElement(setterName, f alse, _typeProvider.intType);
4225 classA.accessors = <PropertyAccessorElement> [setterS]; 4227 classA.accessors = <PropertyAccessorElement> [setterS];
4226 ClassElementImpl classB = ElementFactory.classElement2("B", []); 4228 ClassElementImpl classB = ElementFactory.classElement2("B");
4227 classB.mixins = <InterfaceType> [classA.type]; 4229 classB.mixins = <InterfaceType> [classA.type];
4228 expect(_inheritanceManager.lookupInheritance(classB, "$setterName="), same(s etterS)); 4230 expect(_inheritanceManager.lookupInheritance(classB, "$setterName="), same(s etterS));
4229 _assertNoErrors(classA); 4231 _assertNoErrors(classA);
4230 _assertNoErrors(classB); 4232 _assertNoErrors(classB);
4231 } 4233 }
4232 4234
4233 void test_lookupInheritance_mixin_staticMember() { 4235 void test_lookupInheritance_mixin_staticMember() {
4234 ClassElementImpl classA = ElementFactory.classElement2("A", []); 4236 ClassElementImpl classA = ElementFactory.classElement2("A");
4235 String methodName = "m"; 4237 String methodName = "m";
4236 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid er.intType, []); 4238 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid er.intType);
4237 (methodM as MethodElementImpl).static = true; 4239 (methodM as MethodElementImpl).static = true;
4238 classA.methods = <MethodElement> [methodM]; 4240 classA.methods = <MethodElement> [methodM];
4239 ClassElementImpl classB = ElementFactory.classElement2("B", []); 4241 ClassElementImpl classB = ElementFactory.classElement2("B");
4240 classB.mixins = <InterfaceType> [classA.type]; 4242 classB.mixins = <InterfaceType> [classA.type];
4241 expect(_inheritanceManager.lookupInheritance(classB, methodName), isNull); 4243 expect(_inheritanceManager.lookupInheritance(classB, methodName), isNull);
4242 _assertNoErrors(classA); 4244 _assertNoErrors(classA);
4243 _assertNoErrors(classB); 4245 _assertNoErrors(classB);
4244 } 4246 }
4245 4247
4246 void test_lookupInheritance_noMember() { 4248 void test_lookupInheritance_noMember() {
4247 ClassElementImpl classA = ElementFactory.classElement2("A", []); 4249 ClassElementImpl classA = ElementFactory.classElement2("A");
4248 expect(_inheritanceManager.lookupInheritance(classA, "a"), isNull); 4250 expect(_inheritanceManager.lookupInheritance(classA, "a"), isNull);
4249 _assertNoErrors(classA); 4251 _assertNoErrors(classA);
4250 } 4252 }
4251 4253
4252 void test_lookupInheritance_superclass_getter() { 4254 void test_lookupInheritance_superclass_getter() {
4253 ClassElementImpl classA = ElementFactory.classElement2("A", []); 4255 ClassElementImpl classA = ElementFactory.classElement2("A");
4254 String getterName = "g"; 4256 String getterName = "g";
4255 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, f alse, _typeProvider.intType); 4257 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, f alse, _typeProvider.intType);
4256 classA.accessors = <PropertyAccessorElement> [getterG]; 4258 classA.accessors = <PropertyAccessorElement> [getterG];
4257 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); 4259 ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
4258 expect(_inheritanceManager.lookupInheritance(classB, getterName), same(gette rG)); 4260 expect(_inheritanceManager.lookupInheritance(classB, getterName), same(gette rG));
4259 _assertNoErrors(classA); 4261 _assertNoErrors(classA);
4260 _assertNoErrors(classB); 4262 _assertNoErrors(classB);
4261 } 4263 }
4262 4264
4263 void test_lookupInheritance_superclass_infiniteLoop() { 4265 void test_lookupInheritance_superclass_infiniteLoop() {
4264 ClassElementImpl classA = ElementFactory.classElement2("A", []); 4266 ClassElementImpl classA = ElementFactory.classElement2("A");
4265 classA.supertype = classA.type; 4267 classA.supertype = classA.type;
4266 expect(_inheritanceManager.lookupInheritance(classA, "name"), isNull); 4268 expect(_inheritanceManager.lookupInheritance(classA, "name"), isNull);
4267 _assertNoErrors(classA); 4269 _assertNoErrors(classA);
4268 } 4270 }
4269 4271
4270 void test_lookupInheritance_superclass_infiniteLoop2() { 4272 void test_lookupInheritance_superclass_infiniteLoop2() {
4271 ClassElementImpl classA = ElementFactory.classElement2("A", []); 4273 ClassElementImpl classA = ElementFactory.classElement2("A");
4272 ClassElementImpl classB = ElementFactory.classElement2("B", []); 4274 ClassElementImpl classB = ElementFactory.classElement2("B");
4273 classA.supertype = classB.type; 4275 classA.supertype = classB.type;
4274 classB.supertype = classA.type; 4276 classB.supertype = classA.type;
4275 expect(_inheritanceManager.lookupInheritance(classA, "name"), isNull); 4277 expect(_inheritanceManager.lookupInheritance(classA, "name"), isNull);
4276 _assertNoErrors(classA); 4278 _assertNoErrors(classA);
4277 _assertNoErrors(classB); 4279 _assertNoErrors(classB);
4278 } 4280 }
4279 4281
4280 void test_lookupInheritance_superclass_method() { 4282 void test_lookupInheritance_superclass_method() {
4281 ClassElementImpl classA = ElementFactory.classElement2("A", []); 4283 ClassElementImpl classA = ElementFactory.classElement2("A");
4282 String methodName = "m"; 4284 String methodName = "m";
4283 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid er.intType, []); 4285 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid er.intType);
4284 classA.methods = <MethodElement> [methodM]; 4286 classA.methods = <MethodElement> [methodM];
4285 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); 4287 ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
4286 expect(_inheritanceManager.lookupInheritance(classB, methodName), same(metho dM)); 4288 expect(_inheritanceManager.lookupInheritance(classB, methodName), same(metho dM));
4287 _assertNoErrors(classA); 4289 _assertNoErrors(classA);
4288 _assertNoErrors(classB); 4290 _assertNoErrors(classB);
4289 } 4291 }
4290 4292
4291 void test_lookupInheritance_superclass_setter() { 4293 void test_lookupInheritance_superclass_setter() {
4292 ClassElementImpl classA = ElementFactory.classElement2("A", []); 4294 ClassElementImpl classA = ElementFactory.classElement2("A");
4293 String setterName = "s"; 4295 String setterName = "s";
4294 PropertyAccessorElement setterS = ElementFactory.setterElement(setterName, f alse, _typeProvider.intType); 4296 PropertyAccessorElement setterS = ElementFactory.setterElement(setterName, f alse, _typeProvider.intType);
4295 classA.accessors = <PropertyAccessorElement> [setterS]; 4297 classA.accessors = <PropertyAccessorElement> [setterS];
4296 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); 4298 ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
4297 expect(_inheritanceManager.lookupInheritance(classB, "$setterName="), same(s etterS)); 4299 expect(_inheritanceManager.lookupInheritance(classB, "$setterName="), same(s etterS));
4298 _assertNoErrors(classA); 4300 _assertNoErrors(classA);
4299 _assertNoErrors(classB); 4301 _assertNoErrors(classB);
4300 } 4302 }
4301 4303
4302 void test_lookupInheritance_superclass_staticMember() { 4304 void test_lookupInheritance_superclass_staticMember() {
4303 ClassElementImpl classA = ElementFactory.classElement2("A", []); 4305 ClassElementImpl classA = ElementFactory.classElement2("A");
4304 String methodName = "m"; 4306 String methodName = "m";
4305 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid er.intType, []); 4307 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid er.intType);
4306 (methodM as MethodElementImpl).static = true; 4308 (methodM as MethodElementImpl).static = true;
4307 classA.methods = <MethodElement> [methodM]; 4309 classA.methods = <MethodElement> [methodM];
4308 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); 4310 ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
4309 expect(_inheritanceManager.lookupInheritance(classB, methodName), isNull); 4311 expect(_inheritanceManager.lookupInheritance(classB, methodName), isNull);
4310 _assertNoErrors(classA); 4312 _assertNoErrors(classA);
4311 _assertNoErrors(classB); 4313 _assertNoErrors(classB);
4312 } 4314 }
4313 4315
4314 void test_lookupMember_getter() { 4316 void test_lookupMember_getter() {
4315 ClassElementImpl classA = ElementFactory.classElement2("A", []); 4317 ClassElementImpl classA = ElementFactory.classElement2("A");
4316 String getterName = "g"; 4318 String getterName = "g";
4317 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, f alse, _typeProvider.intType); 4319 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, f alse, _typeProvider.intType);
4318 classA.accessors = <PropertyAccessorElement> [getterG]; 4320 classA.accessors = <PropertyAccessorElement> [getterG];
4319 expect(_inheritanceManager.lookupMember(classA, getterName), same(getterG)); 4321 expect(_inheritanceManager.lookupMember(classA, getterName), same(getterG));
4320 _assertNoErrors(classA); 4322 _assertNoErrors(classA);
4321 } 4323 }
4322 4324
4323 void test_lookupMember_getter_static() { 4325 void test_lookupMember_getter_static() {
4324 ClassElementImpl classA = ElementFactory.classElement2("A", []); 4326 ClassElementImpl classA = ElementFactory.classElement2("A");
4325 String getterName = "g"; 4327 String getterName = "g";
4326 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, t rue, _typeProvider.intType); 4328 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, t rue, _typeProvider.intType);
4327 classA.accessors = <PropertyAccessorElement> [getterG]; 4329 classA.accessors = <PropertyAccessorElement> [getterG];
4328 expect(_inheritanceManager.lookupMember(classA, getterName), isNull); 4330 expect(_inheritanceManager.lookupMember(classA, getterName), isNull);
4329 _assertNoErrors(classA); 4331 _assertNoErrors(classA);
4330 } 4332 }
4331 4333
4332 void test_lookupMember_method() { 4334 void test_lookupMember_method() {
4333 ClassElementImpl classA = ElementFactory.classElement2("A", []); 4335 ClassElementImpl classA = ElementFactory.classElement2("A");
4334 String methodName = "m"; 4336 String methodName = "m";
4335 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid er.intType, []); 4337 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid er.intType);
4336 classA.methods = <MethodElement> [methodM]; 4338 classA.methods = <MethodElement> [methodM];
4337 expect(_inheritanceManager.lookupMember(classA, methodName), same(methodM)); 4339 expect(_inheritanceManager.lookupMember(classA, methodName), same(methodM));
4338 _assertNoErrors(classA); 4340 _assertNoErrors(classA);
4339 } 4341 }
4340 4342
4341 void test_lookupMember_method_static() { 4343 void test_lookupMember_method_static() {
4342 ClassElementImpl classA = ElementFactory.classElement2("A", []); 4344 ClassElementImpl classA = ElementFactory.classElement2("A");
4343 String methodName = "m"; 4345 String methodName = "m";
4344 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid er.intType, []); 4346 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid er.intType);
4345 (methodM as MethodElementImpl).static = true; 4347 (methodM as MethodElementImpl).static = true;
4346 classA.methods = <MethodElement> [methodM]; 4348 classA.methods = <MethodElement> [methodM];
4347 expect(_inheritanceManager.lookupMember(classA, methodName), isNull); 4349 expect(_inheritanceManager.lookupMember(classA, methodName), isNull);
4348 _assertNoErrors(classA); 4350 _assertNoErrors(classA);
4349 } 4351 }
4350 4352
4351 void test_lookupMember_noMember() { 4353 void test_lookupMember_noMember() {
4352 ClassElementImpl classA = ElementFactory.classElement2("A", []); 4354 ClassElementImpl classA = ElementFactory.classElement2("A");
4353 expect(_inheritanceManager.lookupMember(classA, "a"), isNull); 4355 expect(_inheritanceManager.lookupMember(classA, "a"), isNull);
4354 _assertNoErrors(classA); 4356 _assertNoErrors(classA);
4355 } 4357 }
4356 4358
4357 void test_lookupMember_setter() { 4359 void test_lookupMember_setter() {
4358 ClassElementImpl classA = ElementFactory.classElement2("A", []); 4360 ClassElementImpl classA = ElementFactory.classElement2("A");
4359 String setterName = "s"; 4361 String setterName = "s";
4360 PropertyAccessorElement setterS = ElementFactory.setterElement(setterName, f alse, _typeProvider.intType); 4362 PropertyAccessorElement setterS = ElementFactory.setterElement(setterName, f alse, _typeProvider.intType);
4361 classA.accessors = <PropertyAccessorElement> [setterS]; 4363 classA.accessors = <PropertyAccessorElement> [setterS];
4362 expect(_inheritanceManager.lookupMember(classA, "$setterName="), same(setter S)); 4364 expect(_inheritanceManager.lookupMember(classA, "$setterName="), same(setter S));
4363 _assertNoErrors(classA); 4365 _assertNoErrors(classA);
4364 } 4366 }
4365 4367
4366 void test_lookupMember_setter_static() { 4368 void test_lookupMember_setter_static() {
4367 ClassElementImpl classA = ElementFactory.classElement2("A", []); 4369 ClassElementImpl classA = ElementFactory.classElement2("A");
4368 String setterName = "s"; 4370 String setterName = "s";
4369 PropertyAccessorElement setterS = ElementFactory.setterElement(setterName, t rue, _typeProvider.intType); 4371 PropertyAccessorElement setterS = ElementFactory.setterElement(setterName, t rue, _typeProvider.intType);
4370 classA.accessors = <PropertyAccessorElement> [setterS]; 4372 classA.accessors = <PropertyAccessorElement> [setterS];
4371 expect(_inheritanceManager.lookupMember(classA, setterName), isNull); 4373 expect(_inheritanceManager.lookupMember(classA, setterName), isNull);
4372 _assertNoErrors(classA); 4374 _assertNoErrors(classA);
4373 } 4375 }
4374 4376
4375 void test_lookupOverrides_noParentClasses() { 4377 void test_lookupOverrides_noParentClasses() {
4376 ClassElementImpl classA = ElementFactory.classElement2("A", []); 4378 ClassElementImpl classA = ElementFactory.classElement2("A");
4377 String methodName = "m"; 4379 String methodName = "m";
4378 MethodElementImpl methodM = ElementFactory.methodElement(methodName, _typePr ovider.intType, []); 4380 MethodElementImpl methodM = ElementFactory.methodElement(methodName, _typePr ovider.intType);
4379 classA.methods = <MethodElement> [methodM]; 4381 classA.methods = <MethodElement> [methodM];
4380 expect(_inheritanceManager.lookupOverrides(classA, methodName), hasLength(0) ); 4382 expect(_inheritanceManager.lookupOverrides(classA, methodName), hasLength(0) );
4381 _assertNoErrors(classA); 4383 _assertNoErrors(classA);
4382 } 4384 }
4383 4385
4384 void test_lookupOverrides_overrideBaseClass() { 4386 void test_lookupOverrides_overrideBaseClass() {
4385 ClassElementImpl classA = ElementFactory.classElement2("A", []); 4387 ClassElementImpl classA = ElementFactory.classElement2("A");
4386 String methodName = "m"; 4388 String methodName = "m";
4387 MethodElementImpl methodMinA = ElementFactory.methodElement(methodName, _typ eProvider.intType, []); 4389 MethodElementImpl methodMinA = ElementFactory.methodElement(methodName, _typ eProvider.intType);
4388 classA.methods = <MethodElement> [methodMinA]; 4390 classA.methods = <MethodElement> [methodMinA];
4389 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); 4391 ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
4390 MethodElementImpl methodMinB = ElementFactory.methodElement(methodName, _typ eProvider.intType, []); 4392 MethodElementImpl methodMinB = ElementFactory.methodElement(methodName, _typ eProvider.intType);
4391 classB.methods = <MethodElement> [methodMinB]; 4393 classB.methods = <MethodElement> [methodMinB];
4392 List<ExecutableElement> overrides = _inheritanceManager.lookupOverrides(clas sB, methodName); 4394 List<ExecutableElement> overrides = _inheritanceManager.lookupOverrides(clas sB, methodName);
4393 expect(overrides, unorderedEquals([methodMinA])); 4395 expect(overrides, unorderedEquals([methodMinA]));
4394 _assertNoErrors(classA); 4396 _assertNoErrors(classA);
4395 _assertNoErrors(classB); 4397 _assertNoErrors(classB);
4396 } 4398 }
4397 4399
4398 void test_lookupOverrides_overrideInterface() { 4400 void test_lookupOverrides_overrideInterface() {
4399 ClassElementImpl classA = ElementFactory.classElement2("A", []); 4401 ClassElementImpl classA = ElementFactory.classElement2("A");
4400 String methodName = "m"; 4402 String methodName = "m";
4401 MethodElementImpl methodMinA = ElementFactory.methodElement(methodName, _typ eProvider.intType, []); 4403 MethodElementImpl methodMinA = ElementFactory.methodElement(methodName, _typ eProvider.intType);
4402 classA.methods = <MethodElement> [methodMinA]; 4404 classA.methods = <MethodElement> [methodMinA];
4403 ClassElementImpl classB = ElementFactory.classElement2("B", []); 4405 ClassElementImpl classB = ElementFactory.classElement2("B");
4404 classB.interfaces = <InterfaceType> [classA.type]; 4406 classB.interfaces = <InterfaceType> [classA.type];
4405 MethodElementImpl methodMinB = ElementFactory.methodElement(methodName, _typ eProvider.intType, []); 4407 MethodElementImpl methodMinB = ElementFactory.methodElement(methodName, _typ eProvider.intType);
4406 classB.methods = <MethodElement> [methodMinB]; 4408 classB.methods = <MethodElement> [methodMinB];
4407 List<ExecutableElement> overrides = _inheritanceManager.lookupOverrides(clas sB, methodName); 4409 List<ExecutableElement> overrides = _inheritanceManager.lookupOverrides(clas sB, methodName);
4408 expect(overrides, unorderedEquals([methodMinA])); 4410 expect(overrides, unorderedEquals([methodMinA]));
4409 _assertNoErrors(classA); 4411 _assertNoErrors(classA);
4410 _assertNoErrors(classB); 4412 _assertNoErrors(classB);
4411 } 4413 }
4412 4414
4413 void test_lookupOverrides_overrideTwoInterfaces() { 4415 void test_lookupOverrides_overrideTwoInterfaces() {
4414 ClassElementImpl classA = ElementFactory.classElement2("A", []); 4416 ClassElementImpl classA = ElementFactory.classElement2("A");
4415 String methodName = "m"; 4417 String methodName = "m";
4416 MethodElementImpl methodMinA = ElementFactory.methodElement(methodName, _typ eProvider.intType, []); 4418 MethodElementImpl methodMinA = ElementFactory.methodElement(methodName, _typ eProvider.intType);
4417 classA.methods = <MethodElement> [methodMinA]; 4419 classA.methods = <MethodElement> [methodMinA];
4418 ClassElementImpl classB = ElementFactory.classElement2("B", []); 4420 ClassElementImpl classB = ElementFactory.classElement2("B");
4419 MethodElementImpl methodMinB = ElementFactory.methodElement(methodName, _typ eProvider.doubleType, []); 4421 MethodElementImpl methodMinB = ElementFactory.methodElement(methodName, _typ eProvider.doubleType);
4420 classB.methods = <MethodElement> [methodMinB]; 4422 classB.methods = <MethodElement> [methodMinB];
4421 ClassElementImpl classC = ElementFactory.classElement2("C", []); 4423 ClassElementImpl classC = ElementFactory.classElement2("C");
4422 classC.interfaces = <InterfaceType> [classA.type, classB.type]; 4424 classC.interfaces = <InterfaceType> [classA.type, classB.type];
4423 MethodElementImpl methodMinC = ElementFactory.methodElement(methodName, _typ eProvider.numType, []); 4425 MethodElementImpl methodMinC = ElementFactory.methodElement(methodName, _typ eProvider.numType);
4424 classC.methods = <MethodElement> [methodMinC]; 4426 classC.methods = <MethodElement> [methodMinC];
4425 List<ExecutableElement> overrides = _inheritanceManager.lookupOverrides(clas sC, methodName); 4427 List<ExecutableElement> overrides = _inheritanceManager.lookupOverrides(clas sC, methodName);
4426 expect(overrides, unorderedEquals([methodMinA, methodMinB])); 4428 expect(overrides, unorderedEquals([methodMinA, methodMinB]));
4427 _assertNoErrors(classA); 4429 _assertNoErrors(classA);
4428 _assertNoErrors(classB); 4430 _assertNoErrors(classB);
4429 _assertNoErrors(classC); 4431 _assertNoErrors(classC);
4430 } 4432 }
4431 4433
4432 void _assertErrors(ClassElement classElt, List<ErrorCode> expectedErrorCodes) { 4434 void _assertErrors(ClassElement classElt, [List<ErrorCode> expectedErrorCodes = ErrorCode.EMPTY_LIST]) {
4433 GatheringErrorListener errorListener = new GatheringErrorListener(); 4435 GatheringErrorListener errorListener = new GatheringErrorListener();
4434 HashSet<AnalysisError> actualErrors = _inheritanceManager.getErrors(classElt ); 4436 HashSet<AnalysisError> actualErrors = _inheritanceManager.getErrors(classElt );
4435 if (actualErrors != null) { 4437 if (actualErrors != null) {
4436 for (AnalysisError error in actualErrors) { 4438 for (AnalysisError error in actualErrors) {
4437 errorListener.onError(error); 4439 errorListener.onError(error);
4438 } 4440 }
4439 } 4441 }
4440 errorListener.assertErrorsWithCodes(expectedErrorCodes); 4442 errorListener.assertErrorsWithCodes(expectedErrorCodes);
4441 } 4443 }
4442 4444
4443 void _assertNoErrors(ClassElement classElt) { 4445 void _assertNoErrors(ClassElement classElt) {
4444 _assertErrors(classElt, []); 4446 _assertErrors(classElt);
4445 } 4447 }
4446 4448
4447 /** 4449 /**
4448 * Create the inheritance manager used by the tests. 4450 * Create the inheritance manager used by the tests.
4449 * 4451 *
4450 * @return the inheritance manager that was created 4452 * @return the inheritance manager that was created
4451 */ 4453 */
4452 InheritanceManager _createInheritanceManager() { 4454 InheritanceManager _createInheritanceManager() {
4453 AnalysisContextImpl context = AnalysisContextFactory.contextWithCore(); 4455 AnalysisContextImpl context = AnalysisContextFactory.contextWithCore();
4454 FileBasedSource source = new FileBasedSource.con1(FileUtilities2.createFile( "/test.dart")); 4456 FileBasedSource source = new FileBasedSource.con1(FileUtilities2.createFile( "/test.dart"));
(...skipping 24 matching lines...) Expand all
4479 Source librarySource = addSource("/lib.dart", r''' 4481 Source librarySource = addSource("/lib.dart", r'''
4480 library lib; 4482 library lib;
4481 part 'first.dart'; 4483 part 'first.dart';
4482 part 'second.dart';'''); 4484 part 'second.dart';''');
4483 addSource("/first.dart", r''' 4485 addSource("/first.dart", r'''
4484 part of lib; 4486 part of lib;
4485 int get V => 0;'''); 4487 int get V => 0;''');
4486 addSource("/second.dart", r''' 4488 addSource("/second.dart", r'''
4487 part of lib; 4489 part of lib;
4488 void set V(int v) {}'''); 4490 void set V(int v) {}''');
4489 LibraryElement element = _buildLibrary(librarySource, []); 4491 LibraryElement element = _buildLibrary(librarySource);
4490 expect(element, isNotNull); 4492 expect(element, isNotNull);
4491 List<CompilationUnitElement> sourcedUnits = element.parts; 4493 List<CompilationUnitElement> sourcedUnits = element.parts;
4492 expect(sourcedUnits, hasLength(2)); 4494 expect(sourcedUnits, hasLength(2));
4493 List<PropertyAccessorElement> firstAccessors = sourcedUnits[0].accessors; 4495 List<PropertyAccessorElement> firstAccessors = sourcedUnits[0].accessors;
4494 expect(firstAccessors, hasLength(1)); 4496 expect(firstAccessors, hasLength(1));
4495 List<PropertyAccessorElement> secondAccessors = sourcedUnits[1].accessors; 4497 List<PropertyAccessorElement> secondAccessors = sourcedUnits[1].accessors;
4496 expect(secondAccessors, hasLength(1)); 4498 expect(secondAccessors, hasLength(1));
4497 expect(secondAccessors[0].variable, same(firstAccessors[0].variable)); 4499 expect(secondAccessors[0].variable, same(firstAccessors[0].variable));
4498 } 4500 }
4499 4501
4500 void test_empty() { 4502 void test_empty() {
4501 Source librarySource = addSource("/lib.dart", "library lib;"); 4503 Source librarySource = addSource("/lib.dart", "library lib;");
4502 LibraryElement element = _buildLibrary(librarySource, []); 4504 LibraryElement element = _buildLibrary(librarySource);
4503 expect(element, isNotNull); 4505 expect(element, isNotNull);
4504 expect(element.name, "lib"); 4506 expect(element.name, "lib");
4505 expect(element.entryPoint, isNull); 4507 expect(element.entryPoint, isNull);
4506 expect(element.importedLibraries, hasLength(0)); 4508 expect(element.importedLibraries, hasLength(0));
4507 expect(element.imports, hasLength(0)); 4509 expect(element.imports, hasLength(0));
4508 expect(element.library, same(element)); 4510 expect(element.library, same(element));
4509 expect(element.prefixes, hasLength(0)); 4511 expect(element.prefixes, hasLength(0));
4510 expect(element.parts, hasLength(0)); 4512 expect(element.parts, hasLength(0));
4511 CompilationUnitElement unit = element.definingCompilationUnit; 4513 CompilationUnitElement unit = element.definingCompilationUnit;
4512 expect(unit, isNotNull); 4514 expect(unit, isNotNull);
(...skipping 29 matching lines...) Expand all
4542 part 'first.dart'; 4544 part 'first.dart';
4543 part 'second.dart'; 4545 part 'second.dart';
4544 4546
4545 class A {}'''); 4547 class A {}''');
4546 addSource("/first.dart", r''' 4548 addSource("/first.dart", r'''
4547 part of lib; 4549 part of lib;
4548 class B {}'''); 4550 class B {}''');
4549 addSource("/second.dart", r''' 4551 addSource("/second.dart", r'''
4550 part of lib; 4552 part of lib;
4551 class C {}'''); 4553 class C {}''');
4552 LibraryElement element = _buildLibrary(librarySource, []); 4554 LibraryElement element = _buildLibrary(librarySource);
4553 expect(element, isNotNull); 4555 expect(element, isNotNull);
4554 List<CompilationUnitElement> sourcedUnits = element.parts; 4556 List<CompilationUnitElement> sourcedUnits = element.parts;
4555 expect(sourcedUnits, hasLength(2)); 4557 expect(sourcedUnits, hasLength(2));
4556 _assertTypes(element.definingCompilationUnit, ["A"]); 4558 _assertTypes(element.definingCompilationUnit, ["A"]);
4557 if (sourcedUnits[0].name == "first.dart") { 4559 if (sourcedUnits[0].name == "first.dart") {
4558 _assertTypes(sourcedUnits[0], ["B"]); 4560 _assertTypes(sourcedUnits[0], ["B"]);
4559 _assertTypes(sourcedUnits[1], ["C"]); 4561 _assertTypes(sourcedUnits[1], ["C"]);
4560 } else { 4562 } else {
4561 _assertTypes(sourcedUnits[0], ["C"]); 4563 _assertTypes(sourcedUnits[0], ["C"]);
4562 _assertTypes(sourcedUnits[1], ["B"]); 4564 _assertTypes(sourcedUnits[1], ["B"]);
4563 } 4565 }
4564 } 4566 }
4565 4567
4566 void test_singleFile() { 4568 void test_singleFile() {
4567 Source librarySource = addSource("/lib.dart", r''' 4569 Source librarySource = addSource("/lib.dart", r'''
4568 library lib; 4570 library lib;
4569 4571
4570 class A {}'''); 4572 class A {}''');
4571 LibraryElement element = _buildLibrary(librarySource, []); 4573 LibraryElement element = _buildLibrary(librarySource);
4572 expect(element, isNotNull); 4574 expect(element, isNotNull);
4573 _assertTypes(element.definingCompilationUnit, ["A"]); 4575 _assertTypes(element.definingCompilationUnit, ["A"]);
4574 } 4576 }
4575 4577
4576 /** 4578 /**
4577 * Add a source file to the content provider. The file path should be absolute . 4579 * Add a source file to the content provider. The file path should be absolute .
4578 * 4580 *
4579 * @param filePath the path of the file being added 4581 * @param filePath the path of the file being added
4580 * @param contents the contents to be returned by the content provider for the specified file 4582 * @param contents the contents to be returned by the content provider for the specified file
4581 * @return the source object representing the added file 4583 * @return the source object representing the added file
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
4619 4621
4620 /** 4622 /**
4621 * Build the element model for the library whose defining compilation unit has the given source. 4623 * Build the element model for the library whose defining compilation unit has the given source.
4622 * 4624 *
4623 * @param librarySource the source of the defining compilation unit for the li brary 4625 * @param librarySource the source of the defining compilation unit for the li brary
4624 * @param expectedErrorCodes the errors that are expected to be found while bu ilding the element 4626 * @param expectedErrorCodes the errors that are expected to be found while bu ilding the element
4625 * model 4627 * model
4626 * @return the element model that was built for the library 4628 * @return the element model that was built for the library
4627 * @throws Exception if the element model could not be built 4629 * @throws Exception if the element model could not be built
4628 */ 4630 */
4629 LibraryElement _buildLibrary(Source librarySource, List<ErrorCode> expectedErr orCodes) { 4631 LibraryElement _buildLibrary(Source librarySource, [List<ErrorCode> expectedEr rorCodes = ErrorCode.EMPTY_LIST]) {
4630 LibraryResolver resolver = new LibraryResolver(_context); 4632 LibraryResolver resolver = new LibraryResolver(_context);
4631 LibraryElementBuilder builder = new LibraryElementBuilder(resolver.analysisC ontext, resolver.errorListener); 4633 LibraryElementBuilder builder = new LibraryElementBuilder(resolver.analysisC ontext, resolver.errorListener);
4632 Library library = resolver.createLibrary(librarySource); 4634 Library library = resolver.createLibrary(librarySource);
4633 LibraryElement element = builder.buildLibrary(library); 4635 LibraryElement element = builder.buildLibrary(library);
4634 GatheringErrorListener listener = new GatheringErrorListener(); 4636 GatheringErrorListener listener = new GatheringErrorListener();
4635 listener.addAll2(resolver.errorListener); 4637 listener.addAll2(resolver.errorListener);
4636 listener.assertErrorsWithCodes(expectedErrorCodes); 4638 listener.assertErrorsWithCodes(expectedErrorCodes);
4637 return element; 4639 return element;
4638 } 4640 }
4639 } 4641 }
4640 4642
4641 class LibraryImportScopeTest extends ResolverTestCase { 4643 class LibraryImportScopeTest extends ResolverTestCase {
4642 void test_conflictingImports() { 4644 void test_conflictingImports() {
4643 AnalysisContext context = new AnalysisContextImpl(); 4645 AnalysisContext context = new AnalysisContextImpl();
4644 context.sourceFactory = new SourceFactory([]); 4646 context.sourceFactory = new SourceFactory([]);
4645 String typeNameA = "A"; 4647 String typeNameA = "A";
4646 String typeNameB = "B"; 4648 String typeNameB = "B";
4647 String typeNameC = "C"; 4649 String typeNameC = "C";
4648 ClassElement typeA = ElementFactory.classElement2(typeNameA, []); 4650 ClassElement typeA = ElementFactory.classElement2(typeNameA);
4649 ClassElement typeB1 = ElementFactory.classElement2(typeNameB, []); 4651 ClassElement typeB1 = ElementFactory.classElement2(typeNameB);
4650 ClassElement typeB2 = ElementFactory.classElement2(typeNameB, []); 4652 ClassElement typeB2 = ElementFactory.classElement2(typeNameB);
4651 ClassElement typeC = ElementFactory.classElement2(typeNameC, []); 4653 ClassElement typeC = ElementFactory.classElement2(typeNameC);
4652 LibraryElement importedLibrary1 = createTestLibrary(context, "imported1", [] ); 4654 LibraryElement importedLibrary1 = createTestLibrary(context, "imported1");
4653 (importedLibrary1.definingCompilationUnit as CompilationUnitElementImpl).typ es = <ClassElement> [typeA, typeB1]; 4655 (importedLibrary1.definingCompilationUnit as CompilationUnitElementImpl).typ es = <ClassElement> [typeA, typeB1];
4654 ImportElementImpl import1 = ElementFactory.importFor(importedLibrary1, null, []); 4656 ImportElementImpl import1 = ElementFactory.importFor(importedLibrary1, null) ;
4655 LibraryElement importedLibrary2 = createTestLibrary(context, "imported2", [] ); 4657 LibraryElement importedLibrary2 = createTestLibrary(context, "imported2");
4656 (importedLibrary2.definingCompilationUnit as CompilationUnitElementImpl).typ es = <ClassElement> [typeB2, typeC]; 4658 (importedLibrary2.definingCompilationUnit as CompilationUnitElementImpl).typ es = <ClassElement> [typeB2, typeC];
4657 ImportElementImpl import2 = ElementFactory.importFor(importedLibrary2, null, []); 4659 ImportElementImpl import2 = ElementFactory.importFor(importedLibrary2, null) ;
4658 LibraryElementImpl importingLibrary = createTestLibrary(context, "importing" , []); 4660 LibraryElementImpl importingLibrary = createTestLibrary(context, "importing" );
4659 importingLibrary.imports = <ImportElement> [import1, import2]; 4661 importingLibrary.imports = <ImportElement> [import1, import2];
4660 { 4662 {
4661 GatheringErrorListener errorListener = new GatheringErrorListener(); 4663 GatheringErrorListener errorListener = new GatheringErrorListener();
4662 Scope scope = new LibraryImportScope(importingLibrary, errorListener); 4664 Scope scope = new LibraryImportScope(importingLibrary, errorListener);
4663 expect(scope.lookup(AstFactory.identifier3(typeNameA), importingLibrary), typeA); 4665 expect(scope.lookup(AstFactory.identifier3(typeNameA), importingLibrary), typeA);
4664 errorListener.assertNoErrors(); 4666 errorListener.assertNoErrors();
4665 expect(scope.lookup(AstFactory.identifier3(typeNameC), importingLibrary), typeC); 4667 expect(scope.lookup(AstFactory.identifier3(typeNameC), importingLibrary), typeC);
4666 errorListener.assertNoErrors(); 4668 errorListener.assertNoErrors();
4667 Element element = scope.lookup(AstFactory.identifier3(typeNameB), importin gLibrary); 4669 Element element = scope.lookup(AstFactory.identifier3(typeNameB), importin gLibrary);
4668 errorListener.assertErrorsWithCodes([StaticWarningCode.AMBIGUOUS_IMPORT]); 4670 errorListener.assertErrorsWithCodes([StaticWarningCode.AMBIGUOUS_IMPORT]);
4669 EngineTestCase.assertInstanceOf((obj) => obj is MultiplyDefinedElement, Mu ltiplyDefinedElement, element); 4671 EngineTestCase.assertInstanceOf((obj) => obj is MultiplyDefinedElement, Mu ltiplyDefinedElement, element);
4670 List<Element> conflictingElements = (element as MultiplyDefinedElement).co nflictingElements; 4672 List<Element> conflictingElements = (element as MultiplyDefinedElement).co nflictingElements;
4671 expect(conflictingElements, hasLength(2)); 4673 expect(conflictingElements, hasLength(2));
4672 if (identical(conflictingElements[0], typeB1)) { 4674 if (identical(conflictingElements[0], typeB1)) {
4673 expect(conflictingElements[1], same(typeB2)); 4675 expect(conflictingElements[1], same(typeB2));
4674 } else if (identical(conflictingElements[0], typeB2)) { 4676 } else if (identical(conflictingElements[0], typeB2)) {
4675 expect(conflictingElements[1], same(typeB1)); 4677 expect(conflictingElements[1], same(typeB1));
4676 } else { 4678 } else {
4677 expect(conflictingElements[0], same(typeB1)); 4679 expect(conflictingElements[0], same(typeB1));
4678 } 4680 }
4679 } 4681 }
4680 { 4682 {
4681 GatheringErrorListener errorListener = new GatheringErrorListener(); 4683 GatheringErrorListener errorListener = new GatheringErrorListener();
4682 Scope scope = new LibraryImportScope(importingLibrary, errorListener); 4684 Scope scope = new LibraryImportScope(importingLibrary, errorListener);
4683 Identifier identifier = AstFactory.identifier3(typeNameB); 4685 Identifier identifier = AstFactory.identifier3(typeNameB);
4684 AstFactory.methodDeclaration(null, AstFactory.typeName3(identifier, []), n ull, null, AstFactory.identifier3("foo"), null); 4686 AstFactory.methodDeclaration(null, AstFactory.typeName3(identifier), null, null, AstFactory.identifier3("foo"), null);
4685 Element element = scope.lookup(identifier, importingLibrary); 4687 Element element = scope.lookup(identifier, importingLibrary);
4686 errorListener.assertErrorsWithCodes([StaticWarningCode.AMBIGUOUS_IMPORT]); 4688 errorListener.assertErrorsWithCodes([StaticWarningCode.AMBIGUOUS_IMPORT]);
4687 EngineTestCase.assertInstanceOf((obj) => obj is MultiplyDefinedElement, Mu ltiplyDefinedElement, element); 4689 EngineTestCase.assertInstanceOf((obj) => obj is MultiplyDefinedElement, Mu ltiplyDefinedElement, element);
4688 } 4690 }
4689 } 4691 }
4690 4692
4691 void test_creation_empty() { 4693 void test_creation_empty() {
4692 LibraryElement definingLibrary = createDefaultTestLibrary(); 4694 LibraryElement definingLibrary = createDefaultTestLibrary();
4693 GatheringErrorListener errorListener = new GatheringErrorListener(); 4695 GatheringErrorListener errorListener = new GatheringErrorListener();
4694 new LibraryImportScope(definingLibrary, errorListener); 4696 new LibraryImportScope(definingLibrary, errorListener);
4695 } 4697 }
4696 4698
4697 void test_creation_nonEmpty() { 4699 void test_creation_nonEmpty() {
4698 AnalysisContext context = new AnalysisContextImpl(); 4700 AnalysisContext context = new AnalysisContextImpl();
4699 context.sourceFactory = new SourceFactory([]); 4701 context.sourceFactory = new SourceFactory([]);
4700 String importedTypeName = "A"; 4702 String importedTypeName = "A";
4701 ClassElement importedType = new ClassElementImpl.forNode(AstFactory.identifi er3(importedTypeName)); 4703 ClassElement importedType = new ClassElementImpl.forNode(AstFactory.identifi er3(importedTypeName));
4702 LibraryElement importedLibrary = createTestLibrary(context, "imported", []); 4704 LibraryElement importedLibrary = createTestLibrary(context, "imported");
4703 (importedLibrary.definingCompilationUnit as CompilationUnitElementImpl).type s = <ClassElement> [importedType]; 4705 (importedLibrary.definingCompilationUnit as CompilationUnitElementImpl).type s = <ClassElement> [importedType];
4704 LibraryElementImpl definingLibrary = createTestLibrary(context, "importing", []); 4706 LibraryElementImpl definingLibrary = createTestLibrary(context, "importing") ;
4705 ImportElementImpl importElement = new ImportElementImpl(0); 4707 ImportElementImpl importElement = new ImportElementImpl(0);
4706 importElement.importedLibrary = importedLibrary; 4708 importElement.importedLibrary = importedLibrary;
4707 definingLibrary.imports = <ImportElement> [importElement]; 4709 definingLibrary.imports = <ImportElement> [importElement];
4708 GatheringErrorListener errorListener = new GatheringErrorListener(); 4710 GatheringErrorListener errorListener = new GatheringErrorListener();
4709 Scope scope = new LibraryImportScope(definingLibrary, errorListener); 4711 Scope scope = new LibraryImportScope(definingLibrary, errorListener);
4710 expect(scope.lookup(AstFactory.identifier3(importedTypeName), definingLibrar y), importedType); 4712 expect(scope.lookup(AstFactory.identifier3(importedTypeName), definingLibrar y), importedType);
4711 } 4713 }
4712 4714
4713 void test_getErrorListener() { 4715 void test_getErrorListener() {
4714 LibraryElement definingLibrary = createDefaultTestLibrary(); 4716 LibraryElement definingLibrary = createDefaultTestLibrary();
4715 GatheringErrorListener errorListener = new GatheringErrorListener(); 4717 GatheringErrorListener errorListener = new GatheringErrorListener();
4716 LibraryImportScope scope = new LibraryImportScope(definingLibrary, errorList ener); 4718 LibraryImportScope scope = new LibraryImportScope(definingLibrary, errorList ener);
4717 expect(scope.errorListener, errorListener); 4719 expect(scope.errorListener, errorListener);
4718 } 4720 }
4719 4721
4720 void test_nonConflictingImports_fromSdk() { 4722 void test_nonConflictingImports_fromSdk() {
4721 AnalysisContext context = AnalysisContextFactory.contextWithCore(); 4723 AnalysisContext context = AnalysisContextFactory.contextWithCore();
4722 String typeName = "List"; 4724 String typeName = "List";
4723 ClassElement type = ElementFactory.classElement2(typeName, []); 4725 ClassElement type = ElementFactory.classElement2(typeName);
4724 LibraryElement importedLibrary = createTestLibrary(context, "lib", []); 4726 LibraryElement importedLibrary = createTestLibrary(context, "lib");
4725 (importedLibrary.definingCompilationUnit as CompilationUnitElementImpl).type s = <ClassElement> [type]; 4727 (importedLibrary.definingCompilationUnit as CompilationUnitElementImpl).type s = <ClassElement> [type];
4726 ImportElementImpl importCore = ElementFactory.importFor(context.getLibraryEl ement(context.sourceFactory.forUri("dart:core")), null, []); 4728 ImportElementImpl importCore = ElementFactory.importFor(context.getLibraryEl ement(context.sourceFactory.forUri("dart:core")), null);
4727 ImportElementImpl importLib = ElementFactory.importFor(importedLibrary, null , []); 4729 ImportElementImpl importLib = ElementFactory.importFor(importedLibrary, null );
4728 LibraryElementImpl importingLibrary = createTestLibrary(context, "importing" , []); 4730 LibraryElementImpl importingLibrary = createTestLibrary(context, "importing" );
4729 importingLibrary.imports = <ImportElement> [importCore, importLib]; 4731 importingLibrary.imports = <ImportElement> [importCore, importLib];
4730 GatheringErrorListener errorListener = new GatheringErrorListener(); 4732 GatheringErrorListener errorListener = new GatheringErrorListener();
4731 Scope scope = new LibraryImportScope(importingLibrary, errorListener); 4733 Scope scope = new LibraryImportScope(importingLibrary, errorListener);
4732 expect(scope.lookup(AstFactory.identifier3(typeName), importingLibrary), typ e); 4734 expect(scope.lookup(AstFactory.identifier3(typeName), importingLibrary), typ e);
4733 errorListener.assertErrorsWithCodes([StaticWarningCode.CONFLICTING_DART_IMPO RT]); 4735 errorListener.assertErrorsWithCodes([StaticWarningCode.CONFLICTING_DART_IMPO RT]);
4734 } 4736 }
4735 4737
4736 void test_nonConflictingImports_sameElement() { 4738 void test_nonConflictingImports_sameElement() {
4737 AnalysisContext context = new AnalysisContextImpl(); 4739 AnalysisContext context = new AnalysisContextImpl();
4738 context.sourceFactory = new SourceFactory([]); 4740 context.sourceFactory = new SourceFactory([]);
4739 String typeNameA = "A"; 4741 String typeNameA = "A";
4740 String typeNameB = "B"; 4742 String typeNameB = "B";
4741 ClassElement typeA = ElementFactory.classElement2(typeNameA, []); 4743 ClassElement typeA = ElementFactory.classElement2(typeNameA);
4742 ClassElement typeB = ElementFactory.classElement2(typeNameB, []); 4744 ClassElement typeB = ElementFactory.classElement2(typeNameB);
4743 LibraryElement importedLibrary = createTestLibrary(context, "imported", []); 4745 LibraryElement importedLibrary = createTestLibrary(context, "imported");
4744 (importedLibrary.definingCompilationUnit as CompilationUnitElementImpl).type s = <ClassElement> [typeA, typeB]; 4746 (importedLibrary.definingCompilationUnit as CompilationUnitElementImpl).type s = <ClassElement> [typeA, typeB];
4745 ImportElementImpl import1 = ElementFactory.importFor(importedLibrary, null, []); 4747 ImportElementImpl import1 = ElementFactory.importFor(importedLibrary, null);
4746 ImportElementImpl import2 = ElementFactory.importFor(importedLibrary, null, []); 4748 ImportElementImpl import2 = ElementFactory.importFor(importedLibrary, null);
4747 LibraryElementImpl importingLibrary = createTestLibrary(context, "importing" , []); 4749 LibraryElementImpl importingLibrary = createTestLibrary(context, "importing" );
4748 importingLibrary.imports = <ImportElement> [import1, import2]; 4750 importingLibrary.imports = <ImportElement> [import1, import2];
4749 GatheringErrorListener errorListener = new GatheringErrorListener(); 4751 GatheringErrorListener errorListener = new GatheringErrorListener();
4750 Scope scope = new LibraryImportScope(importingLibrary, errorListener); 4752 Scope scope = new LibraryImportScope(importingLibrary, errorListener);
4751 expect(scope.lookup(AstFactory.identifier3(typeNameA), importingLibrary), ty peA); 4753 expect(scope.lookup(AstFactory.identifier3(typeNameA), importingLibrary), ty peA);
4752 errorListener.assertNoErrors(); 4754 errorListener.assertNoErrors();
4753 expect(scope.lookup(AstFactory.identifier3(typeNameB), importingLibrary), ty peB); 4755 expect(scope.lookup(AstFactory.identifier3(typeNameB), importingLibrary), ty peB);
4754 errorListener.assertNoErrors(); 4756 errorListener.assertNoErrors();
4755 } 4757 }
4756 4758
4757 void test_prefixedAndNonPrefixed() { 4759 void test_prefixedAndNonPrefixed() {
4758 AnalysisContext context = new AnalysisContextImpl(); 4760 AnalysisContext context = new AnalysisContextImpl();
4759 context.sourceFactory = new SourceFactory([]); 4761 context.sourceFactory = new SourceFactory([]);
4760 String typeName = "C"; 4762 String typeName = "C";
4761 String prefixName = "p"; 4763 String prefixName = "p";
4762 ClassElement prefixedType = ElementFactory.classElement2(typeName, []); 4764 ClassElement prefixedType = ElementFactory.classElement2(typeName);
4763 ClassElement nonPrefixedType = ElementFactory.classElement2(typeName, []); 4765 ClassElement nonPrefixedType = ElementFactory.classElement2(typeName);
4764 LibraryElement prefixedLibrary = createTestLibrary(context, "import.prefixed ", []); 4766 LibraryElement prefixedLibrary = createTestLibrary(context, "import.prefixed ");
4765 (prefixedLibrary.definingCompilationUnit as CompilationUnitElementImpl).type s = <ClassElement> [prefixedType]; 4767 (prefixedLibrary.definingCompilationUnit as CompilationUnitElementImpl).type s = <ClassElement> [prefixedType];
4766 ImportElementImpl prefixedImport = ElementFactory.importFor(prefixedLibrary, ElementFactory.prefix(prefixName), []); 4768 ImportElementImpl prefixedImport = ElementFactory.importFor(prefixedLibrary, ElementFactory.prefix(prefixName));
4767 LibraryElement nonPrefixedLibrary = createTestLibrary(context, "import.nonPr efixed", []); 4769 LibraryElement nonPrefixedLibrary = createTestLibrary(context, "import.nonPr efixed");
4768 (nonPrefixedLibrary.definingCompilationUnit as CompilationUnitElementImpl).t ypes = <ClassElement> [nonPrefixedType]; 4770 (nonPrefixedLibrary.definingCompilationUnit as CompilationUnitElementImpl).t ypes = <ClassElement> [nonPrefixedType];
4769 ImportElementImpl nonPrefixedImport = ElementFactory.importFor(nonPrefixedLi brary, null, []); 4771 ImportElementImpl nonPrefixedImport = ElementFactory.importFor(nonPrefixedLi brary, null);
4770 LibraryElementImpl importingLibrary = createTestLibrary(context, "importing" , []); 4772 LibraryElementImpl importingLibrary = createTestLibrary(context, "importing" );
4771 importingLibrary.imports = <ImportElement> [prefixedImport, nonPrefixedImpor t]; 4773 importingLibrary.imports = <ImportElement> [prefixedImport, nonPrefixedImpor t];
4772 GatheringErrorListener errorListener = new GatheringErrorListener(); 4774 GatheringErrorListener errorListener = new GatheringErrorListener();
4773 Scope scope = new LibraryImportScope(importingLibrary, errorListener); 4775 Scope scope = new LibraryImportScope(importingLibrary, errorListener);
4774 Element prefixedElement = scope.lookup(AstFactory.identifier5(prefixName, ty peName), importingLibrary); 4776 Element prefixedElement = scope.lookup(AstFactory.identifier5(prefixName, ty peName), importingLibrary);
4775 errorListener.assertNoErrors(); 4777 errorListener.assertNoErrors();
4776 expect(prefixedElement, same(prefixedType)); 4778 expect(prefixedElement, same(prefixedType));
4777 Element nonPrefixedElement = scope.lookup(AstFactory.identifier3(typeName), importingLibrary); 4779 Element nonPrefixedElement = scope.lookup(AstFactory.identifier3(typeName), importingLibrary);
4778 errorListener.assertNoErrors(); 4780 errorListener.assertNoErrors();
4779 expect(nonPrefixedElement, same(nonPrefixedType)); 4781 expect(nonPrefixedElement, same(nonPrefixedType));
4780 } 4782 }
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
4870 LibraryElement definingLibrary = createDefaultTestLibrary(); 4872 LibraryElement definingLibrary = createDefaultTestLibrary();
4871 GatheringErrorListener errorListener = new GatheringErrorListener(); 4873 GatheringErrorListener errorListener = new GatheringErrorListener();
4872 new LibraryScope(definingLibrary, errorListener); 4874 new LibraryScope(definingLibrary, errorListener);
4873 } 4875 }
4874 4876
4875 void test_creation_nonEmpty() { 4877 void test_creation_nonEmpty() {
4876 AnalysisContext context = new AnalysisContextImpl(); 4878 AnalysisContext context = new AnalysisContextImpl();
4877 context.sourceFactory = new SourceFactory([]); 4879 context.sourceFactory = new SourceFactory([]);
4878 String importedTypeName = "A"; 4880 String importedTypeName = "A";
4879 ClassElement importedType = new ClassElementImpl.forNode(AstFactory.identifi er3(importedTypeName)); 4881 ClassElement importedType = new ClassElementImpl.forNode(AstFactory.identifi er3(importedTypeName));
4880 LibraryElement importedLibrary = createTestLibrary(context, "imported", []); 4882 LibraryElement importedLibrary = createTestLibrary(context, "imported");
4881 (importedLibrary.definingCompilationUnit as CompilationUnitElementImpl).type s = <ClassElement> [importedType]; 4883 (importedLibrary.definingCompilationUnit as CompilationUnitElementImpl).type s = <ClassElement> [importedType];
4882 LibraryElementImpl definingLibrary = createTestLibrary(context, "importing", []); 4884 LibraryElementImpl definingLibrary = createTestLibrary(context, "importing") ;
4883 ImportElementImpl importElement = new ImportElementImpl(0); 4885 ImportElementImpl importElement = new ImportElementImpl(0);
4884 importElement.importedLibrary = importedLibrary; 4886 importElement.importedLibrary = importedLibrary;
4885 definingLibrary.imports = <ImportElement> [importElement]; 4887 definingLibrary.imports = <ImportElement> [importElement];
4886 GatheringErrorListener errorListener = new GatheringErrorListener(); 4888 GatheringErrorListener errorListener = new GatheringErrorListener();
4887 Scope scope = new LibraryScope(definingLibrary, errorListener); 4889 Scope scope = new LibraryScope(definingLibrary, errorListener);
4888 expect(scope.lookup(AstFactory.identifier3(importedTypeName), definingLibrar y), importedType); 4890 expect(scope.lookup(AstFactory.identifier3(importedTypeName), definingLibrar y), importedType);
4889 } 4891 }
4890 4892
4891 void test_getErrorListener() { 4893 void test_getErrorListener() {
4892 LibraryElement definingLibrary = createDefaultTestLibrary(); 4894 LibraryElement definingLibrary = createDefaultTestLibrary();
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
5006 /** 5008 /**
5007 * The null type. 5009 * The null type.
5008 */ 5010 */
5009 InterfaceType _nullType; 5011 InterfaceType _nullType;
5010 5012
5011 void setUp() { 5013 void setUp() {
5012 _nullType = new TestTypeProvider().nullType; 5014 _nullType = new TestTypeProvider().nullType;
5013 } 5015 }
5014 5016
5015 void test_MemberMap_copyConstructor() { 5017 void test_MemberMap_copyConstructor() {
5016 MethodElement m1 = ElementFactory.methodElement("m1", _nullType, []); 5018 MethodElement m1 = ElementFactory.methodElement("m1", _nullType);
5017 MethodElement m2 = ElementFactory.methodElement("m2", _nullType, []); 5019 MethodElement m2 = ElementFactory.methodElement("m2", _nullType);
5018 MethodElement m3 = ElementFactory.methodElement("m3", _nullType, []); 5020 MethodElement m3 = ElementFactory.methodElement("m3", _nullType);
5019 MemberMap map = new MemberMap(); 5021 MemberMap map = new MemberMap();
5020 map.put(m1.name, m1); 5022 map.put(m1.name, m1);
5021 map.put(m2.name, m2); 5023 map.put(m2.name, m2);
5022 map.put(m3.name, m3); 5024 map.put(m3.name, m3);
5023 MemberMap copy = new MemberMap.con2(map); 5025 MemberMap copy = new MemberMap.con2(map);
5024 expect(copy.size, map.size); 5026 expect(copy.size, map.size);
5025 expect(copy.get(m1.name), m1); 5027 expect(copy.get(m1.name), m1);
5026 expect(copy.get(m2.name), m2); 5028 expect(copy.get(m2.name), m2);
5027 expect(copy.get(m3.name), m3); 5029 expect(copy.get(m3.name), m3);
5028 } 5030 }
5029 5031
5030 void test_MemberMap_override() { 5032 void test_MemberMap_override() {
5031 MethodElement m1 = ElementFactory.methodElement("m", _nullType, []); 5033 MethodElement m1 = ElementFactory.methodElement("m", _nullType);
5032 MethodElement m2 = ElementFactory.methodElement("m", _nullType, []); 5034 MethodElement m2 = ElementFactory.methodElement("m", _nullType);
5033 MemberMap map = new MemberMap(); 5035 MemberMap map = new MemberMap();
5034 map.put(m1.name, m1); 5036 map.put(m1.name, m1);
5035 map.put(m2.name, m2); 5037 map.put(m2.name, m2);
5036 expect(map.size, 1); 5038 expect(map.size, 1);
5037 expect(map.get("m"), m2); 5039 expect(map.get("m"), m2);
5038 } 5040 }
5039 5041
5040 void test_MemberMap_put() { 5042 void test_MemberMap_put() {
5041 MethodElement m1 = ElementFactory.methodElement("m1", _nullType, []); 5043 MethodElement m1 = ElementFactory.methodElement("m1", _nullType);
5042 MemberMap map = new MemberMap(); 5044 MemberMap map = new MemberMap();
5043 expect(map.size, 0); 5045 expect(map.size, 0);
5044 map.put(m1.name, m1); 5046 map.put(m1.name, m1);
5045 expect(map.size, 1); 5047 expect(map.size, 1);
5046 expect(map.get("m1"), m1); 5048 expect(map.get("m1"), m1);
5047 } 5049 }
5048 } 5050 }
5049 5051
5050 class NonHintCodeTest extends ResolverTestCase { 5052 class NonHintCodeTest extends ResolverTestCase {
5051 void test_deadCode_deadBlock_conditionalElse_debugConst() { 5053 void test_deadCode_deadBlock_conditionalElse_debugConst() {
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
5265 } 5267 }
5266 5268
5267 void test_importDeferredLibraryWithLoadFunction() { 5269 void test_importDeferredLibraryWithLoadFunction() {
5268 resolveWithAndWithoutExperimental(<String> [ 5270 resolveWithAndWithoutExperimental(<String> [
5269 r''' 5271 r'''
5270 library lib1; 5272 library lib1;
5271 f() {}''', 5273 f() {}''',
5272 r''' 5274 r'''
5273 library root; 5275 library root;
5274 import 'lib1.dart' deferred as lib1; 5276 import 'lib1.dart' deferred as lib1;
5275 main() { lib1.f(); }'''], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPP ORTED], <ErrorCode> []); 5277 main() { lib1.f(); }'''], <ErrorCode>[ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPO RTED], ErrorCode.EMPTY_LIST);
5276 } 5278 }
5277 5279
5278 void test_issue20904BuggyTypePromotionAtIfJoin_1() { 5280 void test_issue20904BuggyTypePromotionAtIfJoin_1() {
5279 // https://code.google.com/p/dart/issues/detail?id=20904 5281 // https://code.google.com/p/dart/issues/detail?id=20904
5280 Source source = addSource(r''' 5282 Source source = addSource(r'''
5281 f(var message, var dynamic_) { 5283 f(var message, var dynamic_) {
5282 if (message is Function) { 5284 if (message is Function) {
5283 message = dynamic_; 5285 message = dynamic_;
5284 } 5286 }
5285 int s = message; 5287 int s = message;
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
5794 Source source = addSource(r''' 5796 Source source = addSource(r'''
5795 library L; 5797 library L;
5796 @A() 5798 @A()
5797 import 'lib1.dart';'''); 5799 import 'lib1.dart';''');
5798 Source source2 = addNamedSource("/lib1.dart", r''' 5800 Source source2 = addNamedSource("/lib1.dart", r'''
5799 library lib1; 5801 library lib1;
5800 class A { 5802 class A {
5801 const A() {} 5803 const A() {}
5802 }'''); 5804 }''');
5803 resolve(source); 5805 resolve(source);
5804 assertErrors(source, []); 5806 assertErrors(source);
5805 verify([source, source2]); 5807 verify([source, source2]);
5806 } 5808 }
5807 5809
5808 void test_unusedImport_as_equalPrefixes() { 5810 void test_unusedImport_as_equalPrefixes() {
5809 // 18818 5811 // 18818
5810 Source source = addSource(r''' 5812 Source source = addSource(r'''
5811 library L; 5813 library L;
5812 import 'lib1.dart' as one; 5814 import 'lib1.dart' as one;
5813 import 'lib2.dart' as one; 5815 import 'lib2.dart' as one;
5814 one.A a; 5816 one.A a;
5815 one.B b;'''); 5817 one.B b;''');
5816 Source source2 = addNamedSource("/lib1.dart", r''' 5818 Source source2 = addNamedSource("/lib1.dart", r'''
5817 library lib1; 5819 library lib1;
5818 class A {}'''); 5820 class A {}''');
5819 Source source3 = addNamedSource("/lib2.dart", r''' 5821 Source source3 = addNamedSource("/lib2.dart", r'''
5820 library lib2; 5822 library lib2;
5821 class B {}'''); 5823 class B {}''');
5822 resolve(source); 5824 resolve(source);
5823 assertErrors(source, []); 5825 assertErrors(source);
5824 assertNoErrors(source2); 5826 assertNoErrors(source2);
5825 assertNoErrors(source3); 5827 assertNoErrors(source3);
5826 verify([source, source2, source3]); 5828 verify([source, source2, source3]);
5827 } 5829 }
5828 5830
5829 void test_unusedImport_core_library() { 5831 void test_unusedImport_core_library() {
5830 Source source = addSource(r''' 5832 Source source = addSource(r'''
5831 library L; 5833 library L;
5832 import 'dart:core';'''); 5834 import 'dart:core';''');
5833 resolve(source); 5835 resolve(source);
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
6368 * Assert that the number of errors reported against the given source matches the number of errors 6370 * Assert that the number of errors reported against the given source matches the number of errors
6369 * that are given and that they have the expected error codes. The order in wh ich the errors were 6371 * that are given and that they have the expected error codes. The order in wh ich the errors were
6370 * gathered is ignored. 6372 * gathered is ignored.
6371 * 6373 *
6372 * @param source the source against which the errors should have been reported 6374 * @param source the source against which the errors should have been reported
6373 * @param expectedErrorCodes the error codes of the errors that should have be en reported 6375 * @param expectedErrorCodes the error codes of the errors that should have be en reported
6374 * @throws AnalysisException if the reported errors could not be computed 6376 * @throws AnalysisException if the reported errors could not be computed
6375 * @throws AssertionFailedError if a different number of errors have been repo rted than were 6377 * @throws AssertionFailedError if a different number of errors have been repo rted than were
6376 * expected 6378 * expected
6377 */ 6379 */
6378 void assertErrors(Source source, List<ErrorCode> expectedErrorCodes) { 6380 void assertErrors(Source source, [List<ErrorCode> expectedErrorCodes = ErrorCo de.EMPTY_LIST]) {
6379 GatheringErrorListener errorListener = new GatheringErrorListener(); 6381 GatheringErrorListener errorListener = new GatheringErrorListener();
6380 for (AnalysisError error in analysisContext2.computeErrors(source)) { 6382 for (AnalysisError error in analysisContext2.computeErrors(source)) {
6381 if (error.errorCode == HintCode.UNUSED_LOCAL_VARIABLE && 6383 if (error.errorCode == HintCode.UNUSED_LOCAL_VARIABLE &&
6382 !enableUnusedLocalVariable) { 6384 !enableUnusedLocalVariable) {
6383 continue; 6385 continue;
6384 } 6386 }
6385 errorListener.onError(error); 6387 errorListener.onError(error);
6386 } 6388 }
6387 errorListener.assertErrorsWithCodes(expectedErrorCodes); 6389 errorListener.assertErrorsWithCodes(expectedErrorCodes);
6388 } 6390 }
6389 6391
6390 /** 6392 /**
6391 * Assert that no errors have been reported against the given source. 6393 * Assert that no errors have been reported against the given source.
6392 * 6394 *
6393 * @param source the source against which no errors should have been reported 6395 * @param source the source against which no errors should have been reported
6394 * @throws AnalysisException if the reported errors could not be computed 6396 * @throws AnalysisException if the reported errors could not be computed
6395 * @throws AssertionFailedError if any errors have been reported 6397 * @throws AssertionFailedError if any errors have been reported
6396 */ 6398 */
6397 void assertNoErrors(Source source) { 6399 void assertNoErrors(Source source) {
6398 assertErrors(source, []); 6400 assertErrors(source);
6399 } 6401 }
6400 6402
6401 /** 6403 /**
6402 * Cache the source file content in the source factory but don't add the sourc e to the analysis 6404 * Cache the source file content in the source factory but don't add the sourc e to the analysis
6403 * context. The file path should be absolute. 6405 * context. The file path should be absolute.
6404 * 6406 *
6405 * @param filePath the path of the file being cached 6407 * @param filePath the path of the file being cached
6406 * @param contents the contents to be returned by the content provider for the specified file 6408 * @param contents the contents to be returned by the content provider for the specified file
6407 * @return the source object representing the cached file 6409 * @return the source object representing the cached file
6408 */ 6410 */
6409 Source cacheSource(String filePath, String contents) { 6411 Source cacheSource(String filePath, String contents) {
6410 Source source = new FileBasedSource.con1(FileUtilities2.createFile(filePath) ); 6412 Source source = new FileBasedSource.con1(FileUtilities2.createFile(filePath) );
6411 analysisContext2.setContents(source, contents); 6413 analysisContext2.setContents(source, contents);
6412 return source; 6414 return source;
6413 } 6415 }
6414 6416
6415 /** 6417 /**
6416 * Create a library element that represents a library named `"test"` containin g a single 6418 * Create a library element that represents a library named `"test"` containin g a single
6417 * empty compilation unit. 6419 * empty compilation unit.
6418 * 6420 *
6419 * @return the library element that was created 6421 * @return the library element that was created
6420 */ 6422 */
6421 LibraryElementImpl createDefaultTestLibrary() => createTestLibrary(new Analysi sContextImpl(), "test", []); 6423 LibraryElementImpl createDefaultTestLibrary() => createTestLibrary(new Analysi sContextImpl(), "test");
6422 6424
6423 /** 6425 /**
6424 * Create a library element that represents a library with the given name cont aining a single 6426 * Create a library element that represents a library with the given name cont aining a single
6425 * empty compilation unit. 6427 * empty compilation unit.
6426 * 6428 *
6427 * @param libraryName the name of the library to be created 6429 * @param libraryName the name of the library to be created
6428 * @return the library element that was created 6430 * @return the library element that was created
6429 */ 6431 */
6430 LibraryElementImpl createTestLibrary(AnalysisContext context, String libraryNa me, List<String> typeNames) { 6432 LibraryElementImpl createTestLibrary(AnalysisContext context, String libraryNa me, [List<String> typeNames]) {
6431 int count = typeNames.length; 6433 List<CompilationUnitElement> sourcedCompilationUnits;
6432 List<CompilationUnitElementImpl> sourcedCompilationUnits = new List<Compilat ionUnitElementImpl>(count); 6434 if (typeNames == null) {
6433 for (int i = 0; i < count; i++) { 6435 sourcedCompilationUnits = CompilationUnitElementImpl.EMPTY_ARRAY;
6434 String typeName = typeNames[i]; 6436 } else {
6435 ClassElementImpl type = new ClassElementImpl.forNode(AstFactory.identifier 3(typeName)); 6437 int count = typeNames.length;
6436 String fileName = "$typeName.dart"; 6438 sourcedCompilationUnits = new List<CompilationUnitElement>(count);
6437 CompilationUnitElementImpl compilationUnit = new CompilationUnitElementImp l(fileName); 6439 for (int i = 0; i < count; i++) {
6438 compilationUnit.source = _createNamedSource(fileName); 6440 String typeName = typeNames[i];
6439 compilationUnit.types = <ClassElement> [type]; 6441 ClassElementImpl type = new ClassElementImpl.forNode(AstFactory.identifi er3(typeName));
6440 sourcedCompilationUnits[i] = compilationUnit; 6442 String fileName = "$typeName.dart";
6443 CompilationUnitElementImpl compilationUnit = new CompilationUnitElementI mpl(fileName);
6444 compilationUnit.source = _createNamedSource(fileName);
6445 compilationUnit.types = <ClassElement> [type];
6446 sourcedCompilationUnits[i] = compilationUnit;
6447 }
6441 } 6448 }
6442 String fileName = "$libraryName.dart"; 6449 String fileName = "$libraryName.dart";
6443 CompilationUnitElementImpl compilationUnit = new CompilationUnitElementImpl( fileName); 6450 CompilationUnitElementImpl compilationUnit = new CompilationUnitElementImpl( fileName);
6444 compilationUnit.source = _createNamedSource(fileName); 6451 compilationUnit.source = _createNamedSource(fileName);
6445 LibraryElementImpl library = new LibraryElementImpl.forNode(context, AstFact ory.libraryIdentifier2([libraryName])); 6452 LibraryElementImpl library = new LibraryElementImpl.forNode(context, AstFact ory.libraryIdentifier2([libraryName]));
6446 library.definingCompilationUnit = compilationUnit; 6453 library.definingCompilationUnit = compilationUnit;
6447 library.parts = sourcedCompilationUnits; 6454 library.parts = sourcedCompilationUnits;
6448 return library; 6455 return library;
6449 } 6456 }
6450 6457
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
6700 ScopeBuilder.scopeFor(AstFactory.compilationUnit(), listener); 6707 ScopeBuilder.scopeFor(AstFactory.compilationUnit(), listener);
6701 fail("Expected AnalysisException"); 6708 fail("Expected AnalysisException");
6702 } on AnalysisException catch (exception) { 6709 } on AnalysisException catch (exception) {
6703 // Expected 6710 // Expected
6704 } 6711 }
6705 } 6712 }
6706 6713
6707 ClassDeclaration _createResolvedClassDeclaration() { 6714 ClassDeclaration _createResolvedClassDeclaration() {
6708 CompilationUnit unit = _createResolvedCompilationUnit(); 6715 CompilationUnit unit = _createResolvedCompilationUnit();
6709 String className = "C"; 6716 String className = "C";
6710 ClassDeclaration classNode = AstFactory.classDeclaration(null, className, As tFactory.typeParameterList([]), null, null, null, []); 6717 ClassDeclaration classNode = AstFactory.classDeclaration(null, className, As tFactory.typeParameterList(), null, null, null);
6711 unit.declarations.add(classNode); 6718 unit.declarations.add(classNode);
6712 ClassElement classElement = ElementFactory.classElement2(className, []); 6719 ClassElement classElement = ElementFactory.classElement2(className);
6713 classNode.name.staticElement = classElement; 6720 classNode.name.staticElement = classElement;
6714 (unit.element as CompilationUnitElementImpl).types = <ClassElement> [classEl ement]; 6721 (unit.element as CompilationUnitElementImpl).types = <ClassElement> [classEl ement];
6715 return classNode; 6722 return classNode;
6716 } 6723 }
6717 6724
6718 ClassTypeAlias _createResolvedClassTypeAlias() { 6725 ClassTypeAlias _createResolvedClassTypeAlias() {
6719 CompilationUnit unit = _createResolvedCompilationUnit(); 6726 CompilationUnit unit = _createResolvedCompilationUnit();
6720 String className = "C"; 6727 String className = "C";
6721 ClassTypeAlias classNode = AstFactory.classTypeAlias(className, AstFactory.t ypeParameterList([]), null, null, null, null); 6728 ClassTypeAlias classNode = AstFactory.classTypeAlias(className, AstFactory.t ypeParameterList(), null, null, null, null);
6722 unit.declarations.add(classNode); 6729 unit.declarations.add(classNode);
6723 ClassElement classElement = ElementFactory.classElement2(className, []); 6730 ClassElement classElement = ElementFactory.classElement2(className);
6724 classNode.name.staticElement = classElement; 6731 classNode.name.staticElement = classElement;
6725 (unit.element as CompilationUnitElementImpl).types = <ClassElement> [classEl ement]; 6732 (unit.element as CompilationUnitElementImpl).types = <ClassElement> [classEl ement];
6726 return classNode; 6733 return classNode;
6727 } 6734 }
6728 6735
6729 CompilationUnit _createResolvedCompilationUnit() { 6736 CompilationUnit _createResolvedCompilationUnit() {
6730 CompilationUnit unit = AstFactory.compilationUnit(); 6737 CompilationUnit unit = AstFactory.compilationUnit();
6731 LibraryElementImpl library = ElementFactory.library(AnalysisContextFactory.c ontextWithCore(), "lib"); 6738 LibraryElementImpl library = ElementFactory.library(AnalysisContextFactory.c ontextWithCore(), "lib");
6732 unit.element = library.definingCompilationUnit; 6739 unit.element = library.definingCompilationUnit;
6733 return unit; 6740 return unit;
6734 } 6741 }
6735 6742
6736 ConstructorDeclaration _createResolvedConstructorDeclaration() { 6743 ConstructorDeclaration _createResolvedConstructorDeclaration() {
6737 ClassDeclaration classNode = _createResolvedClassDeclaration(); 6744 ClassDeclaration classNode = _createResolvedClassDeclaration();
6738 String constructorName = "f"; 6745 String constructorName = "f";
6739 ConstructorDeclaration constructorNode = AstFactory.constructorDeclaration(A stFactory.identifier3(constructorName), null, AstFactory.formalParameterList([]) , null); 6746 ConstructorDeclaration constructorNode = AstFactory.constructorDeclaration(A stFactory.identifier3(constructorName), null, AstFactory.formalParameterList(), null);
6740 classNode.members.add(constructorNode); 6747 classNode.members.add(constructorNode);
6741 ConstructorElement constructorElement = ElementFactory.constructorElement2(c lassNode.element, null, []); 6748 ConstructorElement constructorElement = ElementFactory.constructorElement2(c lassNode.element, null);
6742 constructorNode.element = constructorElement; 6749 constructorNode.element = constructorElement;
6743 (classNode.element as ClassElementImpl).constructors = <ConstructorElement> [constructorElement]; 6750 (classNode.element as ClassElementImpl).constructors = <ConstructorElement> [constructorElement];
6744 return constructorNode; 6751 return constructorNode;
6745 } 6752 }
6746 6753
6747 FunctionDeclaration _createResolvedFunctionDeclaration() { 6754 FunctionDeclaration _createResolvedFunctionDeclaration() {
6748 CompilationUnit unit = _createResolvedCompilationUnit(); 6755 CompilationUnit unit = _createResolvedCompilationUnit();
6749 String functionName = "f"; 6756 String functionName = "f";
6750 FunctionDeclaration functionNode = AstFactory.functionDeclaration(null, null , functionName, AstFactory.functionExpression()); 6757 FunctionDeclaration functionNode = AstFactory.functionDeclaration(null, null , functionName, AstFactory.functionExpression());
6751 unit.declarations.add(functionNode); 6758 unit.declarations.add(functionNode);
6752 FunctionElement functionElement = ElementFactory.functionElement(functionNam e); 6759 FunctionElement functionElement = ElementFactory.functionElement(functionNam e);
6753 functionNode.name.staticElement = functionElement; 6760 functionNode.name.staticElement = functionElement;
6754 (unit.element as CompilationUnitElementImpl).functions = <FunctionElement> [ functionElement]; 6761 (unit.element as CompilationUnitElementImpl).functions = <FunctionElement> [ functionElement];
6755 return functionNode; 6762 return functionNode;
6756 } 6763 }
6757 6764
6758 FunctionTypeAlias _createResolvedFunctionTypeAlias() { 6765 FunctionTypeAlias _createResolvedFunctionTypeAlias() {
6759 CompilationUnit unit = _createResolvedCompilationUnit(); 6766 CompilationUnit unit = _createResolvedCompilationUnit();
6760 FunctionTypeAlias aliasNode = AstFactory.typeAlias(AstFactory.typeName4("A", []), "F", AstFactory.typeParameterList([]), AstFactory.formalParameterList([])) ; 6767 FunctionTypeAlias aliasNode = AstFactory.typeAlias(AstFactory.typeName4("A") , "F", AstFactory.typeParameterList(), AstFactory.formalParameterList());
6761 unit.declarations.add(aliasNode); 6768 unit.declarations.add(aliasNode);
6762 SimpleIdentifier aliasName = aliasNode.name; 6769 SimpleIdentifier aliasName = aliasNode.name;
6763 FunctionTypeAliasElement aliasElement = new FunctionTypeAliasElementImpl.for Node(aliasName); 6770 FunctionTypeAliasElement aliasElement = new FunctionTypeAliasElementImpl.for Node(aliasName);
6764 aliasName.staticElement = aliasElement; 6771 aliasName.staticElement = aliasElement;
6765 (unit.element as CompilationUnitElementImpl).typeAliases = <FunctionTypeAlia sElement> [aliasElement]; 6772 (unit.element as CompilationUnitElementImpl).typeAliases = <FunctionTypeAlia sElement> [aliasElement];
6766 return aliasNode; 6773 return aliasNode;
6767 } 6774 }
6768 6775
6769 MethodDeclaration _createResolvedMethodDeclaration() { 6776 MethodDeclaration _createResolvedMethodDeclaration() {
6770 ClassDeclaration classNode = _createResolvedClassDeclaration(); 6777 ClassDeclaration classNode = _createResolvedClassDeclaration();
6771 String methodName = "f"; 6778 String methodName = "f";
6772 MethodDeclaration methodNode = AstFactory.methodDeclaration(null, null, null , null, AstFactory.identifier3(methodName), AstFactory.formalParameterList([])); 6779 MethodDeclaration methodNode = AstFactory.methodDeclaration(null, null, null , null, AstFactory.identifier3(methodName), AstFactory.formalParameterList());
6773 classNode.members.add(methodNode); 6780 classNode.members.add(methodNode);
6774 MethodElement methodElement = ElementFactory.methodElement(methodName, null, []); 6781 MethodElement methodElement = ElementFactory.methodElement(methodName, null) ;
6775 methodNode.name.staticElement = methodElement; 6782 methodNode.name.staticElement = methodElement;
6776 (classNode.element as ClassElementImpl).methods = <MethodElement> [methodEle ment]; 6783 (classNode.element as ClassElementImpl).methods = <MethodElement> [methodEle ment];
6777 return methodNode; 6784 return methodNode;
6778 } 6785 }
6779 } 6786 }
6780 6787
6781 class ScopeTest extends ResolverTestCase { 6788 class ScopeTest extends ResolverTestCase {
6782 void test_define_duplicate() { 6789 void test_define_duplicate() {
6783 GatheringErrorListener errorListener = new GatheringErrorListener(); 6790 GatheringErrorListener errorListener = new GatheringErrorListener();
6784 ScopeTest_TestScope scope = new ScopeTest_TestScope(errorListener); 6791 ScopeTest_TestScope scope = new ScopeTest_TestScope(errorListener);
(...skipping 1145 matching lines...) Expand 10 before | Expand all | Expand 10 after
7930 void test_visitAdjacentStrings() { 7937 void test_visitAdjacentStrings() {
7931 // "a" "b" 7938 // "a" "b"
7932 Expression node = AstFactory.adjacentStrings([_resolvedString("a"), _resolve dString("b")]); 7939 Expression node = AstFactory.adjacentStrings([_resolvedString("a"), _resolve dString("b")]);
7933 expect(_analyze(node), same(_typeProvider.stringType)); 7940 expect(_analyze(node), same(_typeProvider.stringType));
7934 _listener.assertNoErrors(); 7941 _listener.assertNoErrors();
7935 } 7942 }
7936 7943
7937 void test_visitAsExpression() { 7944 void test_visitAsExpression() {
7938 // class A { ... this as B ... } 7945 // class A { ... this as B ... }
7939 // class B extends A {} 7946 // class B extends A {}
7940 ClassElement superclass = ElementFactory.classElement2("A", []); 7947 ClassElement superclass = ElementFactory.classElement2("A");
7941 InterfaceType superclassType = superclass.type; 7948 InterfaceType superclassType = superclass.type;
7942 ClassElement subclass = ElementFactory.classElement("B", superclassType, []) ; 7949 ClassElement subclass = ElementFactory.classElement("B", superclassType);
7943 Expression node = AstFactory.asExpression(AstFactory.thisExpression(), AstFa ctory.typeName(subclass, [])); 7950 Expression node = AstFactory.asExpression(AstFactory.thisExpression(), AstFa ctory.typeName(subclass));
7944 expect(_analyze3(node, superclassType), same(subclass.type)); 7951 expect(_analyze3(node, superclassType), same(subclass.type));
7945 _listener.assertNoErrors(); 7952 _listener.assertNoErrors();
7946 } 7953 }
7947 7954
7948 void test_visitAssignmentExpression_compound() { 7955 void test_visitAssignmentExpression_compound() {
7949 // i += 1 7956 // i += 1
7950 InterfaceType numType = _typeProvider.numType; 7957 InterfaceType numType = _typeProvider.numType;
7951 SimpleIdentifier identifier = _resolvedVariable(_typeProvider.intType, "i"); 7958 SimpleIdentifier identifier = _resolvedVariable(_typeProvider.intType, "i");
7952 AssignmentExpression node = AstFactory.assignmentExpression(identifier, Toke nType.PLUS_EQ, _resolvedInteger(1)); 7959 AssignmentExpression node = AstFactory.assignmentExpression(identifier, Toke nType.PLUS_EQ, _resolvedInteger(1));
7953 MethodElement plusMethod = getMethod(numType, "+"); 7960 MethodElement plusMethod = getMethod(numType, "+");
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
8014 node.staticElement = getMethod(_typeProvider.numType, "/"); 8021 node.staticElement = getMethod(_typeProvider.numType, "/");
8015 expect(_analyze(node), same(_typeProvider.doubleType)); 8022 expect(_analyze(node), same(_typeProvider.doubleType));
8016 _listener.assertNoErrors(); 8023 _listener.assertNoErrors();
8017 } 8024 }
8018 8025
8019 void test_visitBinaryExpression_star_notSpecial() { 8026 void test_visitBinaryExpression_star_notSpecial() {
8020 // class A { 8027 // class A {
8021 // A operator *(double value); 8028 // A operator *(double value);
8022 // } 8029 // }
8023 // (a as A) * 2.0 8030 // (a as A) * 2.0
8024 ClassElementImpl classA = ElementFactory.classElement2("A", []); 8031 ClassElementImpl classA = ElementFactory.classElement2("A");
8025 InterfaceType typeA = classA.type; 8032 InterfaceType typeA = classA.type;
8026 MethodElement operator = ElementFactory.methodElement("*", typeA, [_typeProv ider.doubleType]); 8033 MethodElement operator = ElementFactory.methodElement("*", typeA, [_typeProv ider.doubleType]);
8027 classA.methods = <MethodElement> [operator]; 8034 classA.methods = <MethodElement> [operator];
8028 BinaryExpression node = AstFactory.binaryExpression(AstFactory.asExpression( AstFactory.identifier3("a"), AstFactory.typeName(classA, [])), TokenType.PLUS, _ resolvedDouble(2.0)); 8035 BinaryExpression node = AstFactory.binaryExpression(AstFactory.asExpression( AstFactory.identifier3("a"), AstFactory.typeName(classA)), TokenType.PLUS, _reso lvedDouble(2.0));
8029 node.staticElement = operator; 8036 node.staticElement = operator;
8030 expect(_analyze(node), same(typeA)); 8037 expect(_analyze(node), same(typeA));
8031 _listener.assertNoErrors(); 8038 _listener.assertNoErrors();
8032 } 8039 }
8033 8040
8034 void test_visitBinaryExpression_starID() { 8041 void test_visitBinaryExpression_starID() {
8035 // 1 * 2.0 8042 // 1 * 2.0
8036 BinaryExpression node = AstFactory.binaryExpression(_resolvedInteger(1), Tok enType.PLUS, _resolvedDouble(2.0)); 8043 BinaryExpression node = AstFactory.binaryExpression(_resolvedInteger(1), Tok enType.PLUS, _resolvedDouble(2.0));
8037 node.staticElement = getMethod(_typeProvider.numType, "*"); 8044 node.staticElement = getMethod(_typeProvider.numType, "*");
8038 expect(_analyze(node), same(_typeProvider.doubleType)); 8045 expect(_analyze(node), same(_typeProvider.doubleType));
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
8081 _listener.assertNoErrors(); 8088 _listener.assertNoErrors();
8082 } 8089 }
8083 8090
8084 void test_visitFunctionExpression_named_block() { 8091 void test_visitFunctionExpression_named_block() {
8085 // ({p1 : 0, p2 : 0}) {} 8092 // ({p1 : 0, p2 : 0}) {}
8086 DartType dynamicType = _typeProvider.dynamicType; 8093 DartType dynamicType = _typeProvider.dynamicType;
8087 FormalParameter p1 = AstFactory.namedFormalParameter(AstFactory.simpleFormal Parameter3("p1"), _resolvedInteger(0)); 8094 FormalParameter p1 = AstFactory.namedFormalParameter(AstFactory.simpleFormal Parameter3("p1"), _resolvedInteger(0));
8088 _setType(p1, dynamicType); 8095 _setType(p1, dynamicType);
8089 FormalParameter p2 = AstFactory.namedFormalParameter(AstFactory.simpleFormal Parameter3("p2"), _resolvedInteger(0)); 8096 FormalParameter p2 = AstFactory.namedFormalParameter(AstFactory.simpleFormal Parameter3("p2"), _resolvedInteger(0));
8090 _setType(p2, dynamicType); 8097 _setType(p2, dynamicType);
8091 FunctionExpression node = _resolvedFunctionExpression(AstFactory.formalParam eterList([p1, p2]), AstFactory.blockFunctionBody2([])); 8098 FunctionExpression node = _resolvedFunctionExpression(AstFactory.formalParam eterList([p1, p2]), AstFactory.blockFunctionBody2());
8092 _analyze5(p1); 8099 _analyze5(p1);
8093 _analyze5(p2); 8100 _analyze5(p2);
8094 DartType resultType = _analyze(node); 8101 DartType resultType = _analyze(node);
8095 Map<String, DartType> expectedNamedTypes = new HashMap<String, DartType>(); 8102 Map<String, DartType> expectedNamedTypes = new HashMap<String, DartType>();
8096 expectedNamedTypes["p1"] = dynamicType; 8103 expectedNamedTypes["p1"] = dynamicType;
8097 expectedNamedTypes["p2"] = dynamicType; 8104 expectedNamedTypes["p2"] = dynamicType;
8098 _assertFunctionType(dynamicType, null, null, expectedNamedTypes, resultType) ; 8105 _assertFunctionType(dynamicType, null, null, expectedNamedTypes, resultType) ;
8099 _listener.assertNoErrors(); 8106 _listener.assertNoErrors();
8100 } 8107 }
8101 8108
(...skipping 11 matching lines...) Expand all
8113 _listener.assertNoErrors(); 8120 _listener.assertNoErrors();
8114 } 8121 }
8115 8122
8116 void test_visitFunctionExpression_normal_block() { 8123 void test_visitFunctionExpression_normal_block() {
8117 // (p1, p2) {} 8124 // (p1, p2) {}
8118 DartType dynamicType = _typeProvider.dynamicType; 8125 DartType dynamicType = _typeProvider.dynamicType;
8119 FormalParameter p1 = AstFactory.simpleFormalParameter3("p1"); 8126 FormalParameter p1 = AstFactory.simpleFormalParameter3("p1");
8120 _setType(p1, dynamicType); 8127 _setType(p1, dynamicType);
8121 FormalParameter p2 = AstFactory.simpleFormalParameter3("p2"); 8128 FormalParameter p2 = AstFactory.simpleFormalParameter3("p2");
8122 _setType(p2, dynamicType); 8129 _setType(p2, dynamicType);
8123 FunctionExpression node = _resolvedFunctionExpression(AstFactory.formalParam eterList([p1, p2]), AstFactory.blockFunctionBody2([])); 8130 FunctionExpression node = _resolvedFunctionExpression(AstFactory.formalParam eterList([p1, p2]), AstFactory.blockFunctionBody2());
8124 _analyze5(p1); 8131 _analyze5(p1);
8125 _analyze5(p2); 8132 _analyze5(p2);
8126 DartType resultType = _analyze(node); 8133 DartType resultType = _analyze(node);
8127 _assertFunctionType(dynamicType, <DartType> [dynamicType, dynamicType], null , null, resultType); 8134 _assertFunctionType(dynamicType, <DartType> [dynamicType, dynamicType], null , null, resultType);
8128 _listener.assertNoErrors(); 8135 _listener.assertNoErrors();
8129 } 8136 }
8130 8137
8131 void test_visitFunctionExpression_normal_expression() { 8138 void test_visitFunctionExpression_normal_expression() {
8132 // (p1, p2) -> 0 8139 // (p1, p2) -> 0
8133 DartType dynamicType = _typeProvider.dynamicType; 8140 DartType dynamicType = _typeProvider.dynamicType;
8134 FormalParameter p = AstFactory.simpleFormalParameter3("p"); 8141 FormalParameter p = AstFactory.simpleFormalParameter3("p");
8135 _setType(p, dynamicType); 8142 _setType(p, dynamicType);
8136 FunctionExpression node = _resolvedFunctionExpression(AstFactory.formalParam eterList([p]), AstFactory.expressionFunctionBody(_resolvedInteger(0))); 8143 FunctionExpression node = _resolvedFunctionExpression(AstFactory.formalParam eterList([p]), AstFactory.expressionFunctionBody(_resolvedInteger(0)));
8137 _analyze5(p); 8144 _analyze5(p);
8138 DartType resultType = _analyze(node); 8145 DartType resultType = _analyze(node);
8139 _assertFunctionType(_typeProvider.intType, <DartType> [dynamicType], null, n ull, resultType); 8146 _assertFunctionType(_typeProvider.intType, <DartType> [dynamicType], null, n ull, resultType);
8140 _listener.assertNoErrors(); 8147 _listener.assertNoErrors();
8141 } 8148 }
8142 8149
8143 void test_visitFunctionExpression_normalAndNamed_block() { 8150 void test_visitFunctionExpression_normalAndNamed_block() {
8144 // (p1, {p2 : 0}) {} 8151 // (p1, {p2 : 0}) {}
8145 DartType dynamicType = _typeProvider.dynamicType; 8152 DartType dynamicType = _typeProvider.dynamicType;
8146 FormalParameter p1 = AstFactory.simpleFormalParameter3("p1"); 8153 FormalParameter p1 = AstFactory.simpleFormalParameter3("p1");
8147 _setType(p1, dynamicType); 8154 _setType(p1, dynamicType);
8148 FormalParameter p2 = AstFactory.namedFormalParameter(AstFactory.simpleFormal Parameter3("p2"), _resolvedInteger(0)); 8155 FormalParameter p2 = AstFactory.namedFormalParameter(AstFactory.simpleFormal Parameter3("p2"), _resolvedInteger(0));
8149 _setType(p2, dynamicType); 8156 _setType(p2, dynamicType);
8150 FunctionExpression node = _resolvedFunctionExpression(AstFactory.formalParam eterList([p1, p2]), AstFactory.blockFunctionBody2([])); 8157 FunctionExpression node = _resolvedFunctionExpression(AstFactory.formalParam eterList([p1, p2]), AstFactory.blockFunctionBody2());
8151 _analyze5(p2); 8158 _analyze5(p2);
8152 DartType resultType = _analyze(node); 8159 DartType resultType = _analyze(node);
8153 Map<String, DartType> expectedNamedTypes = new HashMap<String, DartType>(); 8160 Map<String, DartType> expectedNamedTypes = new HashMap<String, DartType>();
8154 expectedNamedTypes["p2"] = dynamicType; 8161 expectedNamedTypes["p2"] = dynamicType;
8155 _assertFunctionType(dynamicType, <DartType> [dynamicType], null, expectedNam edTypes, resultType); 8162 _assertFunctionType(dynamicType, <DartType> [dynamicType], null, expectedNam edTypes, resultType);
8156 _listener.assertNoErrors(); 8163 _listener.assertNoErrors();
8157 } 8164 }
8158 8165
8159 void test_visitFunctionExpression_normalAndNamed_expression() { 8166 void test_visitFunctionExpression_normalAndNamed_expression() {
8160 // (p1, {p2 : 0}) -> 0 8167 // (p1, {p2 : 0}) -> 0
(...skipping 11 matching lines...) Expand all
8172 _listener.assertNoErrors(); 8179 _listener.assertNoErrors();
8173 } 8180 }
8174 8181
8175 void test_visitFunctionExpression_normalAndPositional_block() { 8182 void test_visitFunctionExpression_normalAndPositional_block() {
8176 // (p1, [p2 = 0]) {} 8183 // (p1, [p2 = 0]) {}
8177 DartType dynamicType = _typeProvider.dynamicType; 8184 DartType dynamicType = _typeProvider.dynamicType;
8178 FormalParameter p1 = AstFactory.simpleFormalParameter3("p1"); 8185 FormalParameter p1 = AstFactory.simpleFormalParameter3("p1");
8179 _setType(p1, dynamicType); 8186 _setType(p1, dynamicType);
8180 FormalParameter p2 = AstFactory.positionalFormalParameter(AstFactory.simpleF ormalParameter3("p2"), _resolvedInteger(0)); 8187 FormalParameter p2 = AstFactory.positionalFormalParameter(AstFactory.simpleF ormalParameter3("p2"), _resolvedInteger(0));
8181 _setType(p2, dynamicType); 8188 _setType(p2, dynamicType);
8182 FunctionExpression node = _resolvedFunctionExpression(AstFactory.formalParam eterList([p1, p2]), AstFactory.blockFunctionBody2([])); 8189 FunctionExpression node = _resolvedFunctionExpression(AstFactory.formalParam eterList([p1, p2]), AstFactory.blockFunctionBody2());
8183 _analyze5(p1); 8190 _analyze5(p1);
8184 _analyze5(p2); 8191 _analyze5(p2);
8185 DartType resultType = _analyze(node); 8192 DartType resultType = _analyze(node);
8186 _assertFunctionType(dynamicType, <DartType> [dynamicType], <DartType> [dynam icType], null, resultType); 8193 _assertFunctionType(dynamicType, <DartType> [dynamicType], <DartType> [dynam icType], null, resultType);
8187 _listener.assertNoErrors(); 8194 _listener.assertNoErrors();
8188 } 8195 }
8189 8196
8190 void test_visitFunctionExpression_normalAndPositional_expression() { 8197 void test_visitFunctionExpression_normalAndPositional_expression() {
8191 // (p1, [p2 = 0]) -> 0 8198 // (p1, [p2 = 0]) -> 0
8192 DartType dynamicType = _typeProvider.dynamicType; 8199 DartType dynamicType = _typeProvider.dynamicType;
8193 FormalParameter p1 = AstFactory.simpleFormalParameter3("p1"); 8200 FormalParameter p1 = AstFactory.simpleFormalParameter3("p1");
8194 _setType(p1, dynamicType); 8201 _setType(p1, dynamicType);
8195 FormalParameter p2 = AstFactory.positionalFormalParameter(AstFactory.simpleF ormalParameter3("p2"), _resolvedInteger(0)); 8202 FormalParameter p2 = AstFactory.positionalFormalParameter(AstFactory.simpleF ormalParameter3("p2"), _resolvedInteger(0));
8196 _setType(p2, dynamicType); 8203 _setType(p2, dynamicType);
8197 FunctionExpression node = _resolvedFunctionExpression(AstFactory.formalParam eterList([p1, p2]), AstFactory.expressionFunctionBody(_resolvedInteger(0))); 8204 FunctionExpression node = _resolvedFunctionExpression(AstFactory.formalParam eterList([p1, p2]), AstFactory.expressionFunctionBody(_resolvedInteger(0)));
8198 _analyze5(p1); 8205 _analyze5(p1);
8199 _analyze5(p2); 8206 _analyze5(p2);
8200 DartType resultType = _analyze(node); 8207 DartType resultType = _analyze(node);
8201 _assertFunctionType(_typeProvider.intType, <DartType> [dynamicType], <DartTy pe> [dynamicType], null, resultType); 8208 _assertFunctionType(_typeProvider.intType, <DartType> [dynamicType], <DartTy pe> [dynamicType], null, resultType);
8202 _listener.assertNoErrors(); 8209 _listener.assertNoErrors();
8203 } 8210 }
8204 8211
8205 void test_visitFunctionExpression_positional_block() { 8212 void test_visitFunctionExpression_positional_block() {
8206 // ([p1 = 0, p2 = 0]) {} 8213 // ([p1 = 0, p2 = 0]) {}
8207 DartType dynamicType = _typeProvider.dynamicType; 8214 DartType dynamicType = _typeProvider.dynamicType;
8208 FormalParameter p1 = AstFactory.positionalFormalParameter(AstFactory.simpleF ormalParameter3("p1"), _resolvedInteger(0)); 8215 FormalParameter p1 = AstFactory.positionalFormalParameter(AstFactory.simpleF ormalParameter3("p1"), _resolvedInteger(0));
8209 _setType(p1, dynamicType); 8216 _setType(p1, dynamicType);
8210 FormalParameter p2 = AstFactory.positionalFormalParameter(AstFactory.simpleF ormalParameter3("p2"), _resolvedInteger(0)); 8217 FormalParameter p2 = AstFactory.positionalFormalParameter(AstFactory.simpleF ormalParameter3("p2"), _resolvedInteger(0));
8211 _setType(p2, dynamicType); 8218 _setType(p2, dynamicType);
8212 FunctionExpression node = _resolvedFunctionExpression(AstFactory.formalParam eterList([p1, p2]), AstFactory.blockFunctionBody2([])); 8219 FunctionExpression node = _resolvedFunctionExpression(AstFactory.formalParam eterList([p1, p2]), AstFactory.blockFunctionBody2());
8213 _analyze5(p1); 8220 _analyze5(p1);
8214 _analyze5(p2); 8221 _analyze5(p2);
8215 DartType resultType = _analyze(node); 8222 DartType resultType = _analyze(node);
8216 _assertFunctionType(dynamicType, null, <DartType> [dynamicType, dynamicType] , null, resultType); 8223 _assertFunctionType(dynamicType, null, <DartType> [dynamicType, dynamicType] , null, resultType);
8217 _listener.assertNoErrors(); 8224 _listener.assertNoErrors();
8218 } 8225 }
8219 8226
8220 void test_visitFunctionExpression_positional_expression() { 8227 void test_visitFunctionExpression_positional_expression() {
8221 // ([p1 = 0, p2 = 0]) -> 0 8228 // ([p1 = 0, p2 = 0]) -> 0
8222 DartType dynamicType = _typeProvider.dynamicType; 8229 DartType dynamicType = _typeProvider.dynamicType;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
8291 indexExpression.staticElement = indexMethod; 8298 indexExpression.staticElement = indexMethod;
8292 // list[0] should be in a setter context 8299 // list[0] should be in a setter context
8293 AstFactory.assignmentExpression(indexExpression, TokenType.EQ, AstFactory.in teger(0)); 8300 AstFactory.assignmentExpression(indexExpression, TokenType.EQ, AstFactory.in teger(0));
8294 // analyze and assert result of the index expression 8301 // analyze and assert result of the index expression
8295 expect(_analyze(indexExpression), same(intType)); 8302 expect(_analyze(indexExpression), same(intType));
8296 _listener.assertNoErrors(); 8303 _listener.assertNoErrors();
8297 } 8304 }
8298 8305
8299 void test_visitInstanceCreationExpression_named() { 8306 void test_visitInstanceCreationExpression_named() {
8300 // new C.m() 8307 // new C.m()
8301 ClassElementImpl classElement = ElementFactory.classElement2("C", []); 8308 ClassElementImpl classElement = ElementFactory.classElement2("C");
8302 String constructorName = "m"; 8309 String constructorName = "m";
8303 ConstructorElementImpl constructor = ElementFactory.constructorElement2(clas sElement, constructorName, []); 8310 ConstructorElementImpl constructor = ElementFactory.constructorElement2(clas sElement, constructorName);
8304 constructor.returnType = classElement.type; 8311 constructor.returnType = classElement.type;
8305 FunctionTypeImpl constructorType = new FunctionTypeImpl.con1(constructor); 8312 FunctionTypeImpl constructorType = new FunctionTypeImpl.con1(constructor);
8306 constructor.type = constructorType; 8313 constructor.type = constructorType;
8307 classElement.constructors = <ConstructorElement> [constructor]; 8314 classElement.constructors = <ConstructorElement> [constructor];
8308 InstanceCreationExpression node = AstFactory.instanceCreationExpression2(nul l, AstFactory.typeName(classElement, []), [AstFactory.identifier3(constructorNam e)]); 8315 InstanceCreationExpression node = AstFactory.instanceCreationExpression2(nul l, AstFactory.typeName(classElement), [AstFactory.identifier3(constructorName)]) ;
8309 node.staticElement = constructor; 8316 node.staticElement = constructor;
8310 expect(_analyze(node), same(classElement.type)); 8317 expect(_analyze(node), same(classElement.type));
8311 _listener.assertNoErrors(); 8318 _listener.assertNoErrors();
8312 } 8319 }
8313 8320
8314 void test_visitInstanceCreationExpression_typeParameters() { 8321 void test_visitInstanceCreationExpression_typeParameters() {
8315 // new C<I>() 8322 // new C<I>()
8316 ClassElementImpl elementC = ElementFactory.classElement2("C", ["E"]); 8323 ClassElementImpl elementC = ElementFactory.classElement2("C", ["E"]);
8317 ClassElementImpl elementI = ElementFactory.classElement2("I", []); 8324 ClassElementImpl elementI = ElementFactory.classElement2("I");
8318 ConstructorElementImpl constructor = ElementFactory.constructorElement2(elem entC, null, []); 8325 ConstructorElementImpl constructor = ElementFactory.constructorElement2(elem entC, null);
8319 elementC.constructors = <ConstructorElement> [constructor]; 8326 elementC.constructors = <ConstructorElement> [constructor];
8320 constructor.returnType = elementC.type; 8327 constructor.returnType = elementC.type;
8321 FunctionTypeImpl constructorType = new FunctionTypeImpl.con1(constructor); 8328 FunctionTypeImpl constructorType = new FunctionTypeImpl.con1(constructor);
8322 constructor.type = constructorType; 8329 constructor.type = constructorType;
8323 TypeName typeName = AstFactory.typeName(elementC, [AstFactory.typeName(eleme ntI, [])]); 8330 TypeName typeName = AstFactory.typeName(elementC, [AstFactory.typeName(eleme ntI)]);
8324 typeName.type = elementC.type.substitute4(<DartType> [elementI.type]); 8331 typeName.type = elementC.type.substitute4(<DartType> [elementI.type]);
8325 InstanceCreationExpression node = AstFactory.instanceCreationExpression2(nul l, typeName, []); 8332 InstanceCreationExpression node = AstFactory.instanceCreationExpression2(nul l, typeName);
8326 node.staticElement = constructor; 8333 node.staticElement = constructor;
8327 InterfaceType interfaceType = _analyze(node) as InterfaceType; 8334 InterfaceType interfaceType = _analyze(node) as InterfaceType;
8328 List<DartType> typeArgs = interfaceType.typeArguments; 8335 List<DartType> typeArgs = interfaceType.typeArguments;
8329 expect(typeArgs.length, 1); 8336 expect(typeArgs.length, 1);
8330 expect(typeArgs[0], elementI.type); 8337 expect(typeArgs[0], elementI.type);
8331 _listener.assertNoErrors(); 8338 _listener.assertNoErrors();
8332 } 8339 }
8333 8340
8334 void test_visitInstanceCreationExpression_unnamed() { 8341 void test_visitInstanceCreationExpression_unnamed() {
8335 // new C() 8342 // new C()
8336 ClassElementImpl classElement = ElementFactory.classElement2("C", []); 8343 ClassElementImpl classElement = ElementFactory.classElement2("C");
8337 ConstructorElementImpl constructor = ElementFactory.constructorElement2(clas sElement, null, []); 8344 ConstructorElementImpl constructor = ElementFactory.constructorElement2(clas sElement, null);
8338 constructor.returnType = classElement.type; 8345 constructor.returnType = classElement.type;
8339 FunctionTypeImpl constructorType = new FunctionTypeImpl.con1(constructor); 8346 FunctionTypeImpl constructorType = new FunctionTypeImpl.con1(constructor);
8340 constructor.type = constructorType; 8347 constructor.type = constructorType;
8341 classElement.constructors = <ConstructorElement> [constructor]; 8348 classElement.constructors = <ConstructorElement> [constructor];
8342 InstanceCreationExpression node = AstFactory.instanceCreationExpression2(nul l, AstFactory.typeName(classElement, []), []); 8349 InstanceCreationExpression node = AstFactory.instanceCreationExpression2(nul l, AstFactory.typeName(classElement));
8343 node.staticElement = constructor; 8350 node.staticElement = constructor;
8344 expect(_analyze(node), same(classElement.type)); 8351 expect(_analyze(node), same(classElement.type));
8345 _listener.assertNoErrors(); 8352 _listener.assertNoErrors();
8346 } 8353 }
8347 8354
8348 void test_visitIntegerLiteral() { 8355 void test_visitIntegerLiteral() {
8349 // 42 8356 // 42
8350 Expression node = _resolvedInteger(42); 8357 Expression node = _resolvedInteger(42);
8351 expect(_analyze(node), same(_typeProvider.intType)); 8358 expect(_analyze(node), same(_typeProvider.intType));
8352 _listener.assertNoErrors(); 8359 _listener.assertNoErrors();
8353 } 8360 }
8354 8361
8355 void test_visitIsExpression_negated() { 8362 void test_visitIsExpression_negated() {
8356 // a is! String 8363 // a is! String
8357 Expression node = AstFactory.isExpression(_resolvedString("a"), true, AstFac tory.typeName4("String", [])); 8364 Expression node = AstFactory.isExpression(_resolvedString("a"), true, AstFac tory.typeName4("String"));
8358 expect(_analyze(node), same(_typeProvider.boolType)); 8365 expect(_analyze(node), same(_typeProvider.boolType));
8359 _listener.assertNoErrors(); 8366 _listener.assertNoErrors();
8360 } 8367 }
8361 8368
8362 void test_visitIsExpression_notNegated() { 8369 void test_visitIsExpression_notNegated() {
8363 // a is String 8370 // a is String
8364 Expression node = AstFactory.isExpression(_resolvedString("a"), false, AstFa ctory.typeName4("String", [])); 8371 Expression node = AstFactory.isExpression(_resolvedString("a"), false, AstFa ctory.typeName4("String"));
8365 expect(_analyze(node), same(_typeProvider.boolType)); 8372 expect(_analyze(node), same(_typeProvider.boolType));
8366 _listener.assertNoErrors(); 8373 _listener.assertNoErrors();
8367 } 8374 }
8368 8375
8369 void test_visitListLiteral_empty() { 8376 void test_visitListLiteral_empty() {
8370 // [] 8377 // []
8371 Expression node = AstFactory.listLiteral([]); 8378 Expression node = AstFactory.listLiteral();
8372 DartType resultType = _analyze(node); 8379 DartType resultType = _analyze(node);
8373 _assertType2(_typeProvider.listType.substitute4(<DartType> [_typeProvider.dy namicType]), resultType); 8380 _assertType2(_typeProvider.listType.substitute4(<DartType> [_typeProvider.dy namicType]), resultType);
8374 _listener.assertNoErrors(); 8381 _listener.assertNoErrors();
8375 } 8382 }
8376 8383
8377 void test_visitListLiteral_nonEmpty() { 8384 void test_visitListLiteral_nonEmpty() {
8378 // [0] 8385 // [0]
8379 Expression node = AstFactory.listLiteral([_resolvedInteger(0)]); 8386 Expression node = AstFactory.listLiteral([_resolvedInteger(0)]);
8380 DartType resultType = _analyze(node); 8387 DartType resultType = _analyze(node);
8381 _assertType2(_typeProvider.listType.substitute4(<DartType> [_typeProvider.dy namicType]), resultType); 8388 _assertType2(_typeProvider.listType.substitute4(<DartType> [_typeProvider.dy namicType]), resultType);
8382 _listener.assertNoErrors(); 8389 _listener.assertNoErrors();
8383 } 8390 }
8384 8391
8385 void test_visitMapLiteral_empty() { 8392 void test_visitMapLiteral_empty() {
8386 // {} 8393 // {}
8387 Expression node = AstFactory.mapLiteral2([]); 8394 Expression node = AstFactory.mapLiteral2();
8388 DartType resultType = _analyze(node); 8395 DartType resultType = _analyze(node);
8389 _assertType2(_typeProvider.mapType.substitute4(<DartType> [_typeProvider.dyn amicType, _typeProvider.dynamicType]), resultType); 8396 _assertType2(_typeProvider.mapType.substitute4(<DartType> [_typeProvider.dyn amicType, _typeProvider.dynamicType]), resultType);
8390 _listener.assertNoErrors(); 8397 _listener.assertNoErrors();
8391 } 8398 }
8392 8399
8393 void test_visitMapLiteral_nonEmpty() { 8400 void test_visitMapLiteral_nonEmpty() {
8394 // {"k" : 0} 8401 // {"k" : 0}
8395 Expression node = AstFactory.mapLiteral2([AstFactory.mapLiteralEntry("k", _r esolvedInteger(0))]); 8402 Expression node = AstFactory.mapLiteral2([AstFactory.mapLiteralEntry("k", _r esolvedInteger(0))]);
8396 DartType resultType = _analyze(node); 8403 DartType resultType = _analyze(node);
8397 _assertType2(_typeProvider.mapType.substitute4(<DartType> [_typeProvider.dyn amicType, _typeProvider.dynamicType]), resultType); 8404 _assertType2(_typeProvider.mapType.substitute4(<DartType> [_typeProvider.dyn amicType, _typeProvider.dynamicType]), resultType);
8398 _listener.assertNoErrors(); 8405 _listener.assertNoErrors();
8399 } 8406 }
8400 8407
8401 void test_visitMethodInvocation_then() { 8408 void test_visitMethodInvocation_then() {
8402 // then() 8409 // then()
8403 Expression node = AstFactory.methodInvocation(null, "then", []); 8410 Expression node = AstFactory.methodInvocation(null, "then");
8404 _analyze(node); 8411 _analyze(node);
8405 _listener.assertNoErrors(); 8412 _listener.assertNoErrors();
8406 } 8413 }
8407 8414
8408 void test_visitNamedExpression() { 8415 void test_visitNamedExpression() {
8409 // n: a 8416 // n: a
8410 Expression node = AstFactory.namedExpression2("n", _resolvedString("a")); 8417 Expression node = AstFactory.namedExpression2("n", _resolvedString("a"));
8411 expect(_analyze(node), same(_typeProvider.stringType)); 8418 expect(_analyze(node), same(_typeProvider.stringType));
8412 _listener.assertNoErrors(); 8419 _listener.assertNoErrors();
8413 } 8420 }
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
8578 Expression node = AstFactory.string([ 8585 Expression node = AstFactory.string([
8579 AstFactory.interpolationString("a", "a"), 8586 AstFactory.interpolationString("a", "a"),
8580 AstFactory.interpolationExpression(_resolvedString("b")), 8587 AstFactory.interpolationExpression(_resolvedString("b")),
8581 AstFactory.interpolationString("c", "c")]); 8588 AstFactory.interpolationString("c", "c")]);
8582 expect(_analyze(node), same(_typeProvider.stringType)); 8589 expect(_analyze(node), same(_typeProvider.stringType));
8583 _listener.assertNoErrors(); 8590 _listener.assertNoErrors();
8584 } 8591 }
8585 8592
8586 void test_visitSuperExpression() { 8593 void test_visitSuperExpression() {
8587 // super 8594 // super
8588 InterfaceType superType = ElementFactory.classElement2("A", []).type; 8595 InterfaceType superType = ElementFactory.classElement2("A").type;
8589 InterfaceType thisType = ElementFactory.classElement("B", superType, []).typ e; 8596 InterfaceType thisType = ElementFactory.classElement("B", superType).type;
8590 Expression node = AstFactory.superExpression(); 8597 Expression node = AstFactory.superExpression();
8591 expect(_analyze3(node, thisType), same(thisType)); 8598 expect(_analyze3(node, thisType), same(thisType));
8592 _listener.assertNoErrors(); 8599 _listener.assertNoErrors();
8593 } 8600 }
8594 8601
8595 void test_visitSymbolLiteral() { 8602 void test_visitSymbolLiteral() {
8596 expect(_analyze(AstFactory.symbolLiteral(["a"])), same(_typeProvider.symbolT ype)); 8603 expect(_analyze(AstFactory.symbolLiteral(["a"])), same(_typeProvider.symbolT ype));
8597 } 8604 }
8598 8605
8599 void test_visitThisExpression() { 8606 void test_visitThisExpression() {
8600 // this 8607 // this
8601 InterfaceType thisType = ElementFactory.classElement("B", ElementFactory.cla ssElement2("A", []).type, []).type; 8608 InterfaceType thisType = ElementFactory.classElement("B", ElementFactory.cla ssElement2("A").type).type;
8602 Expression node = AstFactory.thisExpression(); 8609 Expression node = AstFactory.thisExpression();
8603 expect(_analyze3(node, thisType), same(thisType)); 8610 expect(_analyze3(node, thisType), same(thisType));
8604 _listener.assertNoErrors(); 8611 _listener.assertNoErrors();
8605 } 8612 }
8606 8613
8607 void test_visitThrowExpression_withoutValue() { 8614 void test_visitThrowExpression_withoutValue() {
8608 // throw 8615 // throw
8609 Expression node = AstFactory.throwExpression(); 8616 Expression node = AstFactory.throwExpression();
8610 expect(_analyze(node), same(_typeProvider.bottomType)); 8617 expect(_analyze(node), same(_typeProvider.bottomType));
8611 _listener.assertNoErrors(); 8618 _listener.assertNoErrors();
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after
9315 /** 9322 /**
9316 * The compilation unit element containing all of the types setup in each test . 9323 * The compilation unit element containing all of the types setup in each test .
9317 */ 9324 */
9318 CompilationUnitElementImpl _definingCompilationUnit; 9325 CompilationUnitElementImpl _definingCompilationUnit;
9319 9326
9320 void test_computeAllSubtypes_infiniteLoop() { 9327 void test_computeAllSubtypes_infiniteLoop() {
9321 // 9328 //
9322 // class A extends B 9329 // class A extends B
9323 // class B extends A 9330 // class B extends A
9324 // 9331 //
9325 ClassElementImpl classA = ElementFactory.classElement2("A", []); 9332 ClassElementImpl classA = ElementFactory.classElement2("A");
9326 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); 9333 ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
9327 classA.supertype = classB.type; 9334 classA.supertype = classB.type;
9328 _definingCompilationUnit.types = <ClassElement> [classA, classB]; 9335 _definingCompilationUnit.types = <ClassElement> [classA, classB];
9329 HashSet<ClassElement> subtypesOfA = _subtypeManager.computeAllSubtypes(class A); 9336 HashSet<ClassElement> subtypesOfA = _subtypeManager.computeAllSubtypes(class A);
9330 List<ClassElement> arraySubtypesOfA = new List.from(subtypesOfA); 9337 List<ClassElement> arraySubtypesOfA = new List.from(subtypesOfA);
9331 expect(subtypesOfA, hasLength(2)); 9338 expect(subtypesOfA, hasLength(2));
9332 expect(arraySubtypesOfA, unorderedEquals([classA, classB])); 9339 expect(arraySubtypesOfA, unorderedEquals([classA, classB]));
9333 } 9340 }
9334 9341
9335 void test_computeAllSubtypes_manyRecursiveSubtypes() { 9342 void test_computeAllSubtypes_manyRecursiveSubtypes() {
9336 // 9343 //
9337 // class A 9344 // class A
9338 // class B extends A 9345 // class B extends A
9339 // class C extends B 9346 // class C extends B
9340 // class D extends B 9347 // class D extends B
9341 // class E extends B 9348 // class E extends B
9342 // 9349 //
9343 ClassElementImpl classA = ElementFactory.classElement2("A", []); 9350 ClassElementImpl classA = ElementFactory.classElement2("A");
9344 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); 9351 ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
9345 ClassElementImpl classC = ElementFactory.classElement("C", classB.type, []); 9352 ClassElementImpl classC = ElementFactory.classElement("C", classB.type);
9346 ClassElementImpl classD = ElementFactory.classElement("D", classB.type, []); 9353 ClassElementImpl classD = ElementFactory.classElement("D", classB.type);
9347 ClassElementImpl classE = ElementFactory.classElement("E", classB.type, []); 9354 ClassElementImpl classE = ElementFactory.classElement("E", classB.type);
9348 _definingCompilationUnit.types = <ClassElement> [classA, classB, classC, cla ssD, classE]; 9355 _definingCompilationUnit.types = <ClassElement> [classA, classB, classC, cla ssD, classE];
9349 HashSet<ClassElement> subtypesOfA = _subtypeManager.computeAllSubtypes(class A); 9356 HashSet<ClassElement> subtypesOfA = _subtypeManager.computeAllSubtypes(class A);
9350 List<ClassElement> arraySubtypesOfA = new List.from(subtypesOfA); 9357 List<ClassElement> arraySubtypesOfA = new List.from(subtypesOfA);
9351 HashSet<ClassElement> subtypesOfB = _subtypeManager.computeAllSubtypes(class B); 9358 HashSet<ClassElement> subtypesOfB = _subtypeManager.computeAllSubtypes(class B);
9352 List<ClassElement> arraySubtypesOfB = new List.from(subtypesOfB); 9359 List<ClassElement> arraySubtypesOfB = new List.from(subtypesOfB);
9353 expect(subtypesOfA, hasLength(4)); 9360 expect(subtypesOfA, hasLength(4));
9354 expect(arraySubtypesOfA, unorderedEquals([classB, classC, classD, classE])); 9361 expect(arraySubtypesOfA, unorderedEquals([classB, classC, classD, classE]));
9355 expect(subtypesOfB, hasLength(3)); 9362 expect(subtypesOfB, hasLength(3));
9356 expect(arraySubtypesOfB, unorderedEquals([classC, classD, classE])); 9363 expect(arraySubtypesOfB, unorderedEquals([classC, classD, classE]));
9357 } 9364 }
9358 9365
9359 void test_computeAllSubtypes_noSubtypes() { 9366 void test_computeAllSubtypes_noSubtypes() {
9360 // 9367 //
9361 // class A 9368 // class A
9362 // 9369 //
9363 ClassElementImpl classA = ElementFactory.classElement2("A", []); 9370 ClassElementImpl classA = ElementFactory.classElement2("A");
9364 _definingCompilationUnit.types = <ClassElement> [classA]; 9371 _definingCompilationUnit.types = <ClassElement> [classA];
9365 HashSet<ClassElement> subtypesOfA = _subtypeManager.computeAllSubtypes(class A); 9372 HashSet<ClassElement> subtypesOfA = _subtypeManager.computeAllSubtypes(class A);
9366 expect(subtypesOfA, hasLength(0)); 9373 expect(subtypesOfA, hasLength(0));
9367 } 9374 }
9368 9375
9369 void test_computeAllSubtypes_oneSubtype() { 9376 void test_computeAllSubtypes_oneSubtype() {
9370 // 9377 //
9371 // class A 9378 // class A
9372 // class B extends A 9379 // class B extends A
9373 // 9380 //
9374 ClassElementImpl classA = ElementFactory.classElement2("A", []); 9381 ClassElementImpl classA = ElementFactory.classElement2("A");
9375 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); 9382 ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
9376 _definingCompilationUnit.types = <ClassElement> [classA, classB]; 9383 _definingCompilationUnit.types = <ClassElement> [classA, classB];
9377 HashSet<ClassElement> subtypesOfA = _subtypeManager.computeAllSubtypes(class A); 9384 HashSet<ClassElement> subtypesOfA = _subtypeManager.computeAllSubtypes(class A);
9378 List<ClassElement> arraySubtypesOfA = new List.from(subtypesOfA); 9385 List<ClassElement> arraySubtypesOfA = new List.from(subtypesOfA);
9379 expect(subtypesOfA, hasLength(1)); 9386 expect(subtypesOfA, hasLength(1));
9380 expect(arraySubtypesOfA, unorderedEquals([classB])); 9387 expect(arraySubtypesOfA, unorderedEquals([classB]));
9381 } 9388 }
9382 9389
9383 @override 9390 @override
9384 void setUp() { 9391 void setUp() {
9385 super.setUp(); 9392 super.setUp();
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
9489 InterfaceType _typeType; 9496 InterfaceType _typeType;
9490 9497
9491 /** 9498 /**
9492 * The type representing typenames that can't be resolved. 9499 * The type representing typenames that can't be resolved.
9493 */ 9500 */
9494 DartType _undefinedType; 9501 DartType _undefinedType;
9495 9502
9496 @override 9503 @override
9497 InterfaceType get boolType { 9504 InterfaceType get boolType {
9498 if (_boolType == null) { 9505 if (_boolType == null) {
9499 ClassElementImpl boolElement = ElementFactory.classElement2("bool", []); 9506 ClassElementImpl boolElement = ElementFactory.classElement2("bool");
9500 _boolType = boolElement.type; 9507 _boolType = boolElement.type;
9501 ConstructorElementImpl fromEnvironment = ElementFactory.constructorElement (boolElement, "fromEnvironment", true, []); 9508 ConstructorElementImpl fromEnvironment = ElementFactory.constructorElement (boolElement, "fromEnvironment", true);
9502 fromEnvironment.parameters = <ParameterElement> [ 9509 fromEnvironment.parameters = <ParameterElement> [
9503 ElementFactory.requiredParameter2("name", stringType), 9510 ElementFactory.requiredParameter2("name", stringType),
9504 ElementFactory.namedParameter2("defaultValue", _boolType)]; 9511 ElementFactory.namedParameter2("defaultValue", _boolType)];
9505 fromEnvironment.factory = true; 9512 fromEnvironment.factory = true;
9506 boolElement.constructors = <ConstructorElement> [fromEnvironment]; 9513 boolElement.constructors = <ConstructorElement> [fromEnvironment];
9507 } 9514 }
9508 return _boolType; 9515 return _boolType;
9509 } 9516 }
9510 9517
9511 @override 9518 @override
9512 DartType get bottomType { 9519 DartType get bottomType {
9513 if (_bottomType == null) { 9520 if (_bottomType == null) {
9514 _bottomType = BottomTypeImpl.instance; 9521 _bottomType = BottomTypeImpl.instance;
9515 } 9522 }
9516 return _bottomType; 9523 return _bottomType;
9517 } 9524 }
9518 9525
9519 @override 9526 @override
9520 InterfaceType get deprecatedType { 9527 InterfaceType get deprecatedType {
9521 if (_deprecatedType == null) { 9528 if (_deprecatedType == null) {
9522 ClassElementImpl deprecatedElement = ElementFactory.classElement2("Depreca ted", []); 9529 ClassElementImpl deprecatedElement = ElementFactory.classElement2("Depreca ted");
9523 deprecatedElement.constructors = <ConstructorElement> [ElementFactory.cons tructorElement(deprecatedElement, null, true, [stringType])]; 9530 deprecatedElement.constructors = <ConstructorElement> [ElementFactory.cons tructorElement(deprecatedElement, null, true, [stringType])];
9524 _deprecatedType = deprecatedElement.type; 9531 _deprecatedType = deprecatedElement.type;
9525 } 9532 }
9526 return _deprecatedType; 9533 return _deprecatedType;
9527 } 9534 }
9528 9535
9529 @override 9536 @override
9530 InterfaceType get doubleType { 9537 InterfaceType get doubleType {
9531 if (_doubleType == null) { 9538 if (_doubleType == null) {
9532 _initializeNumericTypes(); 9539 _initializeNumericTypes();
9533 } 9540 }
9534 return _doubleType; 9541 return _doubleType;
9535 } 9542 }
9536 9543
9537 @override 9544 @override
9538 DartType get dynamicType { 9545 DartType get dynamicType {
9539 if (_dynamicType == null) { 9546 if (_dynamicType == null) {
9540 _dynamicType = DynamicTypeImpl.instance; 9547 _dynamicType = DynamicTypeImpl.instance;
9541 } 9548 }
9542 return _dynamicType; 9549 return _dynamicType;
9543 } 9550 }
9544 9551
9545 @override 9552 @override
9546 InterfaceType get functionType { 9553 InterfaceType get functionType {
9547 if (_functionType == null) { 9554 if (_functionType == null) {
9548 _functionType = ElementFactory.classElement2("Function", []).type; 9555 _functionType = ElementFactory.classElement2("Function").type;
9549 } 9556 }
9550 return _functionType; 9557 return _functionType;
9551 } 9558 }
9552 9559
9553 @override 9560 @override
9554 InterfaceType get intType { 9561 InterfaceType get intType {
9555 if (_intType == null) { 9562 if (_intType == null) {
9556 _initializeNumericTypes(); 9563 _initializeNumericTypes();
9557 } 9564 }
9558 return _intType; 9565 return _intType;
(...skipping 20 matching lines...) Expand all
9579 iteratorElement.accessors = <PropertyAccessorElement> [ElementFactory.gett erElement("current", false, eType)]; 9586 iteratorElement.accessors = <PropertyAccessorElement> [ElementFactory.gett erElement("current", false, eType)];
9580 _propagateTypeArguments(iteratorElement); 9587 _propagateTypeArguments(iteratorElement);
9581 } 9588 }
9582 return _iteratorType; 9589 return _iteratorType;
9583 } 9590 }
9584 9591
9585 @override 9592 @override
9586 InterfaceType get listType { 9593 InterfaceType get listType {
9587 if (_listType == null) { 9594 if (_listType == null) {
9588 ClassElementImpl listElement = ElementFactory.classElement2("List", ["E"]) ; 9595 ClassElementImpl listElement = ElementFactory.classElement2("List", ["E"]) ;
9589 listElement.constructors = <ConstructorElement> [ElementFactory.constructo rElement2(listElement, null, [])]; 9596 listElement.constructors = <ConstructorElement> [ElementFactory.constructo rElement2(listElement, null)];
9590 _listType = listElement.type; 9597 _listType = listElement.type;
9591 DartType eType = listElement.typeParameters[0].type; 9598 DartType eType = listElement.typeParameters[0].type;
9592 InterfaceType iterableType = this.iterableType.substitute4(<DartType> [eTy pe]); 9599 InterfaceType iterableType = this.iterableType.substitute4(<DartType> [eTy pe]);
9593 listElement.interfaces = <InterfaceType> [iterableType]; 9600 listElement.interfaces = <InterfaceType> [iterableType];
9594 listElement.accessors = <PropertyAccessorElement> [ElementFactory.getterEl ement("length", false, intType)]; 9601 listElement.accessors = <PropertyAccessorElement> [ElementFactory.getterEl ement("length", false, intType)];
9595 listElement.methods = <MethodElement> [ 9602 listElement.methods = <MethodElement> [
9596 ElementFactory.methodElement("[]", eType, [intType]), 9603 ElementFactory.methodElement("[]", eType, [intType]),
9597 ElementFactory.methodElement("[]=", VoidTypeImpl.instance, [intType, e Type]), 9604 ElementFactory.methodElement("[]=", VoidTypeImpl.instance, [intType, e Type]),
9598 ElementFactory.methodElement("add", VoidTypeImpl.instance, [eType])]; 9605 ElementFactory.methodElement("add", VoidTypeImpl.instance, [eType])];
9599 _propagateTypeArguments(listElement); 9606 _propagateTypeArguments(listElement);
(...skipping 13 matching lines...) Expand all
9613 ElementFactory.methodElement("[]", vType, [objectType]), 9620 ElementFactory.methodElement("[]", vType, [objectType]),
9614 ElementFactory.methodElement("[]=", VoidTypeImpl.instance, [kType, vTy pe])]; 9621 ElementFactory.methodElement("[]=", VoidTypeImpl.instance, [kType, vTy pe])];
9615 _propagateTypeArguments(mapElement); 9622 _propagateTypeArguments(mapElement);
9616 } 9623 }
9617 return _mapType; 9624 return _mapType;
9618 } 9625 }
9619 9626
9620 @override 9627 @override
9621 InterfaceType get nullType { 9628 InterfaceType get nullType {
9622 if (_nullType == null) { 9629 if (_nullType == null) {
9623 _nullType = ElementFactory.classElement2("Null", []).type; 9630 _nullType = ElementFactory.classElement2("Null").type;
9624 } 9631 }
9625 return _nullType; 9632 return _nullType;
9626 } 9633 }
9627 9634
9628 @override 9635 @override
9629 InterfaceType get numType { 9636 InterfaceType get numType {
9630 if (_numType == null) { 9637 if (_numType == null) {
9631 _initializeNumericTypes(); 9638 _initializeNumericTypes();
9632 } 9639 }
9633 return _numType; 9640 return _numType;
9634 } 9641 }
9635 9642
9636 @override 9643 @override
9637 InterfaceType get objectType { 9644 InterfaceType get objectType {
9638 if (_objectType == null) { 9645 if (_objectType == null) {
9639 ClassElementImpl objectElement = ElementFactory.object; 9646 ClassElementImpl objectElement = ElementFactory.object;
9640 _objectType = objectElement.type; 9647 _objectType = objectElement.type;
9641 objectElement.constructors = <ConstructorElement> [ElementFactory.construc torElement2(objectElement, null, [])]; 9648 objectElement.constructors = <ConstructorElement> [ElementFactory.construc torElement2(objectElement, null)];
9642 objectElement.methods = <MethodElement> [ 9649 objectElement.methods = <MethodElement> [
9643 ElementFactory.methodElement("toString", stringType, []), 9650 ElementFactory.methodElement("toString", stringType),
9644 ElementFactory.methodElement("==", boolType, [_objectType]), 9651 ElementFactory.methodElement("==", boolType, [_objectType]),
9645 ElementFactory.methodElement("noSuchMethod", dynamicType, [dynamicType ])]; 9652 ElementFactory.methodElement("noSuchMethod", dynamicType, [dynamicType ])];
9646 objectElement.accessors = <PropertyAccessorElement> [ 9653 objectElement.accessors = <PropertyAccessorElement> [
9647 ElementFactory.getterElement("hashCode", false, intType), 9654 ElementFactory.getterElement("hashCode", false, intType),
9648 ElementFactory.getterElement("runtimeType", false, typeType)]; 9655 ElementFactory.getterElement("runtimeType", false, typeType)];
9649 } 9656 }
9650 return _objectType; 9657 return _objectType;
9651 } 9658 }
9652 9659
9653 @override 9660 @override
9654 InterfaceType get stackTraceType { 9661 InterfaceType get stackTraceType {
9655 if (_stackTraceType == null) { 9662 if (_stackTraceType == null) {
9656 _stackTraceType = ElementFactory.classElement2("StackTrace", []).type; 9663 _stackTraceType = ElementFactory.classElement2("StackTrace").type;
9657 } 9664 }
9658 return _stackTraceType; 9665 return _stackTraceType;
9659 } 9666 }
9660 9667
9661 @override 9668 @override
9662 InterfaceType get stringType { 9669 InterfaceType get stringType {
9663 if (_stringType == null) { 9670 if (_stringType == null) {
9664 _stringType = ElementFactory.classElement2("String", []).type; 9671 _stringType = ElementFactory.classElement2("String").type;
9665 ClassElementImpl stringElement = _stringType.element as ClassElementImpl; 9672 ClassElementImpl stringElement = _stringType.element as ClassElementImpl;
9666 stringElement.accessors = <PropertyAccessorElement> [ 9673 stringElement.accessors = <PropertyAccessorElement> [
9667 ElementFactory.getterElement("isEmpty", false, boolType), 9674 ElementFactory.getterElement("isEmpty", false, boolType),
9668 ElementFactory.getterElement("length", false, intType), 9675 ElementFactory.getterElement("length", false, intType),
9669 ElementFactory.getterElement("codeUnits", false, listType.substitute4( <DartType> [intType]))]; 9676 ElementFactory.getterElement("codeUnits", false, listType.substitute4( <DartType> [intType]))];
9670 stringElement.methods = <MethodElement> [ 9677 stringElement.methods = <MethodElement> [
9671 ElementFactory.methodElement("+", _stringType, [_stringType]), 9678 ElementFactory.methodElement("+", _stringType, [_stringType]),
9672 ElementFactory.methodElement("toLowerCase", _stringType, []), 9679 ElementFactory.methodElement("toLowerCase", _stringType),
9673 ElementFactory.methodElement("toUpperCase", _stringType, [])]; 9680 ElementFactory.methodElement("toUpperCase", _stringType)];
9674 ConstructorElementImpl fromEnvironment = ElementFactory.constructorElement (stringElement, "fromEnvironment", true, []); 9681 ConstructorElementImpl fromEnvironment = ElementFactory.constructorElement (stringElement, "fromEnvironment", true);
9675 fromEnvironment.parameters = <ParameterElement> [ 9682 fromEnvironment.parameters = <ParameterElement> [
9676 ElementFactory.requiredParameter2("name", stringType), 9683 ElementFactory.requiredParameter2("name", stringType),
9677 ElementFactory.namedParameter2("defaultValue", _stringType)]; 9684 ElementFactory.namedParameter2("defaultValue", _stringType)];
9678 fromEnvironment.factory = true; 9685 fromEnvironment.factory = true;
9679 stringElement.constructors = <ConstructorElement> [fromEnvironment]; 9686 stringElement.constructors = <ConstructorElement> [fromEnvironment];
9680 } 9687 }
9681 return _stringType; 9688 return _stringType;
9682 } 9689 }
9683 9690
9684 @override 9691 @override
9685 InterfaceType get symbolType { 9692 InterfaceType get symbolType {
9686 if (_symbolType == null) { 9693 if (_symbolType == null) {
9687 ClassElementImpl symbolClass = ElementFactory.classElement2("Symbol", []); 9694 ClassElementImpl symbolClass = ElementFactory.classElement2("Symbol");
9688 ConstructorElementImpl constructor = ElementFactory.constructorElement(sym bolClass, null, true, [stringType]); 9695 ConstructorElementImpl constructor = ElementFactory.constructorElement(sym bolClass, null, true, [stringType]);
9689 constructor.factory = true; 9696 constructor.factory = true;
9690 symbolClass.constructors = <ConstructorElement> [constructor]; 9697 symbolClass.constructors = <ConstructorElement> [constructor];
9691 _symbolType = symbolClass.type; 9698 _symbolType = symbolClass.type;
9692 } 9699 }
9693 return _symbolType; 9700 return _symbolType;
9694 } 9701 }
9695 9702
9696 @override 9703 @override
9697 InterfaceType get typeType { 9704 InterfaceType get typeType {
9698 if (_typeType == null) { 9705 if (_typeType == null) {
9699 _typeType = ElementFactory.classElement2("Type", []).type; 9706 _typeType = ElementFactory.classElement2("Type").type;
9700 } 9707 }
9701 return _typeType; 9708 return _typeType;
9702 } 9709 }
9703 9710
9704 @override 9711 @override
9705 DartType get undefinedType { 9712 DartType get undefinedType {
9706 if (_undefinedType == null) { 9713 if (_undefinedType == null) {
9707 _undefinedType = UndefinedTypeImpl.instance; 9714 _undefinedType = UndefinedTypeImpl.instance;
9708 } 9715 }
9709 return _undefinedType; 9716 return _undefinedType;
9710 } 9717 }
9711 9718
9712 /** 9719 /**
9713 * Initialize the numeric types. They are created as a group so that we can (a ) create the right 9720 * Initialize the numeric types. They are created as a group so that we can (a ) create the right
9714 * hierarchy and (b) add members to them. 9721 * hierarchy and (b) add members to them.
9715 */ 9722 */
9716 void _initializeNumericTypes() { 9723 void _initializeNumericTypes() {
9717 // 9724 //
9718 // Create the type hierarchy. 9725 // Create the type hierarchy.
9719 // 9726 //
9720 ClassElementImpl numElement = ElementFactory.classElement2("num", []); 9727 ClassElementImpl numElement = ElementFactory.classElement2("num");
9721 _numType = numElement.type; 9728 _numType = numElement.type;
9722 ClassElementImpl intElement = ElementFactory.classElement("int", _numType, [ ]); 9729 ClassElementImpl intElement = ElementFactory.classElement("int", _numType);
9723 _intType = intElement.type; 9730 _intType = intElement.type;
9724 ClassElementImpl doubleElement = ElementFactory.classElement("double", _numT ype, []); 9731 ClassElementImpl doubleElement = ElementFactory.classElement("double", _numT ype);
9725 _doubleType = doubleElement.type; 9732 _doubleType = doubleElement.type;
9726 // 9733 //
9727 // Force the referenced types to be cached. 9734 // Force the referenced types to be cached.
9728 // 9735 //
9729 objectType; 9736 objectType;
9730 boolType; 9737 boolType;
9731 stringType; 9738 stringType;
9732 // 9739 //
9733 // Add the methods. 9740 // Add the methods.
9734 // 9741 //
9735 numElement.methods = <MethodElement> [ 9742 numElement.methods = <MethodElement> [
9736 ElementFactory.methodElement("+", _numType, [_numType]), 9743 ElementFactory.methodElement("+", _numType, [_numType]),
9737 ElementFactory.methodElement("-", _numType, [_numType]), 9744 ElementFactory.methodElement("-", _numType, [_numType]),
9738 ElementFactory.methodElement("*", _numType, [_numType]), 9745 ElementFactory.methodElement("*", _numType, [_numType]),
9739 ElementFactory.methodElement("%", _numType, [_numType]), 9746 ElementFactory.methodElement("%", _numType, [_numType]),
9740 ElementFactory.methodElement("/", _doubleType, [_numType]), 9747 ElementFactory.methodElement("/", _doubleType, [_numType]),
9741 ElementFactory.methodElement("~/", _numType, [_numType]), 9748 ElementFactory.methodElement("~/", _numType, [_numType]),
9742 ElementFactory.methodElement("-", _numType, []), 9749 ElementFactory.methodElement("-", _numType),
9743 ElementFactory.methodElement("remainder", _numType, [_numType]), 9750 ElementFactory.methodElement("remainder", _numType, [_numType]),
9744 ElementFactory.methodElement("<", _boolType, [_numType]), 9751 ElementFactory.methodElement("<", _boolType, [_numType]),
9745 ElementFactory.methodElement("<=", _boolType, [_numType]), 9752 ElementFactory.methodElement("<=", _boolType, [_numType]),
9746 ElementFactory.methodElement(">", _boolType, [_numType]), 9753 ElementFactory.methodElement(">", _boolType, [_numType]),
9747 ElementFactory.methodElement(">=", _boolType, [_numType]), 9754 ElementFactory.methodElement(">=", _boolType, [_numType]),
9748 ElementFactory.methodElement("==", _boolType, [_objectType]), 9755 ElementFactory.methodElement("==", _boolType, [_objectType]),
9749 ElementFactory.methodElement("isNaN", _boolType, []), 9756 ElementFactory.methodElement("isNaN", _boolType),
9750 ElementFactory.methodElement("isNegative", _boolType, []), 9757 ElementFactory.methodElement("isNegative", _boolType),
9751 ElementFactory.methodElement("isInfinite", _boolType, []), 9758 ElementFactory.methodElement("isInfinite", _boolType),
9752 ElementFactory.methodElement("abs", _numType, []), 9759 ElementFactory.methodElement("abs", _numType),
9753 ElementFactory.methodElement("floor", _numType, []), 9760 ElementFactory.methodElement("floor", _numType),
9754 ElementFactory.methodElement("ceil", _numType, []), 9761 ElementFactory.methodElement("ceil", _numType),
9755 ElementFactory.methodElement("round", _numType, []), 9762 ElementFactory.methodElement("round", _numType),
9756 ElementFactory.methodElement("truncate", _numType, []), 9763 ElementFactory.methodElement("truncate", _numType),
9757 ElementFactory.methodElement("toInt", _intType, []), 9764 ElementFactory.methodElement("toInt", _intType),
9758 ElementFactory.methodElement("toDouble", _doubleType, []), 9765 ElementFactory.methodElement("toDouble", _doubleType),
9759 ElementFactory.methodElement("toStringAsFixed", _stringType, [_intType]) , 9766 ElementFactory.methodElement("toStringAsFixed", _stringType, [_intType]) ,
9760 ElementFactory.methodElement("toStringAsExponential", _stringType, [_int Type]), 9767 ElementFactory.methodElement("toStringAsExponential", _stringType, [_int Type]),
9761 ElementFactory.methodElement("toStringAsPrecision", _stringType, [_intTy pe]), 9768 ElementFactory.methodElement("toStringAsPrecision", _stringType, [_intTy pe]),
9762 ElementFactory.methodElement("toRadixString", _stringType, [_intType])]; 9769 ElementFactory.methodElement("toRadixString", _stringType, [_intType])];
9763 intElement.methods = <MethodElement> [ 9770 intElement.methods = <MethodElement> [
9764 ElementFactory.methodElement("&", _intType, [_intType]), 9771 ElementFactory.methodElement("&", _intType, [_intType]),
9765 ElementFactory.methodElement("|", _intType, [_intType]), 9772 ElementFactory.methodElement("|", _intType, [_intType]),
9766 ElementFactory.methodElement("^", _intType, [_intType]), 9773 ElementFactory.methodElement("^", _intType, [_intType]),
9767 ElementFactory.methodElement("~", _intType, []), 9774 ElementFactory.methodElement("~", _intType),
9768 ElementFactory.methodElement("<<", _intType, [_intType]), 9775 ElementFactory.methodElement("<<", _intType, [_intType]),
9769 ElementFactory.methodElement(">>", _intType, [_intType]), 9776 ElementFactory.methodElement(">>", _intType, [_intType]),
9770 ElementFactory.methodElement("-", _intType, []), 9777 ElementFactory.methodElement("-", _intType),
9771 ElementFactory.methodElement("abs", _intType, []), 9778 ElementFactory.methodElement("abs", _intType),
9772 ElementFactory.methodElement("round", _intType, []), 9779 ElementFactory.methodElement("round", _intType),
9773 ElementFactory.methodElement("floor", _intType, []), 9780 ElementFactory.methodElement("floor", _intType),
9774 ElementFactory.methodElement("ceil", _intType, []), 9781 ElementFactory.methodElement("ceil", _intType),
9775 ElementFactory.methodElement("truncate", _intType, []), 9782 ElementFactory.methodElement("truncate", _intType),
9776 ElementFactory.methodElement("toString", _stringType, [])]; 9783 ElementFactory.methodElement("toString", _stringType)];
9777 ConstructorElementImpl fromEnvironment = ElementFactory.constructorElement(i ntElement, "fromEnvironment", true, []); 9784 ConstructorElementImpl fromEnvironment = ElementFactory.constructorElement(i ntElement, "fromEnvironment", true);
9778 fromEnvironment.parameters = <ParameterElement> [ 9785 fromEnvironment.parameters = <ParameterElement> [
9779 ElementFactory.requiredParameter2("name", stringType), 9786 ElementFactory.requiredParameter2("name", stringType),
9780 ElementFactory.namedParameter2("defaultValue", _intType)]; 9787 ElementFactory.namedParameter2("defaultValue", _intType)];
9781 fromEnvironment.factory = true; 9788 fromEnvironment.factory = true;
9782 intElement.constructors = <ConstructorElement> [fromEnvironment]; 9789 intElement.constructors = <ConstructorElement> [fromEnvironment];
9783 List<FieldElement> fields = <FieldElement> [ 9790 List<FieldElement> fields = <FieldElement> [
9784 ElementFactory.fieldElement("NAN", true, false, true, _doubleType), 9791 ElementFactory.fieldElement("NAN", true, false, true, _doubleType),
9785 ElementFactory.fieldElement("INFINITY", true, false, true, _doubleType), 9792 ElementFactory.fieldElement("INFINITY", true, false, true, _doubleType),
9786 ElementFactory.fieldElement("NEGATIVE_INFINITY", true, false, true, _dou bleType), 9793 ElementFactory.fieldElement("NEGATIVE_INFINITY", true, false, true, _dou bleType),
9787 ElementFactory.fieldElement("MIN_POSITIVE", true, false, true, _doubleTy pe), 9794 ElementFactory.fieldElement("MIN_POSITIVE", true, false, true, _doubleTy pe),
9788 ElementFactory.fieldElement("MAX_FINITE", true, false, true, _doubleType )]; 9795 ElementFactory.fieldElement("MAX_FINITE", true, false, true, _doubleType )];
9789 doubleElement.fields = fields; 9796 doubleElement.fields = fields;
9790 int fieldCount = fields.length; 9797 int fieldCount = fields.length;
9791 List<PropertyAccessorElement> accessors = new List<PropertyAccessorElement>( fieldCount); 9798 List<PropertyAccessorElement> accessors = new List<PropertyAccessorElement>( fieldCount);
9792 for (int i = 0; i < fieldCount; i++) { 9799 for (int i = 0; i < fieldCount; i++) {
9793 accessors[i] = fields[i].getter; 9800 accessors[i] = fields[i].getter;
9794 } 9801 }
9795 doubleElement.accessors = accessors; 9802 doubleElement.accessors = accessors;
9796 doubleElement.methods = <MethodElement> [ 9803 doubleElement.methods = <MethodElement> [
9797 ElementFactory.methodElement("remainder", _doubleType, [_numType]), 9804 ElementFactory.methodElement("remainder", _doubleType, [_numType]),
9798 ElementFactory.methodElement("+", _doubleType, [_numType]), 9805 ElementFactory.methodElement("+", _doubleType, [_numType]),
9799 ElementFactory.methodElement("-", _doubleType, [_numType]), 9806 ElementFactory.methodElement("-", _doubleType, [_numType]),
9800 ElementFactory.methodElement("*", _doubleType, [_numType]), 9807 ElementFactory.methodElement("*", _doubleType, [_numType]),
9801 ElementFactory.methodElement("%", _doubleType, [_numType]), 9808 ElementFactory.methodElement("%", _doubleType, [_numType]),
9802 ElementFactory.methodElement("/", _doubleType, [_numType]), 9809 ElementFactory.methodElement("/", _doubleType, [_numType]),
9803 ElementFactory.methodElement("~/", _doubleType, [_numType]), 9810 ElementFactory.methodElement("~/", _doubleType, [_numType]),
9804 ElementFactory.methodElement("-", _doubleType, []), 9811 ElementFactory.methodElement("-", _doubleType),
9805 ElementFactory.methodElement("abs", _doubleType, []), 9812 ElementFactory.methodElement("abs", _doubleType),
9806 ElementFactory.methodElement("round", _doubleType, []), 9813 ElementFactory.methodElement("round", _doubleType),
9807 ElementFactory.methodElement("floor", _doubleType, []), 9814 ElementFactory.methodElement("floor", _doubleType),
9808 ElementFactory.methodElement("ceil", _doubleType, []), 9815 ElementFactory.methodElement("ceil", _doubleType),
9809 ElementFactory.methodElement("truncate", _doubleType, []), 9816 ElementFactory.methodElement("truncate", _doubleType),
9810 ElementFactory.methodElement("toString", _stringType, [])]; 9817 ElementFactory.methodElement("toString", _stringType)];
9811 } 9818 }
9812 9819
9813 /** 9820 /**
9814 * Given a class element representing a class with type parameters, propagate those type 9821 * Given a class element representing a class with type parameters, propagate those type
9815 * parameters to all of the accessors, methods and constructors defined for th e class. 9822 * parameters to all of the accessors, methods and constructors defined for th e class.
9816 * 9823 *
9817 * @param classElement the element representing the class with type parameters 9824 * @param classElement the element representing the class with type parameters
9818 */ 9825 */
9819 void _propagateTypeArguments(ClassElementImpl classElement) { 9826 void _propagateTypeArguments(ClassElementImpl classElement) {
9820 List<DartType> typeArguments = TypeParameterTypeImpl.getTypes(classElement.t ypeParameters); 9827 List<DartType> typeArguments = TypeParameterTypeImpl.getTypes(classElement.t ypeParameters);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
9866 manager.exitScope(); 9873 manager.exitScope();
9867 fail("Expected IllegalStateException"); 9874 fail("Expected IllegalStateException");
9868 } on IllegalStateException catch (exception) { 9875 } on IllegalStateException catch (exception) {
9869 // Expected 9876 // Expected
9870 } 9877 }
9871 } 9878 }
9872 9879
9873 void test_getType_enclosedOverride() { 9880 void test_getType_enclosedOverride() {
9874 TypeOverrideManager manager = new TypeOverrideManager(); 9881 TypeOverrideManager manager = new TypeOverrideManager();
9875 LocalVariableElementImpl element = ElementFactory.localVariableElement2("v") ; 9882 LocalVariableElementImpl element = ElementFactory.localVariableElement2("v") ;
9876 InterfaceType type = ElementFactory.classElement2("C", []).type; 9883 InterfaceType type = ElementFactory.classElement2("C").type;
9877 manager.enterScope(); 9884 manager.enterScope();
9878 manager.setType(element, type); 9885 manager.setType(element, type);
9879 manager.enterScope(); 9886 manager.enterScope();
9880 expect(manager.getType(element), same(type)); 9887 expect(manager.getType(element), same(type));
9881 } 9888 }
9882 9889
9883 void test_getType_immediateOverride() { 9890 void test_getType_immediateOverride() {
9884 TypeOverrideManager manager = new TypeOverrideManager(); 9891 TypeOverrideManager manager = new TypeOverrideManager();
9885 LocalVariableElementImpl element = ElementFactory.localVariableElement2("v") ; 9892 LocalVariableElementImpl element = ElementFactory.localVariableElement2("v") ;
9886 InterfaceType type = ElementFactory.classElement2("C", []).type; 9893 InterfaceType type = ElementFactory.classElement2("C").type;
9887 manager.enterScope(); 9894 manager.enterScope();
9888 manager.setType(element, type); 9895 manager.setType(element, type);
9889 expect(manager.getType(element), same(type)); 9896 expect(manager.getType(element), same(type));
9890 } 9897 }
9891 9898
9892 void test_getType_noOverride() { 9899 void test_getType_noOverride() {
9893 TypeOverrideManager manager = new TypeOverrideManager(); 9900 TypeOverrideManager manager = new TypeOverrideManager();
9894 manager.enterScope(); 9901 manager.enterScope();
9895 expect(manager.getType(ElementFactory.localVariableElement2("v")), isNull); 9902 expect(manager.getType(ElementFactory.localVariableElement2("v")), isNull);
9896 } 9903 }
(...skipping 1305 matching lines...) Expand 10 before | Expand all | Expand 10 after
11202 } 11209 }
11203 } 11210 }
11204 11211
11205 class TypeProviderImplTest extends EngineTestCase { 11212 class TypeProviderImplTest extends EngineTestCase {
11206 void test_creation() { 11213 void test_creation() {
11207 // 11214 //
11208 // Create a mock library element with the types expected to be in dart:core. We cannot use 11215 // Create a mock library element with the types expected to be in dart:core. We cannot use
11209 // either ElementFactory or TestTypeProvider (which uses ElementFactory) bec ause we side-effect 11216 // either ElementFactory or TestTypeProvider (which uses ElementFactory) bec ause we side-effect
11210 // the elements in ways that would break other tests. 11217 // the elements in ways that would break other tests.
11211 // 11218 //
11212 InterfaceType objectType = _classElement("Object", null, []).type; 11219 InterfaceType objectType = _classElement("Object", null).type;
11213 InterfaceType boolType = _classElement("bool", objectType, []).type; 11220 InterfaceType boolType = _classElement("bool", objectType).type;
11214 InterfaceType numType = _classElement("num", objectType, []).type; 11221 InterfaceType numType = _classElement("num", objectType).type;
11215 InterfaceType doubleType = _classElement("double", numType, []).type; 11222 InterfaceType doubleType = _classElement("double", numType).type;
11216 InterfaceType functionType = _classElement("Function", objectType, []).type; 11223 InterfaceType functionType = _classElement("Function", objectType).type;
11217 InterfaceType intType = _classElement("int", numType, []).type; 11224 InterfaceType intType = _classElement("int", numType).type;
11218 InterfaceType listType = _classElement("List", objectType, ["E"]).type; 11225 InterfaceType listType = _classElement("List", objectType, ["E"]).type;
11219 InterfaceType mapType = _classElement("Map", objectType, ["K", "V"]).type; 11226 InterfaceType mapType = _classElement("Map", objectType, ["K", "V"]).type;
11220 InterfaceType stackTraceType = _classElement("StackTrace", objectType, []).t ype; 11227 InterfaceType stackTraceType = _classElement("StackTrace", objectType).type;
11221 InterfaceType stringType = _classElement("String", objectType, []).type; 11228 InterfaceType stringType = _classElement("String", objectType).type;
11222 InterfaceType symbolType = _classElement("Symbol", objectType, []).type; 11229 InterfaceType symbolType = _classElement("Symbol", objectType).type;
11223 InterfaceType typeType = _classElement("Type", objectType, []).type; 11230 InterfaceType typeType = _classElement("Type", objectType).type;
11224 CompilationUnitElementImpl coreUnit = new CompilationUnitElementImpl("core.d art"); 11231 CompilationUnitElementImpl coreUnit = new CompilationUnitElementImpl("core.d art");
11225 coreUnit.types = <ClassElement> [ 11232 coreUnit.types = <ClassElement> [
11226 boolType.element, 11233 boolType.element,
11227 doubleType.element, 11234 doubleType.element,
11228 functionType.element, 11235 functionType.element,
11229 intType.element, 11236 intType.element,
11230 listType.element, 11237 listType.element,
11231 mapType.element, 11238 mapType.element,
11232 objectType.element, 11239 objectType.element,
11233 stackTraceType.element, 11240 stackTraceType.element,
(...skipping 14 matching lines...) Expand all
11248 expect(provider.intType, same(intType)); 11255 expect(provider.intType, same(intType));
11249 expect(provider.listType, same(listType)); 11256 expect(provider.listType, same(listType));
11250 expect(provider.mapType, same(mapType)); 11257 expect(provider.mapType, same(mapType));
11251 expect(provider.objectType, same(objectType)); 11258 expect(provider.objectType, same(objectType));
11252 expect(provider.stackTraceType, same(stackTraceType)); 11259 expect(provider.stackTraceType, same(stackTraceType));
11253 expect(provider.stringType, same(stringType)); 11260 expect(provider.stringType, same(stringType));
11254 expect(provider.symbolType, same(symbolType)); 11261 expect(provider.symbolType, same(symbolType));
11255 expect(provider.typeType, same(typeType)); 11262 expect(provider.typeType, same(typeType));
11256 } 11263 }
11257 11264
11258 ClassElement _classElement(String typeName, InterfaceType superclassType, List <String> parameterNames) { 11265 ClassElement _classElement(String typeName, InterfaceType superclassType, [Lis t<String> parameterNames]) {
11259 ClassElementImpl element = new ClassElementImpl.forNode(AstFactory.identifie r3(typeName)); 11266 ClassElementImpl element = new ClassElementImpl.forNode(AstFactory.identifie r3(typeName));
11260 element.supertype = superclassType; 11267 element.supertype = superclassType;
11261 InterfaceTypeImpl type = new InterfaceTypeImpl.con1(element); 11268 InterfaceTypeImpl type = new InterfaceTypeImpl.con1(element);
11262 element.type = type; 11269 element.type = type;
11263 int count = parameterNames.length; 11270 if (parameterNames != null) {
11264 if (count > 0) { 11271 int count = parameterNames.length;
11265 List<TypeParameterElementImpl> typeParameters = new List<TypeParameterElem entImpl>(count); 11272 if (count > 0) {
11266 List<TypeParameterTypeImpl> typeArguments = new List<TypeParameterTypeImpl >(count); 11273 List<TypeParameterElementImpl> typeParameters = new List<TypeParameterEl ementImpl>(count);
11267 for (int i = 0; i < count; i++) { 11274 List<TypeParameterTypeImpl> typeArguments = new List<TypeParameterTypeIm pl>(count);
11268 TypeParameterElementImpl typeParameter = new TypeParameterElementImpl.fo rNode(AstFactory.identifier3(parameterNames[i])); 11275 for (int i = 0; i < count; i++) {
11269 typeParameters[i] = typeParameter; 11276 TypeParameterElementImpl typeParameter = new TypeParameterElementImpl. forNode(AstFactory.identifier3(parameterNames[i]));
11270 typeArguments[i] = new TypeParameterTypeImpl(typeParameter); 11277 typeParameters[i] = typeParameter;
11271 typeParameter.type = typeArguments[i]; 11278 typeArguments[i] = new TypeParameterTypeImpl(typeParameter);
11279 typeParameter.type = typeArguments[i];
11280 }
11281 element.typeParameters = typeParameters;
11282 type.typeArguments = typeArguments;
11272 } 11283 }
11273 element.typeParameters = typeParameters;
11274 type.typeArguments = typeArguments;
11275 } 11284 }
11276 return element; 11285 return element;
11277 } 11286 }
11278 } 11287 }
11279 11288
11280 class TypeResolverVisitorTest extends EngineTestCase { 11289 class TypeResolverVisitorTest extends EngineTestCase {
11281 /** 11290 /**
11282 * The error listener to which errors will be reported. 11291 * The error listener to which errors will be reported.
11283 */ 11292 */
11284 GatheringErrorListener _listener; 11293 GatheringErrorListener _listener;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
11324 _listener.assertNoErrors(); 11333 _listener.assertNoErrors();
11325 } 11334 }
11326 11335
11327 void fail_visitMethodDeclaration() { 11336 void fail_visitMethodDeclaration() {
11328 fail("Not yet tested"); 11337 fail("Not yet tested");
11329 _listener.assertNoErrors(); 11338 _listener.assertNoErrors();
11330 } 11339 }
11331 11340
11332 void fail_visitVariableDeclaration() { 11341 void fail_visitVariableDeclaration() {
11333 fail("Not yet tested"); 11342 fail("Not yet tested");
11334 ClassElement type = ElementFactory.classElement2("A", []); 11343 ClassElement type = ElementFactory.classElement2("A");
11335 VariableDeclaration node = AstFactory.variableDeclaration("a"); 11344 VariableDeclaration node = AstFactory.variableDeclaration("a");
11336 AstFactory.variableDeclarationList(null, AstFactory.typeName(type, []), [nod e]); 11345 AstFactory.variableDeclarationList(null, AstFactory.typeName(type), [node]);
11337 //resolve(node); 11346 //resolve(node);
11338 expect(node.name.staticType, same(type.type)); 11347 expect(node.name.staticType, same(type.type));
11339 _listener.assertNoErrors(); 11348 _listener.assertNoErrors();
11340 } 11349 }
11341 11350
11342 @override 11351 @override
11343 void setUp() { 11352 void setUp() {
11344 _listener = new GatheringErrorListener(); 11353 _listener = new GatheringErrorListener();
11345 SourceFactory factory = new SourceFactory([new FileUriResolver()]); 11354 SourceFactory factory = new SourceFactory([new FileUriResolver()]);
11346 AnalysisContextImpl context = new AnalysisContextImpl(); 11355 AnalysisContextImpl context = new AnalysisContextImpl();
11347 context.sourceFactory = factory; 11356 context.sourceFactory = factory;
11348 Source librarySource = new FileBasedSource.con1(FileUtilities2.createFile("/ lib.dart")); 11357 Source librarySource = new FileBasedSource.con1(FileUtilities2.createFile("/ lib.dart"));
11349 _library = new Library(context, _listener, librarySource); 11358 _library = new Library(context, _listener, librarySource);
11350 LibraryElementImpl element = new LibraryElementImpl.forNode(context, AstFact ory.libraryIdentifier2(["lib"])); 11359 LibraryElementImpl element = new LibraryElementImpl.forNode(context, AstFact ory.libraryIdentifier2(["lib"]));
11351 element.definingCompilationUnit = new CompilationUnitElementImpl("lib.dart") ; 11360 element.definingCompilationUnit = new CompilationUnitElementImpl("lib.dart") ;
11352 _library.libraryElement = element; 11361 _library.libraryElement = element;
11353 _typeProvider = new TestTypeProvider(); 11362 _typeProvider = new TestTypeProvider();
11354 _visitor = new TypeResolverVisitor.con1(_library, librarySource, _typeProvid er); 11363 _visitor = new TypeResolverVisitor.con1(_library, librarySource, _typeProvid er);
11355 _implicitConstructorBuilder = new ImplicitConstructorBuilder.con1(_library, librarySource, _typeProvider); 11364 _implicitConstructorBuilder = new ImplicitConstructorBuilder.con1(_library, librarySource, _typeProvider);
11356 } 11365 }
11357 11366
11358 void test_visitCatchClause_exception() { 11367 void test_visitCatchClause_exception() {
11359 // catch (e) 11368 // catch (e)
11360 CatchClause clause = AstFactory.catchClause("e", []); 11369 CatchClause clause = AstFactory.catchClause("e");
11361 SimpleIdentifier exceptionParameter = clause.exceptionParameter; 11370 SimpleIdentifier exceptionParameter = clause.exceptionParameter;
11362 exceptionParameter.staticElement = new LocalVariableElementImpl.forNode(exce ptionParameter); 11371 exceptionParameter.staticElement = new LocalVariableElementImpl.forNode(exce ptionParameter);
11363 _resolveCatchClause(clause, _typeProvider.dynamicType, null, []); 11372 _resolveCatchClause(clause, _typeProvider.dynamicType, null);
11364 _listener.assertNoErrors(); 11373 _listener.assertNoErrors();
11365 } 11374 }
11366 11375
11367 void test_visitCatchClause_exception_stackTrace() { 11376 void test_visitCatchClause_exception_stackTrace() {
11368 // catch (e, s) 11377 // catch (e, s)
11369 CatchClause clause = AstFactory.catchClause2("e", "s", []); 11378 CatchClause clause = AstFactory.catchClause2("e", "s");
11370 SimpleIdentifier exceptionParameter = clause.exceptionParameter; 11379 SimpleIdentifier exceptionParameter = clause.exceptionParameter;
11371 exceptionParameter.staticElement = new LocalVariableElementImpl.forNode(exce ptionParameter); 11380 exceptionParameter.staticElement = new LocalVariableElementImpl.forNode(exce ptionParameter);
11372 SimpleIdentifier stackTraceParameter = clause.stackTraceParameter; 11381 SimpleIdentifier stackTraceParameter = clause.stackTraceParameter;
11373 stackTraceParameter.staticElement = new LocalVariableElementImpl.forNode(sta ckTraceParameter); 11382 stackTraceParameter.staticElement = new LocalVariableElementImpl.forNode(sta ckTraceParameter);
11374 _resolveCatchClause(clause, _typeProvider.dynamicType, _typeProvider.stackTr aceType, []); 11383 _resolveCatchClause(clause, _typeProvider.dynamicType, _typeProvider.stackTr aceType);
11375 _listener.assertNoErrors(); 11384 _listener.assertNoErrors();
11376 } 11385 }
11377 11386
11378 void test_visitCatchClause_on_exception() { 11387 void test_visitCatchClause_on_exception() {
11379 // on E catch (e) 11388 // on E catch (e)
11380 ClassElement exceptionElement = ElementFactory.classElement2("E", []); 11389 ClassElement exceptionElement = ElementFactory.classElement2("E");
11381 TypeName exceptionType = AstFactory.typeName(exceptionElement, []); 11390 TypeName exceptionType = AstFactory.typeName(exceptionElement);
11382 CatchClause clause = AstFactory.catchClause4(exceptionType, "e", []); 11391 CatchClause clause = AstFactory.catchClause4(exceptionType, "e");
11383 SimpleIdentifier exceptionParameter = clause.exceptionParameter; 11392 SimpleIdentifier exceptionParameter = clause.exceptionParameter;
11384 exceptionParameter.staticElement = new LocalVariableElementImpl.forNode(exce ptionParameter); 11393 exceptionParameter.staticElement = new LocalVariableElementImpl.forNode(exce ptionParameter);
11385 _resolveCatchClause(clause, exceptionElement.type, null, [exceptionElement]) ; 11394 _resolveCatchClause(clause, exceptionElement.type, null, [exceptionElement]) ;
11386 _listener.assertNoErrors(); 11395 _listener.assertNoErrors();
11387 } 11396 }
11388 11397
11389 void test_visitCatchClause_on_exception_stackTrace() { 11398 void test_visitCatchClause_on_exception_stackTrace() {
11390 // on E catch (e, s) 11399 // on E catch (e, s)
11391 ClassElement exceptionElement = ElementFactory.classElement2("E", []); 11400 ClassElement exceptionElement = ElementFactory.classElement2("E");
11392 TypeName exceptionType = AstFactory.typeName(exceptionElement, []); 11401 TypeName exceptionType = AstFactory.typeName(exceptionElement);
11393 (exceptionType.name as SimpleIdentifier).staticElement = exceptionElement; 11402 (exceptionType.name as SimpleIdentifier).staticElement = exceptionElement;
11394 CatchClause clause = AstFactory.catchClause5(exceptionType, "e", "s", []); 11403 CatchClause clause = AstFactory.catchClause5(exceptionType, "e", "s");
11395 SimpleIdentifier exceptionParameter = clause.exceptionParameter; 11404 SimpleIdentifier exceptionParameter = clause.exceptionParameter;
11396 exceptionParameter.staticElement = new LocalVariableElementImpl.forNode(exce ptionParameter); 11405 exceptionParameter.staticElement = new LocalVariableElementImpl.forNode(exce ptionParameter);
11397 SimpleIdentifier stackTraceParameter = clause.stackTraceParameter; 11406 SimpleIdentifier stackTraceParameter = clause.stackTraceParameter;
11398 stackTraceParameter.staticElement = new LocalVariableElementImpl.forNode(sta ckTraceParameter); 11407 stackTraceParameter.staticElement = new LocalVariableElementImpl.forNode(sta ckTraceParameter);
11399 _resolveCatchClause(clause, exceptionElement.type, _typeProvider.stackTraceT ype, [exceptionElement]); 11408 _resolveCatchClause(clause, exceptionElement.type, _typeProvider.stackTraceT ype, [exceptionElement]);
11400 _listener.assertNoErrors(); 11409 _listener.assertNoErrors();
11401 } 11410 }
11402 11411
11403 void test_visitClassDeclaration() { 11412 void test_visitClassDeclaration() {
11404 // class A extends B with C implements D {} 11413 // class A extends B with C implements D {}
11405 // class B {} 11414 // class B {}
11406 // class C {} 11415 // class C {}
11407 // class D {} 11416 // class D {}
11408 ClassElement elementA = ElementFactory.classElement2("A", []); 11417 ClassElement elementA = ElementFactory.classElement2("A");
11409 ClassElement elementB = ElementFactory.classElement2("B", []); 11418 ClassElement elementB = ElementFactory.classElement2("B");
11410 ClassElement elementC = ElementFactory.classElement2("C", []); 11419 ClassElement elementC = ElementFactory.classElement2("C");
11411 ClassElement elementD = ElementFactory.classElement2("D", []); 11420 ClassElement elementD = ElementFactory.classElement2("D");
11412 ExtendsClause extendsClause = AstFactory.extendsClause(AstFactory.typeName(e lementB, [])); 11421 ExtendsClause extendsClause = AstFactory.extendsClause(AstFactory.typeName(e lementB));
11413 WithClause withClause = AstFactory.withClause([AstFactory.typeName(elementC, [])]); 11422 WithClause withClause = AstFactory.withClause([AstFactory.typeName(elementC) ]);
11414 ImplementsClause implementsClause = AstFactory.implementsClause([AstFactory. typeName(elementD, [])]); 11423 ImplementsClause implementsClause = AstFactory.implementsClause([AstFactory. typeName(elementD)]);
11415 ClassDeclaration declaration = AstFactory.classDeclaration(null, "A", null, extendsClause, withClause, implementsClause, []); 11424 ClassDeclaration declaration = AstFactory.classDeclaration(null, "A", null, extendsClause, withClause, implementsClause);
11416 declaration.name.staticElement = elementA; 11425 declaration.name.staticElement = elementA;
11417 _resolveNode(declaration, [elementA, elementB, elementC, elementD]); 11426 _resolveNode(declaration, [elementA, elementB, elementC, elementD]);
11418 expect(elementA.supertype, same(elementB.type)); 11427 expect(elementA.supertype, same(elementB.type));
11419 List<InterfaceType> mixins = elementA.mixins; 11428 List<InterfaceType> mixins = elementA.mixins;
11420 expect(mixins, hasLength(1)); 11429 expect(mixins, hasLength(1));
11421 expect(mixins[0], same(elementC.type)); 11430 expect(mixins[0], same(elementC.type));
11422 List<InterfaceType> interfaces = elementA.interfaces; 11431 List<InterfaceType> interfaces = elementA.interfaces;
11423 expect(interfaces, hasLength(1)); 11432 expect(interfaces, hasLength(1));
11424 expect(interfaces[0], same(elementD.type)); 11433 expect(interfaces[0], same(elementD.type));
11425 _listener.assertNoErrors(); 11434 _listener.assertNoErrors();
11426 } 11435 }
11427 11436
11428 void test_visitClassDeclaration_instanceMemberCollidesWithClass() { 11437 void test_visitClassDeclaration_instanceMemberCollidesWithClass() {
11429 // class A {} 11438 // class A {}
11430 // class B extends A { 11439 // class B extends A {
11431 // void A() {} 11440 // void A() {}
11432 // } 11441 // }
11433 ClassElementImpl elementA = ElementFactory.classElement2("A", []); 11442 ClassElementImpl elementA = ElementFactory.classElement2("A");
11434 ClassElementImpl elementB = ElementFactory.classElement2("B", []); 11443 ClassElementImpl elementB = ElementFactory.classElement2("B");
11435 elementB.methods = <MethodElement> [ElementFactory.methodElement("A", VoidTy peImpl.instance, [])]; 11444 elementB.methods = <MethodElement> [ElementFactory.methodElement("A", VoidTy peImpl.instance)];
11436 ExtendsClause extendsClause = AstFactory.extendsClause(AstFactory.typeName(e lementA, [])); 11445 ExtendsClause extendsClause = AstFactory.extendsClause(AstFactory.typeName(e lementA));
11437 ClassDeclaration declaration = AstFactory.classDeclaration(null, "B", null, extendsClause, null, null, []); 11446 ClassDeclaration declaration = AstFactory.classDeclaration(null, "B", null, extendsClause, null, null);
11438 declaration.name.staticElement = elementB; 11447 declaration.name.staticElement = elementB;
11439 _resolveNode(declaration, [elementA, elementB]); 11448 _resolveNode(declaration, [elementA, elementB]);
11440 expect(elementB.supertype, same(elementA.type)); 11449 expect(elementB.supertype, same(elementA.type));
11441 _listener.assertNoErrors(); 11450 _listener.assertNoErrors();
11442 } 11451 }
11443 11452
11444 void test_visitClassTypeAlias() { 11453 void test_visitClassTypeAlias() {
11445 // class A = B with C implements D; 11454 // class A = B with C implements D;
11446 ClassElement elementA = ElementFactory.classElement2("A", []); 11455 ClassElement elementA = ElementFactory.classElement2("A");
11447 ClassElement elementB = ElementFactory.classElement2("B", []); 11456 ClassElement elementB = ElementFactory.classElement2("B");
11448 ClassElement elementC = ElementFactory.classElement2("C", []); 11457 ClassElement elementC = ElementFactory.classElement2("C");
11449 ClassElement elementD = ElementFactory.classElement2("D", []); 11458 ClassElement elementD = ElementFactory.classElement2("D");
11450 WithClause withClause = AstFactory.withClause([AstFactory.typeName(elementC, [])]); 11459 WithClause withClause = AstFactory.withClause([AstFactory.typeName(elementC) ]);
11451 ImplementsClause implementsClause = AstFactory.implementsClause([AstFactory. typeName(elementD, [])]); 11460 ImplementsClause implementsClause = AstFactory.implementsClause([AstFactory. typeName(elementD)]);
11452 ClassTypeAlias alias = AstFactory.classTypeAlias("A", null, null, AstFactory .typeName(elementB, []), withClause, implementsClause); 11461 ClassTypeAlias alias = AstFactory.classTypeAlias("A", null, null, AstFactory .typeName(elementB), withClause, implementsClause);
11453 alias.name.staticElement = elementA; 11462 alias.name.staticElement = elementA;
11454 _resolveNode(alias, [elementA, elementB, elementC, elementD]); 11463 _resolveNode(alias, [elementA, elementB, elementC, elementD]);
11455 expect(elementA.supertype, same(elementB.type)); 11464 expect(elementA.supertype, same(elementB.type));
11456 List<InterfaceType> mixins = elementA.mixins; 11465 List<InterfaceType> mixins = elementA.mixins;
11457 expect(mixins, hasLength(1)); 11466 expect(mixins, hasLength(1));
11458 expect(mixins[0], same(elementC.type)); 11467 expect(mixins[0], same(elementC.type));
11459 List<InterfaceType> interfaces = elementA.interfaces; 11468 List<InterfaceType> interfaces = elementA.interfaces;
11460 expect(interfaces, hasLength(1)); 11469 expect(interfaces, hasLength(1));
11461 expect(interfaces[0], same(elementD.type)); 11470 expect(interfaces[0], same(elementD.type));
11462 _listener.assertNoErrors(); 11471 _listener.assertNoErrors();
11463 } 11472 }
11464 11473
11465 void test_visitFieldFormalParameter_functionType() { 11474 void test_visitFieldFormalParameter_functionType() {
11466 InterfaceType intType = _typeProvider.intType; 11475 InterfaceType intType = _typeProvider.intType;
11467 TypeName intTypeName = AstFactory.typeName4("int", []); 11476 TypeName intTypeName = AstFactory.typeName4("int");
11468 String innerParameterName = "a"; 11477 String innerParameterName = "a";
11469 SimpleFormalParameter parameter = AstFactory.simpleFormalParameter3(innerPar ameterName); 11478 SimpleFormalParameter parameter = AstFactory.simpleFormalParameter3(innerPar ameterName);
11470 parameter.identifier.staticElement = ElementFactory.requiredParameter(innerP arameterName); 11479 parameter.identifier.staticElement = ElementFactory.requiredParameter(innerP arameterName);
11471 String outerParameterName = "p"; 11480 String outerParameterName = "p";
11472 FormalParameter node = AstFactory.fieldFormalParameter(null, intTypeName, ou terParameterName, AstFactory.formalParameterList([parameter])); 11481 FormalParameter node = AstFactory.fieldFormalParameter(null, intTypeName, ou terParameterName, AstFactory.formalParameterList([parameter]));
11473 node.identifier.staticElement = ElementFactory.requiredParameter(outerParame terName); 11482 node.identifier.staticElement = ElementFactory.requiredParameter(outerParame terName);
11474 DartType parameterType = _resolveFormalParameter(node, [intType.element]); 11483 DartType parameterType = _resolveFormalParameter(node, [intType.element]);
11475 EngineTestCase.assertInstanceOf((obj) => obj is FunctionType, FunctionType, parameterType); 11484 EngineTestCase.assertInstanceOf((obj) => obj is FunctionType, FunctionType, parameterType);
11476 FunctionType functionType = parameterType as FunctionType; 11485 FunctionType functionType = parameterType as FunctionType;
11477 expect(functionType.returnType, same(intType)); 11486 expect(functionType.returnType, same(intType));
11478 expect(functionType.parameters, hasLength(1)); 11487 expect(functionType.parameters, hasLength(1));
11479 _listener.assertNoErrors(); 11488 _listener.assertNoErrors();
11480 } 11489 }
11481 11490
11482 void test_visitFieldFormalParameter_noType() { 11491 void test_visitFieldFormalParameter_noType() {
11483 String parameterName = "p"; 11492 String parameterName = "p";
11484 FormalParameter node = AstFactory.fieldFormalParameter(Keyword.VAR, null, pa rameterName); 11493 FormalParameter node = AstFactory.fieldFormalParameter(Keyword.VAR, null, pa rameterName);
11485 node.identifier.staticElement = ElementFactory.requiredParameter(parameterNa me); 11494 node.identifier.staticElement = ElementFactory.requiredParameter(parameterNa me);
11486 expect(_resolveFormalParameter(node, []), same(_typeProvider.dynamicType)); 11495 expect(_resolveFormalParameter(node), same(_typeProvider.dynamicType));
11487 _listener.assertNoErrors(); 11496 _listener.assertNoErrors();
11488 } 11497 }
11489 11498
11490 void test_visitFieldFormalParameter_type() { 11499 void test_visitFieldFormalParameter_type() {
11491 InterfaceType intType = _typeProvider.intType; 11500 InterfaceType intType = _typeProvider.intType;
11492 TypeName intTypeName = AstFactory.typeName4("int", []); 11501 TypeName intTypeName = AstFactory.typeName4("int");
11493 String parameterName = "p"; 11502 String parameterName = "p";
11494 FormalParameter node = AstFactory.fieldFormalParameter(null, intTypeName, pa rameterName); 11503 FormalParameter node = AstFactory.fieldFormalParameter(null, intTypeName, pa rameterName);
11495 node.identifier.staticElement = ElementFactory.requiredParameter(parameterNa me); 11504 node.identifier.staticElement = ElementFactory.requiredParameter(parameterNa me);
11496 expect(_resolveFormalParameter(node, [intType.element]), same(intType)); 11505 expect(_resolveFormalParameter(node, [intType.element]), same(intType));
11497 _listener.assertNoErrors(); 11506 _listener.assertNoErrors();
11498 } 11507 }
11499 11508
11500 void test_visitSimpleFormalParameter_noType() { 11509 void test_visitSimpleFormalParameter_noType() {
11501 // p 11510 // p
11502 FormalParameter node = AstFactory.simpleFormalParameter3("p"); 11511 FormalParameter node = AstFactory.simpleFormalParameter3("p");
11503 node.identifier.staticElement = new ParameterElementImpl.forNode(AstFactory. identifier3("p")); 11512 node.identifier.staticElement = new ParameterElementImpl.forNode(AstFactory. identifier3("p"));
11504 expect(_resolveFormalParameter(node, []), same(_typeProvider.dynamicType)); 11513 expect(_resolveFormalParameter(node), same(_typeProvider.dynamicType));
11505 _listener.assertNoErrors(); 11514 _listener.assertNoErrors();
11506 } 11515 }
11507 11516
11508 void test_visitSimpleFormalParameter_type() { 11517 void test_visitSimpleFormalParameter_type() {
11509 // int p 11518 // int p
11510 InterfaceType intType = _typeProvider.intType; 11519 InterfaceType intType = _typeProvider.intType;
11511 ClassElement intElement = intType.element; 11520 ClassElement intElement = intType.element;
11512 FormalParameter node = AstFactory.simpleFormalParameter4(AstFactory.typeName (intElement, []), "p"); 11521 FormalParameter node = AstFactory.simpleFormalParameter4(AstFactory.typeName (intElement), "p");
11513 SimpleIdentifier identifier = node.identifier; 11522 SimpleIdentifier identifier = node.identifier;
11514 ParameterElementImpl element = new ParameterElementImpl.forNode(identifier); 11523 ParameterElementImpl element = new ParameterElementImpl.forNode(identifier);
11515 identifier.staticElement = element; 11524 identifier.staticElement = element;
11516 expect(_resolveFormalParameter(node, [intElement]), same(intType)); 11525 expect(_resolveFormalParameter(node, [intElement]), same(intType));
11517 _listener.assertNoErrors(); 11526 _listener.assertNoErrors();
11518 } 11527 }
11519 11528
11520 void test_visitTypeName_noParameters_noArguments() { 11529 void test_visitTypeName_noParameters_noArguments() {
11521 ClassElement classA = ElementFactory.classElement2("A", []); 11530 ClassElement classA = ElementFactory.classElement2("A");
11522 TypeName typeName = AstFactory.typeName(classA, []); 11531 TypeName typeName = AstFactory.typeName(classA);
11523 typeName.type = null; 11532 typeName.type = null;
11524 _resolveNode(typeName, [classA]); 11533 _resolveNode(typeName, [classA]);
11525 expect(typeName.type, same(classA.type)); 11534 expect(typeName.type, same(classA.type));
11526 _listener.assertNoErrors(); 11535 _listener.assertNoErrors();
11527 } 11536 }
11528 11537
11529 void test_visitTypeName_parameters_arguments() { 11538 void test_visitTypeName_parameters_arguments() {
11530 ClassElement classA = ElementFactory.classElement2("A", ["E"]); 11539 ClassElement classA = ElementFactory.classElement2("A", ["E"]);
11531 ClassElement classB = ElementFactory.classElement2("B", []); 11540 ClassElement classB = ElementFactory.classElement2("B");
11532 TypeName typeName = AstFactory.typeName(classA, [AstFactory.typeName(classB, [])]); 11541 TypeName typeName = AstFactory.typeName(classA, [AstFactory.typeName(classB) ]);
11533 typeName.type = null; 11542 typeName.type = null;
11534 _resolveNode(typeName, [classA, classB]); 11543 _resolveNode(typeName, [classA, classB]);
11535 InterfaceType resultType = typeName.type as InterfaceType; 11544 InterfaceType resultType = typeName.type as InterfaceType;
11536 expect(resultType.element, same(classA)); 11545 expect(resultType.element, same(classA));
11537 List<DartType> resultArguments = resultType.typeArguments; 11546 List<DartType> resultArguments = resultType.typeArguments;
11538 expect(resultArguments, hasLength(1)); 11547 expect(resultArguments, hasLength(1));
11539 expect(resultArguments[0], same(classB.type)); 11548 expect(resultArguments[0], same(classB.type));
11540 _listener.assertNoErrors(); 11549 _listener.assertNoErrors();
11541 } 11550 }
11542 11551
11543 void test_visitTypeName_parameters_noArguments() { 11552 void test_visitTypeName_parameters_noArguments() {
11544 ClassElement classA = ElementFactory.classElement2("A", ["E"]); 11553 ClassElement classA = ElementFactory.classElement2("A", ["E"]);
11545 TypeName typeName = AstFactory.typeName(classA, []); 11554 TypeName typeName = AstFactory.typeName(classA);
11546 typeName.type = null; 11555 typeName.type = null;
11547 _resolveNode(typeName, [classA]); 11556 _resolveNode(typeName, [classA]);
11548 InterfaceType resultType = typeName.type as InterfaceType; 11557 InterfaceType resultType = typeName.type as InterfaceType;
11549 expect(resultType.element, same(classA)); 11558 expect(resultType.element, same(classA));
11550 List<DartType> resultArguments = resultType.typeArguments; 11559 List<DartType> resultArguments = resultType.typeArguments;
11551 expect(resultArguments, hasLength(1)); 11560 expect(resultArguments, hasLength(1));
11552 expect(resultArguments[0], same(DynamicTypeImpl.instance)); 11561 expect(resultArguments[0], same(DynamicTypeImpl.instance));
11553 _listener.assertNoErrors(); 11562 _listener.assertNoErrors();
11554 } 11563 }
11555 11564
11556 void test_visitTypeName_void() { 11565 void test_visitTypeName_void() {
11557 ClassElement classA = ElementFactory.classElement2("A", []); 11566 ClassElement classA = ElementFactory.classElement2("A");
11558 TypeName typeName = AstFactory.typeName4("void", []); 11567 TypeName typeName = AstFactory.typeName4("void");
11559 _resolveNode(typeName, [classA]); 11568 _resolveNode(typeName, [classA]);
11560 expect(typeName.type, same(VoidTypeImpl.instance)); 11569 expect(typeName.type, same(VoidTypeImpl.instance));
11561 _listener.assertNoErrors(); 11570 _listener.assertNoErrors();
11562 } 11571 }
11563 11572
11564 /** 11573 /**
11565 * Analyze the given catch clause and assert that the types of the parameters have been set to the 11574 * Analyze the given catch clause and assert that the types of the parameters have been set to the
11566 * given types. The types can be null if the catch clause does not have the co rresponding 11575 * given types. The types can be null if the catch clause does not have the co rresponding
11567 * parameter. 11576 * parameter.
11568 * 11577 *
11569 * @param node the catch clause to be analyzed 11578 * @param node the catch clause to be analyzed
11570 * @param exceptionType the expected type of the exception parameter 11579 * @param exceptionType the expected type of the exception parameter
11571 * @param stackTraceType the expected type of the stack trace parameter 11580 * @param stackTraceType the expected type of the stack trace parameter
11572 * @param definedElements the elements that are to be defined in the scope in which the element is 11581 * @param definedElements the elements that are to be defined in the scope in which the element is
11573 * being resolved 11582 * being resolved
11574 */ 11583 */
11575 void _resolveCatchClause(CatchClause node, DartType exceptionType, InterfaceTy pe stackTraceType, List<Element> definedElements) { 11584 void _resolveCatchClause(CatchClause node, DartType exceptionType, InterfaceTy pe stackTraceType, [List<Element> definedElements]) {
11576 _resolveNode(node, definedElements); 11585 _resolveNode(node, definedElements);
11577 SimpleIdentifier exceptionParameter = node.exceptionParameter; 11586 SimpleIdentifier exceptionParameter = node.exceptionParameter;
11578 if (exceptionParameter != null) { 11587 if (exceptionParameter != null) {
11579 expect(exceptionParameter.staticType, same(exceptionType)); 11588 expect(exceptionParameter.staticType, same(exceptionType));
11580 } 11589 }
11581 SimpleIdentifier stackTraceParameter = node.stackTraceParameter; 11590 SimpleIdentifier stackTraceParameter = node.stackTraceParameter;
11582 if (stackTraceParameter != null) { 11591 if (stackTraceParameter != null) {
11583 expect(stackTraceParameter.staticType, same(stackTraceType)); 11592 expect(stackTraceParameter.staticType, same(stackTraceType));
11584 } 11593 }
11585 } 11594 }
11586 11595
11587 /** 11596 /**
11588 * Return the type associated with the given parameter after the static type a nalyzer has computed 11597 * Return the type associated with the given parameter after the static type a nalyzer has computed
11589 * a type for it. 11598 * a type for it.
11590 * 11599 *
11591 * @param node the parameter with which the type is associated 11600 * @param node the parameter with which the type is associated
11592 * @param definedElements the elements that are to be defined in the scope in which the element is 11601 * @param definedElements the elements that are to be defined in the scope in which the element is
11593 * being resolved 11602 * being resolved
11594 * @return the type associated with the parameter 11603 * @return the type associated with the parameter
11595 */ 11604 */
11596 DartType _resolveFormalParameter(FormalParameter node, List<Element> definedEl ements) { 11605 DartType _resolveFormalParameter(FormalParameter node, [List<Element> definedE lements]) {
11597 _resolveNode(node, definedElements); 11606 _resolveNode(node, definedElements);
11598 return (node.identifier.staticElement as ParameterElement).type; 11607 return (node.identifier.staticElement as ParameterElement).type;
11599 } 11608 }
11600 11609
11601 /** 11610 /**
11602 * Return the element associated with the given identifier after the resolver has resolved the 11611 * Return the element associated with the given identifier after the resolver has resolved the
11603 * identifier. 11612 * identifier.
11604 * 11613 *
11605 * @param node the expression to be resolved 11614 * @param node the expression to be resolved
11606 * @param definedElements the elements that are to be defined in the scope in which the element is 11615 * @param definedElements the elements that are to be defined in the scope in which the element is
11607 * being resolved 11616 * being resolved
11608 * @return the element to which the expression was resolved 11617 * @return the element to which the expression was resolved
11609 */ 11618 */
11610 void _resolveNode(AstNode node, List<Element> definedElements) { 11619 void _resolveNode(AstNode node, [List<Element> definedElements]) {
11611 for (Element element in definedElements) { 11620 if (definedElements != null) {
11612 _library.libraryScope.define(element); 11621 for (Element element in definedElements) {
11622 _library.libraryScope.define(element);
11623 }
11613 } 11624 }
11614 node.accept(_visitor); 11625 node.accept(_visitor);
11615 node.accept(_implicitConstructorBuilder); 11626 node.accept(_implicitConstructorBuilder);
11616 } 11627 }
11617 } 11628 }
11618 11629
11619 main() { 11630 main() {
11620 groupSep = ' | '; 11631 groupSep = ' | ';
11621 runReflectiveTests(AnalysisDeltaTest); 11632 runReflectiveTests(AnalysisDeltaTest);
11622 runReflectiveTests(ChangeSetTest); 11633 runReflectiveTests(ChangeSetTest);
(...skipping 18 matching lines...) Expand all
11641 runReflectiveTests(TypeResolverVisitorTest); 11652 runReflectiveTests(TypeResolverVisitorTest);
11642 runReflectiveTests(CheckedModeCompileTimeErrorCodeTest); 11653 runReflectiveTests(CheckedModeCompileTimeErrorCodeTest);
11643 runReflectiveTests(ErrorResolverTest); 11654 runReflectiveTests(ErrorResolverTest);
11644 runReflectiveTests(HintCodeTest); 11655 runReflectiveTests(HintCodeTest);
11645 runReflectiveTests(MemberMapTest); 11656 runReflectiveTests(MemberMapTest);
11646 runReflectiveTests(NonHintCodeTest); 11657 runReflectiveTests(NonHintCodeTest);
11647 runReflectiveTests(SimpleResolverTest); 11658 runReflectiveTests(SimpleResolverTest);
11648 runReflectiveTests(StrictModeTest); 11659 runReflectiveTests(StrictModeTest);
11649 runReflectiveTests(TypePropagationTest); 11660 runReflectiveTests(TypePropagationTest);
11650 } 11661 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/parser_test.dart ('k') | pkg/analyzer/test/generated/test_support.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698