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

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

Issue 351283003: Move Tokenfactory, AstFactory and ElementFactory from tests to the testing/ Folder. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/analyzer/test/generated/ast_test.dart ('k') | pkg/analyzer/test/generated/parser_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.element_test; 8 library engine.element_test;
9 9
10 import 'package:analyzer/src/generated/java_core.dart'; 10 import 'package:analyzer/src/generated/java_core.dart';
11 import 'package:analyzer/src/generated/java_engine_io.dart';
12 import 'package:analyzer/src/generated/java_junit.dart'; 11 import 'package:analyzer/src/generated/java_junit.dart';
13 import 'package:analyzer/src/generated/source_io.dart'; 12 import 'package:analyzer/src/generated/source_io.dart';
14 import 'package:analyzer/src/generated/utilities_dart.dart';
15 import 'package:analyzer/src/generated/ast.dart'; 13 import 'package:analyzer/src/generated/ast.dart';
16 import 'package:analyzer/src/generated/element.dart'; 14 import 'package:analyzer/src/generated/element.dart';
17 import 'package:analyzer/src/generated/engine.dart' show AnalysisContext, Analys isContextImpl; 15 import 'package:analyzer/src/generated/engine.dart' show AnalysisContext, Analys isContextImpl;
18 import 'package:unittest/unittest.dart' as _ut; 16 import 'package:unittest/unittest.dart' as _ut;
19 import 'test_support.dart'; 17 import 'test_support.dart';
20 import 'ast_test.dart' show AstFactory; 18 import 'package:analyzer/src/generated/testing/ast_factory.dart';
19 import 'package:analyzer/src/generated/testing/element_factory.dart';
21 import 'resolver_test.dart' show TestTypeProvider, AnalysisContextHelper; 20 import 'resolver_test.dart' show TestTypeProvider, AnalysisContextHelper;
22 21
23 class AngularPropertyKindTest extends EngineTestCase { 22 class AngularPropertyKindTest extends EngineTestCase {
24 void test_ATTR() { 23 void test_ATTR() {
25 AngularPropertyKind kind = AngularPropertyKind.ATTR; 24 AngularPropertyKind kind = AngularPropertyKind.ATTR;
26 JUnitTestCase.assertFalse(kind.callsGetter()); 25 JUnitTestCase.assertFalse(kind.callsGetter());
27 JUnitTestCase.assertTrue(kind.callsSetter()); 26 JUnitTestCase.assertTrue(kind.callsSetter());
28 } 27 }
29 28
30 void test_CALLBACK() { 29 void test_CALLBACK() {
(...skipping 978 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 runJUnitTest(__test, __test.test_lookUpSetter_undeclared); 1008 runJUnitTest(__test, __test.test_lookUpSetter_undeclared);
1010 }); 1009 });
1011 _ut.test('test_lookUpSetter_undeclared_recursive', () { 1010 _ut.test('test_lookUpSetter_undeclared_recursive', () {
1012 final __test = new ClassElementImplTest(); 1011 final __test = new ClassElementImplTest();
1013 runJUnitTest(__test, __test.test_lookUpSetter_undeclared_recursive); 1012 runJUnitTest(__test, __test.test_lookUpSetter_undeclared_recursive);
1014 }); 1013 });
1015 }); 1014 });
1016 } 1015 }
1017 } 1016 }
1018 1017
1019 /**
1020 * The class `ElementFactory` defines utility methods used to create elements fo r testing
1021 * purposes. The elements that are created are complete in the sense that as muc h of the element
1022 * model as can be created, given the provided information, has been created.
1023 */
1024 class ElementFactory {
1025 /**
1026 * The element representing the class 'Object'.
1027 */
1028 static ClassElementImpl _objectElement;
1029
1030 static ClassElementImpl classElement(String typeName, InterfaceType superclass Type, List<String> parameterNames) {
1031 ClassElementImpl element = new ClassElementImpl(AstFactory.identifier3(typeN ame));
1032 element.supertype = superclassType;
1033 InterfaceTypeImpl type = new InterfaceTypeImpl.con1(element);
1034 element.type = type;
1035 int count = parameterNames.length;
1036 if (count > 0) {
1037 List<TypeParameterElementImpl> typeParameters = new List<TypeParameterElem entImpl>(count);
1038 List<TypeParameterTypeImpl> typeParameterTypes = new List<TypeParameterTyp eImpl>(count);
1039 for (int i = 0; i < count; i++) {
1040 TypeParameterElementImpl typeParameter = new TypeParameterElementImpl(As tFactory.identifier3(parameterNames[i]));
1041 typeParameters[i] = typeParameter;
1042 typeParameterTypes[i] = new TypeParameterTypeImpl(typeParameter);
1043 typeParameter.type = typeParameterTypes[i];
1044 }
1045 element.typeParameters = typeParameters;
1046 type.typeArguments = typeParameterTypes;
1047 }
1048 return element;
1049 }
1050
1051 static ClassElementImpl classElement2(String typeName, List<String> parameterN ames) => classElement(typeName, object.type, parameterNames);
1052
1053 static CompilationUnitElementImpl compilationUnit(String fileName) {
1054 FileBasedSource source = new FileBasedSource.con1(FileUtilities2.createFile( fileName));
1055 CompilationUnitElementImpl unit = new CompilationUnitElementImpl(fileName);
1056 unit.source = source;
1057 return unit;
1058 }
1059
1060 static ConstructorElementImpl constructorElement(ClassElement definingClass, S tring name, bool isConst, List<DartType> argumentTypes) {
1061 DartType type = definingClass.type;
1062 ConstructorElementImpl constructor = new ConstructorElementImpl.forNode(name == null ? null : AstFactory.identifier3(name));
1063 constructor.const2 = isConst;
1064 int count = argumentTypes.length;
1065 List<ParameterElement> parameters = new List<ParameterElement>(count);
1066 for (int i = 0; i < count; i++) {
1067 ParameterElementImpl parameter = new ParameterElementImpl.con1(AstFactory. identifier3("a${i}"));
1068 parameter.type = argumentTypes[i];
1069 parameter.parameterKind = ParameterKind.REQUIRED;
1070 parameters[i] = parameter;
1071 }
1072 constructor.parameters = parameters;
1073 constructor.returnType = type;
1074 FunctionTypeImpl constructorType = new FunctionTypeImpl.con1(constructor);
1075 constructor.type = constructorType;
1076 return constructor;
1077 }
1078
1079 static ConstructorElementImpl constructorElement2(ClassElement definingClass, String name, List<DartType> argumentTypes) => constructorElement(definingClass, name, false, argumentTypes);
1080
1081 static ExportElementImpl exportFor(LibraryElement exportedLibrary, List<Namesp aceCombinator> combinators) {
1082 ExportElementImpl spec = new ExportElementImpl();
1083 spec.exportedLibrary = exportedLibrary;
1084 spec.combinators = combinators;
1085 return spec;
1086 }
1087
1088 static FieldElementImpl fieldElement(String name, bool isStatic, bool isFinal, bool isConst, DartType type) {
1089 FieldElementImpl field = new FieldElementImpl.con1(AstFactory.identifier3(na me));
1090 field.const3 = isConst;
1091 field.final2 = isFinal;
1092 field.static = isStatic;
1093 field.type = type;
1094 PropertyAccessorElementImpl getter = new PropertyAccessorElementImpl(field);
1095 getter.getter = true;
1096 getter.static = isStatic;
1097 getter.synthetic = true;
1098 getter.variable = field;
1099 getter.returnType = type;
1100 field.getter = getter;
1101 FunctionTypeImpl getterType = new FunctionTypeImpl.con1(getter);
1102 getter.type = getterType;
1103 if (!isConst && !isFinal) {
1104 PropertyAccessorElementImpl setter = new PropertyAccessorElementImpl(field );
1105 setter.setter = true;
1106 setter.static = isStatic;
1107 setter.synthetic = true;
1108 setter.variable = field;
1109 setter.parameters = <ParameterElement> [requiredParameter2("_${name}", typ e)];
1110 setter.returnType = VoidTypeImpl.instance;
1111 setter.type = new FunctionTypeImpl.con1(setter);
1112 field.setter = setter;
1113 }
1114 return field;
1115 }
1116
1117 static FieldFormalParameterElementImpl fieldFormalParameter(Identifier name) = > new FieldFormalParameterElementImpl(name);
1118
1119 static FunctionElementImpl functionElement(String functionName) => functionEle ment4(functionName, null, null, null, null);
1120
1121 static FunctionElementImpl functionElement2(String functionName, ClassElement returnElement) => functionElement3(functionName, returnElement, null, null);
1122
1123 static FunctionElementImpl functionElement3(String functionName, ClassElement returnElement, List<ClassElement> normalParameters, List<ClassElement> optionalP arameters) {
1124 // We don't create parameter elements because we don't have parameter names
1125 FunctionElementImpl functionElement = new FunctionElementImpl.forNode(AstFac tory.identifier3(functionName));
1126 FunctionTypeImpl functionType = new FunctionTypeImpl.con1(functionElement);
1127 functionElement.type = functionType;
1128 // return type
1129 if (returnElement == null) {
1130 functionElement.returnType = VoidTypeImpl.instance;
1131 } else {
1132 functionElement.returnType = returnElement.type;
1133 }
1134 // parameters
1135 int normalCount = normalParameters == null ? 0 : normalParameters.length;
1136 int optionalCount = optionalParameters == null ? 0 : optionalParameters.leng th;
1137 int totalCount = normalCount + optionalCount;
1138 List<ParameterElement> parameters = new List<ParameterElement>(totalCount);
1139 for (int i = 0; i < totalCount; i++) {
1140 ParameterElementImpl parameter = new ParameterElementImpl.con1(AstFactory. identifier3("a${i}"));
1141 if (i < normalCount) {
1142 parameter.type = normalParameters[i].type;
1143 parameter.parameterKind = ParameterKind.REQUIRED;
1144 } else {
1145 parameter.type = optionalParameters[i - normalCount].type;
1146 parameter.parameterKind = ParameterKind.POSITIONAL;
1147 }
1148 parameters[i] = parameter;
1149 }
1150 functionElement.parameters = parameters;
1151 // done
1152 return functionElement;
1153 }
1154
1155 static FunctionElementImpl functionElement4(String functionName, ClassElement returnElement, List<ClassElement> normalParameters, List<String> names, List<Cla ssElement> namedParameters) {
1156 FunctionElementImpl functionElement = new FunctionElementImpl.forNode(AstFac tory.identifier3(functionName));
1157 FunctionTypeImpl functionType = new FunctionTypeImpl.con1(functionElement);
1158 functionElement.type = functionType;
1159 // parameters
1160 int normalCount = normalParameters == null ? 0 : normalParameters.length;
1161 int nameCount = names == null ? 0 : names.length;
1162 int typeCount = namedParameters == null ? 0 : namedParameters.length;
1163 if (names != null && nameCount != typeCount) {
1164 throw new IllegalStateException("The passed String[] and ClassElement[] ar rays had different lengths.");
1165 }
1166 int totalCount = normalCount + nameCount;
1167 List<ParameterElement> parameters = new List<ParameterElement>(totalCount);
1168 for (int i = 0; i < totalCount; i++) {
1169 if (i < normalCount) {
1170 ParameterElementImpl parameter = new ParameterElementImpl.con1(AstFactor y.identifier3("a${i}"));
1171 parameter.type = normalParameters[i].type;
1172 parameter.parameterKind = ParameterKind.REQUIRED;
1173 parameters[i] = parameter;
1174 } else {
1175 ParameterElementImpl parameter = new ParameterElementImpl.con1(AstFactor y.identifier3(names[i - normalCount]));
1176 parameter.type = namedParameters[i - normalCount].type;
1177 parameter.parameterKind = ParameterKind.NAMED;
1178 parameters[i] = parameter;
1179 }
1180 }
1181 functionElement.parameters = parameters;
1182 // return type
1183 if (returnElement == null) {
1184 functionElement.returnType = VoidTypeImpl.instance;
1185 } else {
1186 functionElement.returnType = returnElement.type;
1187 }
1188 return functionElement;
1189 }
1190
1191 static FunctionElementImpl functionElement5(String functionName, List<ClassEle ment> normalParameters) => functionElement3(functionName, null, normalParameters , null);
1192
1193 static FunctionElementImpl functionElement6(String functionName, List<ClassEle ment> normalParameters, List<ClassElement> optionalParameters) => functionElemen t3(functionName, null, normalParameters, optionalParameters);
1194
1195 static FunctionElementImpl functionElement7(String functionName, List<ClassEle ment> normalParameters, List<String> names, List<ClassElement> namedParameters) => functionElement4(functionName, null, normalParameters, names, namedParameters );
1196
1197 static FunctionElementImpl functionElementWithParameters(String functionName, DartType returnType, List<ParameterElement> parameters) {
1198 FunctionElementImpl functionElement = new FunctionElementImpl.forNode(AstFac tory.identifier3(functionName));
1199 functionElement.returnType = returnType == null ? VoidTypeImpl.instance : re turnType;
1200 functionElement.parameters = parameters;
1201 FunctionTypeImpl functionType = new FunctionTypeImpl.con1(functionElement);
1202 functionElement.type = functionType;
1203 return functionElement;
1204 }
1205
1206 static ClassElementImpl get object {
1207 if (_objectElement == null) {
1208 _objectElement = classElement("Object", null, []);
1209 }
1210 return _objectElement;
1211 }
1212
1213 static PropertyAccessorElementImpl getterElement(String name, bool isStatic, D artType type) {
1214 FieldElementImpl field = new FieldElementImpl.con1(AstFactory.identifier3(na me));
1215 field.static = isStatic;
1216 field.synthetic = true;
1217 field.type = type;
1218 PropertyAccessorElementImpl getter = new PropertyAccessorElementImpl(field);
1219 getter.getter = true;
1220 getter.static = isStatic;
1221 getter.variable = field;
1222 getter.returnType = type;
1223 field.getter = getter;
1224 FunctionTypeImpl getterType = new FunctionTypeImpl.con1(getter);
1225 getter.type = getterType;
1226 return getter;
1227 }
1228
1229 static HtmlElementImpl htmlUnit(AnalysisContext context, String fileName) {
1230 FileBasedSource source = new FileBasedSource.con1(FileUtilities2.createFile( fileName));
1231 HtmlElementImpl unit = new HtmlElementImpl(context, fileName);
1232 unit.source = source;
1233 return unit;
1234 }
1235
1236 static ImportElementImpl importFor(LibraryElement importedLibrary, PrefixEleme nt prefix, List<NamespaceCombinator> combinators) {
1237 ImportElementImpl spec = new ImportElementImpl(0);
1238 spec.importedLibrary = importedLibrary;
1239 spec.prefix = prefix;
1240 spec.combinators = combinators;
1241 return spec;
1242 }
1243
1244 static LibraryElementImpl library(AnalysisContext context, String libraryName) {
1245 String fileName = "/${libraryName}.dart";
1246 CompilationUnitElementImpl unit = compilationUnit(fileName);
1247 LibraryElementImpl library = new LibraryElementImpl(context, AstFactory.libr aryIdentifier2([libraryName]));
1248 library.definingCompilationUnit = unit;
1249 return library;
1250 }
1251
1252 static LocalVariableElementImpl localVariableElement(Identifier name) => new L ocalVariableElementImpl(name);
1253
1254 static LocalVariableElementImpl localVariableElement2(String name) => new Loca lVariableElementImpl(AstFactory.identifier3(name));
1255
1256 static MethodElementImpl methodElement(String methodName, DartType returnType, List<DartType> argumentTypes) {
1257 MethodElementImpl method = new MethodElementImpl.forNode(AstFactory.identifi er3(methodName));
1258 int count = argumentTypes.length;
1259 List<ParameterElement> parameters = new List<ParameterElement>(count);
1260 for (int i = 0; i < count; i++) {
1261 ParameterElementImpl parameter = new ParameterElementImpl.con1(AstFactory. identifier3("a${i}"));
1262 parameter.type = argumentTypes[i];
1263 parameter.parameterKind = ParameterKind.REQUIRED;
1264 parameters[i] = parameter;
1265 }
1266 method.parameters = parameters;
1267 method.returnType = returnType;
1268 FunctionTypeImpl methodType = new FunctionTypeImpl.con1(method);
1269 method.type = methodType;
1270 return method;
1271 }
1272
1273 static MethodElementImpl methodElementWithParameters(String methodName, List<D artType> typeArguments, DartType returnType, List<ParameterElement> parameters) {
1274 MethodElementImpl method = new MethodElementImpl.forNode(AstFactory.identifi er3(methodName));
1275 method.parameters = parameters;
1276 method.returnType = returnType;
1277 FunctionTypeImpl methodType = new FunctionTypeImpl.con1(method);
1278 methodType.typeArguments = typeArguments;
1279 method.type = methodType;
1280 return method;
1281 }
1282
1283 static ParameterElementImpl namedParameter(String name) {
1284 ParameterElementImpl parameter = new ParameterElementImpl.con1(AstFactory.id entifier3(name));
1285 parameter.parameterKind = ParameterKind.NAMED;
1286 return parameter;
1287 }
1288
1289 static ParameterElementImpl namedParameter2(String name, DartType type) {
1290 ParameterElementImpl parameter = new ParameterElementImpl.con1(AstFactory.id entifier3(name));
1291 parameter.parameterKind = ParameterKind.NAMED;
1292 parameter.type = type;
1293 return parameter;
1294 }
1295
1296 static ParameterElementImpl positionalParameter(String name) {
1297 ParameterElementImpl parameter = new ParameterElementImpl.con1(AstFactory.id entifier3(name));
1298 parameter.parameterKind = ParameterKind.POSITIONAL;
1299 return parameter;
1300 }
1301
1302 static ParameterElementImpl positionalParameter2(String name, DartType type) {
1303 ParameterElementImpl parameter = new ParameterElementImpl.con1(AstFactory.id entifier3(name));
1304 parameter.parameterKind = ParameterKind.POSITIONAL;
1305 parameter.type = type;
1306 return parameter;
1307 }
1308
1309 static PrefixElementImpl prefix(String name) => new PrefixElementImpl(AstFacto ry.identifier3(name));
1310
1311 static ParameterElementImpl requiredParameter(String name) {
1312 ParameterElementImpl parameter = new ParameterElementImpl.con1(AstFactory.id entifier3(name));
1313 parameter.parameterKind = ParameterKind.REQUIRED;
1314 return parameter;
1315 }
1316
1317 static ParameterElementImpl requiredParameter2(String name, DartType type) {
1318 ParameterElementImpl parameter = new ParameterElementImpl.con1(AstFactory.id entifier3(name));
1319 parameter.parameterKind = ParameterKind.REQUIRED;
1320 parameter.type = type;
1321 return parameter;
1322 }
1323
1324 static PropertyAccessorElementImpl setterElement(String name, bool isStatic, D artType type) {
1325 FieldElementImpl field = new FieldElementImpl.con1(AstFactory.identifier3(na me));
1326 field.static = isStatic;
1327 field.synthetic = true;
1328 field.type = type;
1329 PropertyAccessorElementImpl getter = new PropertyAccessorElementImpl(field);
1330 getter.getter = true;
1331 getter.static = isStatic;
1332 getter.variable = field;
1333 getter.returnType = type;
1334 field.getter = getter;
1335 FunctionTypeImpl getterType = new FunctionTypeImpl.con1(getter);
1336 getter.type = getterType;
1337 ParameterElementImpl parameter = requiredParameter2("a", type);
1338 PropertyAccessorElementImpl setter = new PropertyAccessorElementImpl(field);
1339 setter.setter = true;
1340 setter.static = isStatic;
1341 setter.synthetic = true;
1342 setter.variable = field;
1343 setter.parameters = <ParameterElement> [parameter];
1344 setter.returnType = VoidTypeImpl.instance;
1345 setter.type = new FunctionTypeImpl.con1(setter);
1346 field.setter = setter;
1347 return setter;
1348 }
1349
1350 static TopLevelVariableElementImpl topLevelVariableElement(Identifier name) => new TopLevelVariableElementImpl.con1(name);
1351
1352 static TopLevelVariableElementImpl topLevelVariableElement2(String name) => ne w TopLevelVariableElementImpl.con2(name);
1353
1354 static TopLevelVariableElementImpl topLevelVariableElement3(String name, bool isConst, bool isFinal, DartType type) {
1355 TopLevelVariableElementImpl variable = new TopLevelVariableElementImpl.con2( name);
1356 variable.const3 = isConst;
1357 variable.final2 = isFinal;
1358 PropertyAccessorElementImpl getter = new PropertyAccessorElementImpl(variabl e);
1359 getter.getter = true;
1360 getter.static = true;
1361 getter.synthetic = true;
1362 getter.variable = variable;
1363 getter.returnType = type;
1364 variable.getter = getter;
1365 FunctionTypeImpl getterType = new FunctionTypeImpl.con1(getter);
1366 getter.type = getterType;
1367 if (!isFinal) {
1368 PropertyAccessorElementImpl setter = new PropertyAccessorElementImpl(varia ble);
1369 setter.setter = true;
1370 setter.static = true;
1371 setter.synthetic = true;
1372 setter.variable = variable;
1373 setter.parameters = <ParameterElement> [requiredParameter2("_${name}", typ e)];
1374 setter.returnType = VoidTypeImpl.instance;
1375 setter.type = new FunctionTypeImpl.con1(setter);
1376 variable.setter = setter;
1377 }
1378 return variable;
1379 }
1380 }
1381
1382 class ElementImplTest extends EngineTestCase { 1018 class ElementImplTest extends EngineTestCase {
1383 void test_equals() { 1019 void test_equals() {
1384 LibraryElementImpl library = ElementFactory.library(createAnalysisContext(), "lib"); 1020 LibraryElementImpl library = ElementFactory.library(createAnalysisContext(), "lib");
1385 ClassElementImpl classElement = ElementFactory.classElement2("C", []); 1021 ClassElementImpl classElement = ElementFactory.classElement2("C", []);
1386 (library.definingCompilationUnit as CompilationUnitElementImpl).types = <Cla ssElement> [classElement]; 1022 (library.definingCompilationUnit as CompilationUnitElementImpl).types = <Cla ssElement> [classElement];
1387 FieldElement field = ElementFactory.fieldElement("next", false, false, false , classElement.type); 1023 FieldElement field = ElementFactory.fieldElement("next", false, false, false , classElement.type);
1388 classElement.fields = <FieldElement> [field]; 1024 classElement.fields = <FieldElement> [field];
1389 JUnitTestCase.assertTrue(field == field); 1025 JUnitTestCase.assertTrue(field == field);
1390 JUnitTestCase.assertFalse(field == field.getter); 1026 JUnitTestCase.assertFalse(field == field.getter);
1391 JUnitTestCase.assertFalse(field == field.setter); 1027 JUnitTestCase.assertFalse(field == field.setter);
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after
1989 // ! () -> A <: () -> B 1625 // ! () -> A <: () -> B
1990 FunctionType t = ElementFactory.functionElement2("t", ElementFactory.classEl ement2("A", [])).type; 1626 FunctionType t = ElementFactory.functionElement2("t", ElementFactory.classEl ement2("A", [])).type;
1991 FunctionType s = ElementFactory.functionElement2("s", ElementFactory.classEl ement2("B", [])).type; 1627 FunctionType s = ElementFactory.functionElement2("s", ElementFactory.classEl ement2("B", [])).type;
1992 JUnitTestCase.assertFalse(t.isSubtypeOf(s)); 1628 JUnitTestCase.assertFalse(t.isSubtypeOf(s));
1993 } 1629 }
1994 1630
1995 void test_isSubtypeOf_typeParameters_matchesBounds() { 1631 void test_isSubtypeOf_typeParameters_matchesBounds() {
1996 TestTypeProvider provider = new TestTypeProvider(); 1632 TestTypeProvider provider = new TestTypeProvider();
1997 InterfaceType boolType = provider.boolType; 1633 InterfaceType boolType = provider.boolType;
1998 InterfaceType stringType = provider.stringType; 1634 InterfaceType stringType = provider.stringType;
1999 TypeParameterElementImpl parameterB = new TypeParameterElementImpl(AstFactor y.identifier3("B")); 1635 TypeParameterElementImpl parameterB = new TypeParameterElementImpl.forNode(A stFactory.identifier3("B"));
2000 parameterB.bound = boolType; 1636 parameterB.bound = boolType;
2001 TypeParameterTypeImpl typeB = new TypeParameterTypeImpl(parameterB); 1637 TypeParameterTypeImpl typeB = new TypeParameterTypeImpl(parameterB);
2002 TypeParameterElementImpl parameterS = new TypeParameterElementImpl(AstFactor y.identifier3("S")); 1638 TypeParameterElementImpl parameterS = new TypeParameterElementImpl.forNode(A stFactory.identifier3("S"));
2003 parameterS.bound = stringType; 1639 parameterS.bound = stringType;
2004 TypeParameterTypeImpl typeS = new TypeParameterTypeImpl(parameterS); 1640 TypeParameterTypeImpl typeS = new TypeParameterTypeImpl(parameterS);
2005 FunctionElementImpl functionAliasElement = new FunctionElementImpl.forNode(A stFactory.identifier3("func")); 1641 FunctionElementImpl functionAliasElement = new FunctionElementImpl.forNode(A stFactory.identifier3("func"));
2006 functionAliasElement.parameters = <ParameterElement> [ 1642 functionAliasElement.parameters = <ParameterElement> [
2007 ElementFactory.requiredParameter2("a", typeB), 1643 ElementFactory.requiredParameter2("a", typeB),
2008 ElementFactory.positionalParameter2("b", typeS)]; 1644 ElementFactory.positionalParameter2("b", typeS)];
2009 functionAliasElement.returnType = stringType; 1645 functionAliasElement.returnType = stringType;
2010 FunctionTypeImpl functionAliasType = new FunctionTypeImpl.con1(functionAlias Element); 1646 FunctionTypeImpl functionAliasType = new FunctionTypeImpl.con1(functionAlias Element);
2011 functionAliasElement.type = functionAliasType; 1647 functionAliasElement.type = functionAliasType;
2012 FunctionElementImpl functionElement = new FunctionElementImpl.forNode(AstFac tory.identifier3("f")); 1648 FunctionElementImpl functionElement = new FunctionElementImpl.forNode(AstFac tory.identifier3("f"));
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2057 MethodElementImpl functionElement = new MethodElementImpl.forNode(AstFactory .identifier3("m")); 1693 MethodElementImpl functionElement = new MethodElementImpl.forNode(AstFactory .identifier3("m"));
2058 String namedParameterName = "c"; 1694 String namedParameterName = "c";
2059 functionElement.parameters = <ParameterElement> [ 1695 functionElement.parameters = <ParameterElement> [
2060 ElementFactory.requiredParameter2("a", parameterType), 1696 ElementFactory.requiredParameter2("a", parameterType),
2061 ElementFactory.positionalParameter2("b", parameterType), 1697 ElementFactory.positionalParameter2("b", parameterType),
2062 ElementFactory.namedParameter2(namedParameterName, parameterType)]; 1698 ElementFactory.namedParameter2(namedParameterName, parameterType)];
2063 functionElement.returnType = parameterType; 1699 functionElement.returnType = parameterType;
2064 definingClass.methods = <MethodElement> [functionElement]; 1700 definingClass.methods = <MethodElement> [functionElement];
2065 FunctionTypeImpl functionType = new FunctionTypeImpl.con1(functionElement); 1701 FunctionTypeImpl functionType = new FunctionTypeImpl.con1(functionElement);
2066 functionType.typeArguments = <DartType> [parameterType]; 1702 functionType.typeArguments = <DartType> [parameterType];
2067 InterfaceTypeImpl argumentType = new InterfaceTypeImpl.con1(new ClassElement Impl(AstFactory.identifier3("D"))); 1703 InterfaceTypeImpl argumentType = new InterfaceTypeImpl.con1(new ClassElement Impl.forNode(AstFactory.identifier3("D")));
2068 FunctionType result = functionType.substitute2(<DartType> [argumentType], <D artType> [parameterType]); 1704 FunctionType result = functionType.substitute2(<DartType> [argumentType], <D artType> [parameterType]);
2069 JUnitTestCase.assertEquals(argumentType, result.returnType); 1705 JUnitTestCase.assertEquals(argumentType, result.returnType);
2070 List<DartType> normalParameters = result.normalParameterTypes; 1706 List<DartType> normalParameters = result.normalParameterTypes;
2071 EngineTestCase.assertLength(1, normalParameters); 1707 EngineTestCase.assertLength(1, normalParameters);
2072 JUnitTestCase.assertEquals(argumentType, normalParameters[0]); 1708 JUnitTestCase.assertEquals(argumentType, normalParameters[0]);
2073 List<DartType> optionalParameters = result.optionalParameterTypes; 1709 List<DartType> optionalParameters = result.optionalParameterTypes;
2074 EngineTestCase.assertLength(1, optionalParameters); 1710 EngineTestCase.assertLength(1, optionalParameters);
2075 JUnitTestCase.assertEquals(argumentType, optionalParameters[0]); 1711 JUnitTestCase.assertEquals(argumentType, optionalParameters[0]);
2076 Map<String, DartType> namedParameters = result.namedParameterTypes; 1712 Map<String, DartType> namedParameters = result.namedParameterTypes;
2077 EngineTestCase.assertSizeOfMap(1, namedParameters); 1713 EngineTestCase.assertSizeOfMap(1, namedParameters);
2078 JUnitTestCase.assertEquals(argumentType, namedParameters[namedParameterName] ); 1714 JUnitTestCase.assertEquals(argumentType, namedParameters[namedParameterName] );
2079 } 1715 }
2080 1716
2081 void test_substitute2_notEqual() { 1717 void test_substitute2_notEqual() {
2082 DartType returnType = new InterfaceTypeImpl.con1(new ClassElementImpl(AstFac tory.identifier3("R"))); 1718 DartType returnType = new InterfaceTypeImpl.con1(new ClassElementImpl.forNod e(AstFactory.identifier3("R")));
2083 DartType normalParameterType = new InterfaceTypeImpl.con1(new ClassElementIm pl(AstFactory.identifier3("A"))); 1719 DartType normalParameterType = new InterfaceTypeImpl.con1(new ClassElementIm pl.forNode(AstFactory.identifier3("A")));
2084 DartType optionalParameterType = new InterfaceTypeImpl.con1(new ClassElement Impl(AstFactory.identifier3("B"))); 1720 DartType optionalParameterType = new InterfaceTypeImpl.con1(new ClassElement Impl.forNode(AstFactory.identifier3("B")));
2085 DartType namedParameterType = new InterfaceTypeImpl.con1(new ClassElementImp l(AstFactory.identifier3("C"))); 1721 DartType namedParameterType = new InterfaceTypeImpl.con1(new ClassElementImp l.forNode(AstFactory.identifier3("C")));
2086 FunctionElementImpl functionElement = new FunctionElementImpl.forNode(AstFac tory.identifier3("f")); 1722 FunctionElementImpl functionElement = new FunctionElementImpl.forNode(AstFac tory.identifier3("f"));
2087 String namedParameterName = "c"; 1723 String namedParameterName = "c";
2088 functionElement.parameters = <ParameterElement> [ 1724 functionElement.parameters = <ParameterElement> [
2089 ElementFactory.requiredParameter2("a", normalParameterType), 1725 ElementFactory.requiredParameter2("a", normalParameterType),
2090 ElementFactory.positionalParameter2("b", optionalParameterType), 1726 ElementFactory.positionalParameter2("b", optionalParameterType),
2091 ElementFactory.namedParameter2(namedParameterName, namedParameterType)]; 1727 ElementFactory.namedParameter2(namedParameterName, namedParameterType)];
2092 functionElement.returnType = returnType; 1728 functionElement.returnType = returnType;
2093 FunctionTypeImpl functionType = new FunctionTypeImpl.con1(functionElement); 1729 FunctionTypeImpl functionType = new FunctionTypeImpl.con1(functionElement);
2094 InterfaceTypeImpl argumentType = new InterfaceTypeImpl.con1(new ClassElement Impl(AstFactory.identifier3("D"))); 1730 InterfaceTypeImpl argumentType = new InterfaceTypeImpl.con1(new ClassElement Impl.forNode(AstFactory.identifier3("D")));
2095 TypeParameterTypeImpl parameterType = new TypeParameterTypeImpl(new TypePara meterElementImpl(AstFactory.identifier3("E"))); 1731 TypeParameterTypeImpl parameterType = new TypeParameterTypeImpl(new TypePara meterElementImpl.forNode(AstFactory.identifier3("E")));
2096 FunctionType result = functionType.substitute2(<DartType> [argumentType], <D artType> [parameterType]); 1732 FunctionType result = functionType.substitute2(<DartType> [argumentType], <D artType> [parameterType]);
2097 JUnitTestCase.assertEquals(returnType, result.returnType); 1733 JUnitTestCase.assertEquals(returnType, result.returnType);
2098 List<DartType> normalParameters = result.normalParameterTypes; 1734 List<DartType> normalParameters = result.normalParameterTypes;
2099 EngineTestCase.assertLength(1, normalParameters); 1735 EngineTestCase.assertLength(1, normalParameters);
2100 JUnitTestCase.assertEquals(normalParameterType, normalParameters[0]); 1736 JUnitTestCase.assertEquals(normalParameterType, normalParameters[0]);
2101 List<DartType> optionalParameters = result.optionalParameterTypes; 1737 List<DartType> optionalParameters = result.optionalParameterTypes;
2102 EngineTestCase.assertLength(1, optionalParameters); 1738 EngineTestCase.assertLength(1, optionalParameters);
2103 JUnitTestCase.assertEquals(optionalParameterType, optionalParameters[0]); 1739 JUnitTestCase.assertEquals(optionalParameterType, optionalParameters[0]);
2104 Map<String, DartType> namedParameters = result.namedParameterTypes; 1740 Map<String, DartType> namedParameters = result.namedParameterTypes;
2105 EngineTestCase.assertSizeOfMap(1, namedParameters); 1741 EngineTestCase.assertSizeOfMap(1, namedParameters);
(...skipping 1250 matching lines...) Expand 10 before | Expand all | Expand 10 after
3356 } 2992 }
3357 2993
3358 void test_isMoreSpecificThan_typeParameterType_withBound() { 2994 void test_isMoreSpecificThan_typeParameterType_withBound() {
3359 // 2995 //
3360 // class A {} 2996 // class A {}
3361 // class B<E extends A> {} 2997 // class B<E extends A> {}
3362 // 2998 //
3363 ClassElement classA = ElementFactory.classElement2("A", []); 2999 ClassElement classA = ElementFactory.classElement2("A", []);
3364 InterfaceType typeA = classA.type; 3000 InterfaceType typeA = classA.type;
3365 ClassElementImpl classB = ElementFactory.classElement2("B", []); 3001 ClassElementImpl classB = ElementFactory.classElement2("B", []);
3366 TypeParameterElementImpl parameterEA = new TypeParameterElementImpl(AstFacto ry.identifier3("E")); 3002 TypeParameterElementImpl parameterEA = new TypeParameterElementImpl.forNode( AstFactory.identifier3("E"));
3367 TypeParameterType parameterAEType = new TypeParameterTypeImpl(parameterEA); 3003 TypeParameterType parameterAEType = new TypeParameterTypeImpl(parameterEA);
3368 parameterEA.bound = typeA; 3004 parameterEA.bound = typeA;
3369 parameterEA.type = parameterAEType; 3005 parameterEA.type = parameterAEType;
3370 classB.typeParameters = <TypeParameterElementImpl> [parameterEA]; 3006 classB.typeParameters = <TypeParameterElementImpl> [parameterEA];
3371 JUnitTestCase.assertTrue(parameterAEType.isMoreSpecificThan(typeA)); 3007 JUnitTestCase.assertTrue(parameterAEType.isMoreSpecificThan(typeA));
3372 } 3008 }
3373 3009
3374 void test_isSubtypeOf_directSubtype() { 3010 void test_isSubtypeOf_directSubtype() {
3375 ClassElement classA = ElementFactory.classElement2("A", []); 3011 ClassElement classA = ElementFactory.classElement2("A", []);
3376 ClassElement classB = ElementFactory.classElement("B", classA.type, []); 3012 ClassElement classB = ElementFactory.classElement("B", classA.type, []);
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
3817 InterfaceTypeImpl type = ElementFactory.classElement2("A", []).type as Inter faceTypeImpl; 3453 InterfaceTypeImpl type = ElementFactory.classElement2("A", []).type as Inter faceTypeImpl;
3818 List<DartType> typeArguments = <DartType> [ 3454 List<DartType> typeArguments = <DartType> [
3819 ElementFactory.classElement2("B", []).type, 3455 ElementFactory.classElement2("B", []).type,
3820 ElementFactory.classElement2("C", []).type]; 3456 ElementFactory.classElement2("C", []).type];
3821 type.typeArguments = typeArguments; 3457 type.typeArguments = typeArguments;
3822 JUnitTestCase.assertEquals(typeArguments, type.typeArguments); 3458 JUnitTestCase.assertEquals(typeArguments, type.typeArguments);
3823 } 3459 }
3824 3460
3825 void test_substitute_equal() { 3461 void test_substitute_equal() {
3826 ClassElementImpl classA = ElementFactory.classElement2("A", []); 3462 ClassElementImpl classA = ElementFactory.classElement2("A", []);
3827 TypeParameterElementImpl parameterElement = new TypeParameterElementImpl(Ast Factory.identifier3("E")); 3463 TypeParameterElementImpl parameterElement = new TypeParameterElementImpl.for Node(AstFactory.identifier3("E"));
3828 InterfaceTypeImpl type = new InterfaceTypeImpl.con1(classA); 3464 InterfaceTypeImpl type = new InterfaceTypeImpl.con1(classA);
3829 TypeParameterTypeImpl parameter = new TypeParameterTypeImpl(parameterElement ); 3465 TypeParameterTypeImpl parameter = new TypeParameterTypeImpl(parameterElement );
3830 type.typeArguments = <DartType> [parameter]; 3466 type.typeArguments = <DartType> [parameter];
3831 InterfaceType argumentType = ElementFactory.classElement2("B", []).type; 3467 InterfaceType argumentType = ElementFactory.classElement2("B", []).type;
3832 InterfaceType result = type.substitute2(<DartType> [argumentType], <DartType > [parameter]); 3468 InterfaceType result = type.substitute2(<DartType> [argumentType], <DartType > [parameter]);
3833 JUnitTestCase.assertEquals(classA, result.element); 3469 JUnitTestCase.assertEquals(classA, result.element);
3834 List<DartType> resultArguments = result.typeArguments; 3470 List<DartType> resultArguments = result.typeArguments;
3835 EngineTestCase.assertLength(1, resultArguments); 3471 EngineTestCase.assertLength(1, resultArguments);
3836 JUnitTestCase.assertEquals(argumentType, resultArguments[0]); 3472 JUnitTestCase.assertEquals(argumentType, resultArguments[0]);
3837 } 3473 }
3838 3474
3839 void test_substitute_exception() { 3475 void test_substitute_exception() {
3840 try { 3476 try {
3841 ClassElementImpl classA = ElementFactory.classElement2("A", []); 3477 ClassElementImpl classA = ElementFactory.classElement2("A", []);
3842 InterfaceTypeImpl type = new InterfaceTypeImpl.con1(classA); 3478 InterfaceTypeImpl type = new InterfaceTypeImpl.con1(classA);
3843 InterfaceType argumentType = ElementFactory.classElement2("B", []).type; 3479 InterfaceType argumentType = ElementFactory.classElement2("B", []).type;
3844 type.substitute2(<DartType> [argumentType], <DartType> []); 3480 type.substitute2(<DartType> [argumentType], <DartType> []);
3845 JUnitTestCase.fail("Expected to encounter exception, argument and paramete r type array lengths not equal."); 3481 JUnitTestCase.fail("Expected to encounter exception, argument and paramete r type array lengths not equal.");
3846 } on JavaException catch (e) { 3482 } on JavaException catch (e) {
3847 } 3483 }
3848 } 3484 }
3849 3485
3850 void test_substitute_notEqual() { 3486 void test_substitute_notEqual() {
3851 ClassElementImpl classA = ElementFactory.classElement2("A", []); 3487 ClassElementImpl classA = ElementFactory.classElement2("A", []);
3852 TypeParameterElementImpl parameterElement = new TypeParameterElementImpl(Ast Factory.identifier3("E")); 3488 TypeParameterElementImpl parameterElement = new TypeParameterElementImpl.for Node(AstFactory.identifier3("E"));
3853 InterfaceTypeImpl type = new InterfaceTypeImpl.con1(classA); 3489 InterfaceTypeImpl type = new InterfaceTypeImpl.con1(classA);
3854 TypeParameterTypeImpl parameter = new TypeParameterTypeImpl(parameterElement ); 3490 TypeParameterTypeImpl parameter = new TypeParameterTypeImpl(parameterElement );
3855 type.typeArguments = <DartType> [parameter]; 3491 type.typeArguments = <DartType> [parameter];
3856 InterfaceType argumentType = ElementFactory.classElement2("B", []).type; 3492 InterfaceType argumentType = ElementFactory.classElement2("B", []).type;
3857 TypeParameterTypeImpl parameterType = new TypeParameterTypeImpl(new TypePara meterElementImpl(AstFactory.identifier3("F"))); 3493 TypeParameterTypeImpl parameterType = new TypeParameterTypeImpl(new TypePara meterElementImpl.forNode(AstFactory.identifier3("F")));
3858 InterfaceType result = type.substitute2(<DartType> [argumentType], <DartType > [parameterType]); 3494 InterfaceType result = type.substitute2(<DartType> [argumentType], <DartType > [parameterType]);
3859 JUnitTestCase.assertEquals(classA, result.element); 3495 JUnitTestCase.assertEquals(classA, result.element);
3860 List<DartType> resultArguments = result.typeArguments; 3496 List<DartType> resultArguments = result.typeArguments;
3861 EngineTestCase.assertLength(1, resultArguments); 3497 EngineTestCase.assertLength(1, resultArguments);
3862 JUnitTestCase.assertEquals(parameter, resultArguments[0]); 3498 JUnitTestCase.assertEquals(parameter, resultArguments[0]);
3863 } 3499 }
3864 3500
3865 static dartSuite() { 3501 static dartSuite() {
3866 _ut.group('InterfaceTypeImplTest', () { 3502 _ut.group('InterfaceTypeImplTest', () {
3867 _ut.test('test_computeLongestInheritancePathToObject_multipleInterfacePath s', () { 3503 _ut.test('test_computeLongestInheritancePathToObject_multipleInterfacePath s', () {
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
4302 3938
4303 class InterfaceTypeImpl_FunctionTypeImplTest_test_isSubtypeOf_baseCase_classFunc tion extends InterfaceTypeImpl { 3939 class InterfaceTypeImpl_FunctionTypeImplTest_test_isSubtypeOf_baseCase_classFunc tion extends InterfaceTypeImpl {
4304 InterfaceTypeImpl_FunctionTypeImplTest_test_isSubtypeOf_baseCase_classFunction (ClassElement arg0) : super.con1(arg0); 3940 InterfaceTypeImpl_FunctionTypeImplTest_test_isSubtypeOf_baseCase_classFunction (ClassElement arg0) : super.con1(arg0);
4305 3941
4306 @override 3942 @override
4307 bool get isDartCoreFunction => true; 3943 bool get isDartCoreFunction => true;
4308 } 3944 }
4309 3945
4310 class LibraryElementImplTest extends EngineTestCase { 3946 class LibraryElementImplTest extends EngineTestCase {
4311 void test_creation() { 3947 void test_creation() {
4312 JUnitTestCase.assertNotNull(new LibraryElementImpl(createAnalysisContext(), AstFactory.libraryIdentifier2(["l"]))); 3948 JUnitTestCase.assertNotNull(new LibraryElementImpl.forNode(createAnalysisCon text(), AstFactory.libraryIdentifier2(["l"])));
4313 } 3949 }
4314 3950
4315 void test_getImportedLibraries() { 3951 void test_getImportedLibraries() {
4316 AnalysisContext context = createAnalysisContext(); 3952 AnalysisContext context = createAnalysisContext();
4317 LibraryElementImpl library1 = ElementFactory.library(context, "l1"); 3953 LibraryElementImpl library1 = ElementFactory.library(context, "l1");
4318 LibraryElementImpl library2 = ElementFactory.library(context, "l2"); 3954 LibraryElementImpl library2 = ElementFactory.library(context, "l2");
4319 LibraryElementImpl library3 = ElementFactory.library(context, "l3"); 3955 LibraryElementImpl library3 = ElementFactory.library(context, "l3");
4320 LibraryElementImpl library4 = ElementFactory.library(context, "l4"); 3956 LibraryElementImpl library4 = ElementFactory.library(context, "l4");
4321 PrefixElement prefixA = new PrefixElementImpl(AstFactory.identifier3("a")); 3957 PrefixElement prefixA = new PrefixElementImpl.forNode(AstFactory.identifier3 ("a"));
4322 PrefixElement prefixB = new PrefixElementImpl(AstFactory.identifier3("b")); 3958 PrefixElement prefixB = new PrefixElementImpl.forNode(AstFactory.identifier3 ("b"));
4323 List<ImportElementImpl> imports = [ 3959 List<ImportElementImpl> imports = [
4324 ElementFactory.importFor(library2, null, []), 3960 ElementFactory.importFor(library2, null, []),
4325 ElementFactory.importFor(library2, prefixB, []), 3961 ElementFactory.importFor(library2, prefixB, []),
4326 ElementFactory.importFor(library3, null, []), 3962 ElementFactory.importFor(library3, null, []),
4327 ElementFactory.importFor(library3, prefixA, []), 3963 ElementFactory.importFor(library3, prefixA, []),
4328 ElementFactory.importFor(library3, prefixB, []), 3964 ElementFactory.importFor(library3, prefixB, []),
4329 ElementFactory.importFor(library4, prefixA, [])]; 3965 ElementFactory.importFor(library4, prefixA, [])];
4330 library1.imports = imports; 3966 library1.imports = imports;
4331 List<LibraryElement> libraries = library1.importedLibraries; 3967 List<LibraryElement> libraries = library1.importedLibraries;
4332 EngineTestCase.assertEqualsIgnoreOrder(<LibraryElement> [library2, library3, library4], libraries); 3968 EngineTestCase.assertEqualsIgnoreOrder(<LibraryElement> [library2, library3, library4], libraries);
4333 } 3969 }
4334 3970
4335 void test_getPrefixes() { 3971 void test_getPrefixes() {
4336 AnalysisContext context = createAnalysisContext(); 3972 AnalysisContext context = createAnalysisContext();
4337 LibraryElementImpl library = ElementFactory.library(context, "l1"); 3973 LibraryElementImpl library = ElementFactory.library(context, "l1");
4338 PrefixElement prefixA = new PrefixElementImpl(AstFactory.identifier3("a")); 3974 PrefixElement prefixA = new PrefixElementImpl.forNode(AstFactory.identifier3 ("a"));
4339 PrefixElement prefixB = new PrefixElementImpl(AstFactory.identifier3("b")); 3975 PrefixElement prefixB = new PrefixElementImpl.forNode(AstFactory.identifier3 ("b"));
4340 List<ImportElementImpl> imports = [ 3976 List<ImportElementImpl> imports = [
4341 ElementFactory.importFor(ElementFactory.library(context, "l2"), null, [] ), 3977 ElementFactory.importFor(ElementFactory.library(context, "l2"), null, [] ),
4342 ElementFactory.importFor(ElementFactory.library(context, "l3"), null, [] ), 3978 ElementFactory.importFor(ElementFactory.library(context, "l3"), null, [] ),
4343 ElementFactory.importFor(ElementFactory.library(context, "l4"), prefixA, []), 3979 ElementFactory.importFor(ElementFactory.library(context, "l4"), prefixA, []),
4344 ElementFactory.importFor(ElementFactory.library(context, "l5"), prefixA, []), 3980 ElementFactory.importFor(ElementFactory.library(context, "l5"), prefixA, []),
4345 ElementFactory.importFor(ElementFactory.library(context, "l6"), prefixB, [])]; 3981 ElementFactory.importFor(ElementFactory.library(context, "l6"), prefixB, [])];
4346 library.imports = imports; 3982 library.imports = imports;
4347 List<PrefixElement> prefixes = library.prefixes; 3983 List<PrefixElement> prefixes = library.prefixes;
4348 EngineTestCase.assertLength(2, prefixes); 3984 EngineTestCase.assertLength(2, prefixes);
4349 if (identical(prefixA, prefixes[0])) { 3985 if (identical(prefixA, prefixes[0])) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
4429 LibraryElement library = ElementFactory.library(context, "foo"); 4065 LibraryElement library = ElementFactory.library(context, "foo");
4430 context.setContents(library.definingCompilationUnit.source, "sdfsdff"); 4066 context.setContents(library.definingCompilationUnit.source, "sdfsdff");
4431 // Assert that we are not up to date if the target has an old time stamp. 4067 // Assert that we are not up to date if the target has an old time stamp.
4432 JUnitTestCase.assertFalse(library.isUpToDate(0)); 4068 JUnitTestCase.assertFalse(library.isUpToDate(0));
4433 // Assert that we are up to date with a target modification time in the futu re. 4069 // Assert that we are up to date with a target modification time in the futu re.
4434 JUnitTestCase.assertTrue(library.isUpToDate(JavaSystem.currentTimeMillis() + 1000)); 4070 JUnitTestCase.assertTrue(library.isUpToDate(JavaSystem.currentTimeMillis() + 1000));
4435 } 4071 }
4436 4072
4437 void test_setImports() { 4073 void test_setImports() {
4438 AnalysisContext context = createAnalysisContext(); 4074 AnalysisContext context = createAnalysisContext();
4439 LibraryElementImpl library = new LibraryElementImpl(context, AstFactory.libr aryIdentifier2(["l1"])); 4075 LibraryElementImpl library = new LibraryElementImpl.forNode(context, AstFact ory.libraryIdentifier2(["l1"]));
4440 List<ImportElementImpl> expectedImports = [ 4076 List<ImportElementImpl> expectedImports = [
4441 ElementFactory.importFor(ElementFactory.library(context, "l2"), null, [] ), 4077 ElementFactory.importFor(ElementFactory.library(context, "l2"), null, [] ),
4442 ElementFactory.importFor(ElementFactory.library(context, "l3"), null, [] )]; 4078 ElementFactory.importFor(ElementFactory.library(context, "l3"), null, [] )];
4443 library.imports = expectedImports; 4079 library.imports = expectedImports;
4444 List<ImportElement> actualImports = library.imports; 4080 List<ImportElement> actualImports = library.imports;
4445 EngineTestCase.assertLength(expectedImports.length, actualImports); 4081 EngineTestCase.assertLength(expectedImports.length, actualImports);
4446 for (int i = 0; i < actualImports.length; i++) { 4082 for (int i = 0; i < actualImports.length; i++) {
4447 JUnitTestCase.assertSame(expectedImports[i], actualImports[i]); 4083 JUnitTestCase.assertSame(expectedImports[i], actualImports[i]);
4448 } 4084 }
4449 } 4085 }
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
4546 _ut.test('test_fromElements_nonConflicting', () { 4182 _ut.test('test_fromElements_nonConflicting', () {
4547 final __test = new MultiplyDefinedElementImplTest(); 4183 final __test = new MultiplyDefinedElementImplTest();
4548 runJUnitTest(__test, __test.test_fromElements_nonConflicting); 4184 runJUnitTest(__test, __test.test_fromElements_nonConflicting);
4549 }); 4185 });
4550 }); 4186 });
4551 } 4187 }
4552 } 4188 }
4553 4189
4554 class TypeParameterTypeImplTest extends EngineTestCase { 4190 class TypeParameterTypeImplTest extends EngineTestCase {
4555 void test_creation() { 4191 void test_creation() {
4556 JUnitTestCase.assertNotNull(new TypeParameterTypeImpl(new TypeParameterEleme ntImpl(AstFactory.identifier3("E")))); 4192 JUnitTestCase.assertNotNull(new TypeParameterTypeImpl(new TypeParameterEleme ntImpl.forNode(AstFactory.identifier3("E"))));
4557 } 4193 }
4558 4194
4559 void test_getElement() { 4195 void test_getElement() {
4560 TypeParameterElementImpl element = new TypeParameterElementImpl(AstFactory.i dentifier3("E")); 4196 TypeParameterElementImpl element = new TypeParameterElementImpl.forNode(AstF actory.identifier3("E"));
4561 TypeParameterTypeImpl type = new TypeParameterTypeImpl(element); 4197 TypeParameterTypeImpl type = new TypeParameterTypeImpl(element);
4562 JUnitTestCase.assertEquals(element, type.element); 4198 JUnitTestCase.assertEquals(element, type.element);
4563 } 4199 }
4564 4200
4565 void test_isMoreSpecificThan_typeArguments_bottom() { 4201 void test_isMoreSpecificThan_typeArguments_bottom() {
4566 TypeParameterElementImpl element = new TypeParameterElementImpl(AstFactory.i dentifier3("E")); 4202 TypeParameterElementImpl element = new TypeParameterElementImpl.forNode(AstF actory.identifier3("E"));
4567 TypeParameterTypeImpl type = new TypeParameterTypeImpl(element); 4203 TypeParameterTypeImpl type = new TypeParameterTypeImpl(element);
4568 // E << bottom 4204 // E << bottom
4569 JUnitTestCase.assertTrue(type.isMoreSpecificThan(BottomTypeImpl.instance)); 4205 JUnitTestCase.assertTrue(type.isMoreSpecificThan(BottomTypeImpl.instance));
4570 } 4206 }
4571 4207
4572 void test_isMoreSpecificThan_typeArguments_dynamic() { 4208 void test_isMoreSpecificThan_typeArguments_dynamic() {
4573 TypeParameterElementImpl element = new TypeParameterElementImpl(AstFactory.i dentifier3("E")); 4209 TypeParameterElementImpl element = new TypeParameterElementImpl.forNode(AstF actory.identifier3("E"));
4574 TypeParameterTypeImpl type = new TypeParameterTypeImpl(element); 4210 TypeParameterTypeImpl type = new TypeParameterTypeImpl(element);
4575 // E << dynamic 4211 // E << dynamic
4576 JUnitTestCase.assertTrue(type.isMoreSpecificThan(DynamicTypeImpl.instance)); 4212 JUnitTestCase.assertTrue(type.isMoreSpecificThan(DynamicTypeImpl.instance));
4577 } 4213 }
4578 4214
4579 void test_isMoreSpecificThan_typeArguments_object() { 4215 void test_isMoreSpecificThan_typeArguments_object() {
4580 TypeParameterElementImpl element = new TypeParameterElementImpl(AstFactory.i dentifier3("E")); 4216 TypeParameterElementImpl element = new TypeParameterElementImpl.forNode(AstF actory.identifier3("E"));
4581 TypeParameterTypeImpl type = new TypeParameterTypeImpl(element); 4217 TypeParameterTypeImpl type = new TypeParameterTypeImpl(element);
4582 // E << Object 4218 // E << Object
4583 JUnitTestCase.assertTrue(type.isMoreSpecificThan(ElementFactory.object.type) ); 4219 JUnitTestCase.assertTrue(type.isMoreSpecificThan(ElementFactory.object.type) );
4584 } 4220 }
4585 4221
4586 void test_isMoreSpecificThan_typeArguments_resursive() { 4222 void test_isMoreSpecificThan_typeArguments_resursive() {
4587 ClassElementImpl classS = ElementFactory.classElement2("A", []); 4223 ClassElementImpl classS = ElementFactory.classElement2("A", []);
4588 TypeParameterElementImpl typeParameterU = new TypeParameterElementImpl(AstFa ctory.identifier3("U")); 4224 TypeParameterElementImpl typeParameterU = new TypeParameterElementImpl.forNo de(AstFactory.identifier3("U"));
4589 TypeParameterTypeImpl typeParameterTypeU = new TypeParameterTypeImpl(typePar ameterU); 4225 TypeParameterTypeImpl typeParameterTypeU = new TypeParameterTypeImpl(typePar ameterU);
4590 TypeParameterElementImpl typeParameterT = new TypeParameterElementImpl(AstFa ctory.identifier3("T")); 4226 TypeParameterElementImpl typeParameterT = new TypeParameterElementImpl.forNo de(AstFactory.identifier3("T"));
4591 TypeParameterTypeImpl typeParameterTypeT = new TypeParameterTypeImpl(typePar ameterT); 4227 TypeParameterTypeImpl typeParameterTypeT = new TypeParameterTypeImpl(typePar ameterT);
4592 typeParameterT.bound = typeParameterTypeU; 4228 typeParameterT.bound = typeParameterTypeU;
4593 typeParameterU.bound = typeParameterTypeU; 4229 typeParameterU.bound = typeParameterTypeU;
4594 // <T extends U> and <U extends T> 4230 // <T extends U> and <U extends T>
4595 // T << S 4231 // T << S
4596 JUnitTestCase.assertFalse(typeParameterTypeT.isMoreSpecificThan(classS.type) ); 4232 JUnitTestCase.assertFalse(typeParameterTypeT.isMoreSpecificThan(classS.type) );
4597 } 4233 }
4598 4234
4599 void test_isMoreSpecificThan_typeArguments_self() { 4235 void test_isMoreSpecificThan_typeArguments_self() {
4600 TypeParameterElementImpl element = new TypeParameterElementImpl(AstFactory.i dentifier3("E")); 4236 TypeParameterElementImpl element = new TypeParameterElementImpl.forNode(AstF actory.identifier3("E"));
4601 TypeParameterTypeImpl type = new TypeParameterTypeImpl(element); 4237 TypeParameterTypeImpl type = new TypeParameterTypeImpl(element);
4602 // E << E 4238 // E << E
4603 JUnitTestCase.assertTrue(type.isMoreSpecificThan(type)); 4239 JUnitTestCase.assertTrue(type.isMoreSpecificThan(type));
4604 } 4240 }
4605 4241
4606 void test_isMoreSpecificThan_typeArguments_transitivity_interfaceTypes() { 4242 void test_isMoreSpecificThan_typeArguments_transitivity_interfaceTypes() {
4607 // class A {} 4243 // class A {}
4608 // class B extends A {} 4244 // class B extends A {}
4609 // 4245 //
4610 ClassElement classA = ElementFactory.classElement2("A", []); 4246 ClassElement classA = ElementFactory.classElement2("A", []);
4611 ClassElement classB = ElementFactory.classElement("B", classA.type, []); 4247 ClassElement classB = ElementFactory.classElement("B", classA.type, []);
4612 InterfaceType typeA = classA.type; 4248 InterfaceType typeA = classA.type;
4613 InterfaceType typeB = classB.type; 4249 InterfaceType typeB = classB.type;
4614 TypeParameterElementImpl typeParameterT = new TypeParameterElementImpl(AstFa ctory.identifier3("T")); 4250 TypeParameterElementImpl typeParameterT = new TypeParameterElementImpl.forNo de(AstFactory.identifier3("T"));
4615 typeParameterT.bound = typeB; 4251 typeParameterT.bound = typeB;
4616 TypeParameterTypeImpl typeParameterTypeT = new TypeParameterTypeImpl(typePar ameterT); 4252 TypeParameterTypeImpl typeParameterTypeT = new TypeParameterTypeImpl(typePar ameterT);
4617 // <T extends B> 4253 // <T extends B>
4618 // T << A 4254 // T << A
4619 JUnitTestCase.assertTrue(typeParameterTypeT.isMoreSpecificThan(typeA)); 4255 JUnitTestCase.assertTrue(typeParameterTypeT.isMoreSpecificThan(typeA));
4620 } 4256 }
4621 4257
4622 void test_isMoreSpecificThan_typeArguments_transitivity_typeParameters() { 4258 void test_isMoreSpecificThan_typeArguments_transitivity_typeParameters() {
4623 ClassElementImpl classS = ElementFactory.classElement2("A", []); 4259 ClassElementImpl classS = ElementFactory.classElement2("A", []);
4624 TypeParameterElementImpl typeParameterU = new TypeParameterElementImpl(AstFa ctory.identifier3("U")); 4260 TypeParameterElementImpl typeParameterU = new TypeParameterElementImpl.forNo de(AstFactory.identifier3("U"));
4625 typeParameterU.bound = classS.type; 4261 typeParameterU.bound = classS.type;
4626 TypeParameterTypeImpl typeParameterTypeU = new TypeParameterTypeImpl(typePar ameterU); 4262 TypeParameterTypeImpl typeParameterTypeU = new TypeParameterTypeImpl(typePar ameterU);
4627 TypeParameterElementImpl typeParameterT = new TypeParameterElementImpl(AstFa ctory.identifier3("T")); 4263 TypeParameterElementImpl typeParameterT = new TypeParameterElementImpl.forNo de(AstFactory.identifier3("T"));
4628 typeParameterT.bound = typeParameterTypeU; 4264 typeParameterT.bound = typeParameterTypeU;
4629 TypeParameterTypeImpl typeParameterTypeT = new TypeParameterTypeImpl(typePar ameterT); 4265 TypeParameterTypeImpl typeParameterTypeT = new TypeParameterTypeImpl(typePar ameterT);
4630 // <T extends U> and <U extends S> 4266 // <T extends U> and <U extends S>
4631 // T << S 4267 // T << S
4632 JUnitTestCase.assertTrue(typeParameterTypeT.isMoreSpecificThan(classS.type)) ; 4268 JUnitTestCase.assertTrue(typeParameterTypeT.isMoreSpecificThan(classS.type)) ;
4633 } 4269 }
4634 4270
4635 void test_isMoreSpecificThan_typeArguments_upperBound() { 4271 void test_isMoreSpecificThan_typeArguments_upperBound() {
4636 ClassElementImpl classS = ElementFactory.classElement2("A", []); 4272 ClassElementImpl classS = ElementFactory.classElement2("A", []);
4637 TypeParameterElementImpl typeParameterT = new TypeParameterElementImpl(AstFa ctory.identifier3("T")); 4273 TypeParameterElementImpl typeParameterT = new TypeParameterElementImpl.forNo de(AstFactory.identifier3("T"));
4638 typeParameterT.bound = classS.type; 4274 typeParameterT.bound = classS.type;
4639 TypeParameterTypeImpl typeParameterTypeT = new TypeParameterTypeImpl(typePar ameterT); 4275 TypeParameterTypeImpl typeParameterTypeT = new TypeParameterTypeImpl(typePar ameterT);
4640 // <T extends S> 4276 // <T extends S>
4641 // T << S 4277 // T << S
4642 JUnitTestCase.assertTrue(typeParameterTypeT.isMoreSpecificThan(classS.type)) ; 4278 JUnitTestCase.assertTrue(typeParameterTypeT.isMoreSpecificThan(classS.type)) ;
4643 } 4279 }
4644 4280
4645 void test_substitute_equal() { 4281 void test_substitute_equal() {
4646 TypeParameterElementImpl element = new TypeParameterElementImpl(AstFactory.i dentifier3("E")); 4282 TypeParameterElementImpl element = new TypeParameterElementImpl.forNode(AstF actory.identifier3("E"));
4647 TypeParameterTypeImpl type = new TypeParameterTypeImpl(element); 4283 TypeParameterTypeImpl type = new TypeParameterTypeImpl(element);
4648 InterfaceTypeImpl argument = new InterfaceTypeImpl.con1(new ClassElementImpl (AstFactory.identifier3("A"))); 4284 InterfaceTypeImpl argument = new InterfaceTypeImpl.con1(new ClassElementImpl .forNode(AstFactory.identifier3("A")));
4649 TypeParameterTypeImpl parameter = new TypeParameterTypeImpl(element); 4285 TypeParameterTypeImpl parameter = new TypeParameterTypeImpl(element);
4650 JUnitTestCase.assertSame(argument, type.substitute2(<DartType> [argument], < DartType> [parameter])); 4286 JUnitTestCase.assertSame(argument, type.substitute2(<DartType> [argument], < DartType> [parameter]));
4651 } 4287 }
4652 4288
4653 void test_substitute_notEqual() { 4289 void test_substitute_notEqual() {
4654 TypeParameterTypeImpl type = new TypeParameterTypeImpl(new TypeParameterElem entImpl(AstFactory.identifier3("E"))); 4290 TypeParameterTypeImpl type = new TypeParameterTypeImpl(new TypeParameterElem entImpl.forNode(AstFactory.identifier3("E")));
4655 InterfaceTypeImpl argument = new InterfaceTypeImpl.con1(new ClassElementImpl (AstFactory.identifier3("A"))); 4291 InterfaceTypeImpl argument = new InterfaceTypeImpl.con1(new ClassElementImpl .forNode(AstFactory.identifier3("A")));
4656 TypeParameterTypeImpl parameter = new TypeParameterTypeImpl(new TypeParamete rElementImpl(AstFactory.identifier3("F"))); 4292 TypeParameterTypeImpl parameter = new TypeParameterTypeImpl(new TypeParamete rElementImpl.forNode(AstFactory.identifier3("F")));
4657 JUnitTestCase.assertSame(type, type.substitute2(<DartType> [argument], <Dart Type> [parameter])); 4293 JUnitTestCase.assertSame(type, type.substitute2(<DartType> [argument], <Dart Type> [parameter]));
4658 } 4294 }
4659 4295
4660 static dartSuite() { 4296 static dartSuite() {
4661 _ut.group('TypeParameterTypeImplTest', () { 4297 _ut.group('TypeParameterTypeImplTest', () {
4662 _ut.test('test_creation', () { 4298 _ut.test('test_creation', () {
4663 final __test = new TypeParameterTypeImplTest(); 4299 final __test = new TypeParameterTypeImplTest();
4664 runJUnitTest(__test, __test.test_creation); 4300 runJUnitTest(__test, __test.test_creation);
4665 }); 4301 });
4666 _ut.test('test_getElement', () { 4302 _ut.test('test_getElement', () {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
4788 InterfaceTypeImplTest.dartSuite(); 4424 InterfaceTypeImplTest.dartSuite();
4789 TypeParameterTypeImplTest.dartSuite(); 4425 TypeParameterTypeImplTest.dartSuite();
4790 VoidTypeImplTest.dartSuite(); 4426 VoidTypeImplTest.dartSuite();
4791 ClassElementImplTest.dartSuite(); 4427 ClassElementImplTest.dartSuite();
4792 ElementLocationImplTest.dartSuite(); 4428 ElementLocationImplTest.dartSuite();
4793 ElementImplTest.dartSuite(); 4429 ElementImplTest.dartSuite();
4794 HtmlElementImplTest.dartSuite(); 4430 HtmlElementImplTest.dartSuite();
4795 LibraryElementImplTest.dartSuite(); 4431 LibraryElementImplTest.dartSuite();
4796 MultiplyDefinedElementImplTest.dartSuite(); 4432 MultiplyDefinedElementImplTest.dartSuite();
4797 } 4433 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/ast_test.dart ('k') | pkg/analyzer/test/generated/parser_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698